|
| 1 | +import json |
| 2 | +from pathlib import Path |
| 3 | + |
1 | 4 | from cloudbot import hook |
2 | | -from random import choice |
| 5 | +from cloudbot.util.textgen import TextGenerator |
| 6 | + |
| 7 | +high_five_data = {} |
| 8 | + |
| 9 | + |
| 10 | +@hook.on_start |
| 11 | +def load_data(bot): |
| 12 | + high_five_data.clear() |
| 13 | + data_file = Path(bot.data_dir) / "highfive.json" |
| 14 | + with data_file.open(encoding='utf-8') as f: |
| 15 | + high_five_data.update(json.load(f)) |
3 | 16 |
|
4 | 17 |
|
5 | 18 | @hook.command("high5", "hi5", "highfive") |
6 | | -def highfive(nick, text): |
| 19 | +def highfive(nick, text, message): |
7 | 20 | """Highfives the requested user""" |
8 | | - highfives = [ |
9 | | - "tries to give {nick} a five up high but misses." |
10 | | - "that was awkward", |
11 | | - "gives {nick} a killer high-five", |
12 | | - "gives {nick} an elbow-shattering high-five", |
13 | | - "smashes {nick} up high", |
14 | | - "slaps skin with {nick}", |
15 | | - "{nick} winds up for a killer five but misses and falls flat on his face", |
16 | | - "halfheartedly high-fives {nick}", |
17 | | - "gives {nick} a smooth five down low", |
18 | | - "gives {nick} a friendly high five", |
19 | | - "starts to give {nick} a high five, but leaves them hanging", |
20 | | - "performs an incomprehensible handshake with {nick} that identifies " |
21 | | - "them as the very best of friends", |
22 | | - "makes as if to high five {nick} but pulls his hand away at the last " |
23 | | - "second", |
24 | | - "leaves {nick} hanging", |
25 | | - "offers a fist and {nick} pounds it" |
26 | | - |
27 | | - ] |
28 | | - return nick + " " + choice(highfives).format(nick=text) |
| 21 | + data = {'user': nick, 'nick': text} |
| 22 | + generator = TextGenerator(high_five_data['templates'], high_five_data['parts'], variables=data) |
| 23 | + message(generator.generate_string()) |
0 commit comments