summaryrefslogtreecommitdiff
path: root/mentio.py
diff options
context:
space:
mode:
authorjomo <github@jomo.tv>2014-06-21 01:00:21 +0200
committerjomo <github@jomo.tv>2014-06-21 01:00:21 +0200
commit610e926a546307cbdce34b0cf63c33084be90112 (patch)
tree534b4a8aafb5ef7cac1aaf6a0322e97f4e087b2f /mentio.py
parent151a8525d73cd8b0d878a86ac5bc25497f935668 (diff)
quick fix
Diffstat (limited to 'mentio.py')
-rw-r--r--mentio.py45
1 files changed, 25 insertions, 20 deletions
diff --git a/mentio.py b/mentio.py
index 525b6d6..d5d6460 100644
--- a/mentio.py
+++ b/mentio.py
@@ -1,6 +1,7 @@
#pylint: disable=F0401
from helpers import *
from re import compile as reg_compile
+from traceback import format_exc as print_traceback
arrow = colorify(u"&r&7\u2192&r")
regex = reg_compile(u"\u00A7[\\da-fk-or]")
@@ -8,25 +9,29 @@ regex = reg_compile(u"\u00A7[\\da-fk-or]")
@hook.event("player.AsyncPlayerChatEvent", "normal")
def onChat(event):
- if not event.isCancelled():
- sender = event.getPlayer()
- words = event.getMessage().split(" ")
- recipients = event.getRecipients()
+ try:
+ if not event.isCancelled():
+ sender = event.getPlayer()
+ words = event.getMessage().split(" ")
+ recipients = event.getRecipients()
- for recipient in recipients:
- rec_words = words[:] # copy
- for i in range(len(rec_words)):
- word = rec_words[i]
- if recipient.getName().lower() in word.lower():
- 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
+ for recipient in recipients:
+ rec_words = words[:] # copy
+ for i in range(len(rec_words)):
+ word = rec_words[i]
+ if recipient.getName().lower() in word.lower():
+ 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: # list might not be mutable
- recipients.remove(recipient) # don't send original message
- except:
- pass
- message = " ".join([sender.getDisplayName(), arrow] + rec_words)
- msg(recipient, message, usecolor = False)
- recipient.playSound(recipient.getLocation(), "mob.chicken.plop", 1, 0)
+ # player was mentioned
+ if rec_words != words:
+ try: # list might not be mutable
+ recipients.remove(recipient) # don't send original message
+ except:
+ pass
+ message = " ".join([sender.getDisplayName(), arrow] + rec_words)
+ msg(recipient, message, usecolor = False)
+ recipient.playSound(recipient.getLocation(), "mob.chicken.plop", 1, 0)
+ except Exception, e:
+ error("Failed to handle PlayerChatEvent: %s" % e)
+ error(print_traceback()) \ No newline at end of file