Skip to content
Snippets Groups Projects
Commit 3966d42d authored by amy's avatar amy
Browse files

First prototype

parent f6026f82
No related branches found
No related tags found
No related merge requests found
No preview for this file type
import discord, asyncio
import os, sys, string, random
import os, sys, string, random, time
import msgTemplates, utils
def getPath():
return os.path.dirname(os.path.realpath(__file__))
# Maybe move these to a config?
cslibServerID = 763446305006682142
memberRoleID = 763872584408104960
version = "0.1"
prefix = "!"
client = discord.Client()
registrationDb = {}
registrationUserTimeout = {}
@client.event
async def on_message (message):
......@@ -22,31 +25,54 @@ async def on_message (message):
command[0] = command[0].lower()
# We are in a private chat
if (type(message.channel) is discord.DMChannel):
if (type(message.channel) is not discord.DMChannel):
if (command[0] == "help"):
outMsg = msgTemplates.helpHeader.format(version)
for cmd in msgTemplates.helpMain:
outMsg += "\t- **{}**: `{}`\n".format(cmd, msgTemplates.helpMain[cmd])
return await message.channel.send(outMsg)
else:
if (command[0] == "help"):
outMsg = msgTemplates.helpHeader.format(version)
for cmd in msgTemplates.helpDm:
outMsg += "\t- **{}**: `{}`\n".format(cmd, msgTemplates.helpDm[cmd])
return await message.channel.send(outMsg)
if (command[0] == "register"):
if (len(command) == 1):
return await message.channel.send(msgTemplates.usageRegister)
email = command[1].strip()
if (not utils.validateMail (email)):
return await message.channel.send(msgTemplates.invalidMail.format(email))
return await message.channel.send(msgTemplates.errorInvalidMail.format(email))
verificationCode = ''.join(random.choices(string.ascii_lowercase + string.digits, k=16))
registrationDb[verificationCode] = message.author.id
try:
utils.sendMail(email, msgTemplates.validationMailTextBody.format(email, verificationCode))
utils.sendMail(email, msgTemplates.verificationMailTextBody.format(email, verificationCode))
except:
return await message.channel.send(msgTemplates.errorMail)
await message.channel.send(msgTemplates.validationMailSent.format(email))
await message.channel.send(msgTemplates.verificationMailSent.format(email))
if (command[0] == "verify"):
if (command[1] in registrationDb):
userId = registrationDb[command[1]]
guild = await client.fetch_guild(cslibServerID)
user = await guild.get_member(userId)
await user.edit(roles = [await guild.get_role(memberRoleID)])
if (len(command) == 1):
return await message.channel.send(msgTemplates.usageVerify)
verificationCode = command[1]
if (verificationCode in registrationDb):
userId = registrationDb[verificationCode]
guild = client.get_guild(cslibServerID)
await guild.get_member(userId).edit(roles = [guild.get_role(memberRoleID)])
registrationDb.pop(verificationCode, None)
await message.channel.send(msgTemplates.userVerified)
else:
await message.channel.send(msgTemplates.errorVerificationCode.format(command[1]))
......
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!"""
I will then send you an e-mail with a verification code. Send it to back to me as such: `!verify verification-code` and get verified!"""
invalidMail = "`{}` is an invalid `@soton.ac.uk` e-mail"
validationMailSent = "Sent verification e-mail to: `{}`"
validationMailTextBody = """From: CSLib Authmaster <cslibdiscordbot@gmail.com>
helpHeader = ":gear: **CSLib** Authmaster v{} :gear:\n"
helpDm = {
"!register YOUR-ID@soton.ac.uk": "Send a verification code to your Southampton e-mail address",
"!verify AUTH-CODE": "Verify your discord account with the verification code received via e-mail"
}
helpMain = {
"!help": "Show this message"
}
verificationMailSent = "Sent verification e-mail to: `{}`"
verificationMailTextBody = """From: CSLib Authmaster <cslibdiscordbot@gmail.com>
To: CSLib Apprentice <{}>
Subject: CSLib Verification
Your CSLib verification code is: {}"""
userVerified = "You have been verified! Welcome to the CSLib community."
errorMail = "There has been an error sending an e-mail. Please contact the CSLib Managers!"
errorMail = "There has been an error sending an e-mail. If you think this is a problem, please contact a CSLib Manager!"
errorInvalidMail = "`{}` is an invalid `@soton.ac.uk` e-mail"
errorVerificationCode = "Invalid verification code: `{}`"
usageRegister = "Usage: !register YOUR-ID@soton.ac.uk"
\ No newline at end of file
usageRegister = "Usage: !register `YOUR-ID@soton.ac.uk`"
usageVerify = "Usage: !verify `verification-code`"
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment