From 09e72607f276563b06f68e6a2546588650d7ba61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Mart=C3=ADnez?= Date: Tue, 1 Jan 2013 21:15:45 -0200 Subject: [PATCH] Added basic API docs, implemented !uptime bot command, made quick fix to ignore lines starting with '/' and changed default auto* settings to true. --- doc/API.txt | 45 +++++++++++++++++++++++++++++++++++++++++++++ src/botcmds.lua | 18 ++++++++++++++++++ src/callback.lua | 7 ++++++- src/chatcmds.lua | 9 --------- src/config.lua | 10 ++++------ 5 files changed, 73 insertions(+), 16 deletions(-) create mode 100644 doc/API.txt diff --git a/doc/API.txt b/doc/API.txt new file mode 100644 index 0000000..bdb08e3 --- /dev/null +++ b/doc/API.txt @@ -0,0 +1,45 @@ + +IRC Mod API +----------- +This file documents the API exported by the IRC mod. + + +BASICS +------ +In order to allow your mod to interface with this mod, you must add `irc' + (without the quotes) to your mod's `depends.txt' file. + + +REFERENCE +--------- +These are the functions defined by the mod: + +mt_irc.say ( [name ,] message ) + Sends to either the channel (if is nil or not specified), + or to the given user (if is specified). + Example: + mt_irc.say("Hello, Channel!") + mt_irc.say("john1234", "How are you?") + +mt_irc.register_bot_command ( name, cmddef ) + Registers a new bot command named . + When an user sends a private message to the bot starting with `!name', the + command's function is called. + Here's the command definition (): + cmddef = { + params = " ...", -- A short help text for !help + description = "My command", -- What does the command? (one-liner) + func = function ( from, param ) + -- This function gets called when the command is invoked. + -- is the name of the user that invoked the command. + -- is the rest of the input (after removing !command) + end, + }; + Example: + mt_irc.register_bot_command("hello", { + params = nil, -- No params + description = "Greet user", + func = function ( from, param ) + mt_irc.say(from, "Hello!"); + end, + }); diff --git a/src/botcmds.lua b/src/botcmds.lua index 1afc3d9..de6f06d 100644 --- a/src/botcmds.lua +++ b/src/botcmds.lua @@ -71,3 +71,21 @@ mt_irc.register_bot_command("whereis", { irc.say(from, "There's No player named `"..args.."'"); end; }); + +local starttime = os.time(); + +mt_irc.register_bot_command("uptime", { + params = ""; + description = "Tell how much time the server has been up"; + privs = { shout=true; }; + func = function ( name, param ) + local t = os.time(); + local diff = os.difftime(t, starttime); + local fmt = "Server has been running for %d:%02d:%02d"; + irc.say(name, fmt:format( + math.floor(diff / 60 / 60), + math.mod(math.floor(diff / 60), 60), + math.mod(math.floor(diff), 60) + )); + end; +}); diff --git a/src/callback.lua b/src/callback.lua index 819d268..b95d4c5 100644 --- a/src/callback.lua +++ b/src/callback.lua @@ -93,8 +93,9 @@ minetest.register_on_leaveplayer(function ( player ) end); minetest.register_on_chat_message(function ( name, message ) + if (message:sub(1, 1) == "/") then return; end if (not mt_irc.connected_players[name]) then - minetest.chat_send_player(name, "IRC: You are not connected. Please use /join"); + --minetest.chat_send_player(name, "IRC: You are not connected. Please use /join"); return; end if (not mt_irc.connect_ok) then return; end @@ -106,3 +107,7 @@ minetest.register_on_chat_message(function ( name, message ) message = message; }; end); + +minetest.register_on_shutdown(function ( ) + irc.quit("Game shutting down."); +end); diff --git a/src/chatcmds.lua b/src/chatcmds.lua index c46f72b..4320e5f 100644 --- a/src/chatcmds.lua +++ b/src/chatcmds.lua @@ -108,12 +108,3 @@ minetest.register_chatcommand("who", { minetest.chat_send_player(name, "Players On Channel:"..s); end; }); - -minetest.register_chatcommand("uptime", { - params = ""; - description = "Tell how much time the server has been up"; - privs = { shout=true; }; - func = function ( name, param ) - local t = os.time(); - end; -}); diff --git a/src/config.lua b/src/config.lua index df976ce..37c7ce6 100644 --- a/src/config.lua +++ b/src/config.lua @@ -40,11 +40,9 @@ mt_irc.message_format_in = "<$(name)@IRC> $(message)"; mt_irc.debug = true; -- Whether to automatically join the channed when player joins --- (boolean, default false) --- For now leave this false if using autoconnect. Bot will join channel when first user --- types the /join command in game. -mt_irc.auto_join = false; +-- (boolean, default true) +mt_irc.auto_join = true; -- Whether to automatically connect to the server on mod load --- (boolean, default false) -mt_irc.auto_connect = false; +-- (boolean, default true) +mt_irc.auto_connect = true;