-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathbuffextras.lua
More file actions
160 lines (151 loc) · 4.62 KB
/
buffextras.lua
File metadata and controls
160 lines (151 loc) · 4.62 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
-- SPDX-License-Identifier: MIT
hexchat.register('Buffextras', '1', "Format messages from ZNC's buffextras module")
hexchat.hook_server_attrs('PRIVMSG', function (word, word_eol, attrs)
if not word[1]:match('^:%*buffextras!') then
return
end
local channel = word[3]
local nick, host = word[4]:match('^:([^!]+)!(.*)$')
local function is_event (event)
return word_eol[5]:sub(1, #event) == event
end
local function emit (event, ...)
hexchat.emit_print_attrs(attrs, event, ...)
end
if is_event('joined') then
emit('Join', nick, channel, host)
elseif is_event('quit') then
emit('Quit', nick, word_eol[6], host)
elseif is_event('parted') then
local reason = word_eol[6]
if reason and reason ~= '' then
emit('Part with Reason', nick, host, channel, reason)
else
emit('Part', nick, host, channel)
end
elseif is_event('is now known as') then
emit('Change Nick', nick, word[9])
elseif is_event('changed the topic to') then
emit('Topic Change', nick, word_eol[9], channel)
elseif is_event('kicked') then
emit('Kick', nick, word[6], channel, word_eol[9])
elseif is_event('set mode') then
modes = word_eol[7]:match('^(.*%S)')
name = nick
if name == nil then
name = word[4]:match('^:([^!]+)$')
end
if hexchat.prefs['irc_raw_modes'] == true then
emit('Raw Modes', name, string.format('%s %s', channel, modes))
else
local nickmodes = hexchat.props['nickmodes']
local chanmodes = hexchat.props['chanmodes']
server = hexchat.get_info('server')
local chanmodes = chanmodes[server]
if chanmodes == nil then
chanmodes = 'beI,k,l'
end
modes_for_lists, modes_with_param, modes_with_param_when_set, modes_without_param = chanmodes:match('^([^,]*),?([^,]*),?([^,]*),?([^,]*)$')
local sign
local param_pos = 8
local flags = word[7]
for i = 1, #flags do
flag = flags:sub(i,i)
if flag == '+' then
sign = '+'
elseif flag == '-' then
sign = '-'
elseif flag == 'k' then
if sign == '+' then
param = word[param_pos]
param_pos = param_pos + 1
emit('Channel Set Key', name, param)
else
emit('Channel Remove Keyword', name)
end
elseif flag == 'l' then
if sign == '+' then
param = word[param_pos]
param_pos = param_pos + 1
emit('Channel Set Limit', name, param)
else
emit('Channel Remove Limit', name)
end
elseif flag == 'o' then
param = word[param_pos]
param_pos = param_pos + 1
if sign == '+' then
emit('Channel Operator', name, param)
else
emit('Channel DeOp', name, param)
end
elseif flag == 'h' then
param = word[param_pos]
param_pos = param_pos + 1
if sign == '+' then
emit('Channel Half-Operator', name, param)
else
emit('Channel DeHalfOp', name, param)
end
elseif flag == 'v' then
param = word[param_pos]
param_pos = param_pos + 1
if sign == '+' then
emit('Channel Voice', name, param)
else
emit('Channel DeVoice', name, param)
end
elseif flag == 'b' then
param = word[param_pos]
param_pos = param_pos + 1
if sign == '+' then
emit('Channel Ban', name, param)
else
emit('Channel UnBan', name, param)
end
elseif flag == 'e' then
param = word[param_pos]
param_pos = param_pos + 1
if sign == '+' then
emit('Channel Exempt', name, param)
else
emit('Channel Remove Exempt', name, param)
end
elseif flag == 'I' then
param = word[param_pos]
param_pos = param_pos + 1
if sign == '+' then
emit('Channel INVITE', name, param)
else
emit('Channel Remove Invite', name, param)
end
elseif flag == 'q' and string.find(modes_for_lists, 'q') then
param = word[param_pos]
param_pos = param_pos + 1
if sign == '+' then
emit('Channel Quiet', name, param)
else
emit('Channel UnQuiet', name, param)
end
elseif string.find(nickmodes, flag) or string.find(modes_for_lists, flag) or string.find(modes_with_param, flag) then
param = word[param_pos]
param_pos = param_pos + 1
emit('Channel Mode Generic', name, sign, flag, string.format('%s %s', channel, param))
elseif string.find(modes_with_param_when_set, flag) then
if sign == '+' then
param = word[param_pos]
param_pos = param_pos + 1
emit('Channel Mode Generic', name, sign, flag, string.format('%s %s', channel, param))
else
emit('Channel Mode Generic', name, sign, flag, channel)
end
else
emit('Channel Mode Generic', name, sign, flag, channel)
end
end
end
else
return -- Unknown event
end
return hexchat.EAT_ALL
end, hexchat.PRI_HIGH)