forked from hypogirl/health-bot
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmod_cogs.py
201 lines (165 loc) · 8.09 KB
/
mod_cogs.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
import asyncio
import random
import re
import discord
from discord.ext import commands
import useful
from useful import config, mod_team
open_tickets = {}
open_tickets_id = set()
def get_opened_tickets():
global open_tickets, open_tickets_id
return open_tickets, open_tickets_id
class Modding(commands.Cog):
def __init__(self, bot):
self.bot = bot
self._last_member = None
@commands.command()
@commands.has_any_role(*mod_team)
async def warn(self, ctx, *, arg):
await useful.generic_modding_action(ctx, arg, "warn", "warned", 0xffa500)
@commands.command()
@commands.has_any_role(*mod_team)
async def warnticket(self, ctx, *, arg):
global open_tickets, open_tickets_id
for user_id in re.findall(r"<?@?(\d{18})>?", arg):
if member := ctx.guild.get_member(int(user_id)):
open_tickets, open_tickets_id, ticket_channel = await useful.create_ticket_channel("[React to close the ticket]", "warn-ticket", member, dict(), set())
ticket_channel_embed = discord.Embed(title= f"Warning ticket for {member.nick or member.name} created!", description= ticket_channel.mention)
await ctx.send(embed= ticket_channel_embed)
@commands.command()
@commands.has_any_role(*mod_team)
async def kick(self, ctx, *, arg):
members, _ = await useful.generic_modding_action(ctx, arg, "kick", "kicked", 0xffa500)
for member in members:
await member.kick()
@commands.command()
@commands.has_any_role(*mod_team)
async def ban(self, ctx, *, arg):
members, reason = await useful.generic_modding_action(ctx, arg, "ban", "banned", 0xff0000)
for member in members:
await ctx.guild.ban(member, reason= reason, delete_message_seconds= 0)
@commands.command()
@commands.has_any_role(*mod_team)
async def purgeban(self, ctx, *, arg):
members, reason = await useful.generic_modding_action(ctx, arg, "ban and message purge", "banned and their messages have been purged", 0xff0000)
for member in members:
await ctx.guild.ban(member, reason= reason, delete_message_seconds= 604800)
@commands.command()
@commands.has_any_role(*mod_team)
async def purgeeject(self, ctx, *, arg):
members, reason = await useful.generic_modding_action(ctx, arg, "purge eject", "banned and their messages have been purged", 0xff0000)
for member in members:
await ctx.guild.ban(member, reason= reason, delete_message_seconds= 604800)
@commands.command()
@commands.has_any_role(*mod_team)
async def unban(self, ctx, *, arg):
_, reason = await useful.generic_modding_action(ctx, arg, "unban", "unbanned", 0x149414)
users = useful.get_unban_ids(arg)
for user_id in users:
user = await ctx.bot.fetch_user(user_id)
if not(user):
continue
await ctx.guild.unban(user, reason= reason)
@commands.command()
@commands.has_any_role(*mod_team)
async def mute(self, ctx, *, arg):
time, reason = useful.get_mute_info(arg)
if time[0]:
members, _ = await useful.generic_modding_action(ctx, arg, "mute", f"muted for {time[0]}", 0xfffcbb, reason)
else:
members, _ = await useful.generic_modding_action(ctx, arg, "mute", "muted", 0xfffcbb, reason)
muted_role = ctx.guild.get_role(int(config["MUTED_ROLE_ID"]))
for member in members:
await member.add_roles(muted_role,reason="Muted", atomic=True)
if time[1]:
await asyncio.sleep(time[1])
await member.remove_roles(muted_role, reason="Unmuted", atomic=True)
@commands.command()
@commands.has_any_role(*mod_team)
async def unmute(self, ctx, *, arg):
members, _ = await useful.generic_modding_action(ctx, arg, "unmute", "unmuted", 0xfffcbb)
muted_role = ctx.guild.get_role(int(config["MUTED_ROLE_ID"]))
for member in members:
await member.remove_roles(muted_role, reason="Unmuted", atomic=True)
@commands.command()
@commands.has_any_role(*mod_team)
async def eject(self, ctx, *, arg):
members, reason = useful.get_modding_info(ctx, arg)
for member in members:
if ctx.author.top_role <= member.top_role:
await ctx.send("You cannot eject this user.")
continue
user_message, mod_embed = useful.create_messages(member, reason, "ejected")
modlog_embed, modlog = useful.create_modlog_embed(ctx, "eject", reason, 0xffa500, member)
await modlog.send(embed= modlog_embed)
try:
await member.send(user_message)
except:
print(member.mention, "doesn't allow DMs.")
await useful.eject_animation(ctx, member)
await member.kick()
await ctx.send(embed= mod_embed)
@commands.command()
@commands.has_any_role(*mod_team)
async def baneject(self, ctx, *, arg):
members, reason = useful.get_modding_info(ctx, arg)
for member in members:
if ctx.author.top_role <= member.top_role:
await ctx.send("You cannot ban eject this user.")
continue
user_message, mod_embed = useful.create_messages(member, reason, "ban ejected")
modlog_embed, modlog = useful.create_modlog_embed(ctx, "ban eject", reason, 0xff0000, member)
await modlog.send(embed= modlog_embed)
try:
await member.send(user_message)
except:
print(member.mention, "doesn't allow DMs.")
await useful.eject_animation(ctx, member)
await ctx.guild.ban(member, reason= reason, delete_message_days= 0)
await ctx.send(embed= mod_embed)
class ModMisc(commands.Cog):
def __init__(self, bot):
self.bot = bot
self._last_member = None
@commands.command()
@commands.has_any_role(*mod_team)
async def spam(self, ctx, *, arg):
for x in range(int(arg)):
await ctx.send("spam")
@commands.command()
@commands.has_any_role(*mod_team)
async def purge(self, ctx, *, arg):
await ctx.message.delete()
deleted = await ctx.channel.purge(limit= int(arg))
deleted_text = ""
users = []
visited = []
for message in deleted:
if message.author not in visited:
users.append((message.author,1))
visited.append(message.author)
else:
i = visited.index(message.author)
users[i] = (message.author,users[i][1] + 1)
users.sort(reverse=True, key=lambda x:x[1])
for (user, number_of_messages) in users:
deleted_text += f"**{user.name}#{user.discriminator}:** {number_of_messages}\n"
embed = discord.Embed(title=" ", description="Messages deleted:\n\n" + deleted_text, color=0xff0000)
embed.set_author(name= f"{len(deleted)} messages purged | #{ctx.channel.name}")
await ctx.bot.get_channel(int(config["MOD_LOG_ID"])).send(embed= embed)
@commands.command()
@commands.has_any_role(*mod_team)
async def motd(self, ctx, *, arg):
motd_role = ctx.guild.get_role(int(config["MOTD_ROLE_ID"]))
members, _ = useful.get_modding_info(ctx, arg)
for member in members:
emojis = [697621015337107466,737315507509657661,697879872391086113,697880868743544903,753291933950017627,753291934008606762,804113756622684220,709794793051390153]
emoji = ctx.bot.get_emoji(random.choice(emojis))
await member.add_roles(motd_role,reason="Member of the day", atomic=True)
motd_embed = discord.Embed(title=" ", description=f"{member.mention} is member of the day!", color=0xFFBF00)
motd_embed.set_author(name= f"Member of the day")
motd_message = await ctx.send(embed= motd_embed)
await motd_message.add_reaction(emoji)
await asyncio.sleep(86400)
await member.remove_roles(motd_role,reason="Member of the day", atomic=True)