-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandle.lua
35 lines (29 loc) · 1.09 KB
/
handle.lua
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
local handle = {}
local handlers
function handle.message( msg, msgType, console )
if handlers[msgType] then
local send = handlers[msgType]( msg, console ) -- get the return value from the handler to know what to send
if send then
return send
end
elseif msgType == "unknown" then -- if the message type is unknown then do nothing
else
print( "ERROR: message type " .. msgType .. " for message <" .. msg .. "> does not have a handler." )
end
end
function handleChat( msg, console )
local username = string.sub( msg, string.find( msg, "[%w_]+" ) )
local sStart, sEnd = string.find( msg, "[%w_]+![%w_]+@[%w_]+%.tmi%.twitch%.tv PRIVMSG #[%w_]+ :" )
local chatMsg = string.sub( msg, sEnd + 1 )
console:print( username .. ": " .. chatMsg )
end
function handlePing( pingMsg )
local pongMsg = string.gsub( pingMsg, "PING", "PONG" ) -- replace the string "PING" with "PONG" in the ping message
return pongMsg -- send the pong message back to handle.message so it can send it to main.lua for sending to IRC
end
handlers =
{
chat = handleChat,
ping = handlePing
}
return handle