mirror of
https://github.com/minetest-mods/irc.git
synced 2024-12-28 09:40:17 +01:00
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:
parent
31e7d96de4
commit
09e72607f2
45
doc/API.txt
Normal file
45
doc/API.txt
Normal 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,
|
||||||
|
});
|
@ -71,3 +71,21 @@ mt_irc.register_bot_command("whereis", {
|
|||||||
irc.say(from, "There's No player named `"..args.."'");
|
irc.say(from, "There's No player named `"..args.."'");
|
||||||
end;
|
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;
|
||||||
|
});
|
||||||
|
@ -93,8 +93,9 @@ minetest.register_on_leaveplayer(function ( player )
|
|||||||
end);
|
end);
|
||||||
|
|
||||||
minetest.register_on_chat_message(function ( name, message )
|
minetest.register_on_chat_message(function ( name, message )
|
||||||
|
if (message:sub(1, 1) == "/") then return; end
|
||||||
if (not mt_irc.connected_players[name]) then
|
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;
|
return;
|
||||||
end
|
end
|
||||||
if (not mt_irc.connect_ok) then 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;
|
message = message;
|
||||||
};
|
};
|
||||||
end);
|
end);
|
||||||
|
|
||||||
|
minetest.register_on_shutdown(function ( )
|
||||||
|
irc.quit("Game shutting down.");
|
||||||
|
end);
|
||||||
|
@ -108,12 +108,3 @@ minetest.register_chatcommand("who", {
|
|||||||
minetest.chat_send_player(name, "Players On Channel:"..s);
|
minetest.chat_send_player(name, "Players On Channel:"..s);
|
||||||
end;
|
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;
|
|
||||||
});
|
|
||||||
|
@ -40,11 +40,9 @@ mt_irc.message_format_in = "<$(name)@IRC> $(message)";
|
|||||||
mt_irc.debug = true;
|
mt_irc.debug = true;
|
||||||
|
|
||||||
-- Whether to automatically join the channed when player joins
|
-- Whether to automatically join the channed when player joins
|
||||||
-- (boolean, default false)
|
-- (boolean, default true)
|
||||||
-- For now leave this false if using autoconnect. Bot will join channel when first user
|
mt_irc.auto_join = true;
|
||||||
-- types the /join command in game.
|
|
||||||
mt_irc.auto_join = false;
|
|
||||||
|
|
||||||
-- Whether to automatically connect to the server on mod load
|
-- Whether to automatically connect to the server on mod load
|
||||||
-- (boolean, default false)
|
-- (boolean, default true)
|
||||||
mt_irc.auto_connect = false;
|
mt_irc.auto_connect = true;
|
||||||
|
Loading…
Reference in New Issue
Block a user