irc-bot/contrib/newmont

43 lines
1.3 KiB
Plaintext
Raw Normal View History

2012-11-15 18:33:21 -07:00
#! /usr/bin/lua
--
2012-11-16 12:46:16 -07:00
-- 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.
2012-11-15 18:33:21 -07:00
--
2012-11-16 12:46:16 -07:00
-- 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.
--
2012-11-15 18:33:21 -07:00
prefix = os.getenv("prefix")
forum = os.getenv("forum")
sender = os.getenv("sender")
command = os.getenv("command")
text = os.getenv("text")
2012-11-16 12:46:16 -07:00
io.stderr:write(">>> [" .. command .. "] " ..
(sender or "-") .. "/" ..
(forum or "-") .. " " ..
(text or "") .. "\n")
2012-11-15 18:33:21 -07:00
2012-11-16 12:46:16 -07:00
-- Our behavior depends on what the command is
if (command == "_INIT_") then
2012-11-15 18:33:21 -07:00
-- bot sends this when it first starts up, so we can log in
2012-11-16 12:46:16 -07:00
print("NICK nemont")
print("USER newmont newmont newmont :Sample bot")
2012-11-15 18:33:21 -07:00
elseif (command == "433") then
-- Couldn't get the nickname we asked for
2012-11-16 12:46:16 -07:00
print("NICK bot_" .. (os.time() % 500))
2012-11-15 18:33:21 -07:00
elseif (command == "001") then
-- IRC server sends this after successful login
2012-11-16 12:46:16 -07:00
print("JOIN #newmont")
2012-11-15 18:33:21 -07:00
elseif (command == "PRIVMSG") then
-- Somebody said something!
if (text:find("strawberry")) then
2012-11-16 12:46:16 -07:00
print("PRIVMSG " .. forum .. " :Strawberries are delicious.")
elseif (text:find("die")) then
print("QUIT :goodbye")
2012-11-15 18:33:21 -07:00
end
end