Skip to content

Instantly share code, notes, and snippets.

@jason-s13r
Created November 9, 2012 00:56
Show Gist options
  • Save jason-s13r/4043026 to your computer and use it in GitHub Desktop.
Save jason-s13r/4043026 to your computer and use it in GitHub Desktop.
WIP
import util
from pubsub import pub
import re
import random
words_dict = {}
def add_words(bot):
global words_dict
i = 0
words = bot.remote['message'].split(" ")
if len(words) > 3:
first = words[i]
i += 1
second = words[i]
i += 1
while i < len(words):
third = words[i]
i += 1
key = "%s %s" % (first, second)
if key not in words_dict.keys():
words_dict[key] = []
words_dict[key].append(third)
first = second
second = third
print words_dict
pub.subscribe(add_words, 'scanner')
def get_string(bot, args):
if len(args) > 1:
keys = words_dict.keys()
key = random.choice(keys)
message = key
while len(message.split(" ")) < int(args[1]) and key in words_dict.keys():
value = random.choice(words_dict[key])
message = "%s %s" % (message, value)
key = "%s %s" % (key.split(" ")[1], value)
util.answer(bot, message)
else:
util.give_help(bot, args[0], "<string length>")
util.register(get_string, "common", "chat")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment