-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsetup.py
326 lines (262 loc) · 15.3 KB
/
setup.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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
import json
import os
import DiscordUtils
import discord
from discord.ext import commands
from discord.ext.commands import BucketType, cooldown
import motor.motor_asyncio
import nest_asyncio
from assets.reactor import reactor
from pymongo import MongoClient
from assets.reactor import reactor
nest_asyncio.apply()
mongo_url = os.environ['enalevel']
cluster = motor.motor_asyncio.AsyncIOMotorClient(mongo_url)
ledb = cluster["discord"]["enalevel"]
secondmongo = os.environ.get("tst")
cluster = motor.motor_asyncio.AsyncIOMotorClient(secondmongo)
predb = cluster["tst"]["prefix"]
def createem(text,color=0x71C562):
return discord.Embed(description=text,color=color)
class Setup(commands.Cog, description='Basic Setup for Tessarect !'):
def __init__(self, bot):
self.bot = bot
@commands.command(name='setup', description='Used to set the bot up, for welcome messages, mute roles, etc.\n'
'Recommended to set the bot up as early as possible when it joins a '
'server.')
@commands.guild_only()
async def setup(self, ctx):
embed = discord.Embed(title=f'{self.bot.user} Setup',
timestamp=ctx.message.created_at,
color=discord.Color.greyple())
embed.add_field(name='Set default reason when kicking/banning members',
value=f'<:rightarrow:941994550124245013>`[p]setkickreason [reason]`\nExample: `[p]setkickreason Being a jerk :rofl:`\n'
f'__**What the kicked member would see**__:\n'
f'You have been kicked from **{ctx.guild.name}** for **Being a jerk :rofl:**.',
inline=False)
embed.add_field(name='Set the mute role for this server',
value=f'<:rightarrow:941994550124245013>`[p]setmuterole [role]`\nExample: `[p]setmuterole muted` '
f'(muted must be an actual role).\n'
f'You can create a mute role by `[p]createmuterole [role name]`',
inline=False)
embed.add_field(name='Set the default Member role for this server',
value=f'<:rightarrow:941994550124245013>`[p]setmemberrole [role]`\nExample: `[p]setmemberrole Member`'
f' (Member must be an actual role).\n'
f'If you want to turn off MemberRole, make a role, assign the member role to that role, and delete the role. It is for verify command',
inline=False)
embed2=discord.Embed(timestamp=ctx.message.created_at,
color=discord.Color.green())
embed2.add_field(name="Switch antiswear filter for this server",value=f"<:rightarrow:941994550124245013>Tessarect offers a very advanced antiswear filter to keep your server safe , to enable by disable it do `[p]antiswear [enable/disable]`")
embed2.add_field(name="Switch antiscam filter for this server",value=f"<:rightarrow:941994550124245013>Tessarect offers a very advanced antiscam filter to keep your server safe , to enable by disable it do `[p]antiscam [enable/disable]`")
embed.add_field(name='Set the Security Logs channel [important]',
value=f'<:rightarrow:941994550124245013>Set the security logs channel use `[p]securitylogschannel <channel>`',
inline=False)
embed2.add_field(name="Switch Levelling System for this server",value=f"<:rightarrow:941994550124245013>Tessarect offers a very advanced and good levelling system , if you want to switch it (disabled by default) you can do \n `[p]levelconfig [enable/disable]`. \n Get more info on its commands by using `[p]help Level`")
embed2.set_footer(text=f' Note there are other setups too for each cog you are requested to go through it while using them | Requested by {ctx.author.name}')
paginator = DiscordUtils.Pagination.CustomEmbedPaginator(ctx,remove_reactions=True)
embeds = [embed, embed2]
paginator.add_reaction('<:arrow_left:940845517703889016>', "first")
paginator.add_reaction('<:leftarrow:941994549935472670>', "back")
paginator.add_reaction('<:rightarrow:941994550124245013>', "next")
paginator.add_reaction('<:arrow_right:940608259075764265>', "last")
paginator.add_reaction('<:DiscordCross:940914829781270568>', "lock")
await paginator.run(embeds)
@commands.command(name='setkickreason', description='Used to set the default kick/ban reason '
'in a case where no reason is given.\n'
'Check the description of the `setup` command '
'for more information.')
@commands.has_permissions(manage_guild=True)
@commands.guild_only()
async def set_kick_reason(self, ctx, *, reason):
if os.path.exists(f'./configs/{ctx.guild.id}.json'):
with open(f'./configs/{ctx.guild.id}.json', 'r') as jsonFile:
data = json.load(jsonFile)
else:
data = {}
data['default_kick_ban_reason'] = str(reason)
with open(f'./configs/{ctx.guild.id}.json', 'w') as jsonFile:
json.dump(data, jsonFile, indent=4)
await ctx.send(embed=createem(f'Default kick/ban reason set to **{reason}** successfully.'))
@commands.command(name='securitylogschannel', description='Set logs channel for security related messages')
@commands.has_permissions(manage_guild=True)
@commands.guild_only()
async def securitylogs(self, ctx, role: discord.TextChannel):
if os.path.exists(f'./configs/{ctx.guild.id}.json'):
with open(f'./configs/{ctx.guild.id}.json', 'r') as jsonFile:
data = json.load(jsonFile)
else:
data = {}
data['securitylogs'] = role.id
with open(f'./configs/{ctx.guild.id}.json', 'w') as jsonFile:
json.dump(data, jsonFile, indent=3)
await ctx.send(embed=createem(f'Security Logs Channel set to **{role.mention}** successfully.'))
@commands.command(name='setmemberrole', description='Set role which user gets on using verify command')
@commands.has_permissions(manage_guild=True)
@commands.guild_only()
async def set_member_role(self, ctx, role: discord.Role):
if os.path.exists(f'./configs/{ctx.guild.id}.json'):
with open(f'./configs/{ctx.guild.id}.json', 'r') as jsonFile:
data = json.load(jsonFile)
else:
data = {}
data['member_role'] = role.id
with open(f'./configs/{ctx.guild.id}.json', 'w') as jsonFile:
json.dump(data, jsonFile, indent=3)
await ctx.send(embed=createem(f'Member role set to **{role.name}** successfully.'))
@commands.command(name='setmuterole', description='Sets the role assigned to muted people. '
'Use `createmuterole` for creating a muted role and '
'automatically setting permissions to every channel.')
@commands.has_permissions(manage_guild=True)
@commands.guild_only()
async def set_mute_role(self, ctx, role: discord.Role):
if os.path.exists(f'./configs/{ctx.guild.id}.json'):
with open(f'./configs/{ctx.guild.id}.json', 'r') as jsonFile:
data = json.load(jsonFile)
else:
data = {}
data['mute_role'] = role.id
with open(f'./configs/{ctx.guild.id}.json', 'w') as jsonFile:
json.dump(data, jsonFile, indent=4)
await ctx.send(embed=createem(f'Mute role set to **{role.name}** successfully.'))
@commands.command(name='createmuterole', description='Creates a mute role, and sets messaging permissions to '
'every channel.\n '
'the `rolename` argument is optional. (Defaults to "Muted")')
@commands.has_permissions(manage_roles=True)
@commands.guild_only()
async def create_mute_role(self, ctx, rolename=None):
if rolename is None:
rolename = 'Muted'
guild = ctx.guild
mutedRole = await guild.create_role(name=rolename) # creating the role
for channel in guild.channels:
await channel.set_permissions(mutedRole, speak=False, send_messages=False, use_slash_commands=False)
# setting permissions for each channel
await ctx.send(embed=createem(f'Created role **{mutedRole}** and set permissions accordingly.'))
await Setup.set_mute_role(self, ctx, mutedRole)
@commands.command(name='antiswear', description='Toggle Antiswear filter (enable or disable only)')
@commands.has_permissions(manage_guild=True)
@commands.guild_only()
async def antiswear(self, ctx, *, choice):
lst = ["enable", "disable"]
if choice in lst:
if os.path.exists(f'./configs/{ctx.guild.id}.json'):
with open(f'./configs/{ctx.guild.id}.json', 'r') as jsonFile:
data = json.load(jsonFile)
else:
data = {}
data['antiswear'] = str(choice)
with open(f'./configs/{ctx.guild.id}.json', 'w') as jsonFile:
json.dump(data, jsonFile, indent=4)
await ctx.send(embed=createem(f'**Changes Saved | Choice : {choice}**'))
else:
await ctx.send(embed=createem('Invalid Choice'))
@commands.command(name='antiscam', description='Toggle Antiscam filter (enable or disable only)')
@commands.has_permissions(manage_guild=True)
@commands.guild_only()
async def antiscam(self, ctx, *, choice):
lst = ["enable", "disable"]
if choice in lst:
if os.path.exists(f'./configs/{ctx.guild.id}.json'):
with open(f'./configs/{ctx.guild.id}.json', 'r') as jsonFile:
data = json.load(jsonFile)
else:
data = {}
data['antiscam'] = str(choice)
with open(f'./configs/{ctx.guild.id}.json', 'w') as jsonFile:
json.dump(data, jsonFile, indent=4)
await ctx.send(embed=createem(f'**Changes Saved | Choice : {choice}**'))
else:
await ctx.send(embed=createem('Invalid Choice') )
@commands.command(name='antispam', description='Toggle Antispam filter (enable or disable only)')
@commands.has_permissions(manage_guild=True)
@commands.guild_only()
async def antispamr(self, ctx, *, choice):
lst = ["enable", "disable"]
if choice in lst:
if os.path.exists(f'./configs/{ctx.guild.id}.json'):
with open(f'./configs/{ctx.guild.id}.json', 'r') as jsonFile:
data = json.load(jsonFile)
else:
data = {}
data['antispam'] = str(choice)
with open(f'./configs/{ctx.guild.id}.json', 'w') as jsonFile:
json.dump(data, jsonFile, indent=4)
await ctx.send(embed=createem(f'**Changes Saved | Choice : {choice}**'))
else:
await ctx.send(embed=createem('Invalid Choice') )
@commands.command(aliases=["levelling"], description="Enable or disable levelling")
@commands.has_permissions(administrator=True)
async def levelconfig(self, ctx, choice):
lst = ["enable", "disable"]
stats = await ledb.find_one({"id": ctx.guild.id})
if choice in lst:
if choice == "enable" :
choice = 0
stats = await ledb.find_one({"id": ctx.guild.id})
if stats is None:
newuser = {"id": ctx.guild.id, "type": choice}
await ledb.insert_one(newuser)
await ctx.send(embed=createem("**Changes are saved**"))
elif stats["type"] == 0:
await ctx.send(embed=createem("**Command is already enabled**"))
else:
await ledb.update_one(
{"id": ctx.guild.id}, {"$set": {"type": choice}}
)
await ctx.send(embed=createem("**Changes are saved | Command enabled**"))
else:
choice = 1
stats = await ledb.find_one({"id": ctx.guild.id})
if stats is None:
newuser = {"id": ctx.guild.id, "type": choice}
await ledb.insert_one(newuser)
await ctx.send(embed=createem("**Changes are saved**"))
elif stats["type"] == 1:
await ctx.send(embed=createem("**Command is already disabled**"))
else:
await ledb.update_one(
{"id": ctx.guild.id}, {"$set": {"type": choice}}
)
await ctx.send(embed=createem("**Changes are saved | Command disabled**"))
else:
await ctx.send(embed=createem("**It can be enable/disable only**"))
@commands.command(
cooldown_after_parsing=True, description="Changes Bot prefix for this server"
)
@cooldown(1, 10, BucketType.user)
@commands.has_permissions(administrator=True)
async def setprefix(self, ctx, new_prefix):
if len(new_prefix) > 20:
embed = discord.Embed(
timestamp=ctx.message.created_at,
#title="Not So long... ",
description=f"> Looks like the prefix is very big.. \n> Try something else ( lower than 20 characters) and you are {len(new_prefix)-20} characters above the limit",
color=0xFF0000,
).set_author(icon_url="https://cdn.discordapp.com/emojis/942777902125158473.webp?size=96&quality=lossless",name="Not So long... ")
await ctx.send(embed=embed)
else:
new_prefix = str(new_prefix)
stats = await predb.find_one({"guild": ctx.guild.id})
if stats is None:
updated = {"guild": ctx.guild.id, "prefix": new_prefix}
await predb.insert_one(updated)
embed = discord.Embed(
timestamp=ctx.message.created_at,
title="Changing Server Prefix..",
description=f"<:Servers:946289809289281566> This server prefix is now {new_prefix}",
color=0x24787c,
).set_thumbnail(url="https://media.discordapp.net/attachments/942735208195711050/1001484524212981771/5161-mixer-devbot.png")
await ctx.send(embed=embed)
else:
await predb.update_one(
{"guild": ctx.guild.id}, {"$set": {"prefix": new_prefix}}
)
embed = discord.Embed(
timestamp=ctx.message.created_at,
title="Changing Server Prefix..",
description=f"<:Servers:946289809289281566> This server prefix is now {new_prefix}",
color=0x24787c,
).set_thumbnail(url="https://media.discordapp.net/attachments/942735208195711050/1001484524212981771/5161-mixer-devbot.png")
await ctx.send(embed=embed)
def setup(bot):
bot.add_cog(Setup(bot))