This repository was archived by the owner on Nov 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathflairbot.py
More file actions
149 lines (121 loc) · 4.74 KB
/
flairbot.py
File metadata and controls
149 lines (121 loc) · 4.74 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
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
import discord
prefix = "!"
client = discord.Client()
flairs = { #(role_name, twower/command name)
'meester': '#TeamMeester',
'midnight': '#TeamMidnight',
'yessoan': '#TeamYessoan'
}
debug = True #set false for normal use
if debug:
guild_id = 297811083308171264
owner_id = [240995021208289280]
else:
guild_id =184755239952318464
owner_id = [
140564059417346049,
149313154512322560,
98569889437990912,
154825973278310400,
185164223259607040,
127373929600778240,
184884413664854016,
164379304879194112,
184079890373541889,
110461599176724480
]
@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 (not message.content.startswith(prefix)) or message.content.startswith(prefix+prefix):
return
command = message.content.split(' ')[0][len(prefix):].lower()
htc = client.get_guild(guild_id)
bot = htc.get_member(client.user.id)
inHTC = (htc.get_member(message.author.id) != None)
isOwner = message.author.id in owner_id
if isOwner:
if command == "permcheck":
hasPerm = bot.guild_permissions.manage_roles
if not hasPerm:
print("**Alert:** The bot does not have permission to manage roles.")
else:
print("The bot currently has permission to manage roles.")
if command == "teamstats":
if htc.large: await client.request_offline_members(htc)
d = "--- FLAIR STATS ---\n"
for name, role in flairs.items():
d += '**{}**: {}\n'.format(name.title(), get_role_count(role,htc))
d += "--- END STATS ---"
print(d)
await message.channel.send(d)
if (command == "help" and message.channel.name != "music" and
(isinstance(message.channel, discord.abc.PrivateChannel) or message.guild.id == guild_id)):
names = ['`!{}`'.format(name.lower()) for name in flairs.keys()]
if len(names) > 1:
names[-1] = 'or {}'.format(names[-1])
await message.channel.send(
'To join a team, say {}. To leave your team, say `!remove`'.format(', '.join(names))
)
try:
if (inHTC and not message.channel.name in ['serious','music'] and
(isinstance(message.channel, discord.abc.PrivateChannel) or message.guild.id == guild_id)):
user = htc.get_member(message.author.id)
roles = htc.roles
teams =[]
for role in roles:
if role.name.startswith("#Team"):
teams.append(role)
if command == "remove":
removed = False
for role in teams:
if role in user.roles:
removed = True
await user.remove_roles(role)
sent_message = None
if removed: d = "You have successfully been removed from your team."
else: d = "You're not on a team!"
if isinstance(message.channel, discord.abc.PrivateChannel):
await message.channel.send(d)
else:
await message.channel.send(d, delete_after=5)
try: await message.delete()
except discord.Forbidden: pass
else:
if command in flairs:
for role in teams:
if role in user.roles:
await user.remove_roles(role)
team = discord.utils.get(teams,name=flairs[command])
await user.add_roles(team)
if isinstance(message.channel, discord.abc.PrivateChannel):
await message.channel.send("You have joined {}.".format(team.name))
else:
await message.channel.send(
"You have joined {}.".format(team.name),
delete_after=5
)
try: await message.delete()
except: pass
except Exception as e:
if debug:
raise e
else:
print("[ERROR] A bot-crashing error occured somewhere in the code.")
def get_role_count(role_name, guild):
team = discord.utils.get(guild.roles,name=role_name)
count = len(
list(
filter(
lambda x:team in x.roles,
guild.members
)
)
)
return count
client.run(open("bot-token.txt").read().split("\n")[0])