|
| 1 | +import json |
1 | 2 | import random |
| 3 | +from pathlib import Path |
| 4 | + |
2 | 5 | 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)) |
3 | 17 |
|
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"] |
8 | 18 |
|
9 | 19 | @hook.command("fight", "fite", "spar", "challenge") |
10 | 20 | def fight(text, nick, message): |
11 | 21 | """<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