-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
626 lines (581 loc) · 32 KB
/
main.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
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
"""Isobot, the bot to make your server (a little bit) better.\n\nisobot (C) NKA 2022-2024.\nRun `/credits` in the Discord bot to see the credits.\n\nWARNING: This client is meant to be run standalone. Not as a Python import."""
# Imports
import os
import os.path
import json
import time
import datetime
import discord, discord.errors
import asyncio
import api.auth
from utils import logger, ping
from math import floor
from random import randint
from framework.isobot import currency, colors, settings, commands as _commands, isocard
from framework.isobot.shop import ShopData
from framework.isobot.db import levelling, items, userdata, automod, weather, warnings, presence as _presence, serverconfig, embeds
from discord import ApplicationContext, option
from discord.ext import commands
from cogs.isocoin import create_isocoin_key
# Variables
intents = discord.Intents.default()
intents.message_content = True
intents.members = True
client = discord.Bot(intents=intents)
color = discord.Color.random()
start_time = ""
# Pre-Initialization Commands
def initial_setup():
"""Runs the initial setup for isobot's directories.\nThis creates missing directories, new log files, as well as new databases for any missing `.json` database files."""
# Create required client directories
try:
paths = ("database", "database/isobank", "config", "logs", "themes")
for p in paths:
if not os.path.isdir(p):
logger.warn(f"'{p}' directory appears to be missing. Created new directory for '{p}'.", module="main/Setup", nolog=True)
os.mkdir(p)
except OSError:
logger.error(f"Failed to make directory: {e}", module="main/Setup")
# Generating database files
try:
databases = (
"automod",
"currency",
"isocard",
"items",
"levels",
"serverconfig",
"serververification",
"warnings",
"presence",
"user_data",
"weather",
"embeds",
"isocard_transactions",
"isocard_transaction_history",
"isobank/accounts",
"isobank/auth"
)
for f in databases:
if not os.path.isfile(f"database/{f}.json"):
logger.warn(f"[main/Setup] '{f}.json' was not found in database directory. Creating new database...", module="main/Setup", nolog=True)
if f == "currency":
with open(f"database/{f}.json", 'x', encoding="utf-8") as f:
json.dump({"treasury": 100000000, "wallet": {}, "bank": {}}, f)
f.close()
else:
with open(f"database/{f}.json", 'x', encoding="utf-8") as f:
json.dump({}, f)
f.close()
time.sleep(0.5)
except IOError as e:
logger.error(f"Failed to make database file: {e}", module="main/Setup")
# Generating other files
try:
if not os.path.isfile(f"config/settings.json"):
logger.warn(f"[main/Setup] Settings database file was not found in config directory. Creating new database...", module="main/Setup", nolog=True)
with open(f"config/settings.json", 'x', encoding="utf-8") as f:
json.dump({}, f)
f.close()
except IOError as e:
logger.error(f"Failed to make settings database file: {e}", module="main/Setup")
# Generating client log files
try:
if not os.path.isfile("logs/info-log.txt"):
with open('logs/info-log.txt', 'x', encoding="utf-8") as this:
this.write("# All information and warnings will be logged here!\n")
this.close()
logger.info("Created info log", module="main/Setup", nolog=True)
time.sleep(0.5)
if not os.path.isfile("logs/error-log.txt"):
with open('logs/error-log.txt', 'x', encoding="utf-8") as this:
this.write("# All exceptions will be logged here!\n")
this.close()
logger.info("Created error log", module="main/Setup", nolog=True)
time.sleep(0.5)
if not os.path.isfile("logs/currency.log"):
with open('logs/currency.log', 'x', encoding="utf-8") as this:
this.close()
logger.info("Created currency log", module="main/Setup", nolog=True)
time.sleep(0.5)
if not os.path.isfile("logs/startup-log.txt"):
with open("logs/startup-log.txt", 'x', encoding="utf-8") as this:
this.close()
time.sleep(0.5)
if not os.path.isfile("logs/isocard_transactions.log"):
with open("logs/isocard_transactions.log", 'x', encoding="utf-8") as this:
this.write("# All IsoCard transaction updates will be logged here.\n")
this.close()
time.sleep(0.5)
except IOError as e:
logger.error(f"Failed to make log file: {e}", module="main/Setup", nolog=True)
initial_setup() # Check for any missing sub-directories or databases in bot directory
# Framework Module Loader
colors = colors.Colors()
s = logger.StartupLog("logs/startup-log.txt", clear_old_logs=True)
currency = currency.CurrencyAPI("database/currency.json", "logs/currency.log")
settings = settings.Configurator()
levelling = levelling.Levelling()
items = items.Items()
serverconfig = serverconfig.ServerConfig()
warningsdb = warnings.Warnings()
userdata = userdata.UserData()
automod = automod.Automod()
_presence = _presence.Presence()
weather = weather.Weather()
embeds = embeds.Embeds()
_commands = _commands.Commands()
shop_data = ShopData("config/shop.json")
# Theme Loader
if api.auth.get_runtime_options()["themes"]:
with open("themes/halloween.theme.json", 'r', encoding="utf-8") as f:
theme = json.load(f)
try:
color_loaded = theme["theme"]["embed_color"]
color = int(color_loaded, 16)
except KeyError:
logger.warn("The theme file being loaded might be broken. Rolling back to default configuration...", module="main/Themes")
color = discord.Color.random()
else:
color = discord.Color.random()
# Events
@client.event
async def on_ready():
"""This event is fired when the bot client is ready"""
start_time = datetime.datetime.now()
s.log(f"[main/Client] {colors.green}Client ready!{colors.end}")
s.log("""
Isobot Copyright (C) 2022-2024 NKA
This program comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it
under certain conditions.
__________________________________________________""")
time.sleep(1)
if api.auth.get_runtime_options()["show_ping_on_startup"]:
s.log("Client Information:")
s.log(f" Latency/Ping: {round((client.latency * 1000), 2)} ms")
s.log("--------------------")
s.log(f'[main/Client] Logged in as {client.user.name}. Start time: {start_time.strftime("%H:%M:%S")}\n[main/Client] Ready to accept commands. Click Ctrl+C to shut down the bot.')
await client.change_presence(activity=discord.Activity(type=discord.ActivityType.playing, name="I-I-I be poppin bottles 🗣🗣🔥"), status=discord.Status.idle)
s.log(f'[main/Log] {colors.green}Status set to IDLE. Rich presence set.{colors.end}')
# Deploy IsoCard Payments Server
isocard.deploy_server()
time.sleep(0.5)
# Start and Deploy Ping Server
if api.auth.get_mode() or api.auth.get_runtime_options()["ping_server_override"]:
# If ping_server_override is set to true, it will start the pinging server no matter what. If it's set to false, it will only start if client mode is set to replit.
s.log(f"[main/Flask] {f'{colors.yellow}Ping server override.{colors.end} ' if api.auth.get_runtime_options()['ping_server_override'] else ''}Starting pinger service...")
ping.host()
time.sleep(5)
@client.event
async def on_member_join(ctx):
"""This event is fired whenever a new member joins a server."""
# Automatically assigning roles to new members (autorole)
autorole = serverconfig.fetch_autorole(ctx.guild.id)
if autorole is not None:
role = discord.Guild.get_role(ctx.guild, int(autorole))
await ctx.add_roles(role, reason="Role assigned due to autoroles.")
# Welcome Message Autoresponder
welcome_message = serverconfig.fetch_welcome_message(ctx.guild.id)
if welcome_message["message"] is not None:
welcome_message_autoresponder_channel = client.get_channel(welcome_message["channel"])
# Perform attribute formatting for welcome message
welcome_message_formatted = welcome_message["message"]
welcome_message_formatted = welcome_message_formatted.replace("[user.nickname]", str(ctx.author.display_name))
welcome_message_formatted = welcome_message_formatted.replace("[user.username]", str(ctx.author.name))
welcome_message_formatted = welcome_message_formatted.replace("[user.mention]", str(ctx.author.mention))
welcome_message_formatted = welcome_message_formatted.replace("[server.name]", str(ctx.guild.name))
welcome_message_formatted = welcome_message_formatted.replace("[server.membercount]", str(ctx.guild.member_count))
await welcome_message_autoresponder_channel.send(welcome_message_formatted)
@client.event
async def on_member_leave(ctx):
"""This event is fired whenever a member leaves a server."""
# Goodbye Message Autoresponder
goodbye_message = serverconfig.fetch_goodbye_message(ctx.guild.id)
if goodbye_message["message"] is not None:
goodbye_message_autoresponder_channel = client.get_channel(goodbye_message["channel"])
# Perform attribute formatting for goodbye message
goodbye_message_formatted = goodbye_message["message"]
goodbye_message_formatted = goodbye_message_formatted.replace("[user.nickname]", str(ctx.author.display_name))
goodbye_message_formatted = goodbye_message_formatted.replace("[user.username]", str(ctx.author.name))
goodbye_message_formatted = goodbye_message_formatted.replace("[user.mention]", str(ctx.author.mention))
goodbye_message_formatted = goodbye_message_formatted.replace("[server.name]", str(ctx.guild.name))
goodbye_message_formatted = goodbye_message_formatted.replace("[server.membercount]", str(ctx.guild.member_count))
await goodbye_message_autoresponder_channel.send(goodbye_message_formatted)
@client.event
async def on_message(ctx):
"""This event is fired whenever a message is sent (in a readable channel)."""
runtimeconf = api.auth.get_runtime_options()
# Server Activity Logger
if runtimeconf["log_messages"]:
_user = str(ctx.author).split('#')[0]
_discrim = str(ctx.author).split('#')[-1]
try:
if str(ctx.guild.id) not in runtimeconf["guild_log_blacklist"]:
if _discrim == "0000":
logger.info(f"[{ctx.guild.name} -> #{ctx.channel.name}] New message received from {_user}[webhook] ({ctx.author.display_name})", timestamp=True)
elif _discrim == "0":
logger.info(f"[{ctx.guild.name} -> #{ctx.channel.name}] New message received from @{_user} ({ctx.author.display_name})", timestamp=True)
else:
logger.info(f"[{ctx.guild.name} -> #{ctx.channel.name}] New message received from {ctx.author} ({ctx.author.display_name})", timestamp=True)
except AttributeError:
if _discrim == "0":
logger.info(f"[DM] New message received from @{_user} ({ctx.author.display_name})", timestamp=True)
elif _discrim == "0000":
logger.info(f"[DM] New message received from {_user}[webhook] ({ctx.author.display_name})", timestamp=True)
else:
logger.info(f"[DM] New message received from {ctx.author} ({ctx.author.display_name})", timestamp=True)
if not ctx.author.bot:
# Check and initialize databases with new data for user.
currency.new_wallet(ctx.author.id)
currency.new_bank(ctx.author.id)
create_isocoin_key(ctx.author.id)
userdata.generate(ctx.author.id)
settings.generate(ctx.author.id)
items.generate(ctx.author.id)
levelling.generate(ctx.author.id)
try:
automod.generate(ctx.guild.id)
serverconfig.generate(ctx.guild.id)
embeds.generate_server_key(ctx.guild.id)
warningsdb.generate(ctx.guild.id, ctx.author.id)
except AttributeError: pass
try:
# AFK System Checker
presence_user_list = list()
presence = _presence.get_raw()
if str(ctx.guild.id) in presence:
for userid in presence[str(ctx.guild.id)].keys():
presence_user_list.append(userid)
for user in presence_user_list:
if str(user) in ctx.content and not ctx.author.bot:
fetch_user = await client.fetch_user(int(user))
await ctx.channel.send(f"{fetch_user.display_name} went AFK <t:{floor(presence[str(ctx.guild.id)][str(user)]['time'])}:R>: {presence[str(ctx.guild.id)][str(user)]['response']}")
if str(ctx.guild.id) in presence and str(ctx.author.id) in presence[str(ctx.guild.id)]:
_presence.remove_afk(ctx.guild.id, ctx.author.id)
afk_cleared_message = await ctx.channel.send(f"Welcome back {ctx.author.mention}. Your AFK has been removed.")
await asyncio.sleep(5)
await afk_cleared_message.delete()
# Swear-Filter
automod_config = automod.fetch_config(ctx.guild.id)
if (automod_config["swear_filter"]["enabled"]) and (not ctx.channel.is_nsfw()):
if (automod_config["swear_filter"]["keywords"]["use_default"] and any(x in ctx.content.lower() for x in automod_config["swear_filter"]["keywords"]["default"])) or (automod_config["swear_filter"]["keywords"]["custom"] != [] and any(x in ctx.content.lower() for x in automod_config["swear_filter"]["keywords"]["custom"])):
await ctx.delete()
await ctx.channel.send(f'{ctx.author.mention} watch your language.', delete_after=5)
# Link Blocker
if ("http://" in ctx.content.lower()) or ("https://" in ctx.content.lower()):
automod_config = automod.fetch_config(ctx.guild.id)
if automod_config["link_blocker"]["enabled"]:
if automod_config["link_blocker"]["use_whitelist_only"]:
if not any(x in ctx.content.lower() for x in automod_config["link_blocker"]["whitelisted"]["default"]):
await ctx.delete()
await ctx.channel.send(f'{ctx.author.mention} This link is not allowed in this server.', delete_after=5)
else:
if any(x in ctx.content.lower() for x in automod_config["link_blocker"]["blacklisted"]["default"]):
await ctx.delete()
await ctx.channel.send(f'{ctx.author.mention} This link is not allowed in this server.', delete_after=5)
except AttributeError: pass # Raised if the message isn't from a guild.
# Levelling System
levelling.add_xp(ctx.author.id, randint(1, 5))
xpreq = 0
for level in range(levelling.get_level(ctx.author.id)):
xpreq += 50
if xpreq >= 5000: break
if levelling.get_xp(ctx.author.id) >= xpreq:
levelling.set_xp(ctx.author.id, 0)
levelling.add_levels(ctx.author.id, 1)
if settings.fetch_setting(ctx.author.id, "levelup_messages") is True:
try:
if serverconfig.fetch_levelup_override_channel(ctx.guild.id) is None:
await ctx.author.send(f"{ctx.author.mention}, you just ranked up to **level {levelling.get_level(ctx.author.id)}**. Nice!\n\n{':bulb: Tip: This is your global message level and is the same across all servers. If you want to disable DMs for levelling up, run `/settings levelup_messages enabled: False`' if levelling.get_level(ctx.author.id) == 1 else ''}")
else:
channel = await client.get_channel(int(serverconfig.fetch_levelup_override_channel(ctx.guild.id)))
await channel.send(f"{ctx.author.mention}, you just ranked up to **level {levelling.get_level(ctx.author.id)}**. Nice!\n\n{':bulb: Tip: This is your global message level and is the same across all servers. If you want to disable messages for levelling up, run `/settings levelup_messages enabled: False`' if levelling.get_level(ctx.author.id) == 1 else ''}")
except discord.errors.Forbidden:
# Error is raised when the user isnt accepting DMs (or has blocked isobot)
# In that case isobot will automatically stop sending levelup messages to them
logger.warn(f"Unable to send level up message to {ctx.author} ({ctx.author.id}), as they are not accepting DMs from isobot. This ID has been added to `levelup_messages` blacklist.", module="main/Levelling")
settings.edit_setting(ctx.author.id, "levelup_messages", False)
# Autoresponder System
server_autoresponder_config: dict = serverconfig.fetch_autoresponder_configuration(ctx.guild.id)
for config in server_autoresponder_config.keys():
if server_autoresponder_config[config]["active_channel"] == None or server_autoresponder_config[config]["active_channel"] == ctx.channel.id:
if server_autoresponder_config[config]["match_case"]:
if server_autoresponder_config[config]["autoresponder_trigger_condition"] == "MATCH_MESSAGE":
if ctx.content == server_autoresponder_config[config]["autoresponder_trigger"]:
await ctx.channel.send(server_autoresponder_config[config]["autoresponder_text"])
elif server_autoresponder_config[config]["autoresponder_trigger_condition"] == "WITHIN_MESSAGE":
if server_autoresponder_config[config]["autoresponder_trigger"] in ctx.content:
await ctx.channel.send(server_autoresponder_config[config]["autoresponder_text"])
else:
if server_autoresponder_config[config]["autoresponder_trigger_condition"] == "MATCH_MESSAGE":
if ctx.content.lower() == server_autoresponder_config[config]["autoresponder_trigger"]:
await ctx.channel.send(server_autoresponder_config[config]["autoresponder_text"])
elif server_autoresponder_config[config]["autoresponder_trigger_condition"] == "WITHIN_MESSAGE":
if server_autoresponder_config[config]["autoresponder_trigger"] in ctx.content.lower():
await ctx.channel.send(server_autoresponder_config[config]["autoresponder_text"])
# Error handler
@client.event
async def on_application_command_error(ctx: ApplicationContext, error: discord.DiscordException):
"""An event handler to handle command exceptions when things go wrong.\n\nSome exceptions may be pre-handled, but any unhandable exceptions will be logged as an error."""
if not api.auth.get_runtime_options()["debug_mode"]:
if isinstance(error, commands.CommandOnCooldown): await ctx.respond(f":stopwatch: Not now! Please try after **{str(datetime.timedelta(seconds=int(round(error.retry_after))))}**")
elif isinstance(error, commands.MissingPermissions): await ctx.respond(":warning: You don't have the required server permissions to run this command!", ephemeral=True)
elif isinstance(error, commands.BadArgument): await ctx.respond(":x: Invalid argument.", ephemeral=True)
elif isinstance(error, commands.BotMissingPermissions): await ctx.respond(":x: I don\'t have the required permissions to use this.\nIf you think this is a mistake, please go to server settings and fix isobot's role permissions.")
elif isinstance(error, commands.BadBoolArgument): await ctx.respond(":x: Invalid true/false argument.", ephemeral=True)
elif isinstance(error, commands.NoPrivateMessage): await ctx.respond(":x: You can only use this command in a server!", ephemeral=True)
elif isinstance(error, commands.PrivateMessageOnly): await ctx.respond(":x: You can only use this command in isobot's DMs!", ephemeral=True)
else:
logger.error(f"Command failure: An uncaught error occured while running the command.\n >>> {error}", module="main/Client")
await ctx.respond(f"An uncaught error occured while running the command. (don't worry, developers will fix this soon)\n```\n{error}\n```")
# Help Commands
help_cmds = client.create_group("help", "Commands used for getting command help in the bot.")
@help_cmds.command(
name="list",
description="Get a list of all bot commands, or search for specific commands."
)
@option(name="search", description="Search query for looking-up commands", type=str, default=None)
async def help_list(ctx: ApplicationContext, search: str = None):
"""Get a list of all bot commands, or search for specific commands."""
commandsdb = _commands.fetch_raw()
commands_list = str()
localembed = None
if search is not None:
for _command in commandsdb:
if (search in _command) and (commandsdb[_command]["type"] != "DevTools"):
commands_list += f"`/{_command}` "
if commands_list == "":
commands_list = "*No commands were found*"
localembed = discord.Embed(title="Isobot Command Help", description=f"**Bot Commands:**\n{commands_list}", color=color)
localembed.set_footer(text=f"Search results for \"{search}\"")
else:
economy_commands = str()
levelling_commands = str()
utility_commands = str()
fun_commands = str()
reddit_commands = str()
afk_commands = str()
automod_moderation_commands = str()
serverconfig_commands = str()
maths_commands = str()
other_commands = str()
for _command in commandsdb:
command_type = commandsdb[_command]["type"]
if commandsdb[_command]["type"] != "DevTools":
if command_type == "economy system" or command_type == "minigames": economy_commands += f"`/{_command}` "
elif command_type == "levelling": levelling_commands += f"`/{_command}` "
elif command_type == "general utilities": utility_commands += f"`/{_command}` "
elif command_type == "fun": fun_commands += f"`/{_command}` "
elif command_type == "reddit media": reddit_commands += f"`/{_command}` "
elif command_type == "AFK system": afk_commands += f"`/{_command}` "
elif command_type == "automod" or command_type == "moderation": automod_moderation_commands += f"`/{_command}` "
elif command_type == "serverconfig": serverconfig_commands += f"`/{_command}` "
elif command_type == "maths": maths_commands += f"`/{_command}` "
else: other_commands += f"`/{_command}` "
commands_list = f"**:money_with_wings: Economy System:**\n{economy_commands}\n\n**:arrow_up: Levelling System:**\n{levelling_commands}\n\n**:toolbox: Utilities:**\n{utility_commands}\n\n**:joy: Fun Commands:**\n{fun_commands}\n\n**:crescent_moon: AFK System**\n{afk_commands}\n\n**:tools: Moderation and Automod:**\n{automod_moderation_commands}\n\n**:gear: Server Configuration:**\n{serverconfig_commands}\n\n**:1234: Maths Commands:**\n{maths_commands}\n\n**:frame_photo: Reddit Media Commands:**\n{reddit_commands}\n\n**:sparkles: Miscellaneous:**\n{other_commands}"
localembed = discord.Embed(title="Isobot Command Help", description=commands_list, color=color)
localembed.set_footer(text="Run \"/help info\" to get more information on a command.")
await ctx.respond(embed=localembed)
@help_cmds.command(
name="info",
description="Get detailed information on a specific isobot command."
)
@option(name="command", description="The name of the command you want help on.", type=str)
async def help_info(ctx: ApplicationContext, command: str):
"""Get detailed information on a specific isobot command."""
commandsdb = _commands.fetch_raw()
try:
localembed = discord.Embed(
title=f"{commandsdb[command]['name']} Command (/{command})",
description=commandsdb[command]['description'],
color=color
)
localembed.add_field(name="Command Type", value=commandsdb[command]['type'], inline=False)
if commandsdb[command]['cooldown'] is not None:
localembed.add_field(name="Cooldown", value=f"{str(datetime.timedelta(seconds=commandsdb[command]['cooldown']))}", inline=False)
localembed.add_field(name="Usable By", value=commandsdb[command]['usable_by'], inline=False)
if commandsdb[command]['args'] is not None:
args = ""
for arg in commandsdb[command]['args']: args += f"`{arg}` "
localembed.add_field(name="Arguments", value=args, inline=False)
if commandsdb[command]['bugged'] is True:
localembed.set_footer(text="⚠ This command might be bugged (experiencing issues), but will be fixed later.")
if commandsdb[command]['disabled'] is True:
localembed.set_footer(text="⚠ This command is currently disabled")
await ctx.respond(embed=localembed)
except KeyError:
return await ctx.respond(
embed=discord.Embed(description=f"No results found for {command}."),
ephemeral=True
)
# Cog Commands (these cannot be moved into a cog)
cogs = client.create_group("cog", "Commands for working with isobot cogs.")
@cogs.command(
name="load",
description="Loads a cog."
)
@option(name="cog", description="What cog do you want to load?", type=str)
async def load(ctx: ApplicationContext, cog: str):
"""Loads a cog."""
if ctx.author.id != 738290097170153472:
return await ctx.respond("You can't use this command!", ephemeral=True)
try:
client.load_extension(f"cogs.{cog}")
await ctx.respond(
embed=discord.Embed(
description=f"{cog} cog successfully loaded.",
color=discord.Color.green()
)
)
except discord.errors.ExtensionNotFound:
return await ctx.respond(
embed=discord.Embed(
title=f"{cog} failed to load",
description="Cog does not exist.",
color=discord.Color.red()
)
)
except discord.errors.ExtensionAlreadyLoaded:
return await ctx.respond(
embed=discord.Embed(
title=f"{cog} failed to load",
description="Cog is already loaded to the client.",
color=discord.Color.red()
)
)
@cogs.command(
name="disable",
description="Disables a cog."
)
@option(name="cog", description="What cog do you want to disable?", type=str)
async def disable(ctx: ApplicationContext, cog: str):
"""Disables a cog."""
if ctx.author.id != 738290097170153472:
return await ctx.respond("You can't use this command!", ephemeral=True)
try:
client.unload_extension(f"cogs.{cog}")
await ctx.respond(
embed=discord.Embed(
description=f"{cog} cog successfully disabled.",
color=discord.Color.green()
)
)
except discord.errors.ExtensionNotFound:
return await ctx.respond(
embed=discord.Embed(
title=f"{cog} failed to disable",
description="Cog does not exist.",
color=discord.Color.red()
)
)
@cogs.command(
name="reload",
description="Reloads a cog."
)
@option(name="cog", description="What cog do you want to reload?", type=str)
async def reload(ctx: ApplicationContext, cog: str):
"""Reloads a cog."""
if ctx.author.id != 738290097170153472:
return await ctx.respond("You can't use this command!", ephemeral=True)
try:
client.reload_extension(f"cogs.{cog}")
await ctx.respond(
embed=discord.Embed(
description=f"{cog} cog successfully reloaded.",
color=discord.Color.green()
)
)
except discord.errors.ExtensionNotFound:
return await ctx.respond(
embed=discord.Embed(
title=f"{cog} failed to reload",
description="Cog does not exist.",
color=discord.Color.red()
)
)
# Settings commands
config = client.create_group("settings", "Commands used to change bot settings.")
@config.command(
name="levelup_messages",
description="Configure whether you want to be notified for level ups or not."
)
@option(name="enabled", description="Do you want this setting enabled?", type=bool)
async def levelup_messages(ctx: ApplicationContext, enabled: bool):
"""Configure whether you want to be notified for level ups or not."""
if settings.fetch_setting(ctx.author.id, "levelup_messages") == enabled:
return await ctx.respond("This is already done.", ephemeral=True)
settings.edit_setting(ctx.author.id, "levelup_messages", enabled)
localembed = discord.Embed(
description="Setting successfully updated.",
color=discord.Color.green()
)
await ctx.respond(embed=localembed)
# Extra commands
@client.slash_command(
name="delete_my_data",
description="Deletes all of your isobot data permanently."
)
async def delete_my_data(ctx: ApplicationContext):
"""Deletes all of your isobot data permanently."""
currency.delete_user(ctx.author.id)
levelling.delete_user(ctx.author.id)
items.delete_user(ctx.author.id)
userdata.delete_user(ctx.author.id)
weather.delete_user(ctx.author.id)
localembed = discord.Embed(title=":white_check_mark: Successfully deleted all of your isobot data.", color=discord.Color.green())
localembed.add_field(
name="What has been deleted",
value="- Your currency wallet and bank data\n- Your user levels\n- Items in your inventory\n- Weather save data\n- All of your isobot user settings"
)
localembed.add_field(
name="What has not been deleted",
value="- Any isobot data relating to your servers"
)
await ctx.respond(embed=localembed, ephemeral=True)
@client.slash_command(
name="credits",
description="See the credits for isobot's development."
)
async def credits(ctx: ApplicationContext):
"""See the credits for isobot's development."""
localembed = discord.Embed(
title="Credits",
description="A very big thank you to everyone who has helped support the isobot project's development! :)\n\n**Head Devs:**\n- @notsniped (owner)\n- @dtxc (head-dev)\n- @XyrenChess (head-dev)\n\nisobot (C) 2020-2024\nNKA (C) 2022-2024",
color=color
)
await ctx.respond(embed=localembed)
# Initialization
active_cogs = (
"economy",
"maths",
"reddit",
"moderation",
"minigames",
"automod",
"serverconfig",
"isobank",
"levelling",
"fun",
"utils",
"afk",
# "osu", Disabled due to ossapi library metadata issues. (will probably remove osu cog anyway, because cog code is outdated with ossapi library)
"weather",
"isocard"
)
i = 1
cog_errors = 0
for x in active_cogs:
s.log(f"[main/Cogs] Loading isobot '{x}' Cog ({i}/{len(active_cogs)})")
i += 1
try: client.load_extension(f"cogs.{x}")
except discord.errors.ExtensionFailed as e:
cog_errors += 1
logger.error(f"Cog '{x}' failed to load: {e}", module="main/Cogs")
if cog_errors == 0: s.log(f"[main/Cogs] {colors.green}All cogs successfully loaded.{colors.end}")
else: s.log(f"[main/Cogs] {colors.yellow}{cog_errors}/{len(active_cogs)} cogs failed to load.{colors.end}")
s.log("--------------------")
s.log(f"[main/Client] Starting client in {f'{colors.cyan}Replit mode{colors.end}' if api.auth.get_mode() else f'{colors.orange}local mode{colors.end}'}...")
if api.auth.get_mode(): client.run(os.getenv("TOKEN"))
else: client.run(api.auth.get_token())
# btw i use arch