Restructure command parsing

This commit is contained in:
Joscha 2018-08-04 10:36:45 +00:00
parent ac04e7fd30
commit aee21f359c
2 changed files with 47 additions and 42 deletions

View file

@ -13,21 +13,25 @@ logging.basicConfig(level=logging.DEBUG)
class ExampleBot(yaboli.Bot):
async def on_send(self, room, message):
ping = "ExamplePong!"
short_help = "Example bot for the yaboli bot library"
async def on_command_specific(self, room, message, command, nick, argstr):
long_help = (
"I'm an example bot for the yaboli bot library,"
" which can be found at https://github.com/Garmelon/yaboli"
)
await self.botrulez_ping_general(room, message, text=ping)
await self.botrulez_ping_specific(room, message, text=ping)
await self.botrulez_help_general(room, message, text=short_help)
await self.botrulez_help_specific(room, message, text=long_help)
await self.botrulez_uptime(room, message)
await self.botrulez_kill(room, message, text="/me dies spectacularly")
await self.botrulez_restart(room, message, text="/me restarts spectacularly")
if similar(nick, room.session.nick) and not argstr:
await self.botrulez_ping(room, message, command, text="ExamplePong!")
await self.botrulez_help(room, message, command, text=long_help)
await self.botrulez_uptime(room, message, command)
await self.botrulez_kill(room, message, command)
await self.botrulez_restart(room, message, command)
async def on_command_general(self, room, message, command, argstr):
short_help = "Example bot for the yaboli bot library"
if not argstr:
await self.botrulez_ping(room, message, command, text="ExamplePong!")
await self.botrulez_help(room, message, command, text=short_help)
def main(configfile):
config = configparser.ConfigParser(allow_no_value=True)
@ -35,7 +39,6 @@ def main(configfile):
nick = config.get("general", "nick")
cookiefile = config.get("general", "cookiefile", fallback=None)
print(cookiefile)
bot = ExampleBot(nick, cookiefile=cookiefile)
for room, password in config.items("rooms"):