Add !restart command to botrulez

This commit is contained in:
Joscha 2019-04-12 23:14:16 +00:00
parent b7579b5b78
commit b726d8f9f0
4 changed files with 20 additions and 3 deletions

View file

@ -2,6 +2,8 @@
## Next version ## Next version
- add !restart to botrulez
## 0.2.0 (2019-04-12) ## 0.2.0 (2019-04-12)
- change config file format - change config file format

View file

@ -58,7 +58,6 @@ i. e. the text between the end of the "!echo" and the end of the whole message.
## TODOs ## TODOs
- [ ] implement !restart
- [ ] document yaboli (markdown files in a "docs" folder?) - [ ] document yaboli (markdown files in a "docs" folder?)
- [ ] cookie support - [ ] cookie support
- [ ] fancy argument parsing - [ ] 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] make it easier to run bots
- [x] package in a distutils-compatible way (users should be able to install - [x] package in a distutils-compatible way (users should be able to install
yaboli using `pip install git+https://github.com/Garmelon/yaboli`) yaboli using `pip install git+https://github.com/Garmelon/yaboli`)
- [x] implement !restart

View file

@ -52,7 +52,8 @@ def run(
config_file: str = "bot.conf" config_file: str = "bot.conf"
) -> None: ) -> None:
async def _run() -> None: async def _run() -> None:
client_ = client(config_file) while True:
await client_.run() client_ = client(config_file)
await client_.run()
asyncio.run(_run()) asyncio.run(_run())

View file

@ -20,6 +20,7 @@ class Bot(Client):
HELP_GENERAL: Optional[str] = None HELP_GENERAL: Optional[str] = None
HELP_SPECIFIC: Optional[List[str]] = None HELP_SPECIFIC: Optional[List[str]] = None
KILL_REPLY: str = "/me dies" KILL_REPLY: str = "/me dies"
RESTART_REPLY: str = "/me restarts"
GENERAL_SECTION = "general" GENERAL_SECTION = "general"
ROOMS_SECTION = "rooms" ROOMS_SECTION = "rooms"
@ -102,6 +103,7 @@ class Bot(Client):
help_: bool = True, help_: bool = True,
uptime: bool = True, uptime: bool = True,
kill: bool = False, kill: bool = False,
restart: bool = False,
) -> None: ) -> None:
if ping: if ping:
self.register_general("ping", self.cmd_ping, args=False) self.register_general("ping", self.cmd_ping, args=False)
@ -120,6 +122,9 @@ class Bot(Client):
if kill: if kill:
self.register_specific("kill", self.cmd_kill, args=False) 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, async def cmd_ping(self,
room: Room, room: Room,
message: LiveMessage, message: LiveMessage,
@ -161,3 +166,12 @@ class Bot(Client):
logger.info(f"Killed in &{room.name} by {message.sender.atmention}") logger.info(f"Killed in &{room.name} by {message.sender.atmention}")
await message.reply(self.KILL_REPLY) await message.reply(self.KILL_REPLY)
await self.part(room) 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()