From 201f76802abd43113c478934d24c06b602ca9b6e Mon Sep 17 00:00:00 2001
From: amy <milkdrop2000@protonmail.com>
Date: Mon, 19 Oct 2020 21:03:29 +0200
Subject: [PATCH] SMTP test

---
 __pycache__/msgTemplates.cpython-37.pyc | Bin 0 -> 577 bytes
 __pycache__/utils.cpython-37.pyc        | Bin 0 -> 372 bytes
 bot.py                                  |  57 +++++++++++++++++++++---
 msgTemplates.py                         |   6 +++
 utils.py                                |  11 +++++
 5 files changed, 68 insertions(+), 6 deletions(-)
 create mode 100644 __pycache__/msgTemplates.cpython-37.pyc
 create mode 100644 __pycache__/utils.cpython-37.pyc
 create mode 100644 msgTemplates.py
 create mode 100644 utils.py

diff --git a/__pycache__/msgTemplates.cpython-37.pyc b/__pycache__/msgTemplates.cpython-37.pyc
new file mode 100644
index 0000000000000000000000000000000000000000..b7908bcc6380a484050a1c71c4377b4062213260
GIT binary patch
literal 577
zcmZ?b<>g{vU|{Ha&>O#lk%8echy%ln3=9ko3=9m#0t^fcDGX5zDU4B!DNIpJDa^qP
znk<QWj0_A`>8XiDRtn*%Im!9CsR||e3R+su!9JNuT3QNFIWA9y^30qZg|y6~;u3|t
z)YKG^va-~o%(O~{%KXwIg~a6K{L;J<MTOwhycC7pRETJTLvemdex6=pvR-L+f<kFt
zW?5=cab`)SLaJ_VVrGs)VoFL;YH_hbQl&y^ab{k+l|q7IQEGZ-aY<^CLZp9akglf-
ziWxAMlw_plDHMb3s?0A{NX&y7Se{vu0pcc>f>e}bCMT9;=I1FS=clCVLEM&E0&;s&
zVsbW!&P`QFELJEkP0j#W4fT;@Xo!cdv%iaLf<j_mib8s7i2_(AGc`rAN+Y4VHbEh?
z7-UOkURh#JW{LuuKOvs0QUQfUW?ni}Gt?;%NrjSpD+Q2Aewxg;cp#=j6x`y0n(7J)
zp<4p5;K<BN2aBv^C}Lq?fDpfQ^fU5vQ}q*bEA<14^0QKtON#ZAi*quQbd&N+^mB{T
kLsD}KauQ2Yi}eaBZ*kb<=BJeAq}nlqk_5;U7A6)(0RQH>9RL6T

literal 0
HcmV?d00001

diff --git a/__pycache__/utils.cpython-37.pyc b/__pycache__/utils.cpython-37.pyc
new file mode 100644
index 0000000000000000000000000000000000000000..6e0ae6d828d37d1d90c575ea92d4b1d36424a629
GIT binary patch
literal 372
zcmZ?b<>g{vU|@KAzc>C80|Ucj5C?{t7#J8F7#J9eMHm<uQW#Pga~Pr+QkYVhTNt7k
zQy7C8G+ADP)cPeef+z+C29ORG1_lOakS+@b28Ifi8U`1JSeaVJ8paZaED&ZAXGmcb
zXUJwRVoPBPW+-F}XQ*LVz?{Ookg?bVB$C1s%%I8YSH+?i@1X5g#p6(%Uy`4vmzb<q
znjNCaa*M6Fq$o2l{T6RxadKv6d`@afNorB?Ew+@*^vsgtTO6r*DaGZPB^jDbw^&ni
z6EkyeF($8MDB@sXVECn~pOK%Ns-Ku!sUJ|3pOu<iQmmg`oRgWPo0MOoUs{rxQ><4|
zd5gC!F()%6u_V<Mq@Nk&8y=7s8Mzom7&(}@7+IK#K;fpzR0Q%em<_f7iQr^lV7SF$
TlbfGXnv-e=3ZY_<S`H=vYvELY

literal 0
HcmV?d00001

diff --git a/bot.py b/bot.py
index b736627..daf3b6f 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 0000000..3a59c8d
--- /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 0000000..7c143f5
--- /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
-- 
GitLab