Advertisement
kofany

red.py

May 13th, 2023
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. import weechat
  2. import time
  3.  
  4. weechat.register("redirect_script", "ChatGPT", "1.0", "GPL3", "Redirect NOTICE and WHOIS responses to current buffer", "", "")
  5.  
  6. def notice_redirect(data, signal, signal_data):
  7. parsed = weechat.info_get_hashtable("irc_message_parse", {"message": signal_data})
  8. nick, host = parsed["host"].split('!', 1)
  9. buffer = weechat.current_buffer()
  10.  
  11. weechat.prnt(buffer, "{}Notice from {}{}{} ({}): {}{}".format(weechat.color("magenta"), weechat.color("yellow"), nick, weechat.color("reset"), host, weechat.color("magenta"), parsed["arguments"].split(" :", 1)[1]))
  12.  
  13. return weechat.WEECHAT_RC_OK
  14.  
  15.  
  16. def whois_redirect(data, signal, signal_data):
  17. parsed = weechat.info_get_hashtable("irc_message_parse", {"message": signal_data})
  18. whois_codes = ["311", "312", "313", "317", "318", "319", "320", "324", "330", "335", "378", "379", "671"]
  19. if parsed["command"] in whois_codes:
  20. buffer = weechat.current_buffer()
  21. args = parsed["arguments"].split(" ")
  22. if len(args) >= 2:
  23. nick = args[1]
  24. args_remaining = " ".join(args[2:])
  25. if parsed["command"] == "311": # Start of WHOIS responses
  26. weechat.prnt(buffer, "\n{}[{}]{} {}@{}{}".format(weechat.color("magenta"), nick, weechat.color("reset"), args[2], weechat.color("yellow"), " ".join(args[3:])))
  27. elif parsed["command"] == "319": # Channels the user is on
  28. weechat.prnt(buffer, "{}[{}]{} {}".format(weechat.color("magenta"), nick, weechat.color("yellow"), " ".join(args[2:])))
  29. elif parsed["command"] == "317": # Idle time and signon time
  30. idle_seconds = int(args[2])
  31. idle_hours = idle_seconds // 3600
  32. idle_minutes = (idle_seconds % 3600) // 60
  33. idle_seconds = idle_seconds % 60
  34. signon_time = time.strftime('%a, %d %b %Y %H:%M:%S', time.localtime(int(args[3])))
  35. weechat.prnt(buffer, "{}[{}]{} idle: {:02d} hours {:02d} minutes {:02d} seconds, signon at: {}".format(weechat.color("magenta"), nick, weechat.color("reset"), idle_hours, idle_minutes, idle_seconds, signon_time))
  36. else:
  37. weechat.prnt(buffer, "{}[{}]{} {}".format(weechat.color("magenta"), nick, weechat.color("reset"), " ".join(args[2:])))
  38. return weechat.WEECHAT_RC_OK
  39.  
  40. weechat.hook_signal("*,irc_in_notice", "notice_redirect", "")
  41. weechat.hook_signal("*,irc_in2_*", "whois_redirect", "")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement