-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.py
66 lines (51 loc) · 2.62 KB
/
bot.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
import discord
from fuzzywuzzy import fuzz, process
school_validity = False #check for school abbrevation validity against school_filter, set to true to apply the check
open_organiser_role = False #opens the organiser role to anyone, set to true to open. If set to False, request for manual verification will be send in manual_verification_channel
manual_verification_channel = 1060257828851417138
roles = ['participant', 'organiser']
with open('token') as f:
token = f.read()
intents = discord.Intents.default()
intents.messages = True
with open('school_filter') as f:
school_filter = f.read().splitlines()
client = discord.Client(intents=intents)
@client.event
async def on_ready():
print(f'We have logged in as {client.user}')
@client.event
async def on_message(message):
if message.author == client.user or message.author.bot:
return
if message.content.startswith('!verify'):
arg = message.content.split()
role = arg[1]
role_fuzz = process.extract(role, roles, limit=1)
if role_fuzz[0][1] < 70:
await message.channel.send('Role syntax invalid or spelling wrong')
return
else:
role = role_fuzz[0][0]
school = arg[2].upper()
if school_validity:
if school not in school_filter:
await message.channel.send('School not found in list of school abbreviations, list of allowed abbreviations can be viewed at: https://drive.google.com/file/d/1gK6BKyT_uORc5wDoJaURvDbnx1TTfcEY/view?usp=sharing, please contact kek#8034 if your school is not present')
return
name = message.content[message.content.index(arg[3]):]
if len(name) + len(school) + 1 > 32:
await message.channel.send('Name provided is too long, please shorten ^^(enforced by discord\'s global limit)')
return
if open_organiser_role or role == "participant":
await message.author.edit(nick=school+' '+name)
discordrole = discord.utils.get(message.author.guild.roles, name=role)
await message.author.add_roles(discordrole)
await message.delete()
else:
await message.author.edit(nick=school+' '+name)
discordrole = discord.utils.get(message.author.guild.roles, name=role)
await message.author.add_roles(discordrole)
await message.delete()
channel = client.get_channel(manual_verification_channel)
channel.send('User: {user} requested for organiser role'.format(user=message.author))
client.run(token)