Skip to content
Snippets Groups Projects
Commit 201f7680 authored by amy's avatar amy
Browse files

SMTP test

parent 00ec66b0
Branches
No related tags found
No related merge requests found
File added
File added
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
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
utils.py 0 → 100644
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment