Commit 94a6ac5c authored by IS1_4M's avatar IS1_4M
Browse files

Fixed email link function

parent f1748d19
......@@ -315,11 +315,14 @@ class ClubSuite(AbstractChanSuite):
return 1
return -12
elif content.startswith("!setupemail"): #!setupemail discordname#id:email channel_to_be_active_in
if len(message_parts) != 3:
return -19
if ':' not in message_parts[1]:
return -20
discord_name, dest_email = message_parts_[1].split(':')
colon_containing = 0
for colon_containing in range(len(message_parts)):
if ':' in message_parts[colon_containing]:
break
discord_name, dest_email = message_parts_[colon_containing].split(':')
if colon_containing != 1:
discord_name = ' '.join(message_parts_[1:colon_containing] + [discord_name])
# Confirm that the discord user in the server at the moment.
print(discord_name)
user = get_member_by_discord_name(message.guild, discord_name)
......@@ -334,7 +337,8 @@ class ClubSuite(AbstractChanSuite):
pass
else:
return -15
await (await message.channel.send('EMAIL LINK ESTABLISHED IN ' + chan.name + ' . ' + message_parts_[1])).pin()
await (await message.channel.send('EMAIL LINK ESTABLISHED IN ' + chan.name + ' . ' +discord_name + ':' + dest_email)).pin()
return 1
elif content.startswith('!requestbot'):
return 6#unimplemented. To implement Soon
return 0
......@@ -417,17 +421,31 @@ class ClubSuite(AbstractChanSuite):
discord_user = None
dest_email_addr = None
for pin in await cli.pins():
if pin.content.startswith('EMAIL LINK ESTABLISHED IN '):
pin_parts = pin.content.split(' ')
target_chan = await ClubSuite.get_text_channel(cat, pin_parts[4])
discord_name, dest_email_addr = pin_parts[6].split(':')
discord_name = ''
if len(pin_parts) == 7:
discord_name, dest_email_addr = pin_parts[6].split(':')
else:
for ind, part in enumerate(pin_parts[6:]):
if ':' in part:
last_part_of_disc_name, dest_email_addr = part.split(':')
discord_name += ' ' + last_part_of_disc_name
break
discord_name += ' ' + part
discord_name = discord_name[1:]
print(discord_name)
discord_user = get_member_by_discord_name(message.guild, discord_name)
# If we mentioned the user in question, email them!
if int(discord_user.id) == int(uid) and message.channel == target_chan:
email, passw = EmailSuite.get_send_email_credentials(message.guild)
await cli.send('Sent email alert to: '+ dest_email_addr + '.', delete_after=3)
EmailSuite.send_email_to_addr(dest_email_addr, email, passw, 'You have been mentioned in ' + message.channel.name + '!', 'Here is the message ' + message.author.name + ' mentioend you in! :\n\t' + discord_name + ' ' + ' '.join(message_parts[1:]))
return
else:
return 0
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment