diff --git a/CHANGELOG.md b/CHANGELOG.md index f754075..0437e49 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Next version +- add !restart to botrulez + ## 0.2.0 (2019-04-12) - change config file format diff --git a/README.md b/README.md index 0c0b0bd..e779c40 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,6 @@ i. e. the text between the end of the "!echo" and the end of the whole message. ## TODOs -- [ ] implement !restart - [ ] document yaboli (markdown files in a "docs" folder?) - [ ] cookie support - [ ] fancy argument parsing @@ -74,3 +73,4 @@ i. e. the text between the end of the "!echo" and the end of the whole message. - [x] make it easier to run bots - [x] package in a distutils-compatible way (users should be able to install yaboli using `pip install git+https://github.com/Garmelon/yaboli`) +- [x] implement !restart diff --git a/yaboli/__init__.py b/yaboli/__init__.py index ac1c244..a964c61 100644 --- a/yaboli/__init__.py +++ b/yaboli/__init__.py @@ -52,7 +52,8 @@ def run( config_file: str = "bot.conf" ) -> None: async def _run() -> None: - client_ = client(config_file) - await client_.run() + while True: + client_ = client(config_file) + await client_.run() asyncio.run(_run()) diff --git a/yaboli/bot.py b/yaboli/bot.py index 7c96f29..de6af0e 100644 --- a/yaboli/bot.py +++ b/yaboli/bot.py @@ -20,6 +20,7 @@ class Bot(Client): HELP_GENERAL: Optional[str] = None HELP_SPECIFIC: Optional[List[str]] = None KILL_REPLY: str = "/me dies" + RESTART_REPLY: str = "/me restarts" GENERAL_SECTION = "general" ROOMS_SECTION = "rooms" @@ -102,6 +103,7 @@ class Bot(Client): help_: bool = True, uptime: bool = True, kill: bool = False, + restart: bool = False, ) -> None: if ping: self.register_general("ping", self.cmd_ping, args=False) @@ -120,6 +122,9 @@ class Bot(Client): if kill: self.register_specific("kill", self.cmd_kill, args=False) + if restart: + self.register_specific("restart", self.cmd_restart, args=False) + async def cmd_ping(self, room: Room, message: LiveMessage, @@ -161,3 +166,12 @@ class Bot(Client): logger.info(f"Killed in &{room.name} by {message.sender.atmention}") await message.reply(self.KILL_REPLY) await self.part(room) + + async def cmd_restart(self, + room: Room, + message: LiveMessage, + args: SpecificArgumentData + ) -> None: + logger.info(f"Restarted in &{room.name} by {message.sender.atmention}") + await message.reply(self.RESTART_REPLY) + await self.stop()