Merge branch 'dev' of bitbucket.org:redstonesheep/redstoner-utils into dev

This commit is contained in:
jomo
2014-07-25 00:05:51 +02:00

View File

@@ -16,18 +16,27 @@ except Exception, e:
@hook.event("player.AsyncPlayerChatEvent", "high")
def on_chat(event):
def onChat(event):
try:
if not event.isCancelled():
sender = event.getPlayer()
words = event.getMessage().split(" ")
recipients = event.getRecipients()
listeners = mentions[sender.getUniqueId()]
for recipient in list(recipients):
rec_words = words[:] # copy
for i in range(len(rec_words)):
word = rec_words[i]
if recipient.getName().lower() in word.lower():
isMentioned = False
if recipient.getName().lower() in word.lower(): # is the player's full ign in the list
isMentioned = True
if word.lower() in [i.lower() for i in listeners]: # is the word in the listeners list
isMentioned = True
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
@@ -45,13 +54,12 @@ def on_chat(event):
error("Failed to handle PlayerChatEvent:")
error(print_traceback())
@hook.command("listen")
def on_listen_command(sender, args):
def onListenCommand(sender, args):
try:
currWords = []
if uid(sender) in mentions.keys():
currWords = mentions[uid(sender)]
if str(sender.getUniqueId()) in mentions.keys():
currWords = mentions[str(sender.getUniqueId())]
# /listen add <word>
if len(args) == 2 and args[0].lower() == "add":
@@ -59,15 +67,17 @@ def on_listen_command(sender, args):
if len(currWords) >= max_amount:
msg(sender, "&cYou are already listening for %s words! Try &6/listen del <word>" % max_amount)
return True
if len(args[1].lower()) > 16:
msg(sender, "&cThis word is longer than 16 characters. Pick a shorter one!")
if args[1].lower() in currWords:
msg(sender, "&cYou are already listening for this word! Try &6/listen list")
return True
if args[1].lower() is sender.getName():
msg(sender, "&cYou are always listening for your full ingame name by default")
currWords.append(args[1].lower())
mentions[uid(sender)] = currWords
mentions[str(sender.getUniqueId())] = currWords
msg(sender, "&aYou are now listening for '&2"+args[1].lower()+"'!")
save_mentions()
saveMentions()
return True
# /listen del <word>
elif len(args) == 2 and args[0].lower() == "del":
@@ -78,10 +88,10 @@ def on_listen_command(sender, args):
for word in currWords[:]:
if word.lower() == args[1].lower():
currWords.remove(word.lower())
mentions[uid(sender)] = currWords
mentions[str(sender.getUniqueId())] = currWords
success = True
if success == True:
save_mentions()
saveMentions()
msg(sender, "&eYou are no longer listening for '&2"+args[1].lower()+"&e'!")
else:
msg(sender, "&cWe can't remove something that doesn't exist! Try &6/listen list")
@@ -93,14 +103,14 @@ def on_listen_command(sender, args):
for word in currWords:
msg(sender, "&c- &3"+word)
else:
msg(sender, "&eNobody calls you %s &efor some particular reason? Too long? Add some aliases!\n\n" % sender.getDisplayName())
msg(sender, "&6/listen add <word>")
msg(sender, "&6/listen del <word>")
msg(sender, "&6/listen list")
except Exception, e:
error(e)
def save_mentions():
def saveMentions():
try:
mentio_file = open(mentio_filename, "w")
mentio_file.write(json.dumps(mentions))