forked from Sparsh752/TLE_Python
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathrating_roles.py
More file actions
73 lines (71 loc) · 3.18 KB
/
rating_roles.py
File metadata and controls
73 lines (71 loc) · 3.18 KB
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
from discord.utils import get
import os
#Whenever this function is called it will remove all the rating roles for the given username
async def remove_rating_roles(username):
rating_roles = ["Newbie", "Pupil", "Specialist", "Expert", "Candidate Master", "Master", "Internation Master", "Grandmaster", "International Grandmaster", "Legendary Grandmaster"]
for role in rating_roles:
for user_role in username.roles:
if role == user_role.name:
await username.remove_roles(user_role)
print("All roles removed")
#This function will add the rating role to the user based on the rating
async def rating_role(id, rating,bot,channel, msg):
#Fetch the guild from the environment variable
GUILD=os.environ.get('GUILD')
guild = await bot.fetch_guild(GUILD)
#Get the user from the id and guild then fetch the username
user = await guild.query_members(user_ids=[id])
username=user[0]
if (msg is None):
msg = await channel.send(f"Fetching rating changes")
#Now based on the rating add the role to the user
if (rating < 800):
await remove_rating_roles(username)
return
elif (rating < 1200):
role = get(username.guild.roles, name="Newbie")
if role is None:
role = await username.guild.create_role(name="Newbie")
elif (rating < 1400):
role = get(username.guild.roles, name="Pupil")
if role is None:
role = await username.guild.create_role(name="Pupil")
elif (rating < 1600):
role = get(username.guild.roles, name="Specialist")
if role is None:
role = await username.guild.create_role(name="Specialist")
elif (rating < 1900):
role = get(username.guild.roles, name="Expert")
if role is None:
role = await username.guild.create_role(name="Expert")
elif (rating < 2100):
role = get(username.guild.roles, name="Candidate Master")
if role is None:
role = await username.guild.create_role(name="Candidate Master")
elif (rating < 2300):
role = get(username.guild.roles, name="Master")
if role is None:
role = await username.guild.create_role(name="Master")
elif (rating < 2400):
role = get(username.guild.roles, name="International Master")
if role is None:
role = await username.guild.create_role(name="International Master")
elif (rating < 2600):
role = get(username.guild.roles, name="Grandmaster")
if role is None:
role = await username.guild.create_role(name="Grandmaster")
elif (rating < 3000):
role = get(username.guild.roles, name="International Grandmaster")
if role is None:
role = await username.guild.create_role(name="International Grandmaster")
else:
role = get(username.guild.roles, name="Legendary Grandmaster")
if role is None:
role = await username.guild.create_role(name="Legendary Grandmaster")
if (role in username.roles):
return msg
await remove_rating_roles(username)
await username.add_roles(role)
print("Role added")
await msg.edit(content=f"{username.mention} is a <@&{role.id}>")
return None