Added basic API docs, implemented !uptime bot command, made quick fix to ignore lines starting with '/' and changed default auto* settings to true.

This commit is contained in:
Diego Martínez 2013-01-01 21:15:45 -02:00
parent 31e7d96de4
commit 09e72607f2
5 changed files with 73 additions and 16 deletions

45
doc/API.txt Normal file
View File

@ -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 <message> to either the channel (if <name> is nil or not specified),
or to the given user (if <name> 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 <name>.
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>):
cmddef = {
params = "<param1> ...", -- 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.
-- <from> is the name of the user that invoked the command.
-- <param> 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,
});

View File

@ -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;
});

View File

@ -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);

View File

@ -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;
});

View File

@ -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;