forked from Poorchop/hexchat-scripts
/
follow.py
58 lines (41 loc) · 1.87 KB
/
follow.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import hexchat
__module_name__ = "Follow"
__module_author__ = "Poorchop"
__module_version__ = "0.3"
__module_description__ = "Format messages from specific users to make them easier to follow"
colors = (19, 20, 22, 24, 25, 26, 27, 28, 29)
userlist = []
edited = False
def nick_color(nick):
total = sum(ord(letter) for letter in nick)
total %= len(colors)
return colors[total]
def follow_cb(word, word_eol, userdata):
if len(word) >= 2 and word[1] not in userlist:
userlist.append(word[1])
hexchat.prnt("-\002Follow\002-\tYou are now following \002\003{0}{1}\017".format(nick_color(word[1]), word[1]))
return hexchat.EAT_ALL
def unfollow_cb(word, word_eol, userdata):
if len(word) >= 2 and word[1] in userlist:
userlist.remove(word[1])
hexchat.prnt("-\002Follow\002-\tYou have unfollowed \002\003{0}{1}\017".format(nick_color(word[1]), word[1]))
return hexchat.EAT_ALL
def format_cb(word, word_eol, event):
global edited
nick = hexchat.strip(word[0])
if edited:
return
if nick in userlist:
formatted_nick = "\002{0}\017".format(word[0])
# TODO: Use regular nick color for formatted_msg if colored nickname preference is disabled
formatted_msg = "\003{0}{1}\017".format(nick_color(nick), word[1])
word = [(word[i] if len(word) > i else "") for i in range(4)]
edited = True
hexchat.emit_print(event, formatted_nick, formatted_msg, word[2], word[3])
edited = False
return hexchat.EAT_ALL
hexchat.hook_command("FOLLOW", follow_cb)
hexchat.hook_command("UNFOLLOW", unfollow_cb)
hexchat.hook_print("Channel Action", format_cb, "Channel Action", priority=hexchat.PRI_HIGH)
hexchat.hook_print("Channel Message", format_cb, "Channel Message", priority=hexchat.PRI_HIGH)
hexchat.prnt(__module_name__ + " version " + __module_version__ + " loaded")