Skip to content

Commit 48a082b

Browse files
committed
Move fight data out to a data file
1 parent cdff1db commit 48a082b

2 files changed

Lines changed: 80 additions & 11 deletions

File tree

data/fight.json

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
{
2+
"templates": [
3+
"{bang}! {bang}! {bang}! {user1} {victory} over {user2} with a {blow_type} {blow}.",
4+
"{bang}! {bang}! {bang}! {user2} {victory} over {user1} with a {blow_type} {blow}."
5+
],
6+
"parts": {
7+
"bang": [
8+
"BANG",
9+
"POW",
10+
"SLAM",
11+
"WHACK",
12+
"SLAP",
13+
"KAPOW",
14+
"ZAM",
15+
"BOOM"
16+
],
17+
"blow_type": [
18+
"devastating",
19+
"destructive",
20+
"ruthless",
21+
"damaging",
22+
"ruinous",
23+
"catastrophic",
24+
"traumatic",
25+
"shattering",
26+
"overwhelming",
27+
"crushing",
28+
"fierce",
29+
"deadly",
30+
"lethal",
31+
"fatal",
32+
"savage",
33+
"violent"
34+
],
35+
"victory": [
36+
"wins",
37+
"stands victorious",
38+
"triumphs",
39+
"conquers",
40+
"is the champion",
41+
"is the victor"
42+
],
43+
"blow": [
44+
"uppercut",
45+
"hammerfist",
46+
"elbow strike",
47+
"shoulder strike",
48+
"front kick",
49+
"side kick",
50+
"roundhouse kick",
51+
"knee strike",
52+
"butt strike",
53+
"headbutt",
54+
"haymaker punch",
55+
"palm strike",
56+
"pocket bees"
57+
]
58+
}
59+
}

plugins/fight.py

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,28 @@
1+
import json
12
import random
3+
from pathlib import Path
4+
25
from cloudbot import hook
6+
from cloudbot.util.textgen import TextGenerator
7+
8+
fight_data = {}
9+
10+
11+
@hook.on_start
12+
def load_data(bot):
13+
fight_data.clear()
14+
data_file = Path(bot.data_dir) / "fight.json"
15+
with data_file.open(encoding='utf-8') as f:
16+
fight_data.update(json.load(f))
317

4-
bang = ["BANG", "POW", "SLAM", "WHACK", "SLAP", "KAPOW", "ZAM", "BOOM"]
5-
blow_type = ["devastating", "destructive", "ruthless", "damaging", "ruinous", "catastrophic", "traumatic", "shattering", "overwhelming", "crushing", "fierce", "deadly", "lethal", "fatal", "savage", "violent"]
6-
victory = ["wins", "stands victorious", "triumphs", "conquers", "is the champion", "is the victor" ]
7-
blow = ["uppercut", "hammerfist", "elbow strike", "shoulder strike", "front kick", "side kick", "roundhouse kick", "knee strike", "butt strike", "headbutt", "haymaker punch", "palm strike", "pocket bees"]
818

919
@hook.command("fight", "fite", "spar", "challenge")
1020
def fight(text, nick, message):
1121
"""<nick>, makes you fight <nick> and generates a winner."""
12-
fighter1 = nick
13-
fighter2 = text.strip()
14-
if random.random() < .5:
15-
out = "{}! {}! {}! {} {} over {} with a {} {}.".format(random.choice(bang), random.choice(bang), random.choice(bang), fighter1, random.choice(victory),fighter2, random.choice(blow_type), random.choice(blow))
16-
else:
17-
out = "{}! {}! {}! {} {} over {} with a {} {}.".format(random.choice(bang), random.choice(bang), random.choice(bang), fighter2, random.choice(victory),fighter1, random.choice(blow_type), random.choice(blow))
18-
message(out)
22+
data = {
23+
'user1': nick,
24+
'user2': text,
25+
}
26+
27+
generator = TextGenerator(fight_data['templates'], fight_data['parts'], variables=data)
28+
message(generator.generate_string())

0 commit comments

Comments
 (0)