-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
105 lines (81 loc) · 3.11 KB
/
main.py
File metadata and controls
105 lines (81 loc) · 3.11 KB
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
import os
import datetime
from dotenv import load_dotenv
import discord
from discord.ext import commands
from discord.ext.commands.errors import CommandNotFound, NotOwner
from api import maplist
from core.commands import Commands
from core.appcommands import AppCommands
from core.event_listeners import EventListeners
from core.scheduled_tasks import ScheduledTasks
from core.config import Config
load_dotenv()
TOKEN = os.getenv('TOKEN')
CONFIGPATH = os.getenv('CONFIGPATH')
bot = commands.Bot(
command_prefix='\\',
intents=discord.Intents.all(),
help_command=None
)
config = Config(CONFIGPATH, bot)
@bot.event
async def on_ready():
config.load()
await bot.add_cog(Commands(bot, config))
await bot.add_cog(AppCommands(bot, config))
await bot.add_cog(EventListeners(bot, config))
await bot.add_cog(ScheduledTasks(bot, config))
await ScheduledTasks.update_map_embeds(bot.guilds, config)
await ScheduledTasks.update_shop_embeds(bot.guilds, config)
await ScheduledTasks.check_new_patch(bot.guilds, config)
print(f'Connected: {datetime.datetime.now().strftime("%m/%d/%Y %H:%M:%S")}')
@bot.event
async def on_command_error(ctx: commands.Context, error):
if isinstance(error, (CommandNotFound, NotOwner)):
return
if debug_id := config[ctx.guild.id]['channels']['debug']:
await ctx.guild.get_channel(debug_id).send(f'{error}')
raise error
# DEBUG COMMANDS
@bot.command(name='sync')
@commands.is_owner()
async def sync_app_commands(ctx: commands.Context):
""" Only bot owner can use. Syncs application commands. """
msg = await ctx.reply('Syncing...')
synced = await bot.tree.sync()
await msg.edit(content=f'Synced {len(synced)} app commands.')
@bot.command(name='get-config')
@commands.is_owner()
async def get_config(ctx: commands.Context):
""" Only bot owner can use. Send config.json file for debugging. """
await ctx.send(file=discord.File(config.path))
@bot.command(name='set-config')
@commands.is_owner()
async def set_config(ctx: commands.Context):
""" Only bot owner can use. Overwrite config.json with given file. """
if not ctx.message.attachments:
await ctx.send('Missing attachment')
return
await ctx.send(content='Old config:', file=discord.File(config.path))
await ctx.message.attachments[0].save(fp=config.path)
config.load()
await ctx.send('Successfully updated config')
@bot.command(name='get-maplist')
@commands.is_owner()
async def get_config(ctx: commands.Context):
""" Only bot owner can use. Send maplist.json file. """
await ctx.send(file=discord.File(maplist.path))
@bot.command(name='set-maplist')
@commands.is_owner()
async def set_config(ctx: commands.Context):
""" Only bot owner can use. Overwrite maplist.json with given file. """
if not ctx.message.attachments:
await ctx.send('Missing attachment')
return
# await ctx.send(content='Old maplist:', file=discord.File(maplist.path))
await ctx.message.attachments[0].save(fp=maplist.path)
maplist.reload()
await ctx.send('Successfully updated maplist')
if __name__ == '__main__':
bot.run(TOKEN)