2023-10-29 12:55:08 +02:00
|
|
|
import sys
|
|
|
|
|
2023-10-10 22:21:19 +03:00
|
|
|
import discord
|
|
|
|
from discord.ext import commands, tasks
|
|
|
|
from dotenv import load_dotenv
|
2024-07-28 21:19:29 +03:00
|
|
|
import gettext
|
2023-10-10 22:21:19 +03:00
|
|
|
import logging
|
|
|
|
import os
|
|
|
|
|
2023-10-29 15:56:52 +02:00
|
|
|
import errlogging
|
2023-10-10 22:21:19 +03:00
|
|
|
from cog_notificator import Notificator
|
|
|
|
|
|
|
|
# Set up constants and logger
|
|
|
|
logger = logging.Logger('General Log')
|
|
|
|
load_dotenv()
|
|
|
|
TOKEN = os.getenv('TOKEN')
|
|
|
|
AUTHOR_ID = int(os.getenv('AUTHOR_ID'))
|
|
|
|
|
|
|
|
handler = logging.StreamHandler()
|
2023-10-29 15:56:52 +02:00
|
|
|
logger.addHandler(handler)
|
2023-10-10 22:21:19 +03:00
|
|
|
|
|
|
|
bot = commands.Bot('!', intents=discord.Intents.all())
|
|
|
|
tree = bot.tree
|
|
|
|
|
|
|
|
|
|
|
|
@bot.event
|
|
|
|
async def on_message(msg: discord.Message):
|
|
|
|
# Special command to sync messages
|
|
|
|
if msg.content == '/sync_cmds' and msg.author.id == AUTHOR_ID:
|
|
|
|
print('syncing')
|
|
|
|
await msg.reply('Syncing...', delete_after=3)
|
|
|
|
await Notificator.setup(bot, handler)
|
|
|
|
await tree.sync()
|
|
|
|
print('synced')
|
|
|
|
await msg.reply('Synced!', delete_after=3)
|
|
|
|
|
|
|
|
|
|
|
|
@bot.event
|
|
|
|
async def on_ready():
|
|
|
|
await bot.change_presence(activity=discord.Activity(name='for HFC alerts.', type=discord.ActivityType.watching))
|
|
|
|
|
2023-10-29 15:56:52 +02:00
|
|
|
errlogging.generate_errlog_folder()
|
2023-10-29 12:55:08 +02:00
|
|
|
|
|
|
|
await Notificator.setup(bot, handler)
|
|
|
|
|
|
|
|
|
2024-07-28 21:19:29 +03:00
|
|
|
@bot.event
|
|
|
|
async def on_resume():
|
|
|
|
if bot.get_cog('Notificator') is None:
|
|
|
|
await Notificator.setup(bot, handler)
|
|
|
|
|
|
|
|
|
2023-10-29 12:55:08 +02:00
|
|
|
@bot.event
|
|
|
|
async def on_error(event, *args, **kwargs):
|
2023-10-29 15:56:52 +02:00
|
|
|
logger.error('An error has occurred! Check the latest ERRLOG for more info')
|
|
|
|
errlogging.new_errlog(sys.exc_info()[1])
|
2023-10-10 22:21:19 +03:00
|
|
|
|
|
|
|
bot.run(token=TOKEN, log_handler=handler)
|