diff --git a/__pycache__/msgTemplates.cpython-37.pyc b/__pycache__/msgTemplates.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..b7908bcc6380a484050a1c71c4377b4062213260 Binary files /dev/null and b/__pycache__/msgTemplates.cpython-37.pyc differ diff --git a/__pycache__/utils.cpython-37.pyc b/__pycache__/utils.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..6e0ae6d828d37d1d90c575ea92d4b1d36424a629 Binary files /dev/null and b/__pycache__/utils.cpython-37.pyc differ diff --git a/bot.py b/bot.py index b736627669d7743c59ac216fcd9d3963a7d810db..daf3b6f7f4353689d2adcf44b771552ac4a25689 100644 --- a/bot.py +++ b/bot.py @@ -1,25 +1,70 @@ import discord, asyncio -import os, sys +import os, sys, string +import msgTemplates, utils +from smtplib import SMTP def getPath(): return os.path.dirname(os.path.realpath(__file__)) +version = "0.1" prefix = "!" client = discord.Client() +registrationDb = {} @client.event -async def on_ready(): - print(client.user.name + " booted up.") - await client.change_presence(activity = discord.Game(name = prefix + "help")) +async def on_message (message): + if (message.author == client.user): + return + + if (message.content.lower ().startswith (prefix)): + command = message.content[len(prefix):].split(" ") + command[0] = command[0].lower() + + # We are in a private chat + if (message.channel.guild == None): + if (command[0] == "register"): + email = command[1].trim() + if (not validateEmail (email)): + await message.channel.send(msgTemplates.invalidEmail.format(email)) + return + + await message.channel.send(msgTemplates.registeringEmail.format(email)) @client.event async def on_member_join(member): - print(member) + print(member.display_name + "#" + member.discriminator + " Joined.") + + dmChannel = member.create_dm() + sentIntroBefore = False + async for message in dmChannel.history(limit=200): + if message.author == client.user: + sentIntroBefore = True + break + + if (not sentIntroBefore): + await dmChannel.send(msgTemplates.verification) + +@client.event +async def on_ready(): + print(client.user.name + "v" + version + " booted up.\n" + "\"Something needs tinkerin'?\"") + await client.change_presence(activity = discord.Game(name = prefix + "help")) tokenFile = getPath() + "/token" if (not os.path.isfile(tokenFile)): print("Please create a 'token' file with the discord bot token in it.") sys.exit(1) +sender = 'cslman@soton.ac.uk' +receivers = ['sf1u20@soton.ac.uk'] + +message = """From: CSLib Authmaster <cslman@soton.ac.uk> +To: CSLib Apprentice <sf1u20@soton.ac.uk> +Subject: SMTP e-mail test + +This is a test e-mail message. +""" + +smtpObj = smtplib.SMTP('smtp.soton.ac.uk') +smtpObj.sendmail(sender, receivers, message) token = open(tokenFile, "r").read().strip() -client.run(token + " Joined.") \ No newline at end of file +client.run(token) \ No newline at end of file diff --git a/msgTemplates.py b/msgTemplates.py new file mode 100644 index 0000000000000000000000000000000000000000..3a59c8db4f47178f349859516149f4fb5cebb685 --- /dev/null +++ b/msgTemplates.py @@ -0,0 +1,6 @@ +verification = """:gear: Welcome to **CSLib** :gear: +I will first need to verify your account! Send me your `@soton.ac.uk` university e-mail address by using: `!register YOUR-ID@soton.ac.uk` +I will then send you an e-mail with an authentication code. Send it to back to me as such: `!verify AUTH-CODE` and get verified!""" + +invalidEmail = "`{}` is an invalid `@soton.ac.uk` e-mail" +registeringEmail = "Sending verification e-mail to: `{}`" \ No newline at end of file diff --git a/utils.py b/utils.py new file mode 100644 index 0000000000000000000000000000000000000000..7c143f5a6f44e20f2c40d40def1467fd01100d27 --- /dev/null +++ b/utils.py @@ -0,0 +1,11 @@ +import string + +def validateEmail(email): + for c in email: + if (c not in string.ascii_letters + string.digits + "._@+"): + return False + + if (not email.endswith("@soton.ac.uk")): + return False + + return True \ No newline at end of file