Skip to content

Instantly share code, notes, and snippets.

@boxmein
Forked from JanneSalokoski/ExpBot II.lua
Last active December 19, 2015 09:19
Show Gist options
  • Save boxmein/5932637 to your computer and use it in GitHub Desktop.
Save boxmein/5932637 to your computer and use it in GitHub Desktop.
I fixed the commenting up a bit, and added a few todos which in my opinion should help the developer (@jenn4).
--ExpBot II (Experimental Bot V2.1) - An simple IRC bot written in Lua - the programming language.
-- Comments are written in the luadoc style
-- http://keplerproject.github.io/luadoc/manual.html#tags
require "socket"
s = socket.tcp()
-- passwords are received from standard input
passLine = io.read()
network = "chat.eu.freenode.net" --
nick = "ExpBot" --
user = "jenn4" --
mode = "8" -- leave this as such
realname = "ExpBot" -- reported as the "Real Name"
channels = "#jenn4" -- auto-joining - separate multiple channels with ONLY a comma "#a,#b,##c"
prefix = "!!" -- prefix commands with this
msg = {}
--- Pause running for a little while.
-- @param n {number} seconds to pause
clock = os.clock
function sleep(n)
local t = clock()
while clock() - t <= n do end
end
--- Tell the IRC server about us
-- @see RFC 1459
function sendInitialConfig()
print("<< Sending configuration. >>")
print("<< Your password, please. >>")
-- TODO replace with a raw IRC wrapper? (automatically adds \r\n if needed, validates)
s:send("PASS " .. passLine .. "\r\n")
s:send("NICK " .. nick .. "\r\n")
s:send("USER " .. user .. " " .. mode .. " * " .. " :" .. realname .. "\r\n")
s:send("JOIN " .. channels .. "\r\n")
end
--- Interprets the IRC data and handles pingpongs
function handleRawIRC()
if output:match "PING :" then
s:send("PONG :" .. output:match"^PING :(.*)") -- idk but boxmein
end
end
--- Okay now actually connect to the server, promise
-- This is also the entry point for the application.
function init()
s:connect(network, 6667)
sendInitialConfig()
while true do
output = s:receive("*l*") -- A trick to remove \r\n from input.
print(output) -- debug!
-- TODO don't use global variables here?
handleRawIRC()
end
end
init()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment