config initialization

This commit is contained in:
Sebastian Mäki 2024-02-20 12:52:25 +02:00
parent 25bc1f21c0
commit fdd2aed0b8
1 changed files with 17 additions and 2 deletions

View File

@ -12,8 +12,8 @@ from ovos_utils.log import LOG
from ovos_utils import classproperty from ovos_utils import classproperty
from ovos_utils.process_utils import RuntimeRequirements from ovos_utils.process_utils import RuntimeRequirements
from json_database import JsonConfigXDG from json_database import JsonConfigXDG
class DiscordBotPlugin(PHALPlugin): class DiscordBotPlugin(PHALPlugin):
def __init__(self, bus=None, config=None): def __init__(self, bus=None, config=None):
super().__init__(bus, "ovos-PHAL-plugin-discord-bot", config) super().__init__(bus, "ovos-PHAL-plugin-discord-bot", config)
@ -28,6 +28,17 @@ class DiscordBotPlugin(PHALPlugin):
self.bus.on("configuration.updated", self.init_configuration) self.bus.on("configuration.updated", self.init_configuration)
reinstall_hint = "pip install --upgrade --no-deps --force-reinstall git+https://git.sebastianmaki.fi/sebastian/ovos-PHAL-plugin-discord-bot.git" reinstall_hint = "pip install --upgrade --no-deps --force-reinstall git+https://git.sebastianmaki.fi/sebastian/ovos-PHAL-plugin-discord-bot.git"
LOG.info(f"Reinstall hint: {reinstall_hint}") LOG.info(f"Reinstall hint: {reinstall_hint}")
# Discord event: bot is ready
@self.bot.event
async def on_ready():
myLoop.start()
print(f'{bot.user} has connected to Discord!')
admin = await get_discord_user_by_id(DISCORD_ADMIN_ID)
if admin:
print(f"Admin is {admin.name}")
await admin.send("I'm now online")
self.setup_configuration() self.setup_configuration()
@classproperty @classproperty
@ -94,5 +105,9 @@ class DiscordBotPlugin(PHALPlugin):
# Start the Discord bot # Start the Discord bot
LOG.info("Starting the bot") LOG.info("Starting the bot")
self.bot.run(self.api_token) self.bot.run(self.api_token)
# Helper function to get Discord user by ID
async def get_discord_user_by_id(user_id) -> discord.User:
return await self.bot.fetch_user(user_id)