forked from sh-edraft.de/sh_discord_bot
Added restart command
This commit is contained in:
@@ -15,7 +15,7 @@ __title__ = 'bot'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2022 sh-edraft.de'
|
||||
__version__ = '1.0.0.dev1'
|
||||
__version__ = '1.0.0.dev2'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='1', minor='0', micro='0.dev1')
|
||||
version_info = VersionInfo(major='1', minor='0', micro='0.dev2')
|
||||
|
@@ -66,3 +66,6 @@ class Application(DiscordBotApplicationABC):
|
||||
self._logger.error(__name__, 'stop failed', e)
|
||||
|
||||
Console.write_line()
|
||||
|
||||
def is_restart(self):
|
||||
return True if self._configuration.get_configuration('IS_RESTART') == 'true' else False
|
||||
|
@@ -4,7 +4,7 @@
|
||||
"Version": {
|
||||
"Major": "1",
|
||||
"Minor": "0",
|
||||
"Micro": "0.dev1"
|
||||
"Micro": "0.dev2"
|
||||
},
|
||||
"Author": "Sven Heidemann",
|
||||
"AuthorEmail": "sven.heidemann@sh-edraft.de",
|
||||
@@ -50,7 +50,9 @@
|
||||
"../modules/base/base.json",
|
||||
"../modules/boot_log/boot-log.json",
|
||||
"../modules/database/database.json",
|
||||
"../modules/permission/permission.json"
|
||||
"../modules/permission/permission.json",
|
||||
"../modules/admin/admin.json",
|
||||
"../modules/moderator/moderator.json"
|
||||
]
|
||||
}
|
||||
}
|
@@ -17,7 +17,7 @@
|
||||
},
|
||||
"DiscordBot": {
|
||||
"Token": "OTk4MTYwNDI3Njg5MTgxMjM3.GI7h67.BqD6Lu1Tz0MuG8iktYrcLnHi1pNozyMiWFGTKI",
|
||||
"Prefix": "!kde "
|
||||
"Prefix": "!ke "
|
||||
},
|
||||
"Bot": {
|
||||
"910199451145076828": {
|
||||
|
@@ -2,6 +2,7 @@ import asyncio
|
||||
from typing import Optional
|
||||
|
||||
from cpl_core.application import ApplicationBuilder
|
||||
from cpl_core.console import Console
|
||||
|
||||
from bot.application import Application
|
||||
from bot.startup import Startup
|
||||
@@ -11,31 +12,46 @@ from modules.boot_log.boot_log_extension import BootLogExtension
|
||||
from modules.database.database_extension import DatabaseExtension
|
||||
|
||||
|
||||
class Main:
|
||||
class Program:
|
||||
|
||||
def __init__(self):
|
||||
self._app: Optional[Application] = None
|
||||
self.app: Optional[Application] = None
|
||||
|
||||
async def main(self):
|
||||
async def start(self):
|
||||
app_builder = ApplicationBuilder(Application)
|
||||
app_builder.use_extension(StartupDiscordExtension)
|
||||
app_builder.use_extension(StartupMigrationExtension)
|
||||
app_builder.use_extension(BootLogExtension)
|
||||
app_builder.use_extension(DatabaseExtension)
|
||||
app_builder.use_startup(Startup)
|
||||
self._app: Application = await app_builder.build_async()
|
||||
await self._app.run_async()
|
||||
self.app: Application = await app_builder.build_async()
|
||||
await self.app.run_async()
|
||||
|
||||
async def stop(self):
|
||||
await self._app.stop_async()
|
||||
await self.app.stop_async()
|
||||
|
||||
|
||||
def main():
|
||||
program = Program()
|
||||
try:
|
||||
asyncio.run(program.start())
|
||||
except KeyboardInterrupt:
|
||||
asyncio.run(program.stop())
|
||||
except Exception as e:
|
||||
Console.error(f'[ ERROR ] [ {__name__} ]: Cannot start the bot', str(e))
|
||||
finally:
|
||||
try:
|
||||
asyncio.run(program.stop())
|
||||
except Exception as e:
|
||||
Console.error(f'[ ERROR ] [ {__name__} ]: Cannot stop the bot', str(e))
|
||||
|
||||
if program.app is not None and program.app.is_restart():
|
||||
del program
|
||||
main()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main = Main()
|
||||
try:
|
||||
asyncio.run(main.main())
|
||||
except KeyboardInterrupt:
|
||||
asyncio.run(main.stop())
|
||||
main()
|
||||
|
||||
# ((
|
||||
# ( `)
|
||||
|
@@ -5,6 +5,7 @@ from cpl_core.environment import ApplicationEnvironmentABC
|
||||
from cpl_discord import get_discord_collection
|
||||
from cpl_discord.discord_event_types_enum import DiscordEventTypesEnum
|
||||
|
||||
from modules.admin.command.restart_command import RestartCommand
|
||||
from modules.base.command.afk_command import AFKCommand
|
||||
from modules.base.command.help_command import HelpCommand
|
||||
from modules.base.command.info_command import InfoCommand
|
||||
@@ -33,11 +34,15 @@ class StartupDiscordExtension(StartupExtensionABC):
|
||||
services.add_discord()
|
||||
dc = get_discord_collection(services)
|
||||
""" commands """
|
||||
# admin
|
||||
dc.add_command(RestartCommand)
|
||||
# moderator
|
||||
dc.add_command(PurgeCommand)
|
||||
# simple
|
||||
dc.add_command(AFKCommand)
|
||||
dc.add_command(HelpCommand)
|
||||
dc.add_command(InfoCommand)
|
||||
dc.add_command(PingCommand)
|
||||
dc.add_command(PurgeCommand)
|
||||
dc.add_command(UserInfoCommand)
|
||||
""" events """
|
||||
# on_member_join
|
||||
|
@@ -6,6 +6,10 @@
|
||||
"not_implemented_yet": "Ey Alter, das kann ich noch nicht..."
|
||||
},
|
||||
"modules": {
|
||||
"admin": {
|
||||
"restart_message": "Bin gleich wieder da :D"
|
||||
},
|
||||
"moderator": {},
|
||||
"base": {
|
||||
"welcome_message": "Hello There!\nIch heiße dich bei {} herzlichst willkommen!",
|
||||
"welcome_message_for_team": "{} hat gerade das Irrenhaus betreten.",
|
||||
|
Reference in New Issue
Block a user