Add kwam and backronym commands

This commit is contained in:
minerobber 2018-12-09 15:53:42 +00:00
parent a2d1457070
commit d86527d2fa
2 changed files with 26 additions and 1 deletions

10
bot.py
View File

@ -1,4 +1,4 @@
import teambot, sys, traceback, requests, random, notes
import teambot, sys, traceback, requests, random, notes, words
BOTOP = "~minerobber@127.0.0.1"
PREFIX = "!"
@ -71,8 +71,16 @@ class MinerbotPhoenix(teambot.Handler):
msg = " ".join(msg)
NOTEBOOK.addNote(target,nick,msg)
NOTEBOOK.save("messages.json")
def on_backronym(self,channel,nick,word):
result = []
for char in word:
result.append(random.choice(words.getWords("^{}.*".format(char))))
self.say(channel,nick+": "+(" ".join(result).title()))
def on_kwam(self,channel,nick,*a):
self.on_backronym(channel,nick,"kwam")
if __name__=="__main__":
words.loadDict("american-english-small")
channels = "#bots".split()
bot = teambot.TeamBot(channels,"minerbot","localhost",chandler=MinerbotPhoenix)
bot.start()

17
words.py Normal file
View File

@ -0,0 +1,17 @@
import random,re
WORDS = []
def _isASCII(s):
for c in s:
if ord(c) not in range(128):
return False
return True
def loadDict(name="words"):
global WORDS
with open("/usr/share/dict/"+name) as f:
WORDS = [l.strip() for l in f if l.strip() and _isASCII(l.strip())]
def getWords(pattern=".*"):
return list(filter(lambda x: (re.match(pattern,x) is not None),WORDS))