Update to yaboli 1.1.2

This commit is contained in:
Joscha 2019-04-14 21:49:30 +00:00
parent 45e5c006e7
commit bf5c619da0
5 changed files with 286 additions and 292 deletions

14
.gitignore vendored
View file

@ -1,3 +1,13 @@
**/__pycache__
*.cookie
# python stuff
__pycache__/
# venv stuff
bin/
include/
lib/
lib64
pyvenv.cfg
# config files
*.conf
cookie_jar

6
bot.conf.default Normal file
View file

@ -0,0 +1,6 @@
[general]
nick = tom
cookiefile = bot.cookie
[rooms]
test

1
requirements.txt Normal file
View file

@ -0,0 +1 @@
yaboli >=1.1.2, <1.2.0

View file

@ -1,9 +0,0 @@
[general]
nick = tom
cookiefile = tom.cookie
[rooms]
# Format:
# room
# room=password
test

72
tom.py
View file

@ -1,11 +1,7 @@
import asyncio
import configparser
import logging
import re
import yaboli
from yaboli.utils import *
ELEMENTS = [
("H", "Hydrogen"),
@ -271,30 +267,37 @@ def shortest_path(text):
return path
class Tom(yaboli.Module):
DESCRIPTION = (
"'tom' attempts to spell a word using the symbols of the periodic table."
" For example, 'Hi' becomes 'Hydrogen Iodine'.\n"
"Because of this, only the letters a-z and A-Z may be used in a word.\n"
"'tom' uses en.wikipedia.org/wiki/List_of_chemical_elements for the element names.\n"
)
COMMANDS = "!tom <word> - attempts to spell the word using chemical elements\n"
AUTHOR = "Created by @Garmy using github.com/Garmelon/yaboli\n"
CREDITS = "Inspired by Tomsci. Algorithm based on a suggestion by Xyzzy.\n"
SHORT_DESCRIPTION = "spell a word using chemical elements, if possible"
SHORT_HELP = "/me spells a word using chemical elements, if possible"
LONG_DESCRIPTION = DESCRIPTION + COMMANDS + CREDITS
LONG_HELP = DESCRIPTION + COMMANDS + AUTHOR + CREDITS
DESCRIPTION = "spell a word using chemical elements, if possible"
HELP_GENERAL = "/me spells a word using chemical elements, if possible"
HELP_SPECIFIC = [
"'tom' attempts to spell a word using the symbols of the periodic"
" table. For example, 'Hi' becomes 'Hydrogen Iodine'.",
"Because of this, only the letters a-z and A-Z may be used in a word.",
"'tom' uses en.wikipedia.org/wiki/List_of_chemical_elements for the"
" element names.",
"",
"!tom <word> - attempts to spell the word using chemical elements",
"",
"Inspired by Tomsci. Algorithm based on a suggestion by Xyzzy.",
"Made by @Garmy with https://github.com/Garmelon/yaboli.",
]
ALLOWED_CHARS = r"a-zA-Z*\w"
ELEM_RE = "([" + ALLOWED_CHARS + "]*)([^" + ALLOWED_CHARS + "]*)"
async def on_command_general(self, room, message, command, argstr):
await self.command_tom(room, message, command, argstr)
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
if self.standalone:
self.register_botrulez(kill=True, restart=True)
self.register_general("tom", self.cmd_tom)
async def cmd_tom(self, room, message, args_):
# The weird naming of args_ is because I don't want to touch the below
# function and it's easier to just rename the function parameter.
argstr = args_.raw
@yaboli.command("tom")
async def command_tom(self, room, message, argstr):
args = []
while argstr:
match = re.match(self.ELEM_RE, argstr)
@ -312,26 +315,9 @@ class Tom(yaboli.Module):
spellings.append(spelling)
text = "".join(spellings)
await room.send(text, message.mid)
await message.reply(text)
def main(configfile):
logging.basicConfig(level=logging.INFO)
config = configparser.ConfigParser(allow_no_value=True)
config.read(configfile)
nick = config.get("general", "nick")
cookiefile = config.get("general", "cookiefile", fallback=None)
module = Tom()
bot = yaboli.ModuleBot(module, 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("tom.conf")
yaboli.enable_logging(level=logging.DEBUG)
yaboli.run(Tom)