-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
324 lines (289 loc) · 12.4 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
# bot.py
"""
Author: Axel Eschholz
Description: A verification protocol for the Mcgill 2024 class server.
Contact: [email protected]
Last edited: 9/22/2020
"""
import os
import discord
from discord.ext import commands
from discord.utils import get
import random
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
TOKEN = os.getenv('DISCORD_TOKEN')
GUILD = os.getenv('DISCORD_GUILD')
bot = commands.Bot(command_prefix='.')
codes = {}
checks = [
'check check, roger that',
"check 1 2, we're all good here",
'checkirooskies!',
'right away sir',
'thanks for checking up on me',
"actually I'm not feeling well... oh nevermind",
'are you implying that I malfunction!!',
'mate',
"I'm just a robot, virtually standing in front of a human, asking them to love me",
'checkin, get it, checkin... like chicken',
'mate, checkmate'
]
quotes = [
'History is lethal.',
'If one seeks to become pregnant, one has no other choice but to live a lie and go to prison.',
"Diving headfirst into other people's misery gives birth to shame.",
'Blessed be the sun who strikes his problems, but more blessed be the son who strikes his apples.',
'The only difference between self-realization and a non-sexual relationship, is that a non-sexual relationship means nothing.',
'Tickling is bad for your brand.',
'Decrease realism.',
'Only old people give up popularity.',
'Napalm likes you.',
'You are a god. Remember that.',
'Internet addiction is a lot like a meat grinder. Painful, but interesting.',
'Kik an insect.',
'You can be a joke.',
'Obey the law.',
'Fit in.',
'Never stop being socially isolated and have a confusing Monday.',
'If one wishes to stop a global pandemic, there is but one possibility: be sexy.',
'Milk cats.',
'A bug and a writer should not be combined.',
'Ask not "at what cost", but "at what cost".',
'Losing your virginity is a lot like the Spanish Inquisition. It happens.',
"You're nervous.",
"Confuse the government?",
"A lover's infidelity is mother nature telling you to form a cult.",
'Get chlamydia.',
'Generosity. Sure, but why?',
'No u .quote',
"Carry a big stick.",
"Spam materwelon.",
"Confusing each other begins with confusing ourselves.",
"Always resist authority.",
'Love food.',
'Always try drugs.',
'Ask Neuro.',
'If they tell you that you cannot leave home, do exactly that.',
'eNgInEeRs',
"Most people don't know that the next stock market collapse is big business.",
"There is a proven link between being single and human sacrifice.",
'These days people say "license and registration, please" the same way they say "party with me".',
"AI shouldn't drive.",
"I just got intel from the HQ: ETA 5 minutes 'til bedtime boys, let's rap it up.",
"There is a close link between education and death.",
"Who are Rick and, I cannot stress this enough, Morty?",
"Stop educating.",
"You are a huuuuuuuuuuuge dog.",
"Support a prostitute.",
"Donate to my patreon and I will shout your name.",
"Should we make tomorrow respectable?",
"Modern art is to have lots of cats."
]
consents = ["you're all set!",
"you're good to go!",
"have a good time!",
"nicely done!"]
@bot.event
async def on_member_join(member):
print(f"{member} has joined {member.guild.name}")
if member.guild.name == GUILD:
guild = get(bot.guilds, name=member.guild.name)
info = get(guild.channels, name='information')
log = get(guild.channels, name='verification-log')
entry = "<@" + str(member.id) + "> has joined the server, welcome message has been sent."
message = "Welcome <@" + str(member.id) + ">!\nYou should give our rules a read at <#" + str(info.id) + ">.\nBy verifying yourself, you agree to our rules set out in <#" + str(info.id) + "> and failure to abide by the rules may result in a warning or ban.\nFeel free to peruse the rest of the announcements and information or message an Administrator/Moderator if you need any help!"
await member.send(message)
nextmessage = "Please enter your mcgill email address in the following format to verify yourself: ```.email [email protected]```"
await member.send(nextmessage)
await log.send(entry)
@bot.command(name='kik', help='Kiks jim')
async def check(ctx, *targets: discord.Member):
print(targets)
if any(targets):
target = targets[0]
response = '<@' + str(target.id) + '> has been kiked'
#await target.kick()
else:
for member in ctx.guild.members:
if member.name == "Jim":
break
response = "kicked <@" + str(member.id) + ">"
await ctx.send(response)
@bot.command(name='roll', help='admin command - rolls house for target')
@commands.has_role('Moderator')
async def check(ctx, target: discord.Member):
houses = []
for role in ctx.guild.roles:
if 'House ' in role.name:
houses.append(role)
if not any(houses):
await ctx.send("There don't seem to be houses on this channel.")
else:
for role in target.roles:
if role in houses:
await target.remove_roles(role)
new = random.choice(houses)
print(new)
try:
await target.add_roles(new)
response = target.nick + ' is assigned to ' + new.name
except Exception:
response = Exception
await ctx.send(response)
@bot.command(name='check', help='responds')
async def check(ctx):
response = random.choice(checks)
await ctx.send(response)
@bot.command(name='fancy', help='makes fancy')
async def check(ctx, *args):
response = ' '.join(args)
await ctx.send('```' + response +'```')
@bot.command(name='quote', help='gives some wisdom')
async def quote(ctx):
response = random.choice(quotes)
await ctx.send(response)
@bot.command()
@commands.has_role('Moderator')
async def dm(ctx, user: discord.User, *, message=None):
await user.send(message)
@bot.command()
async def newverify(ctx, *targets: discord.Member):
if not any(targets):
members = [ctx.message.author]
else:
members = []
for target in targets:
members.append(target)
for member in members:
guild = get(bot.guilds, name=member.guild.name)
info = get(guild.channels, name='information')
message = "Welcome <@" + str(member.id) + ">!\nYou should give our rules a read at <#" + str(info.id) + ">.\nBy verifying yourself, you agree to our rules set out in <#" + str(info.id) + "> and failure to abide by the rules may result in a warning or ban.\nFeel free to peruse the rest of the announcements and information or message an Administrator/Moderator if you need any help!"
await member.send(message)
nextmessage = "Please enter your mcgill email address in the following format to verify yourself: ```.email [email protected]```"
await member.send(nextmessage)
@bot.command(name='email', help='sends email verification code')
async def email(ctx, arg):
user = ctx.message.author
guild = get(bot.guilds, name=GUILD)
log = get(guild.channels, name='verification-log')
entries = []
entries.append("<@" + str(user.id) + "> has submitted their email")
if '@mail.mcgill.ca' in arg:
def generate_code():
global codes
code = ''
for i in range(4):
num = random.randint(0,9)
code += str(num)
if code not in list(codes.keys()):
codes[code] = [user, arg]
return code
else:
return generate_code()
def send_msg(sender, to, subject, body):
msg = MIMEMultipart()
msg['From'] = sender
msg['To'] = to
msg['Subject'] = subject
msg.attach(MIMEText(body, 'plain'))
s.send_message(msg)
if __name__ == "__main__":
s = smtplib.SMTP(host='smtp.gmail.com', port=587)
s.starttls()
s.login('[email protected]', 'emailtime')
code = generate_code()
body = 'Your verification code is ' + code + '\nThis code is valid for 10 minutes. \n\nDO NOT REPLY TO THIS EMAIL'
send_msg('[email protected]', arg, 'Verification', body)
s.quit()
response = "An email has been sent to that address with a verification code. Please respond to this message as follows in order to be verified: ```.code (insert code here)```At the risk of pointing out the obvious, please don't include the parentheses, thanks!\n**Note that by getting verified, your nickname on the discord server McGill Entering Class of 2020 will be changed to name provided in your McGill e-mail.**"
entries.append("<@" + str(user.id) + "> has been sent a verification code of " + code + ".")
else:
response = "That is not a valid mcgill email address."
entries.append("<@" + str(user.id) + ">'s email was not valid")
await ctx.send(response)
for each in entries:
await log.send(each)
@bot.command()
async def code(ctx, arg):
code = arg
user = ctx.message.author
guild = get(bot.guilds, name=GUILD)
log = get(guild.channels, name='verification-log')
entries = []
entries.append("<@" + str(user.id) + "> has submitted the code: " + code + ".")
if code in list(codes.keys()):
if user == codes[code][0]:
#get objects
guild = get(bot.guilds, name=GUILD)
target = get(guild.members, id=user.id)
role = get(guild.roles, name="Certified Admitted")
#name breakdown
email = codes[code][1]
name = email.split('@')[0].split('.')
for y,part in enumerate(name):
new = ''
for x,letter in enumerate(part):
if x == 0:
letter = letter.upper()
new += letter
name[y] = new
nickname = name[0] + ' ' + name[1]
#finish
await target.add_roles(role)
message = "You're all set, thanks for verifying and please proceed to the main server. Enjoy!"
entries.append("<@" + str(target.id) + "> has been verified.")
codes.pop(code)
place = get(guild.channels, name='welcome')
await target.edit(nick=nickname)
entries.append("<@" + str(target.id) + ">'s nickname has been changed to " + nickname + ".")
welcome = "Welcome! <@" + str(target.id) + ">"
await user.send(message)
await place.send(welcome)
else:
message = "That's someone else's code, don't try to fool me!"
entries.append("<@" + str(target.id) + "> tried to use someone else's code! Arrest them!")
await user.send(message)
else:
message = "Invalid code, please try again or contact a moderator for help.\nIf you did not request the email in the last 10 minutes, please do so again."
entries.append("<@" + str(user.id) + ">'s code was invalid.")
await user.send(message)
for each in entries:
await log.send(each)
@bot.command(name='verify', help='verifies that person is in server')
async def verify(ctx):
if ctx.channel.name == 'verification':
for guild in bot.guilds:
if guild.name == GUILD:
break
target = ctx.message.author
members = [member for member in guild.members]
try:
await ctx.message.delete()
except:
pass
checkrole = get(guild.roles, name="Certified Admitted")
role = get(ctx.guild.roles, name="Verified")
if not role:
role = get(ctx.guild.roles, id=725648846675247134)
if role in target.roles:
response = "You're already verified, thanks for checking!"
elif target in members:
checked = False
member = members[members.index(target)]
for otherrole in member.roles:
if otherrole == checkrole:
checked = True
if checked:
response = "You're verified, have a lovely day"
await target.add_roles(role)
else:
response = "You're on the McGill server but not verified, go go go!"
else:
response = 'You are not verified, to become verified, logon to the mcgill 2020 server.'
await ctx.send("<@" + str(ctx.author.id) + "> " + response)
else:
response = "This command is restricted to the verification channel"
await ctx.send(response)
bot.run(TOKEN)