Adapt to yaboli changes
Also rewrote the help message.
This commit is contained in:
parent
12035ec576
commit
b7feb58a58
2 changed files with 48 additions and 20 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -1,5 +1,5 @@
|
|||
**/__pycache__
|
||||
yaboli
|
||||
websockets
|
||||
join_rooms.py
|
||||
*.cookie
|
||||
*.conf
|
||||
|
|
|
|||
66
roller.py
66
roller.py
|
|
@ -1,11 +1,12 @@
|
|||
import asyncio
|
||||
import configparser
|
||||
import logging
|
||||
import random
|
||||
import re
|
||||
|
||||
import yaboli
|
||||
from yaboli.utils import *
|
||||
from join_rooms import join_rooms # List of rooms kept in separate file, which is .gitignore'd
|
||||
|
||||
|
||||
# Turn all debugging on
|
||||
asyncio.get_event_loop().set_debug(True)
|
||||
|
|
@ -20,20 +21,37 @@ ADVANTAGE = r"\s*([+-])?\s*(\d+)?([ad])d(\d+)" # 1: sign, 2: amount (default 2),
|
|||
NUMBER = r"\s*([+-])?\s*(\d+)" # 1: sign, 2: number
|
||||
|
||||
class Roller(yaboli.Bot):
|
||||
async def on_send(self, room, message):
|
||||
long_help = (
|
||||
"!roll 2d4 - roll 2 4-sided dice\n"
|
||||
"!roll 2d4+5 - roll 2 4-sided dice with a bonus of 5\n"
|
||||
"/roll can be used instead of !roll.\n"
|
||||
)
|
||||
await self.botrulez_ping_general(room, message)
|
||||
await self.botrulez_ping_specific(room, message)
|
||||
await self.botrulez_help_general(room, message, text="I roll dice")
|
||||
await self.botrulez_help_specific(room, message, text=long_help)
|
||||
await self.botrulez_uptime(room, message)
|
||||
await self.botrulez_kill(room, message)
|
||||
await self.botrulez_restart(room, message)
|
||||
LONG_HELP = (
|
||||
"!roll <dice> <description> - roll dice\n"
|
||||
"/roll can be used instead of !roll. !r and /r also work.\n"
|
||||
"\n"
|
||||
"Dice throws, can be added/subtracted to each other:\n"
|
||||
"XdY - Throw X Y-sided dice. X defaults to 1.\n"
|
||||
"XadY - Throw X Y-sided dice with advantage. X defaults to 2.\n"
|
||||
"XddY - Throw X Y-sided dice with disadvantage. X defaults to 2.\n"
|
||||
"X - Constant number\n"
|
||||
"\n"
|
||||
"Example throws:\n"
|
||||
"!roll d20\n"
|
||||
"/roll ad20 + 5 damage\n"
|
||||
"!r 2d20-d10+10\n"
|
||||
)
|
||||
|
||||
async def on_command_specific(self, room, message, command, nick, argstr):
|
||||
if similar(nick, room.session.nick) and not argstr:
|
||||
await self.botrulez_ping(room, message, command)
|
||||
await self.botrulez_help(room, message, command, text=self.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):
|
||||
if not argstr:
|
||||
await self.botrulez_ping(room, message, command)
|
||||
await self.botrulez_help(room, message, command, text="I roll dice for dnd")
|
||||
|
||||
async def on_send(self, room, message):
|
||||
await super().on_send(room, message)
|
||||
await self.trigger_roll(room, message)
|
||||
|
||||
@yaboli.trigger(ROLL)
|
||||
|
|
@ -121,17 +139,27 @@ class Roller(yaboli.Bot):
|
|||
results = [random.randint(1, sides) for _ in range(amount)]
|
||||
result = min(results) if dis else max(results)
|
||||
resultstr = "(" + ",".join(str(r) for r in results) + ")"
|
||||
resultstr = ("min" if dis else "max") + resultstr
|
||||
resultstr = ("d" if dis else "a") + resultstr
|
||||
return result, resultstr
|
||||
|
||||
@staticmethod
|
||||
def number(number):
|
||||
return number, str(number)
|
||||
|
||||
def main():
|
||||
bot = Roller("Roller", "roller.cookie")
|
||||
join_rooms(bot)
|
||||
def main(configfile):
|
||||
config = configparser.ConfigParser(allow_no_value=True)
|
||||
config.read(configfile)
|
||||
|
||||
nick = config.get("general", "nick")
|
||||
cookiefile = config.get("general", "cookiefile", fallback=None)
|
||||
bot = Roller(nick, cookiefile=cookiefile)
|
||||
|
||||
for room, password in config.items("rooms"):
|
||||
if not password:
|
||||
password = None
|
||||
bot.join_room(room, password=password)
|
||||
|
||||
asyncio.get_event_loop().run_forever()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
main("roller.conf")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue