Skip to content

Instantly share code, notes, and snippets.

@not-inept
Created November 8, 2016 00:16
Show Gist options
  • Save not-inept/c545778869430d3d267aba994008b457 to your computer and use it in GitHub Desktop.
Save not-inept/c545778869430d3d267aba994008b457 to your computer and use it in GitHub Desktop.
import discord
import asyncio
emailUser = '<insert your email username>' # gmail username
emailPass = '<insert your gmail password>' # gmail password
roleName = '<insert your role name>' # name of the role you'd like to award to verifiers
botToken = '<insert your token>' # token given to app
client = discord.Client()
def send_email(user, pwd, recipient, subject, body):
import smtplib
gmail_user = user
gmail_pwd = pwd
FROM = user
TO = recipient if type(recipient) is list else [recipient]
SUBJECT = subject
TEXT = body
# Prepare actual message
message = """From: %s\nTo: %s\nSubject: %s\n\n%s
""" % (FROM, ", ".join(TO), SUBJECT, TEXT)
try:
server = smtplib.SMTP("smtp.gmail.com", 587)
server.ehlo()
server.starttls()
server.login(gmail_user, gmail_pwd)
server.sendmail(FROM, TO, message)
server.close()
print('successfully sent the mail')
except:
print('failed to send mail')
@client.event
async def on_ready():
print('Logged in as')
print(client.user.name)
print(client.user.id)
print('------')
@client.event
async def on_message(message):
if message.content.startswith('!verifyme') and message.server is not None:
role = None
for i in message.server.roles:
if i.name == roleName:
role = i
print(role)
msg = 'What is your RPI email?'
await client.send_message(message.author, msg)
res = await client.wait_for_message(timeout=120.0, author=message.author)
email = res.content
if role is not None:
splitEmail = email.split('@')
if len(splitEmail) == 2 and splitEmail[1] == 'rpi.edu':
msg = 'Sure :3, now verifying ' + email
await client.send_message(message.author, msg)
import os
import binascii
verifToken = binascii.b2a_hex(os.urandom(15)).decode("utf-8")
title = 'RPI Discord Verification Email'
msg = 'Send this token to me on discord: ' + verifToken
send_email(emailUser, emailPass, email, title, msg)
msg = 'Email sent! Please send the code back :)'
await client.send_message(message.author, msg)
res = await client.wait_for_message(timeout=120.0, author=message.author)
if res is None:
await client.send_message(message.author, 'Oops, looks like you timed out. Try verifying again later!')
elif res.content == verifToken:
await client.add_roles(message.author,role)
await client.send_message(message.author, 'Woah, that was correct! Congrats on being verified')
else:
await client.send_message(message.author, 'Oops, looks like you were wrong. Try again later!')
else:
await client.send_message(message.author, 'Oops, please use an /rpi/ email!')
else:
await client.send_message(message.author, 'To verify, please send: !verifyme <rpi_email_address>')
client.run(botToken)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment