This repository has been archived by the owner on Aug 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
227 lines (208 loc) · 8.55 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
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
##################################################################
# #
# twitch mod activity tracker #
# #
# Copyright (C) 2022 X Gamer Guide #
# https://github.com/X-Gamer-Guide/twitch-mod-activity-tracker #
# #
##################################################################
from typing import Optional
import disnake
from disnake.ext import commands
from config import config, language
from twitch import get_mod_actions
from utils import command_help, get_action, get_actions, get_command
bot = commands.Bot(sync_commands=True)
@bot.event
async def on_ready():
get_mod_actions.start()
print("Online")
@bot.slash_command(
name=language.commands.help.display_name.lower(),
description=language.commands.help.description
)
async def help(
inter: disnake.ApplicationCommandInteraction,
command: Optional[str] = commands.Param(
None,
name=language.commands.help.arguments.command.display_name.lower(),
description=language.commands.help.arguments.command.description,
choices=[language.commands[command].display_name for command in language.commands]
)
):
if command is None:
embed = disnake.Embed(
title=language.commands.help.embed.title,
description="\n".join([f"{command_help(command)}\n{language.commands[command].description}" for command in language.commands]),
color=config.discord.embed.color.normal
)
else:
command = get_command(command)
embed = disnake.Embed(
title=command_help(command),
description=language.commands[command].description,
color=config.discord.embed.color.normal
)
embed.set_footer(text=language.required_optional_footer)
await inter.response.send_message(
embed=embed,
ephemeral=config.discord.embed.ephemeral
)
@bot.slash_command(
name=language.commands.top.display_name.lower(),
description=language.commands.top.description
)
async def top(
inter: disnake.ApplicationCommandInteraction
):
mods = get_actions(True)
if mods == {}:
embed = disnake.Embed(
title=language.commands.top.embed.title,
description=language.no_data,
color=config.discord.embed.color.error
)
else:
embed = disnake.Embed(
title=language.commands.top.embed.title,
color=config.discord.embed.color.normal
)
# Sorts all moderators by most actions
for place, (mod, actions) in enumerate(sorted(mods.items(), key=lambda x: sum(x[1].values()), reverse=True)):
if place >= 5:
break
action_list = []
for action in sorted(mods[mod], key=lambda x: mods[mod][x], reverse=True):
action_list.append(f"{language.actions.get(action, action)}: **{actions[action]}**")
embed.add_field(
name=f"{place + 1}. {mod} | `{sum(actions.values())}`",
value="\n".join(action_list),
inline=False
)
await inter.response.send_message(
embed=embed,
ephemeral=config.discord.embed.ephemeral
)
@bot.slash_command(
name=language.commands.list.display_name.lower(),
description=language.commands.list.description
)
async def list(
inter: disnake.ApplicationCommandInteraction,
action: Optional[str] = commands.Param(
None,
name=language.commands.list.arguments.action.display_name.lower(),
description=language.commands.list.arguments.action.description,
choices=[language.actions[action] for action in language.actions]
)
):
mod_list = []
if action is None:
total_actions = 0
mods = get_actions(True)
if mods == {}:
embed = disnake.Embed(
title=language.commands.top.embed.title,
description=language.no_data,
color=config.discord.embed.color.error
)
else:
# Sorts all moderators by most actions
for place, (mod, actions) in enumerate(sorted(mods.items(), key=lambda x: sum(x[1].values()), reverse=True)):
for action in actions:
total_actions += actions[action]
if place >= 50:
continue
mod_list.append(f"**{place + 1}.** `{mod}`: {sum(actions.values())}")
description = "\n".join(mod_list)
embed = disnake.Embed(
title=language.commands.list.embed.title,
description=f"{language.commands.list.embed.total.format(total=total_actions)}\n\n{description}",
color=config.discord.embed.color.normal
)
else:
total_count = 0
original_action = get_action(action)
actions = get_actions()
if original_action in actions:
# Sorts all moderators by most actions
for place, (mod, count) in enumerate(sorted(actions[original_action].items(), key=lambda x: x[1], reverse=True)):
total_count += count
if place >= 50:
continue
mod_list.append(f"**{place + 1}.** `{mod}`: {count}")
description = "\n".join(mod_list)
embed = disnake.Embed(
title=language.commands.list.embed.specialized.title.format(total=total_count, action=action),
description=f"{language.commands.list.embed.specialized.total.format(total=total_count, action=action)}\n\n{description}",
color=config.discord.embed.color.normal
)
else:
embed = disnake.Embed(
title=language.commands.list.embed.specialized.title.format(action=action),
description=language.commands.list.embed.specialized.no_action,
color=config.discord.embed.color.error
)
await inter.response.send_message(
embed=embed,
ephemeral=config.discord.embed.ephemeral
)
@bot.slash_command(
name=language.commands.stats.display_name.lower(),
description=language.commands.stats.description
)
async def stats(
inter: disnake.ApplicationCommandInteraction,
moderator: str = commands.Param(
name=language.commands.stats.arguments.moderator.display_name.lower(),
description=language.commands.stats.arguments.moderator.description
)
):
moderator = moderator.lower()
mods = get_actions(True)
if moderator in mods:
action_list = []
total_actions = 0
for action in sorted(mods[moderator], key=lambda x: mods[moderator][x], reverse=True):
total_actions += mods[moderator][action]
action_list.append(f"{language.actions.get(action, action)}: **{mods[moderator][action]}**")
description = "\n".join(action_list)
embed = disnake.Embed(
title=language.commands.stats.embed.title.format(total=total_actions, mod=moderator),
description=f"{language.commands.stats.embed.total.format(total=total_actions, mod=moderator)}\n\n{description}",
color=config.discord.embed.color.normal
)
await inter.response.send_message(
embed=embed,
ephemeral=config.discord.embed.ephemeral
)
else:
embed = disnake.Embed(
title=language.commands.stats.embed.mod_not_found.title,
description=language.commands.stats.embed.mod_not_found.description.format(mod=moderator),
color=config.discord.embed.color.error
)
await inter.response.send_message(
embed=embed,
ephemeral=config.discord.embed.ephemeral
)
if config.discord.enable_about_command:
@bot.slash_command(
name=language.commands.about.display_name.lower(),
description=language.commands.about.description
)
async def about(
inter: disnake.ApplicationCommandInteraction,
):
embed = disnake.Embed(
description="Visit on GitHub: https://github.com/X-Gamer-Guide/twitch-mod-activity-tracker",
color=config.discord.embed.color.normal
)
embed.set_author(
name="Copyright (C) 2022 X Gamer Guide",
url="https://github.com/X-Gamer-Guide/twitch-mod-activity-tracker"
)
await inter.response.send_message(
embed=embed,
ephemeral=config.discord.embed.ephemeral
)