initial
This commit is contained in:
53
lib/discord_bot.py
Normal file
53
lib/discord_bot.py
Normal file
@@ -0,0 +1,53 @@
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
# from apscheduler.schedulers.background import BackgroundScheduler
|
||||
from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
||||
|
||||
|
||||
from dotenv import dotenv_values
|
||||
from lib.logging_data import logger
|
||||
|
||||
|
||||
|
||||
|
||||
# Bot configuration
|
||||
intents = discord.Intents.default()
|
||||
intents.message_content = True
|
||||
intents.members = True
|
||||
|
||||
|
||||
class ScheduleBot(commands.Bot):
|
||||
def __init__(self,console=None, **kwargs):
|
||||
super().__init__(
|
||||
command_prefix='!',
|
||||
intents=intents,
|
||||
help_command=None,
|
||||
**kwargs
|
||||
)
|
||||
self.console = console if console else logger("./log/app.log",gotify_config=dotenv_values('.env')['gotify_token'])
|
||||
|
||||
self.dotenv_path='.env'
|
||||
|
||||
self.scheduler = AsyncIOScheduler(
|
||||
job_defaults={
|
||||
'misfire_grace_time': 300, # run if up to 5 minutes late
|
||||
'max_instances': 1, # prevent overlapping runs for the same job
|
||||
'coalesce': True # useful for cron/interval jobs
|
||||
})
|
||||
# self.sonarr_ip = dotenv_values(self.dotenv_path)['sonarr_ip']
|
||||
# self.sonarr_key = dotenv_values(self.dotenv_path)['sonarr_key']
|
||||
# self.sonarr = Sonarr_API(self.sonarr_ip, self.sonarr_key)
|
||||
|
||||
|
||||
|
||||
async def setup_hook(self):
|
||||
"""Called when the bot is starting up"""
|
||||
self.console.log(f"Logged in as {self.user} (ID: {self.user.id})")
|
||||
|
||||
# Sync slash commands
|
||||
try:
|
||||
synced = await self.tree.sync()
|
||||
self.console.log(f"Synced {len(synced)} command(s)")
|
||||
# threading.Thread(target=vt_worker).start() # Start the download worker in the background
|
||||
except Exception as e:
|
||||
self.console.log(f"Failed to sync commands: {e}")
|
||||
Reference in New Issue
Block a user