From d005b8d7b235489efad0edfb53465ec4ae35b902 Mon Sep 17 00:00:00 2001 From: Sam Townsend Date: Fri, 2 Sep 2016 20:09:03 -0500 Subject: [PATCH 1/7] Improved handling of mode changes in buffextras.lua --- HexChat/buffextras.lua | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/HexChat/buffextras.lua b/HexChat/buffextras.lua index f5e642d..53e5a37 100644 --- a/HexChat/buffextras.lua +++ b/HexChat/buffextras.lua @@ -38,7 +38,12 @@ hexchat.hook_server_attrs('PRIVMSG', function (word, word_eol, attrs) elseif is_event('kicked') then emit('Kick', nick, word[6], channel, strip_brackets(word_eol[8])) elseif is_event('set mode') then - emit('Raw Modes', nick, string.format('%s %s', channel, word_eol[7])) + if nick == nil then + server = word[4]:match('^:([^!]+)$') + emit('Channel Mode Generic', server, string.format('%s %s', word_eol[7]:match('^(.*%S)'), channel)) + else + emit('Channel Mode Generic', nick, string.format('%s %s', word_eol[7]:match('^(.*%S)'), channel)) + end else return -- Unknown event end From efe1b1ec97ad834b77873162124835ad43fd5ec5 Mon Sep 17 00:00:00 2001 From: Sam Townsend Date: Sat, 3 Sep 2016 01:26:14 -0500 Subject: [PATCH 2/7] Restored "Raw Modes" format when appropriate in buffextras.lua --- HexChat/buffextras.lua | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/HexChat/buffextras.lua b/HexChat/buffextras.lua index 53e5a37..0bb039c 100644 --- a/HexChat/buffextras.lua +++ b/HexChat/buffextras.lua @@ -38,11 +38,15 @@ hexchat.hook_server_attrs('PRIVMSG', function (word, word_eol, attrs) elseif is_event('kicked') then emit('Kick', nick, word[6], channel, strip_brackets(word_eol[8])) elseif is_event('set mode') then - if nick == nil then - server = word[4]:match('^:([^!]+)$') - emit('Channel Mode Generic', server, string.format('%s %s', word_eol[7]:match('^(.*%S)'), channel)) + 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 - emit('Channel Mode Generic', nick, string.format('%s %s', word_eol[7]:match('^(.*%S)'), channel)) + emit('Channel Mode Generic', name, string.format('%s %s', modes, channel)) end else return -- Unknown event From ec3d9f7680d88a654b98064e64ace9e47d3c3c7c Mon Sep 17 00:00:00 2001 From: Sam Townsend Date: Sat, 3 Sep 2016 13:59:56 -0500 Subject: [PATCH 3/7] Implemented splitting modes and support for specific modes in buffextras.lua This should now pretty much emulate what HexChat does normally. I haven't yet tested it enough for full confidence though. --- HexChat/buffextras.lua | 133 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 132 insertions(+), 1 deletion(-) diff --git a/HexChat/buffextras.lua b/HexChat/buffextras.lua index 0bb039c..31fa99b 100644 --- a/HexChat/buffextras.lua +++ b/HexChat/buffextras.lua @@ -1,9 +1,30 @@ hexchat.register('Buffextras', '1', "Format messages from ZNC's buffextras module") +local modes_for_lists = {} +local modes_with_param = {} +local modes_with_param_when_set = {} +local modes_without_param = {} + local function strip_brackets (str) return str:sub(2, #str - 1) end +hexchat.hook_server_attrs('005', function (word, word_eol, attrs) + for key,value in pairs(word) do + modes = value:match('^CHANMODES=(.*)$') + if modes ~= nil then + server = word[1]:match('^:(.*)$') + modes_a, modes_b, modes_c, modes_d = modes:match('^(.*),(.*),(.*),(.*)$') + modes_for_lists[server] = modes_a + modes_with_param[server] = modes_b + modes_with_param_when_set[server] = modes_c + modes_without_param[server] = modes_d + break + end + end + return +end, hexchat.PRI_HIGH) + hexchat.hook_server_attrs('PRIVMSG', function (word, word_eol, attrs) if not word[1]:match('^:%*buffextras!') then return @@ -46,7 +67,117 @@ hexchat.hook_server_attrs('PRIVMSG', function (word, word_eol, attrs) if hexchat.prefs['irc_raw_modes'] == true then emit('Raw Modes', name, string.format('%s %s', channel, modes)) else - emit('Channel Mode Generic', name, string.format('%s %s', modes, channel)) + local nickmodes + for chan in hexchat.iterate('channels') do + if chan.context == hexchat.get_context() then + nickmodes = chan.nickmodes + break + end + end + + server = hexchat.get_info('server') + local modes_for_lists = modes_for_lists[server] + local modes_with_param = modes_with_param[server] + local modes_with_param_when_set = modes_with_param_when_set[server] + local modes_without_param = modes_without_param[server] + + 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 From 341652a8c084f3b19ad22ddd84a3264674a36b11 Mon Sep 17 00:00:00 2001 From: Sam Townsend Date: Sat, 3 Sep 2016 15:34:35 -0500 Subject: [PATCH 4/7] Cleanup, minor fix, and added commented-out use of hexchat.props['chanmodes'] in buffextras.lua --- HexChat/buffextras.lua | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/HexChat/buffextras.lua b/HexChat/buffextras.lua index 31fa99b..f9f48ea 100644 --- a/HexChat/buffextras.lua +++ b/HexChat/buffextras.lua @@ -1,9 +1,6 @@ hexchat.register('Buffextras', '1', "Format messages from ZNC's buffextras module") -local modes_for_lists = {} -local modes_with_param = {} -local modes_with_param_when_set = {} -local modes_without_param = {} +local chanmodes = {} local function strip_brackets (str) return str:sub(2, #str - 1) @@ -14,11 +11,7 @@ hexchat.hook_server_attrs('005', function (word, word_eol, attrs) modes = value:match('^CHANMODES=(.*)$') if modes ~= nil then server = word[1]:match('^:(.*)$') - modes_a, modes_b, modes_c, modes_d = modes:match('^(.*),(.*),(.*),(.*)$') - modes_for_lists[server] = modes_a - modes_with_param[server] = modes_b - modes_with_param_when_set[server] = modes_c - modes_without_param[server] = modes_d + chanmodes[server] = modes break end end @@ -67,19 +60,16 @@ hexchat.hook_server_attrs('PRIVMSG', function (word, word_eol, attrs) if hexchat.prefs['irc_raw_modes'] == true then emit('Raw Modes', name, string.format('%s %s', channel, modes)) else - local nickmodes - for chan in hexchat.iterate('channels') do - if chan.context == hexchat.get_context() then - nickmodes = chan.nickmodes - break - end - end + nickmodes = hexchat.props['nickmodes'] + --chanmodes = hexchat.props['chanmodes'] server = hexchat.get_info('server') - local modes_for_lists = modes_for_lists[server] - local modes_with_param = modes_with_param[server] - local modes_with_param_when_set = modes_with_param_when_set[server] - local modes_without_param = modes_without_param[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 From 5fb1897246a4cb0ddb1654eefa72d3057f453efb Mon Sep 17 00:00:00 2001 From: Sam Townsend Date: Thu, 26 Jul 2018 12:37:53 -0500 Subject: [PATCH 5/7] Updated script to use chanmodes property and to account for changes in ZNC 1.7 --- HexChat/buffextras.lua | 32 +++++++------------------------- 1 file changed, 7 insertions(+), 25 deletions(-) diff --git a/HexChat/buffextras.lua b/HexChat/buffextras.lua index f9f48ea..e5357e5 100644 --- a/HexChat/buffextras.lua +++ b/HexChat/buffextras.lua @@ -1,23 +1,5 @@ hexchat.register('Buffextras', '1', "Format messages from ZNC's buffextras module") -local chanmodes = {} - -local function strip_brackets (str) - return str:sub(2, #str - 1) -end - -hexchat.hook_server_attrs('005', function (word, word_eol, attrs) - for key,value in pairs(word) do - modes = value:match('^CHANMODES=(.*)$') - if modes ~= nil then - server = word[1]:match('^:(.*)$') - chanmodes[server] = modes - break - end - end - return -end, hexchat.PRI_HIGH) - hexchat.hook_server_attrs('PRIVMSG', function (word, word_eol, attrs) if not word[1]:match('^:%*buffextras!') then return @@ -36,11 +18,11 @@ hexchat.hook_server_attrs('PRIVMSG', function (word, word_eol, attrs) if is_event('joined') then emit('Join', nick, channel, host) - elseif is_event('quit with message') then - emit('Quit', nick, strip_brackets(word_eol[8]), host) - elseif is_event('parted with message') then - local reason = strip_brackets(word_eol[8]) - if reason ~= '' then + 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) @@ -50,7 +32,7 @@ hexchat.hook_server_attrs('PRIVMSG', function (word, word_eol, attrs) 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, strip_brackets(word_eol[8])) + emit('Kick', nick, word[6], channel, word_eol[9]) elseif is_event('set mode') then modes = word_eol[7]:match('^(.*%S)') name = nick @@ -61,7 +43,7 @@ hexchat.hook_server_attrs('PRIVMSG', function (word, word_eol, attrs) emit('Raw Modes', name, string.format('%s %s', channel, modes)) else nickmodes = hexchat.props['nickmodes'] - --chanmodes = hexchat.props['chanmodes'] + chanmodes = hexchat.props['chanmodes'] server = hexchat.get_info('server') local chanmodes = chanmodes[server] From 5d8a60fc58753c13dbaa0d692828b9923c908da4 Mon Sep 17 00:00:00 2001 From: Sam Townsend Date: Thu, 26 Jul 2018 12:53:28 -0500 Subject: [PATCH 6/7] Re-added missing license indicator --- HexChat/buffextras.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/HexChat/buffextras.lua b/HexChat/buffextras.lua index e5357e5..383da7a 100644 --- a/HexChat/buffextras.lua +++ b/HexChat/buffextras.lua @@ -1,3 +1,4 @@ +--- 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) From 8f4707c12c7a800861a5e9d145060255c74b8f28 Mon Sep 17 00:00:00 2001 From: Sam Townsend Date: Thu, 26 Jul 2018 14:52:25 -0500 Subject: [PATCH 7/7] Made nickmodes and chanmodes variables local and removed erroneous dash --- HexChat/buffextras.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/HexChat/buffextras.lua b/HexChat/buffextras.lua index 383da7a..43d2ef9 100644 --- a/HexChat/buffextras.lua +++ b/HexChat/buffextras.lua @@ -1,4 +1,4 @@ ---- SPDX-License-Identifier: MIT +-- 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) @@ -43,8 +43,8 @@ hexchat.hook_server_attrs('PRIVMSG', function (word, word_eol, attrs) if hexchat.prefs['irc_raw_modes'] == true then emit('Raw Modes', name, string.format('%s %s', channel, modes)) else - nickmodes = hexchat.props['nickmodes'] - chanmodes = hexchat.props['chanmodes'] + local nickmodes = hexchat.props['nickmodes'] + local chanmodes = hexchat.props['chanmodes'] server = hexchat.get_info('server') local chanmodes = chanmodes[server]