Skip to content

Commit 5fb1504

Browse files
committed
Move highfive data to data file
1 parent fe85047 commit 5fb1504

2 files changed

Lines changed: 37 additions & 23 deletions

File tree

data/highfive.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"templates": [
3+
"{user} tries to give {nick} a five up high but misses. that was awkward",
4+
"{user} gives {nick} a killer high-five",
5+
"{user} gives {nick} an elbow-shattering high-five",
6+
"{user} smashes {nick} up high",
7+
"{user} slaps skin with {nick}",
8+
"{user} {nick} winds up for a killer five but misses and falls flat on his face",
9+
"{user} halfheartedly high-fives {nick}",
10+
"{user} gives {nick} a smooth five down low",
11+
"{user} gives {nick} a friendly high five",
12+
"{user} starts to give {nick} a high five, but leaves them hanging",
13+
"{user} performs an incomprehensible handshake with {nick} that identifies them as the very best of friends",
14+
"{user} makes as if to high five {nick} but pulls his hand away at the last second",
15+
"{user} leaves {nick} hanging",
16+
"{user} offers a fist and {nick} pounds it"
17+
],
18+
"parts": {}
19+
}

plugins/highfive.py

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,23 @@
1+
import json
2+
from pathlib import Path
3+
14
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))
316

417

518
@hook.command("high5", "hi5", "highfive")
6-
def highfive(nick, text):
19+
def highfive(nick, text, message):
720
"""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

Comments
 (0)