summaryrefslogtreecommitdiff
path: root/mentio.py
diff options
context:
space:
mode:
authorjomo <github@jomo.tv>2014-07-27 19:42:33 +0200
committerjomo <github@jomo.tv>2014-07-27 19:42:33 +0200
commitb1a3a92e49b353dfa42b52b448cdbc3b27bb33f8 (patch)
tree1b135af4f422d2ebcb96e814c08923d52b2f85c3 /mentio.py
parente9b0ad656b71841fa23f332ddf8eff43e5cf1986 (diff)
apply file read/save helpers
Diffstat (limited to 'mentio.py')
-rw-r--r--mentio.py27
1 files changed, 9 insertions, 18 deletions
diff --git a/mentio.py b/mentio.py
index f557a5f..bb065f7 100644
--- a/mentio.py
+++ b/mentio.py
@@ -1,18 +1,12 @@
-import json
from helpers import *
from re import compile as reg_compile
from traceback import format_exc as print_traceback
-mentio_filename = "plugins/redstoner-utils.py.dir/files/mentio.json"
-mentions = {}
-max_amount = 3
-arrow = colorify(u"&r&7\u2192&r")
-regex = reg_compile(u"\u00A7[\\da-fk-or]")
-try:
- mentions = json.loads(open(mentio_filename).read())
-except Exception, e:
- error("Failed to load mentions: %s" % e)
+mentions = open_json_file("mentio", {})
+max_amount = 3
+arrow = colorify(u"&r&7\u2192&r")
+regex = reg_compile(u"\u00A7[\\da-fk-or]")
@hook.event("player.AsyncPlayerChatEvent", "high")
@@ -39,7 +33,7 @@ def onChat(event):
if isMentioned:
colors = "".join(regex.findall("".join(words[:i+1]))) # join all color codes used upto this word
rec_words[i] = colorify("&r&a<&6") + stripcolors(word) + colorify("&r&a>&r") + colors # extra fancy highlight
-
+
# player was mentioned
if rec_words != words:
try:
@@ -54,13 +48,14 @@ def onChat(event):
error("Failed to handle PlayerChatEvent:")
error(print_traceback())
+
@hook.command("listen")
def onListenCommand(sender, args):
try:
currWords = []
if str(sender.getUniqueId()) in mentions.keys():
currWords = mentions[str(sender.getUniqueId())]
-
+
# /listen add <word>
if len(args) == 2 and args[0].lower() == "add":
@@ -110,10 +105,6 @@ def onListenCommand(sender, args):
except Exception, e:
error(e)
+
def saveMentions():
- try:
- mentio_file = open(mentio_filename, "w")
- mentio_file.write(json.dumps(mentions))
- mentio_file.close()
- except Exception, e:
- error("Failed to write mentions: " + str(e))
+ save_json_file("mentio", mentions) \ No newline at end of file