Add su command
This commit is contained in:
parent
8a884625ff
commit
46e23995ac
7
bot.py
7
bot.py
|
@ -1,4 +1,4 @@
|
|||
import teambot, sys, traceback, requests, random, notes, words
|
||||
import teambot, sys, traceback, requests, random, notes, words, markovuniverse
|
||||
from titlecase import titlecase
|
||||
|
||||
BOTOP = "~minerobber@127.0.0.1"
|
||||
|
@ -79,6 +79,11 @@ class MinerbotPhoenix(teambot.Handler):
|
|||
self.say(channel,nick+": "+titlecase(" ".join(result)))
|
||||
def on_kwam(self,channel,nick,*a):
|
||||
self.on_backronym(channel,nick,"kwam")
|
||||
def on_su(self,channel,nick,subcmd="help",*args):
|
||||
if subcmd=="help":
|
||||
self.say(channel,nick+": Current subcommands: !su fake-leak")
|
||||
elif subcmd=="fake-leak":
|
||||
self.say(channel,nick+": {} - {}".format(*markovuniverse.new_episode()))
|
||||
|
||||
if __name__=="__main__":
|
||||
words.loadDict("american-english-small")
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
import markov,tvdb_api
|
||||
|
||||
t = tvdb_api.Tvdb(language="en")
|
||||
first = True
|
||||
synopses = markov.Chain()
|
||||
for season in t['Steven Universe']:
|
||||
if first:
|
||||
first = False
|
||||
continue
|
||||
for episode in t['Steven Universe'][season]:
|
||||
synopses.train(t['Steven Universe'][season][episode]['overview'])
|
||||
with open("synopses.json","w") as f:
|
||||
f.write(synopses.to_json())
|
|
@ -0,0 +1,13 @@
|
|||
import markov,tvdb_api
|
||||
|
||||
t = tvdb_api.Tvdb(language="en")
|
||||
first = True
|
||||
titles = markov.Chain()
|
||||
for season in t['Steven Universe']:
|
||||
if first:
|
||||
first = False
|
||||
continue
|
||||
for episode in t['Steven Universe'][season]:
|
||||
titles.train(t['Steven Universe'][season][episode]['episodename'])
|
||||
with open("titles.json","w") as f:
|
||||
f.write(titles.to_json())
|
|
@ -0,0 +1,42 @@
|
|||
import random,json
|
||||
class Chain:
|
||||
def __init__(self):
|
||||
self.map = {}
|
||||
|
||||
def addWord(self,lastWord,word):
|
||||
if lastWord in self.map and not word in self.map[lastWord]:
|
||||
self.map[lastWord].append(word)
|
||||
elif not lastWord in self.map:
|
||||
self.map[lastWord] = [word]
|
||||
|
||||
def train(self,sentance):
|
||||
words = sentance.split(" ")
|
||||
lastWord = words.pop(0)
|
||||
self.addWord("",lastWord)
|
||||
for word in words:
|
||||
self.addWord(lastWord,word)
|
||||
lastWord = word
|
||||
self.addWord(lastWord,"")
|
||||
|
||||
def generate(self):
|
||||
lastWord = random.choice(self.map[""])
|
||||
sentence = lastWord
|
||||
while lastWord != "":
|
||||
word = random.choice(self.map[lastWord])
|
||||
sentence += " " + word
|
||||
lastWord = word
|
||||
return sentence[:-1]
|
||||
|
||||
def to_json(self):
|
||||
return json.dumps(self.map)
|
||||
|
||||
@classmethod
|
||||
def from_json(cls,jsonstr):
|
||||
ret = cls()
|
||||
ret.map = json.loads(jsonstr)
|
||||
return ret
|
||||
|
||||
def addLinesFromFile(chain,filename):
|
||||
with open(filename) as f:
|
||||
for line in f.readlines():
|
||||
chain.train(line.rstrip())
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,42 @@
|
|||
import random,json
|
||||
class Chain:
|
||||
def __init__(self):
|
||||
self.map = {}
|
||||
|
||||
def addWord(self,lastWord,word):
|
||||
if lastWord in self.map and not word in self.map[lastWord]:
|
||||
self.map[lastWord].append(word)
|
||||
elif not lastWord in self.map:
|
||||
self.map[lastWord] = [word]
|
||||
|
||||
def train(self,sentance):
|
||||
words = sentance.split(" ")
|
||||
lastWord = words.pop(0)
|
||||
self.addWord("",lastWord)
|
||||
for word in words:
|
||||
self.addWord(lastWord,word)
|
||||
lastWord = word
|
||||
self.addWord(lastWord,"")
|
||||
|
||||
def generate(self):
|
||||
lastWord = random.choice(self.map[""])
|
||||
sentence = lastWord
|
||||
while lastWord != "":
|
||||
word = random.choice(self.map[lastWord])
|
||||
sentence += " " + word
|
||||
lastWord = word
|
||||
return sentence[:-1]
|
||||
|
||||
def to_json(self):
|
||||
return json.dumps(self.map)
|
||||
|
||||
@classmethod
|
||||
def from_json(cls,jsonstr):
|
||||
ret = cls()
|
||||
ret.map = json.loads(jsonstr)
|
||||
return ret
|
||||
|
||||
def addLinesFromFile(chain,filename):
|
||||
with open(filename) as f:
|
||||
for line in f.readlines():
|
||||
chain.train(line.rstrip())
|
|
@ -0,0 +1,17 @@
|
|||
import markov
|
||||
|
||||
def chainFromFile(filename):
|
||||
with open(filename) as f:
|
||||
return markov.Chain.from_json(f.read())
|
||||
|
||||
titles = chainFromFile("data/titles.json")
|
||||
synopses = chainFromFile("data/synopses.json")
|
||||
|
||||
def new_episode():
|
||||
title = titles.generate()
|
||||
synopsis = synopses.generate()
|
||||
return (title,synopsis)
|
||||
|
||||
if __name__=="__main__":
|
||||
details = new_episode()
|
||||
print("New episode:\n{} - {}".format(*details))
|
Reference in New Issue