Skip to content

Instantly share code, notes, and snippets.

@sebres
Last active June 1, 2021 13:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sebres/b22fc2ab8b63aeee1281586728a0d02b to your computer and use it in GitHub Desktop.
Save sebres/b22fc2ab8b63aeee1281586728a0d02b to your computer and use it in GitHub Desktop.
bot-bridge-nicks.lua -- HexChat plug-in to wrap IRC bots to real user nicknames
hexchat.register("bot-bridge-nicks", "0.1", "Rewrites messages of bots to display bridge users as IRC users")
-- ijchain, ischain, liberachain are bridges:
botspattern = {"i.*chain", "^[<«](.-)[>»] (.*)$", "^<?(.-)>? (.*)$"}
botspattern2 = {"l.*chain", "^[<«](.-)[>»] (.*)$", "^%* (.-) (.*)$"}
local function fullname(user, nick)
return user:gsub("%s+", "-").."!"..user:gsub("%s+", "_").."@behind.the.bridge/"..nick
end
local function on_message(args)
local nick = args[1]
local msg = args[2]
local chan = hexchat.get_info("channel")
-- matches bridges pattern:
if string.match(nick, botspattern[1]) then
-- check and wrap "<user> message" from bridge user message:
v = {string.match(msg, botspattern[2])}
if #v ~= 0 then
msg = v[2]
local pnick = nick
nick = v[1]
-- second match (triple bridge?):
if string.match(nick, botspattern2[1]) then
-- check and wrap "<user> message" from bridge user message:
v = {string.match(msg, botspattern2[2])}
if #v ~= 0 then
msg = v[2]
pnick = nick
nick = v[1]
end
end
nick = fullname(nick, pnick)
hexchat.command("RECV :"..nick.." PRIVMSG "..chan.." -"..msg)
return hexchat.EAT_ALL -- drop original message
end
end
return hexchat.EAT_NONE -- bypass (do nothing)
end
local function on_action(args)
local nick = args[1]
local msg = args[2]
local chan = hexchat.get_info("channel")
-- matches bridges pattern:
if string.match(nick, botspattern[1]) then
-- check and wrap "has become available"/"has left" actions from bridge to JOIN/QUIT messages
local v = {string.match(msg, botspattern[3])}
if #v ~= 0 then
msg = v[2]
local pnick = nick
nick = v[1]
-- second match (triple bridge?):
if string.match(nick, botspattern2[1]) then
-- check and wrap "<user> message" from bridge user message:
v = {string.match(msg, botspattern2[3])}
if #v ~= 0 then
msg = v[2]
pnick = nick
nick = v[1]
end
end
nick = fullname(nick, pnick)
if msg == "has left" then
msg = "QUIT :"..msg
elseif msg == "has become available" then
msg = "JOIN "..chan
else
msg = "PRIVMSG "..chan.." :\x01ACTION "..msg.."\x01"
end
hexchat.command("RECV :"..nick.." "..msg)
return hexchat.EAT_ALL -- drop original message
end
end
return hexchat.EAT_NONE -- bypass (do nothing)
end
hexchat.hook_print("Channel Message", on_message, hexchat.PRI_HIGHEST)
hexchat.hook_print("Channel Msg Hilight", on_message, hexchat.PRI_HIGHEST)
hexchat.hook_print("Channel Action", on_action, hexchat.PRI_HIGHEST)
hexchat.hook_print("Channel Action Hilight", on_action, hexchat.PRI_HIGHEST)
hexchat.print("Loaded bot-bridge-nicks script")
-- to test on load whether it works:
-- on_message({'ischain','<Tester Alex> -0.0, Test message'})
-- on_message({'ischain', '<liberachain> «tester» test'})
-- on_message({'ijchain', '<liberachain> <Tester> test message'})
-- on_action({'ijchain', 'Tester tests chat'})
-- on_action({'ijchain', '<liberachain> * Tester tests chat from libera side'})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment