Advertisement
Fierydemise

discord_disinfectant_weechat

Jul 30th, 2016
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.18 KB | None | 0 0
  1. import weechat
  2. import re
  3.  
  4. SCRIPT_NAME = "discord_disinfectant"
  5. SCRIPT_AUTHOR = "Ben"
  6. SCRIPT_VERSION = "0.1"
  7. SCRIPT_LICENSE = "GPL3"
  8. SCRIPT_DESC = "Make IRC great again"
  9.  
  10. discord_bot_names = ["RHDiscord", "RHDiscord1", "RHDiscord2", "RHDiscord3", "RHBridge", "RHBridge1", "RHBridge2"]
  11. #build an re
  12. pattern = ".*" + "|.*".join(discord_bot_names)
  13. bot_filter = re.compile(pattern)
  14.  
  15. def strip_discord(data, modifier, modifier_data, line):
  16.     full_name = modifier_data.split(';')[1]
  17.     channel = '.'.join(full_name.split('.')[1:])
  18.     if channel != "#ravenholdt":
  19.         return line
  20.  
  21.     nick, message = line.split("\t")
  22.    
  23.     if bot_filter.match(nick):
  24.     #f nick == "RHBridge":
  25.         strings = re.split("(^<.*?>)", message, maxsplit=1)
  26.         #weechat.prnt("", str(strings))
  27.         if strings[0] == "":
  28.             name = strings[1]
  29.             message = strings[2]
  30.         else:
  31.             name = ""
  32.             message = strings[0]
  33.  
  34.         return "%s%s\t%s" % (weechat.info_get("nick_color", name), name, message)
  35.     else:
  36.         return line
  37.  
  38.  
  39.     return line
  40.  
  41. if __name__ == "__main__":
  42.     if weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE, SCRIPT_DESC, "", ""):
  43.  
  44.         weechat.hook_modifier("weechat_print", "strip_discord", "")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement