Update to yaboli 1.1.2
This commit is contained in:
parent
45e5c006e7
commit
bf5c619da0
5 changed files with 286 additions and 292 deletions
14
.gitignore
vendored
14
.gitignore
vendored
|
|
@ -1,3 +1,13 @@
|
||||||
**/__pycache__
|
# python stuff
|
||||||
*.cookie
|
__pycache__/
|
||||||
|
|
||||||
|
# venv stuff
|
||||||
|
bin/
|
||||||
|
include/
|
||||||
|
lib/
|
||||||
|
lib64
|
||||||
|
pyvenv.cfg
|
||||||
|
|
||||||
|
# config files
|
||||||
*.conf
|
*.conf
|
||||||
|
cookie_jar
|
||||||
|
|
|
||||||
6
bot.conf.default
Normal file
6
bot.conf.default
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
[general]
|
||||||
|
nick = tom
|
||||||
|
cookiefile = bot.cookie
|
||||||
|
|
||||||
|
[rooms]
|
||||||
|
test
|
||||||
1
requirements.txt
Normal file
1
requirements.txt
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
yaboli >=1.1.2, <1.2.0
|
||||||
|
|
@ -1,9 +0,0 @@
|
||||||
[general]
|
|
||||||
nick = tom
|
|
||||||
cookiefile = tom.cookie
|
|
||||||
|
|
||||||
[rooms]
|
|
||||||
# Format:
|
|
||||||
# room
|
|
||||||
# room=password
|
|
||||||
test
|
|
||||||
72
tom.py
72
tom.py
|
|
@ -1,11 +1,7 @@
|
||||||
import asyncio
|
|
||||||
import configparser
|
|
||||||
import logging
|
import logging
|
||||||
import re
|
import re
|
||||||
|
|
||||||
import yaboli
|
import yaboli
|
||||||
from yaboli.utils import *
|
|
||||||
|
|
||||||
|
|
||||||
ELEMENTS = [
|
ELEMENTS = [
|
||||||
("H", "Hydrogen"),
|
("H", "Hydrogen"),
|
||||||
|
|
@ -271,30 +267,37 @@ def shortest_path(text):
|
||||||
return path
|
return path
|
||||||
|
|
||||||
class Tom(yaboli.Module):
|
class Tom(yaboli.Module):
|
||||||
DESCRIPTION = (
|
DESCRIPTION = "spell a word using chemical elements, if possible"
|
||||||
"'tom' attempts to spell a word using the symbols of the periodic table."
|
HELP_GENERAL = "/me spells a word using chemical elements, if possible"
|
||||||
" For example, 'Hi' becomes 'Hydrogen Iodine'.\n"
|
HELP_SPECIFIC = [
|
||||||
"Because of this, only the letters a-z and A-Z may be used in a word.\n"
|
"'tom' attempts to spell a word using the symbols of the periodic"
|
||||||
"'tom' uses en.wikipedia.org/wiki/List_of_chemical_elements for the element names.\n"
|
" table. For example, 'Hi' becomes 'Hydrogen Iodine'.",
|
||||||
)
|
"Because of this, only the letters a-z and A-Z may be used in a word.",
|
||||||
COMMANDS = "!tom <word> - attempts to spell the word using chemical elements\n"
|
"'tom' uses en.wikipedia.org/wiki/List_of_chemical_elements for the"
|
||||||
AUTHOR = "Created by @Garmy using github.com/Garmelon/yaboli\n"
|
" element names.",
|
||||||
CREDITS = "Inspired by Tomsci. Algorithm based on a suggestion by Xyzzy.\n"
|
"",
|
||||||
|
"!tom <word> - attempts to spell the word using chemical elements",
|
||||||
SHORT_DESCRIPTION = "spell a word using chemical elements, if possible"
|
"",
|
||||||
SHORT_HELP = "/me spells a word using chemical elements, if possible"
|
"Inspired by Tomsci. Algorithm based on a suggestion by Xyzzy.",
|
||||||
|
"Made by @Garmy with https://github.com/Garmelon/yaboli.",
|
||||||
LONG_DESCRIPTION = DESCRIPTION + COMMANDS + CREDITS
|
]
|
||||||
LONG_HELP = DESCRIPTION + COMMANDS + AUTHOR + CREDITS
|
|
||||||
|
|
||||||
ALLOWED_CHARS = r"a-zA-Z*\w"
|
ALLOWED_CHARS = r"a-zA-Z*\w"
|
||||||
ELEM_RE = "([" + ALLOWED_CHARS + "]*)([^" + ALLOWED_CHARS + "]*)"
|
ELEM_RE = "([" + ALLOWED_CHARS + "]*)([^" + ALLOWED_CHARS + "]*)"
|
||||||
|
|
||||||
async def on_command_general(self, room, message, command, argstr):
|
def __init__(self, *args, **kwargs):
|
||||||
await self.command_tom(room, message, command, argstr)
|
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 = []
|
args = []
|
||||||
while argstr:
|
while argstr:
|
||||||
match = re.match(self.ELEM_RE, argstr)
|
match = re.match(self.ELEM_RE, argstr)
|
||||||
|
|
@ -312,26 +315,9 @@ class Tom(yaboli.Module):
|
||||||
spellings.append(spelling)
|
spellings.append(spelling)
|
||||||
|
|
||||||
text = "".join(spellings)
|
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__":
|
if __name__ == "__main__":
|
||||||
main("tom.conf")
|
yaboli.enable_logging(level=logging.DEBUG)
|
||||||
|
yaboli.run(Tom)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue