def bite(text, chan, action): """bites the specified nick somewhere random.""" if not text: return "please tell me who to bite." name = text.split(' ')[0] generator = TextGenerator(bites['templates'], bites['parts'], variables={'user': name}) action(generator.generate_string(), chan)
def highfive(nick, text, message): """Highfives the requested user""" data = {'user': nick, 'nick': text} generator = TextGenerator(high_five_data['templates'], high_five_data['parts'], variables=data) message(generator.generate_string())
def hookup(db, chan): """- matches two users from the channel in a sultry scene.""" if seen_table.name not in metadata.tables: return times = time.time() - 86400 results = db.execute( select([seen_table.c.name], and_(seen_table.c.chan == chan, seen_table.c.time > times))).fetchall() if not results or len(results) < 2: return "something went wrong" # Make sure the list of people is unique people = list(set(row[0] for row in results)) random.shuffle(people) person1, person2 = people[:2] variables = { 'user1': person1, 'user2': person2, } generator = TextGenerator(hookups['templates'], hookups['parts'], variables=variables) return generator.generate_string()
def fight(text, nick, message): """<nick>, makes you fight <nick> and generates a winner.""" data = { 'user1': nick, 'user2': text, } generator = TextGenerator(fight_data['templates'], fight_data['parts'], variables=data) message(generator.generate_string())
def kserving(text, action): """Servers a Kosher dish to some one in the channel. Part of halal.py. Made with help of snoonet user Yat""" data = {} if text: templates = kosher_data['target_templates'] data['target'] = text else: templates = kosher_data['templates'] generator = TextGenerator(templates, kosher_data['parts'], variables=data) action(generator.generate_string())
def serving(text, action): """Serves halaal dishes to some one in the channel""" data = {} if text: templates = halal_data['target_templates'] data['target'] = text else: templates = halal_data['templates'] generator = TextGenerator(templates, halal_data['parts'], variables=data) action(generator.generate_string())
def hug(text, nick, message): """hugs <user>""" data = { 'nick': nick, 'target': text, } generator = TextGenerator(hug_data['templates'], hug_data['parts'], variables=data) message(generator.generate_string())
def lurve(text, nick, message): """lurves all over <user>""" data = { 'nick': nick, 'target': text, } generator = TextGenerator(love_data['templates'], love_data['parts'], variables=data) message(generator.generate_string())
def test_textgenerator(): from cloudbot.util.textgen import TextGenerator generator = TextGenerator(['{thing} is {stuff}'], { 'thing': ['a', 'b'], 'stuff': [ 'c', ('d', 2), ] }) for s in generator.generate_strings(4): assert re.match(r'[ab] is [cd]', s) assert generator.get_template(0) == '{thing} is {stuff}'
def hookup(db, chan): """matches two users from the channel in a sultry scene.""" times = time.time() - 86400 results = db.execute("select name from seen_user where chan = :chan and time > :time", {"chan": chan, "time": times}).fetchall() if not results or len(results) < 2: return "something went wrong" # Make sure the list of people is unique people = list(set(row[0] for row in results)) random.shuffle(people) person1, person2 = people[:2] variables = { 'user1': person1, 'user2': person2, } generator = TextGenerator(hookups['templates'], hookups['parts'], variables=variables) return generator.generate_string()
def test_textgen_default_tmpl(): from cloudbot.util.textgen import TextGenerator generator = TextGenerator([ '{thing} is {stuff} {a}', '{thing} are {stuff} {a}', ], { 'thing': ['a', 'b'], 'stuff': [ 'c', ('d', 2), ] }, default_templates=[1], variables={'a': 'foo'}) for s in generator.generate_strings(4): assert re.match(r'[ab] are [cd] foo', s) assert generator.get_template(0) == '{thing} is {stuff} {a}' assert generator.get_template(1) == '{thing} are {stuff} {a}'