-
Notifications
You must be signed in to change notification settings - Fork 10
/
bot.py
313 lines (236 loc) · 9.25 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
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
#!/usr/bin/python3
import discord
from discord import Intents
import random
import time
import os
from discord.ext import commands
from cogs.usefullTools.dbIntegration import *
# Get prefix
def get_prefix(bot, message):
return fetch_prefix(message.guild.id)["prefix"]
intents = Intents.default()
intents.members = True
bot = commands.Bot(command_prefix=get_prefix, case_insensitive=True, intents=intents)
bot.remove_command('help')
working_directory = os.getcwd()
try:
for filename in os.listdir('./cogs'):
if filename.endswith('.py'):
bot.load_extension(f"cogs.{filename[:-3]}")
except Exception as e:
print("Cogs error: Cannot load cogs")
print("\033[5;37;40m\033[1;33;40mWARNING\033[1;33;40m\033[0;37;40m", end=' ')
print("Functionality limited!\n")
print(f"exception thrown:\n{e}")
# Shows command prefix if asked
@bot.event
async def on_message(message):
reply_choices = [
"Hi",
"Hi there",
"Hey",
"Hey there",
"Whatsup",
"Waddup",
"Whats going on",
"Hello",
"Hello!",
"Sup",
"Howdy"
]
message_var = message.content
if message.author.bot:
return
elif (bot.user in message.mentions) and message_var.lower().find('prefix') != -1:
await message.channel.send(f'My command prefix is `{fetch_prefix(message.guild.id)["prefix"]}`, **{message.author.display_name}**')
elif bot.user in message.mentions:
if message_var.lower().find('awesome') != -1 or message_var.lower().find('cool') != -1 or message_var.lower().find('good') != -1 or message_var.lower().find('nice') != -1 :
await message.channel.send(f'Thanks bro 😁')
elif message_var.lower().find('bad') != -1 or message_var.lower().find('horrible') != -1 or message_var.lower().find('suck') != -1 or message_var.lower().find('terrible') != -1 or message_var.lower().find('waste') != -1 or message_var.lower().find('fk') != -1 or message_var.lower().find('fuck') != -1:
await message.channel.send(f'No you\nI do the basic functions okay I aint dyno or mee6\n\nJesus christ.')
elif message_var.lower().find('how are you') != -1 :
await message.channel.send(f'I am fine, {message.author.display_name}')
else:
await message.channel.send(f'{random.choice(reply_choices)}, **{message.author.display_name}**!')
if str(message.channel.type) == 'private':
if len(message.content.split()) > 20:
bugs_channel1 = bot.get_channel(769510637486997514)
bugs_channel2 = bot.get_channel(769490617771884565)
bugs_channel3 = bot.get_channel(782252610874638347)
embed = discord.Embed(
title='BUG REPORTED',
colour = 0x008000
)
embed.add_field(name='Username', value=message.author)
embed.add_field(name='User id', value=message.author.id)
embed.add_field(name='Bug: ', value=message.content)
if bugs_channel1 is not None:
await bugs_channel1.send(embed=embed)
await bugs_channel2.send(embed=embed)
await bugs_channel3.send(embed=embed)
elif bugs_channel2 is not None:
await bugs_channel2.send(embed=embed)
await bugs_channel3.send(embed=embed)
await message.channel.send("Your bug has been reported")
else:
await message.channel.send("Please enter your bug in more than 20 words, try describing everything")
await bot.process_commands(message)
# Basic stuff
@bot.event
async def on_ready():
await bot.change_presence(status=discord.Status.online, activity=discord.Game('with your lives'))
print("+[ONLINE] Rexbot is online")
@bot.event
async def on_member_join(member):
try:
print(f'+[NEW_MEMBER] {member} has joined the server: {member.guild.name}')
channel = None
if fetch_join_log_channel(int(member.guild.id)) is not None:
channel = bot.get_channel(fetch_join_log_channel(int(member.guild.id))["channel_id"])
if channel is not None:
embed = discord.Embed(
title = 'Member joined the server',
description=f'Member **{member.name}** joined the server!',
colour=0x008000
)
members = await member.guild.fetch_members().flatten()
bot_count = 0
for people in members:
if people.bot is True:
bot_count += 1
embed.set_thumbnail(url=member.avatar_url)
embed.add_field(name='Number of members', value=len(members) - bot_count)
embed.add_field(name='Number of bots', value=bot_count)
embed.set_footer(text=f'id: {member.id}')
await channel.send(embed=embed)
else:
pass
except Exception as e:
raise Exception
@bot.event
async def on_member_remove(member):
try:
print(f'+[REMOVE_MEMBER] {member} has left the server: {member.guild.name}')
delete_warns(member.guild.id, member.id)
channel = None
if fetch_leave_log_channel(int(member.guild.id)):
channel = bot.get_channel(fetch_leave_log_channel(int(member.guild.id))["channel_id"])
if channel is not None:
embed = discord.Embed(
title = 'Member left the server',
description=f'Member **{member.name}** has left the server!',
colour=0xFF0000
)
try:
members = await member.guild.fetch_members().flatten()
bot_count = 0
for people in members:
if people.bot is True:
bot_count += 1
embed.set_thumbnail(url=member.avatar_url)
embed.add_field(name='Number of members', value=len(members) - bot_count)
embed.add_field(name='Number of bots', value=bot_count)
embed.set_footer(text=f'id: {member.id}')
await channel.send(embed=embed)
except:
pass
else:
pass
except Exception as e:
raise Exception
@bot.event
async def on_guild_channel_delete(channel):
join_channel = None
if fetch_join_log_channel(int(channel.guild.id)) is not None:
join_channel = fetch_join_log_channel(int(channel.guild.id))["channel_id"]
if channel.id == join_channel:
delete_join_log_channel(int(channel.guild.id))
leave_channel = None
if fetch_leave_log_channel(int(channel.guild.id)) is not None:
leave_channel = fetch_leave_log_channel(int(channel.guild.id))["channel_id"]
if channel.id == leave_channel:
delete_leave_log_channel(int(channel.guild.id))
log_channel = None
if fetch_mod_log_channel(int(channel.guild.id)) is not None:
mod_channel = fetch_mod_log_channel(int(channel.guild.id))["channel_id"]
if channel.id == mod_channel:
delete_mod_log_channel(int(channel.guild.id))
@bot.event
async def on_guild_join(guild):
insert_prefix(guild.id, "r$")
@bot.event
async def on_guild_remove(guild):
clear_server_data(guild.id)
@bot.event
async def on_bulk_message_delete(messages):
message_channel = fetch_message_edit_log_channel(int(messages[0].guild.id))
if message_channel is not None:
message_channel = fetch_message_edit_log_channel(int(messages[0].guild.id))["channel_id"]
message_channel = bot.get_channel(message_channel)
embed = discord.Embed(
title='Bulk message delete',
description=f'{len(messages)} messages deleted in {messages[0].channel.mention}',
color=0xff0000
)
if message_channel.id != messages[0].channel.id:
await message_channel.send(embed=embed)
@bot.event
async def on_message_delete(message):
message_channel = fetch_message_edit_log_channel(int(message.guild.id))
if message_channel is not None:
message_channel = fetch_message_edit_log_channel(int(message.guild.id))["channel_id"]
message_channel = bot.get_channel(message_channel)
embed = discord.Embed(
title='Message deleted',
description=f'Message deleted in {message.channel.mention}\nContents:\n```\n{message.content}\n```\n'
f'Author of the message:\n{message.author.mention}',
color=0xff0000
)
if message_channel.id != message.channel.id:
await message_channel.send(embed=embed)
@bot.event
async def on_message_edit(before, after):
if not after.author.bot:
if before.content != after.content:
message_channel = fetch_message_edit_log_channel(int(before.guild.id))
if message_channel is not None:
message_channel = fetch_message_edit_log_channel(int(before.guild.id))["channel_id"]
message_channel = bot.get_channel(message_channel)
embed = discord.Embed(
title='Message edited',
description=f'Message edited in {before.channel.mention}\nbefore:\n```\n{before.content}\n```\n\nAfter:\n```\n{after.content}\n```\n'
f'Author of the message:\n{after.author.mention}\n'
f'[jump](https://discordapp.com/channels/{after.guild.id}/{after.channel.id}/{after.id}) to the message',
color=0xff0000
)
if message_channel.id != before.channel.id:
await message_channel.send(embed=embed)
# Ping
@bot.command()
async def ping(ctx):
await ctx.send(f'Ping: {round(bot.latency * 1000)}ms')
# If the user enters something bonkers
@bot.event
async def on_command_error(ctx, error):
if isinstance(error, commands.CommandNotFound):
prefix = fetch_prefix(ctx.guild.id)["prefix"]
await ctx.send(f"command not found\nPlease use `{prefix}help` to see all commands")
TOKEN = os.getenv("REXBOT_TOKEN")
try:
if TOKEN is None:
try:
with open('./token.0', 'r', encoding='utf-8') as file_handle:
TOKEN = file_handle.read()
if TOKEN is not None:
print('Using token found in token file..')
bot.run(TOKEN)
else:
print("Token error: Token not found")
except FileNotFoundError:
print("No token file or environment variable\nQuitting")
else:
print('Using token found in Environment variable....')
bot.run(TOKEN)
except discord.errors.LoginFailure:
print("\033[1;31;40mFATAL ERROR\033[0m 1;31;40m\nToken is malformed; invalid token")