mirror of https://github.com/nealey/irc-bot
43 lines
1.3 KiB
Lua
Executable File
43 lines
1.3 KiB
Lua
Executable File
#! /usr/bin/lua
|
|
|
|
--
|
|
-- A very simple bot which will join IRC, join #newmont, and
|
|
-- respond to any messages with "strawberry" in them. It also
|
|
-- has some naïve nickname collision avoidance.
|
|
--
|
|
-- This is a good place to start if you're not going to write
|
|
-- your handler in lua. If you *do* want to use lua, you should
|
|
-- take a look at bot.lua instead.
|
|
--
|
|
|
|
prefix = os.getenv("prefix")
|
|
forum = os.getenv("forum")
|
|
sender = os.getenv("sender")
|
|
command = os.getenv("command")
|
|
text = os.getenv("text")
|
|
|
|
io.stderr:write(">>> [" .. command .. "] " ..
|
|
(sender or "-") .. "/" ..
|
|
(forum or "-") .. " " ..
|
|
(text or "") .. "\n")
|
|
|
|
-- Our behavior depends on what the command is
|
|
if (command == "_INIT_") then
|
|
-- bot sends this when it first starts up, so we can log in
|
|
print("NICK nemont")
|
|
print("USER newmont newmont newmont :Sample bot")
|
|
elseif (command == "433") then
|
|
-- Couldn't get the nickname we asked for
|
|
print("NICK bot_" .. (os.time() % 500))
|
|
elseif (command == "001") then
|
|
-- IRC server sends this after successful login
|
|
print("JOIN #newmont")
|
|
elseif (command == "PRIVMSG") then
|
|
-- Somebody said something!
|
|
if (text:find("strawberry")) then
|
|
print("PRIVMSG " .. forum .. " :Strawberries are delicious.")
|
|
elseif (text:find("die")) then
|
|
print("QUIT :goodbye")
|
|
end
|
|
end
|