Skip to content

Commit 44ef985

Browse files
author
Foxlet
committed
You guys update quite quickly...
2 parents 3e45088 + 42d6363 commit 44ef985

5 files changed

Lines changed: 17 additions & 12 deletions

File tree

plugins/eightball.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import asyncio
3+
import codecs
34
import random
45

56
from cloudbot import hook
@@ -10,7 +11,7 @@
1011
def load_responses(bot):
1112
path = os.path.join(bot.data_dir, "8ball_responses.txt")
1213
global responses
13-
with open(path) as f:
14+
with codecs.open(path, encoding="utf-8") as f:
1415
responses = [line.strip() for line in
1516
f.readlines() if not line.startswith("//")]
1617

plugins/fortune.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import codecs
23
import random
34
import asyncio
45

@@ -9,7 +10,7 @@
910
def load_fortunes(bot):
1011
path = os.path.join(bot.data_dir, "fortunes.txt")
1112
global fortunes
12-
with open(path) as f:
13+
with codecs.open(path, encoding="utf-8") as f:
1314
fortunes = [line.strip() for line in f.readlines() if not line.startswith("//")]
1415

1516

plugins/name_generator.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import json
2+
import codecs
23
import os
34

45
from cloudbot import hook
@@ -43,7 +44,9 @@ def namegen(text, bot, notice):
4344
return "{} is not a valid name generator.".format(inp)
4445

4546
# load the name generator
46-
with open(os.path.join(bot.data_dir, "name_files", "{}.json".format(selected_module))) as f:
47+
path = os.path.join(bot.data_dir, "name_files", "{}.json".format(selected_module))
48+
49+
with codecs.open(path, encoding="utf-8") as f:
4750
try:
4851
generator = get_generator(f.read())
4952
except ValueError as error:

plugins/password.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
# Just use the regular random module, not the strong one
1212
gen = std_random.SystemRandom()
1313

14-
print(gen)
1514
with open("data/password_words.txt") as f:
1615
common_words = [line.strip() for line in f.readlines()]
1716

plugins/slap.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
import json
2+
import codecs
3+
import os
24

35
from cloudbot import hook
46
from cloudbot.util import textgen
57

68

7-
def get_generator(_json, variables):
8-
data = json.loads(_json)
9-
return textgen.TextGenerator(data["templates"],
10-
data["parts"], variables=variables)
9+
@hook.onload
10+
def load_slaps(bot):
11+
global slaps
12+
with codecs.open(os.path.join(bot.data_dir, "kills.json"), encoding="utf-8") as f:
13+
slaps = json.load(f)
1114

1215

13-
@hook.command()
16+
@hook.command
1417
def slap(text, action, nick, conn, notice):
1518
"""slap <user> -- Makes the bot slap <user>."""
1619
target = text.strip()
@@ -26,9 +29,7 @@ def slap(text, action, nick, conn, notice):
2629
variables = {
2730
"user": target
2831
}
29-
30-
with open("./data/slaps.json") as f:
31-
generator = get_generator(f.read(), variables)
32+
generator = textgen.TextGenerator(slaps["templates"], slaps["parts"], variables=variables)
3233

3334
# act out the message
3435
action(generator.generate_string())

0 commit comments

Comments
 (0)