Skip to content

Instantly share code, notes, and snippets.

@jacob1
Created July 7, 2017 23:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jacob1/f54a947e45dd3b876dd4ff2c184fcfc4 to your computer and use it in GitHub Desktop.
Save jacob1/f54a947e45dd3b876dd4ff2c184fcfc4 to your computer and use it in GitHub Desktop.
Hexchat example Lua script
hexchat.register("myscript", "0.1", "script description goes here")
local function DelayedMessage(context, message)
context:command("say "..message)
end
local function makeFancyCallback(f, ...)
local arg = {...}
return function() return f(unpack(arg)) end
end
local function test(data)
local nick = data[1]
local text = data[2]
if not nick or not text then return end
if text:sub(1, 8) == "!luatato" then
hexchat.hook_timer(100, makeFancyCallback(DelayedMessage, hexchat.get_context(), "How are you holding up? Because i'm a potato"))
elseif text:sub(1, 4) == "!lua" then
local args = text:sub(5)
local func,err = loadstring("return "..args, "!lua")
if not func then
func,err = loadstring(args, "!lua")
end
if func then
local ret, err = pcall(func)
if not err then
hexchat.hook_timer(100, makeFancyCallback(DelayedMessage, hexchat.get_context(), "No output"))
else
hexchat.hook_timer(100, makeFancyCallback(DelayedMessage, hexchat.get_context(), "Result: "..tostring(err)))
end
else
hexchat.hook_timer(100, makeFancyCallback(DelayedMessage, hexchat.get_context(), "Error: "..tostring(err)))
end
end
end
hexchat.hook_command("rainbow", function(w, we)
local s = ""
for i = 1, #we[2] do
s = s .. ("\3%02d"):format(({4,7,8,9,3,10,11,12,2,6,13})[i % 11 + 1]) .. we[2]:sub(i,i)
end
hexchat.command("say ".. s)
return hexchat.EAT_HEXCHAT
end)
hexchat.hook_print("Your Message", test)
hexchat.print("Loaded test script")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment