Merge pull request #2 from Elkien3/master

Updating Fork again.
This commit is contained in:
Coder12a 2017-10-13 17:03:31 -07:00 committed by GitHub
commit c69b117a51
41 changed files with 640 additions and 1634 deletions

View File

@ -423,7 +423,7 @@ end
minetest.register_tool(
"backpack:backpack",
{
description = "Backpack",
description = "Backpack (WORK IN PROGRESS, USE AT YOUR OWN RISK)",
groups = { bag = BAG_WIDTH*BAG_HEIGHT, flammable = 1 },
inventory_image = "inventory_plus_backpack.png",
wield_image = "inventory_plus_backpack.png",
@ -453,7 +453,6 @@ minetest.register_tool(
-- detached proxy that doesn't allow the bag's stack to be changed
-- while open!
})
--[[
minetest.register_craft(
{
output = "backpack:backpack",
@ -463,5 +462,4 @@ minetest.register_craft(
{ "group:wool", "", "group:wool" },
{ "group:wool", "group:wool", "group:wool" },
}
})
--]]
})

View File

@ -50,7 +50,7 @@ for i, size in ipairs(sizes) do
-- clicker:set_hp(clicker:get_hp() + 1)
local name = clicker:get_player_name()
local h = tonumber(hud.hunger[name])
h = h + 4
h = h + 2
hud.hunger[name] = h
hud.set_hunger(clicker)
if i < #sizes then

View File

@ -126,12 +126,35 @@ local def = {
{"creatures:chicken_flesh"},
{"creatures:feather", {min = 1, max = 2}, chance = 0.45},
},
on_rightclick = function(self, clicker)
local item = clicker:get_wielded_item()
if item then
local name = item:get_name()
if name == "farming:seed_wheat" then
if not self.tamed then
self.fed_cnt = (self.fed_cnt or 0) + 1
end
-- play eat sound?
item:take_item()
if not core.setting_getbool("creative_mode") then
clicker:set_wielded_item(item)
end
end
end
end,
on_step = function(self, dtime)
if self.mode == "lay_egg" then
dropEgg(self.object)
self.modetimer = 2
end
if self.fed_cnt and self.fed_cnt > 4 then
self.tamed = true
self.fed_cnt = nil
end
end
}

View File

@ -30,6 +30,6 @@ minetest.register_craft({
minetest.register_craft({
output = "default:dirt",
recipe = {
{"default:sand", "default:leaves"}
{"default:sand", "group:leaves"}
}
})

View File

@ -11,13 +11,41 @@ minetest.register_craftitem("default:paper", {
inventory_image = "default_paper.png",
})
local function book_on_use(itemstack, user, pointed_thing)
local lpp = 14 -- Lines per book's page
local function book_on_use(itemstack, user)
local player_name = user:get_player_name()
local data = minetest.deserialize(itemstack:get_metadata())
local meta = itemstack:get_meta()
local title, text, owner = "", "", player_name
if data then
title, text, owner = data.title, data.text, data.owner
local page, page_max, lines, string = 1, 1, {}, ""
-- Backwards compatibility
local old_data = minetest.deserialize(itemstack:get_metadata())
if old_data then
meta:from_table({ fields = old_data })
end
local data = meta:to_table().fields
if data.owner then
title = data.title
text = data.text
owner = data.owner
for str in (text .. "\n"):gmatch("([^\n]*)[\n]") do
lines[#lines+1] = str
end
if data.page then
page = data.page
page_max = data.page_max
for i = ((lpp * page) - lpp) + 1, lpp * page do
if not lines[i] then break end
string = string .. lines[i] .. "\n"
end
end
end
local formspec
if owner == player_name then
formspec = "size[8,8]" .. default.gui_bg ..
@ -31,61 +59,111 @@ local function book_on_use(itemstack, user, pointed_thing)
formspec = "size[8,8]" .. default.gui_bg ..
default.gui_bg_img ..
"label[0.5,0.5;by " .. owner .. "]" ..
"label[0.5,0;" .. minetest.formspec_escape(title) .. "]" ..
"textarea[0.5,1.5;7.5,7;text;;" ..
minetest.formspec_escape(text) .. "]"
"tablecolumns[color;text]" ..
"tableoptions[background=#00000000;highlight=#00000000;border=false]" ..
"table[0.4,0;7,0.5;title;#FFFF00," .. minetest.formspec_escape(title) .. "]" ..
"textarea[0.5,1.5;7.5,7;;" ..
minetest.formspec_escape(string ~= "" and string or text) .. ";]" ..
"button[2.4,7.6;0.8,0.8;book_prev;<]" ..
"label[3.2,7.7;Page " .. page .. " of " .. page_max .. "]" ..
"button[4.9,7.6;0.8,0.8;book_next;>]"
end
minetest.show_formspec(user:get_player_name(), "default:book", formspec)
minetest.show_formspec(player_name, "default:book", formspec)
return itemstack
end
minetest.register_on_player_receive_fields(function(player, form_name, fields)
if form_name ~= "default:book" or not fields.save or
fields.title == "" or fields.text == "" then
return
end
local max_text_size = 10000
local max_title_size = 80
local short_title_size = 35
minetest.register_on_player_receive_fields(function(player, formname, fields)
if formname ~= "default:book" then return end
local inv = player:get_inventory()
local stack = player:get_wielded_item()
local new_stack, data
if stack:get_name() ~= "default:book_written" then
local count = stack:get_count()
if count == 1 then
stack:set_name("default:book_written")
if fields.save and fields.title and fields.text
and fields.title ~= "" and fields.text ~= "" then
local new_stack, data
if stack:get_name() ~= "default:book_written" then
local count = stack:get_count()
if count == 1 then
stack:set_name("default:book_written")
else
stack:set_count(count - 1)
new_stack = ItemStack("default:book_written")
end
else
stack:set_count(count - 1)
new_stack = ItemStack("default:book_written")
data = stack:get_meta():to_table().fields
end
else
data = minetest.deserialize(stack:get_metadata())
end
if not data then data = {} end
data.title = fields.title
data.text = fields.text
data.owner = player:get_player_name()
local data_str = minetest.serialize(data)
if new_stack then
new_stack:set_metadata(data_str)
if inv:room_for_item("main", new_stack) then
inv:add_item("main", new_stack)
if data and data.owner and data.owner ~= player:get_player_name() then
return
end
if not data then data = {} end
data.title = fields.title:sub(1, max_title_size)
data.owner = player:get_player_name()
local short_title = data.title
-- Don't bother triming the title if the trailing dots would make it longer
if #short_title > short_title_size + 3 then
short_title = short_title:sub(1, short_title_size) .. "..."
end
data.description = "\""..short_title.."\" by "..data.owner
data.text = fields.text:sub(1, max_text_size)
data.page = 1
data.page_max = math.ceil((#data.text:gsub("[^\n]", "") + 1) / lpp)
if new_stack then
new_stack:get_meta():from_table({ fields = data })
if inv:room_for_item("main", new_stack) then
inv:add_item("main", new_stack)
else
minetest.add_item(player:getpos(), new_stack)
end
else
minetest.add_item(player:getpos(), new_stack)
stack:get_meta():from_table({ fields = data })
end
else
stack:set_metadata(data_str)
elseif fields.book_next or fields.book_prev then
local data = stack:get_meta():to_table().fields
if not data or not data.page then
return
end
data.page = tonumber(data.page)
data.page_max = tonumber(data.page_max)
if fields.book_next then
data.page = data.page + 1
if data.page > data.page_max then
data.page = 1
end
else
data.page = data.page - 1
if data.page == 0 then
data.page = data.page_max
end
end
stack:get_meta():from_table({fields = data})
stack = book_on_use(stack, player)
end
-- Update stack
player:set_wielded_item(stack)
end)
minetest.register_craftitem("default:book", {
description = "Book",
inventory_image = "default_book.png",
groups = {book = 1},
groups = {book = 1, flammable = 3},
on_use = book_on_use,
})
minetest.register_craftitem("default:book_written", {
description = "Book With Text",
inventory_image = "default_book_written.png",
groups = {book = 1, not_in_creative_inventory = 1},
groups = {book = 1, not_in_creative_inventory = 1, flammable = 3},
stack_max = 1,
on_use = book_on_use,
})
@ -101,7 +179,6 @@ minetest.register_on_craft(function(itemstack, player, old_craft_grid, craft_inv
return
end
local copy = ItemStack("default:book_written")
local original
local index
for i = 1, player:get_inventory():get_size("craft") do
@ -113,9 +190,9 @@ minetest.register_on_craft(function(itemstack, player, old_craft_grid, craft_inv
if not original then
return
end
local copymeta = original:get_metadata()
local copymeta = original:get_meta():to_table()
-- copy of the book held by player's mouse cursor
itemstack:set_metadata(copymeta)
itemstack:get_meta():from_table(copymeta)
-- put the book with metadata back in the craft grid
craft_inv:set_stack("craft", index, original)
end)

14
mods/irc/.luacheckrc Normal file
View File

@ -0,0 +1,14 @@
allow_defined_top = true
read_globals = {
"minetest",
}
exclude_files = {
"irc/*",
}
globals = {
"irc",
}

View File

@ -13,14 +13,14 @@ to your mod's `depends.txt` file.
Reference
---------
irc:say([name,] message)
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:
irc:say("Hello, Channel!")
irc:say("john1234", "How are you?")
irc.say("Hello, Channel!")
irc.say("john1234", "How are you?")
irc:register_bot_command(name, cmdDef)
irc.register_bot_command(name, cmdDef)
Registers a new bot command named <name>.
When an user sends a private message to the bot with the command name, the
command's function is called.
@ -38,7 +38,7 @@ irc:register_bot_command(name, cmdDef)
end,
};
Example:
irc:register_bot_command("hello", {
irc.register_bot_command("hello", {
params = "",
description = "Greet user",
func = function(user, param)
@ -55,12 +55,12 @@ irc.joined_players[name]
-- Joe is talking on IRC
end
irc:register_hook(name, func)
irc.register_hook(name, func)
Registers a function to be called when an event happens. <name> is the name
of the event, and <func> is the function to be called. See HOOKS below
for more information
Example:
irc:register_hook("OnSend", function(line)
irc.register_hook("OnSend", function(line)
print("SEND: "..line)
end)
@ -83,7 +83,7 @@ not modify these settings at runtime or you might crash the server!
Hooks
-----
The `irc:register_hook` function can register functions to be called
The `irc.register_hook` function can register functions to be called
when some events happen. The events supported are the same as the LuaIRC
ones with a few added (mostly for internal use).
See src/LuaIRC/doc/irc.luadoc for more information.

View File

@ -1,12 +1,16 @@
IRC Mod for Minetest
====================
Introduction
------------
This mod is just a glue between IRC and Minetest. It provides two-way
communication between the in-game chat, and an arbitrary IRC channel.
The forum topic is at https://forum.minetest.net/viewtopic.php?f=11&t=3905
The forum topic is [here][forum].
[forum]: https://forum.minetest.net/viewtopic.php?f=11&t=3905
Installing
@ -14,17 +18,17 @@ Installing
Quick one line install for Linux:
cd <Mods directory> && git clone --recursive https://github.com/kaeza/minetest-irc.git irc
cd <Mods directory> && git clone --recursive https://github.com/minetest-mods/irc.git
Please change `<Mods directory>` to fit your installation of Minetest.
For more information, see [the wiki](http://wiki.minetest.net/Installing_mods).
For more information, see [the wiki][wiki].
The IRC mod's git repository uses submodules, therefore you will have to run
`git submodule init` when first installing the mod (unless you used
`--recursive` as above), and `git submodule update` every time that a submodule
is updated. These steps can be combined into `git submodule update --init`.
is updated. These steps can be combined into `git submodule update --init`.
You'll need to install LuaSocket. You can do so with your package manager on
You'll need to install LuaSocket. You can do so with your package manager on
many distributions, for example:
# # On Arch Linux:
@ -35,95 +39,100 @@ many distributions, for example:
# luarocks install luasocket
You will also need to add IRC to your trusted mods if you haven't disabled mod
security. Here's an example configuration line:
security. Here's an example configuration line:
secure.trusted_mods = irc
[wiki]: https://wiki.minetest.net/Installing_mods
Settings
--------
All settings are changed in `minetest.conf`. If any of these settings
are not set, the default value is used.
* `irc.server` (string)
The address of the IRC server to connect to.
* `irc.server` (string):
The address of the IRC server to connect to.
* `irc.channel` (string)
The IRC channel to join.
* `irc.channel` (string):
The IRC channel to join.
* `irc.interval` (number, default 2.0)
This prevents the server from flooding. It should be at
least 2.0 but can be higher. After four messages this much
time must pass between folowing messages.
* `irc.interval` (number, default 2.0):
This prevents the server from flooding. It should be at
least 2.0 but can be higher. After four messages this much
time must pass between folowing messages.
* `irc.nick` (string)
Nickname the server uses when it connects to IRC.
* `irc.nick` (string):
Nickname the server uses when it connects to IRC.
* `irc.password` (string, default nil)
Password to use when connecting to the server.
* `irc.password` (string, default nil):
Password to use when connecting to the server.
* `irc.NSPass` (string, default nil)
NickServ password. Don't set this if you use SASL authentication.
* `irc.NSPass` (string, default nil):
NickServ password. Don't set this if you use SASL authentication.
* `irc.sasl.pass` (string, default nil)
SASL password, same as nickserv password.
You should use this instead of NickServ authentication
if the server supports it.
* `irc.sasl.pass` (string, default nil):
SASL password, same as nickserv password.
You should use this instead of NickServ authentication
if the server supports it.
* `irc.sasl.user` (string, default `irc.nick`)
The SASL username. This should normaly be set to your NickServ account name.
* `irc.sasl.user` (string, default `irc.nick`):
The SASL username. This should normaly be set to your
NickServ account name.
* `irc.debug` (boolean, default false)
Whether to output debug information.
* `irc.debug` (boolean, default false):
Whether to output debug information.
* `irc.disable_auto_connect` (boolean, default false)
If false, the bot is connected by default. If true, a player with
the 'irc_admin' privilege has to use the /irc_connect command to
connect to the server.
* `irc.disable_auto_connect` (boolean, default false):
If false, the bot is connected by default. If true, a player with
the 'irc_admin' privilege has to use the `/irc_connect` command to
connect to the server.
* `irc.disable_auto_join` (boolean, default false)
If false, players join the channel automatically upon entering the
game. If true, each user must manually use the /join command to
join the channel. In any case, the players may use the /part
command to opt-out of being in the channel.
* `irc.disable_auto_join` (boolean, default false):
If false, players join the channel automatically upon entering the
game. If true, each user must manually use the `/join` command to
join the channel. In any case, the players may use the `/part`
command to opt-out of being in the channel.
* `irc.send_join_part` (boolean, default true):
Determines whether to send player join and part messages to the channel.
* `irc.send_join_part` (boolean, default true)
Determines whether to send player join and part messages to the channel.
Usage
-----
Once the game is connected to the IRC channel, chatting in-game will send
messages to the channel, and will be visible by anyone. Also, messages sent
messages to the channel, and will be visible by anyone. Also, messages sent
to the channel will be visible in-game.
Messages that begin with `[off]` from in-game or IRC are not sent to the other side.
Messages that begin with `[off]` from in-game or IRC are not sent to the
other side.
This mod also adds a few chat commands:
* `/irc_msg <nick> <message>`
Sends a private message to a IRC user.
* `/irc_msg <nick> <message>`:
Send a private message to a IRC user.
* `/join`
Join the IRC chat.
* `/join`:
Join the IRC chat.
* `/part`
Part the IRC chat.
* `/part`:
Part the IRC chat.
* `/irc_connect`
Connect the bot manually to the IRC network.
* `/irc_connect`:
Connect the bot manually to the IRC network.
* `/irc_disconnect`
Disconnect the bot manually from the IRC network (this does not
shutdown the game).
* `/irc_disconnect`:
Disconnect the bot manually from the IRC network (this does not
shutdown the game).
* `/irc_reconnect`
Equivilant to `/irc_disconnect` followed by `/irc_connect`.
* `/irc_reconnect`:
Equivalent to `/irc_disconnect` followed by `/irc_connect`.
You can also send private messages from IRC to in-game players.
To do so, you must send a private message to the bot (set with
the `irc.nick` option above), in the following format:
You can also send private messages from IRC to in-game players
by sending a private message to the bot (set with the `irc.nick`
option above), in the following format:
@playername message
@ -132,21 +141,29 @@ a private message from IRC with:
/msg server_nick @mtuser Hello!
To avoid possible misunderstandings (since all in-game players use the
same IRC user to converse with you), the "proxy" user will reject any
private messages that are not in that format, and will send back a
nice reminder as a private message.
The bot also supports some basic commands, which are invoked by saying
the bot name followed by either a colon or a comma and the command, or
sending a private message to it. For example: `ServerBot: help whereis`.
The bot also supports some basic commands, which are invoked by sending
a private message to it. Use `!list` to get a list of commands, and
`!help <command>` to get help about a specific command.
* `help [<command>]`:
Prints help about a command, or a list of supported commands if no
command is given.
* `uptime`:
Prints the server's running time.
* `whereis <player>`:
Prints the coordinates of the given player.
* `players`:
Lists players currently in the server.
Thanks
------
I'd like to thank the users who supported this mod both on the Minetest
Forums and on the #minetest channel. In no particular order:
Forums and on the `#minetest` channel. In no particular order:
0gb.us, ShadowNinja, Shaun/kizeren, RAPHAEL, DARGON, Calinou, Exio,
vortexlabs/mrtux, marveidemanis, marktraceur, jmf/john\_minetest,
@ -158,10 +175,7 @@ forum topic. Thanks to you all!
License
-------
Copyright © 2012-2013 Diego Martínez <kaeza@users.sf.net>
See LICENSE.txt for licensing information.
The files in the irc directory are part of the LuaIRC project.
See irc/LICENSE.txt for licensing information.
See `LICENSE.txt` for details.
The files in the `irc` directory are part of the LuaIRC project.
See `irc/LICENSE.txt` for details.

View File

@ -1,39 +1,58 @@
irc.bot_commands = {}
function irc:check_botcmd(msg)
-- From RFC1459:
-- "Because of IRCs scandanavian origin, the characters {}| are
-- considered to be the lower case equivalents of the characters
-- []\, respectively."
local irctolower = { ["["]="{", ["\\"]="|", ["]"]="}" }
local function irclower(s)
return (s:lower():gsub("[%[%]\\]", irctolower))
end
local function nickequals(nick1, nick2)
return irclower(nick1) == irclower(nick2)
end
function irc.check_botcmd(msg)
local prefix = irc.config.command_prefix
local nick = irc.conn.nick:lower()
local nick = irc.conn.nick
local text = msg.args[2]
local nickpart = text:sub(1, #nick + 2):lower()
local nickpart = text:sub(1, #nick)
local suffix = text:sub(#nick+1, #nick+2)
-- First check for a nick prefix
if nickpart == nick..": " or
nickpart == nick..", " then
self:bot_command(msg, text:sub(#nick + 3))
if nickequals(nickpart, nick)
and (suffix == ": " or suffix == ", ") then
irc.bot_command(msg, text:sub(#nick + 3))
return true
-- Then check for the configured prefix
elseif prefix and text:sub(1, #prefix):lower() == prefix:lower() then
self:bot_command(msg, text:sub(#prefix + 1))
irc.bot_command(msg, text:sub(#prefix + 1))
return true
end
return false
end
function irc:bot_command(msg, text)
function irc.bot_command(msg, text)
-- Remove leading whitespace
text = text:match("^%s*(.*)")
if text:sub(1, 1) == "@" then
local found, _, player_to, message = text:find("^.([^%s]+)%s(.+)$")
if not minetest.get_player_by_name(player_to) then
irc:reply("User '"..player_to.."' is not in the game.")
local _, _, player_to, message = text:find("^.([^%s]+)%s(.+)$")
if not player_to then
return
elseif not minetest.get_player_by_name(player_to) then
irc.reply("User '"..player_to.."' is not in the game.")
return
elseif not irc.joined_players[player_to] then
irc:reply("User '"..player_to.."' is not using IRC.")
irc.reply("User '"..player_to.."' is not using IRC.")
return
end
minetest.chat_send_player(player_to,
"PM from "..msg.user.nick.."@IRC: "..message, false)
irc:reply("Message sent!")
irc.reply("Message sent!")
return
end
local pos = text:find(" ", 1, true)
@ -45,45 +64,51 @@ function irc:bot_command(msg, text)
cmd = text
args = ""
end
if not self.bot_commands[cmd] then
self:reply("Unknown command '"..cmd.."'. Try 'list'."
if not irc.bot_commands[cmd] then
irc.reply("Unknown command '"..cmd.."'. Try 'help'."
.." Or use @playername <message> to send a private message")
return
end
local success, message = self.bot_commands[cmd].func(msg.user, args)
local _, message = irc.bot_commands[cmd].func(msg.user, args)
if message then
self:reply(message)
irc.reply(message)
end
end
function irc:register_bot_command(name, def)
function irc.register_bot_command(name, def)
if (not def.func) or (type(def.func) ~= "function") then
error("Erroneous bot command definition. def.func missing.", 2)
elseif name:sub(1, 1) == "@" then
error("Erroneous bot command name. Command name begins with '@'.", 2)
end
self.bot_commands[name] = def
irc.bot_commands[name] = def
end
irc:register_bot_command("help", {
irc.register_bot_command("help", {
params = "<command>",
description = "Get help about a command",
func = function(user, args)
func = function(_, args)
if args == "" then
return false, "No command name specified. Use 'list' for a list of commands."
local cmdlist = { }
for name in pairs(irc.bot_commands) do
cmdlist[#cmdlist+1] = name
end
return true, "Available commands: "..table.concat(cmdlist, ", ")
.." -- Use 'help <command name>' to get"
.." help about a specific command."
end
local cmd = irc.bot_commands[args]
if not cmd then
return false, "Unknown command '"..cmdname.."'."
return false, "Unknown command '"..args.."'."
end
return true, ("Usage: %c%s %s -- %s"):format(
irc.config.command_prefix,
return true, ("Usage: %s%s %s -- %s"):format(
irc.config.command_prefix or "",
args,
cmd.params or "<no parameters>",
cmd.description or "<no description>")
@ -91,24 +116,20 @@ irc:register_bot_command("help", {
})
irc:register_bot_command("list", {
irc.register_bot_command("list", {
params = "",
description = "List available commands.",
func = function(user, args)
local cmdlist = "Available commands: "
for name, cmd in pairs(irc.bot_commands) do
cmdlist = cmdlist..name..", "
end
return true, cmdlist.." -- Use 'help <command name>' to get"
.." help about a specific command."
func = function()
return false, "The `list` command has been merged into `help`."
.." Use `help` with no arguments to get a list."
end
})
--[[
irc:register_bot_command("whereis", {
irc.register_bot_command("whereis", {
params = "<player>",
description = "Tell the location of <player>",
func = function(user, args)
func = function(_, args)
if args == "" then
return false, "Player name required."
end
@ -120,13 +141,13 @@ irc:register_bot_command("whereis", {
local pos = player:getpos()
return true, fmt:format(args, pos.x, pos.y, pos.z)
end
})--]]
})
local starttime = os.time()
irc:register_bot_command("uptime", {
irc.register_bot_command("uptime", {
description = "Tell how much time the server has been up",
func = function(user, args)
func = function()
local cur_time = os.time()
local diff = os.difftime(cur_time, starttime)
local fmt = "Server has been running for %d:%02d:%02d"
@ -139,9 +160,9 @@ irc:register_bot_command("uptime", {
})
irc:register_bot_command("players", {
irc.register_bot_command("players", {
description = "List the players on the server",
func = function(user, args)
func = function()
local players = minetest.get_connected_players()
local names = {}
for _, player in pairs(players) do

View File

@ -5,15 +5,16 @@
minetest.register_on_joinplayer(function(player)
local name = player:get_player_name()
if irc.connected and irc.config.send_join_part then
irc:say("*** "..name.." joined the game")
irc.say("*** "..name.." joined the game")
end
end)
minetest.register_on_leaveplayer(function(player)
minetest.register_on_leaveplayer(function(player, timed_out)
local name = player:get_player_name()
if irc.connected and irc.config.send_join_part then
irc:say("*** "..name.." left the game")
irc.say("*** "..name.." left the game"..
(timed_out and " (Timed out)" or ""))
end
end)
@ -30,11 +31,11 @@ minetest.register_on_chat_message(function(name, message)
if nl then
message = message:sub(1, nl - 1)
end
irc:say(irc:playerMessage(name, message))
irc.say(irc.playerMessage(name, core.strip_colors(message)))
end)
minetest.register_on_shutdown(function()
irc:disconnect("Game shutting down.")
irc.disconnect("Game shutting down.")
end)

View File

@ -11,32 +11,30 @@ minetest.register_chatcommand("irc_msg", {
privs = {shout=true},
func = function(name, param)
if not irc.connected then
minetest.chat_send_player(name, "Not connected to IRC. Use /irc_connect to connect.")
return
return false, "Not connected to IRC. Use /irc_connect to connect."
end
local found, _, toname, message = param:find("^([^%s]+)%s(.+)")
if not found then
minetest.chat_send_player(name, "Invalid usage, see /help irc_msg.")
return
return false, "Invalid usage, see /help irc_msg."
end
local toname_l = toname:lower()
local validNick = false
for nick, user in pairs(irc.conn.channels[irc.config.channel].users) do
local hint = "They have to be in the channel"
for nick in pairs(irc.conn.channels[irc.config.channel].users) do
if nick:lower() == toname_l then
validNick = true
break
end
end
if toname_l:find("serv$") or toname_l:find("bot$") then
hint = "it looks like a bot or service"
validNick = false
end
if not validNick then
minetest.chat_send_player(name,
"You can not message that user. (Hint: They have to be in the channel)")
return
return false, "You can not message that user. ("..hint..")"
end
irc:say(toname, irc:playerMessage(name, message))
minetest.chat_send_player(name, "Message sent!")
irc.say(toname, irc.playerMessage(name, message))
return true, "Message sent!"
end
})
@ -44,16 +42,15 @@ minetest.register_chatcommand("irc_msg", {
minetest.register_chatcommand("irc_names", {
params = "",
description = "List the users in IRC.",
func = function(name, params)
func = function()
if not irc.connected then
minetest.chat_send_player(name, "Not connected to IRC. Use /irc_connect to connect.")
return
return false, "Not connected to IRC. Use /irc_connect to connect."
end
local users = { }
for k, v in pairs(irc.conn.channels[irc.config.channel].users) do
table.insert(users, k)
for nick in pairs(irc.conn.channels[irc.config.channel].users) do
table.insert(users, nick)
end
minetest.chat_send_player(name, "Users in IRC: "..table.concat(users, ", "))
return true, "Users in IRC: "..table.concat(users, ", ")
end
})
@ -61,13 +58,12 @@ minetest.register_chatcommand("irc_names", {
minetest.register_chatcommand("irc_connect", {
description = "Connect to the IRC server.",
privs = {irc_admin=true},
func = function(name, param)
func = function(name)
if irc.connected then
minetest.chat_send_player(name, "You are already connected to IRC.")
return
return false, "You are already connected to IRC."
end
minetest.chat_send_player(name, "IRC: Connecting...")
irc:connect()
irc.connect()
end
})
@ -78,13 +74,12 @@ minetest.register_chatcommand("irc_disconnect", {
privs = {irc_admin=true},
func = function(name, param)
if not irc.connected then
minetest.chat_send_player(name, "You are not connected to IRC.")
return
return false, "Not connected to IRC. Use /irc_connect to connect."
end
if params == "" then
params = "Manual disconnect by "..name
if param == "" then
param = "Manual disconnect by "..name
end
irc:disconnect(param)
irc.disconnect(param)
end
})
@ -92,13 +87,13 @@ minetest.register_chatcommand("irc_disconnect", {
minetest.register_chatcommand("irc_reconnect", {
description = "Reconnect to the IRC server.",
privs = {irc_admin=true},
func = function(name, param)
func = function(name)
if not irc.connected then
minetest.chat_send_player(name, "You are not connected to IRC.")
return
return false, "Not connected to IRC. Use /irc_connect to connect."
end
irc:disconnect("Reconnecting...")
irc:connect()
minetest.chat_send_player(name, "IRC: Reconnecting...")
irc.disconnect("Reconnecting...")
irc.connect()
end
})
@ -109,18 +104,31 @@ minetest.register_chatcommand("irc_quote", {
privs = {irc_admin=true},
func = function(name, param)
if not irc.connected then
minetest.chat_send_player(name, "You are not connected to IRC.")
return
return false, "Not connected to IRC. Use /irc_connect to connect."
end
irc:queue(param)
irc.queue(param)
minetest.chat_send_player(name, "Command sent!")
end
})
local oldme = minetest.chatcommands["me"].func
-- luacheck: ignore
minetest.chatcommands["me"].func = function(name, param, ...)
oldme(name, param, ...)
irc:say(("* %s %s"):format(name, param))
irc.say(("* %s %s"):format(name, param))
return oldme(name, param, ...)
end
if irc.config.send_kicks and minetest.chatcommands["kick"] then
local oldkick = minetest.chatcommands["kick"].func
-- luacheck: ignore
minetest.chatcommands["kick"].func = function(name, param, ...)
local plname, reason = param:match("^(%S+)%s*(.*)$")
if not plname then
return false, "Usage: /kick player [reason]"
end
irc.say(("*** Kicked %s.%s"):format(name,
reason~="" and " Reason: "..reason or ""))
return oldkick(name, param, ...)
end
end

View File

@ -32,10 +32,13 @@ setting("string", "server", nil, true) -- Server address to connect to
setting("number", "port", 6667) -- Server port to connect to
setting("string", "NSPass") -- NickServ password
setting("string", "sasl.user", irc.config.nick) -- SASL username
setting("string", "username", "Minetest") -- Username/ident
setting("string", "realname", "Minetest") -- Real name/GECOS
setting("string", "sasl.pass") -- SASL password
setting("string", "channel", nil, true) -- Channel to join
setting("string", "key") -- Key for the channel
setting("bool", "send_join_part", true) -- Whether to send player join and part messages to the channel
setting("bool", "send_kicks", false) -- Whether to send player kicked messages to the channel
-----------------------
-- ADVANCED SETTINGS --
@ -44,6 +47,7 @@ setting("bool", "send_join_part", true) -- Whether to send player join and par
setting("string", "password") -- Server password
setting("bool", "secure", false) -- Enable a TLS connection, requires LuaSEC
setting("number", "timeout", 60) -- Underlying socket timeout in seconds.
setting("number", "reconnect", 600) -- Time between reconnection attempts, in seconds.
setting("string", "command_prefix") -- Prefix to use for bot commands
setting("bool", "debug", false) -- Enable debug output
setting("bool", "enable_player_part", true) -- Whether to enable players joining and parting the channel

4
mods/irc/description.txt Normal file
View File

@ -0,0 +1,4 @@
This mod is just a glue between IRC and Minetest.
It provides two-way communication between the
in-game chat, and an arbitrary IRC channel.

View File

@ -10,12 +10,7 @@ irc.hooks = {}
irc.registered_hooks = {}
-- TODO: Add proper conversion from CP1252 to UTF-8.
local stripped_chars = {"\2", "\31"}
for c = 127, 255 do
table.insert(stripped_chars, string.char(c))
end
stripped_chars = "["..table.concat(stripped_chars, "").."]"
local stripped_chars = "[\2\31]"
local function normalize(text)
-- Strip colors
@ -25,8 +20,8 @@ local function normalize(text)
end
function irc:doHook(conn)
for name, hook in pairs(self.registered_hooks) do
function irc.doHook(conn)
for name, hook in pairs(irc.registered_hooks) do
for _, func in pairs(hook) do
conn:hook(name, func)
end
@ -34,9 +29,9 @@ function irc:doHook(conn)
end
function irc:register_hook(name, func)
self.registered_hooks[name] = self.registered_hooks[name] or {}
table.insert(self.registered_hooks[name], func)
function irc.register_hook(name, func)
irc.registered_hooks[name] = irc.registered_hooks[name] or {}
table.insert(irc.registered_hooks[name], func)
end
@ -85,13 +80,13 @@ function irc.hooks.ctcp(msg)
local command = args[1]:upper()
local function reply(s)
irc:queue(irc.msgs.notice(msg.user.nick,
irc.queue(irc.msgs.notice(msg.user.nick,
("\1%s %s\1"):format(command, s)))
end
if command == "ACTION" and msg.args[1] == irc.config.channel then
local action = text:sub(8, -1)
irc:sendLocal(("* %s@IRC %s"):format(msg.user.nick, action))
irc.sendLocal(("* %s@IRC %s"):format(msg.user.nick, action))
elseif command == "VERSION" then
reply(("Minetest version %s, IRC mod version %s.")
:format(get_core_version(), irc.version))
@ -106,11 +101,12 @@ end
function irc.hooks.channelChat(msg)
local text = normalize(msg.args[2])
irc:check_botcmd(msg)
irc.check_botcmd(msg)
-- Don't let a user impersonate someone else by using the nick "IRC"
if msg.user.nick == "IRC" then
irc:sendLocal("<IRC@IRC> "..text)
local fake = msg.user.nick:lower():match("^[il|]rc$")
if fake then
irc.sendLocal("<"..msg.user.nick.."@IRC> "..text)
return
end
@ -130,19 +126,19 @@ function irc.hooks.channelChat(msg)
if text:sub(1, 5) == "[off]" then
return
elseif foundchat then
irc:sendLocal(("<%s@%s> %s")
irc.sendLocal(("<%s@%s> %s")
:format(chatnick, msg.user.nick, chatmessage))
elseif foundjoin then
irc:sendLocal(("*** %s joined %s")
irc.sendLocal(("*** %s joined %s")
:format(joinnick, msg.user.nick))
elseif foundleave then
irc:sendLocal(("*** %s left %s")
irc.sendLocal(("*** %s left %s")
:format(leavenick, msg.user.nick))
elseif foundaction then
irc:sendLocal(("* %s@%s %s")
irc.sendLocal(("* %s@%s %s")
:format(actionnick, msg.user.nick, actionmessage))
else
irc:sendLocal(("<%s@IRC> %s"):format(msg.user.nick, text))
irc.sendLocal(("<%s@IRC> %s"):format(msg.user.nick, text))
end
end
@ -154,16 +150,16 @@ function irc.hooks.pm(msg)
if prefix and text:sub(1, #prefix) == prefix then
text = text:sub(#prefix + 1)
end
irc:bot_command(msg, text)
irc.bot_command(msg, text)
end
function irc.hooks.kick(channel, target, prefix, reason)
if target == irc.conn.nick then
minetest.chat_send_all("IRC: kicked from "..channel.." by "..prefix.nick..".")
irc:disconnect("Kicked")
irc.disconnect("Kicked")
else
irc:sendLocal(("-!- %s was kicked from %s by %s [%s]")
irc.sendLocal(("-!- %s was kicked from %s by %s [%s]")
:format(target, channel, prefix.nick, reason))
end
end
@ -171,7 +167,7 @@ end
function irc.hooks.notice(user, target, message)
if user.nick and target == irc.config.channel then
irc:sendLocal("-"..user.nick.."@IRC- "..message)
irc.sendLocal("-"..user.nick.."@IRC- "..message)
end
end
@ -192,31 +188,31 @@ end
function irc.hooks.nick(user, newNick)
irc:sendLocal(("-!- %s is now known as %s")
irc.sendLocal(("-!- %s is now known as %s")
:format(user.nick, newNick))
end
function irc.hooks.join(user, channel)
irc:sendLocal(("-!- %s joined %s")
irc.sendLocal(("-!- %s joined %s")
:format(user.nick, channel))
end
function irc.hooks.part(user, channel, reason)
reason = reason or ""
irc:sendLocal(("-!- %s has left %s [%s]")
irc.sendLocal(("-!- %s has left %s [%s]")
:format(user.nick, channel, reason))
end
function irc.hooks.quit(user, reason)
irc:sendLocal(("-!- %s has quit [%s]")
irc.sendLocal(("-!- %s has quit [%s]")
:format(user.nick, reason))
end
function irc.hooks.disconnect(message, isError)
function irc.hooks.disconnect(_, isError)
irc.connected = false
if isError then
minetest.log("error", "IRC: Error: Disconnected, reconnecting in one minute.")
@ -244,19 +240,19 @@ function irc.hooks.preregister(conn)
end
irc:register_hook("PreRegister", irc.hooks.preregister)
irc:register_hook("OnRaw", irc.hooks.raw)
irc:register_hook("OnSend", irc.hooks.send)
irc:register_hook("DoPrivmsg", irc.hooks.chat)
irc:register_hook("OnPart", irc.hooks.part)
irc:register_hook("OnKick", irc.hooks.kick)
irc:register_hook("OnJoin", irc.hooks.join)
irc:register_hook("OnQuit", irc.hooks.quit)
irc:register_hook("NickChange", irc.hooks.nick)
irc:register_hook("OnCTCP", irc.hooks.ctcp)
irc:register_hook("PrivateMessage", irc.hooks.pm)
irc:register_hook("OnNotice", irc.hooks.notice)
irc:register_hook("OnChannelChat", irc.hooks.channelChat)
irc:register_hook("OnModeChange", irc.hooks.mode)
irc:register_hook("OnDisconnect", irc.hooks.disconnect)
irc.register_hook("PreRegister", irc.hooks.preregister)
irc.register_hook("OnRaw", irc.hooks.raw)
irc.register_hook("OnSend", irc.hooks.send)
irc.register_hook("DoPrivmsg", irc.hooks.chat)
irc.register_hook("OnPart", irc.hooks.part)
irc.register_hook("OnKick", irc.hooks.kick)
irc.register_hook("OnJoin", irc.hooks.join)
irc.register_hook("OnQuit", irc.hooks.quit)
irc.register_hook("NickChange", irc.hooks.nick)
irc.register_hook("OnCTCP", irc.hooks.ctcp)
irc.register_hook("PrivateMessage", irc.hooks.pm)
irc.register_hook("OnNotice", irc.hooks.notice)
irc.register_hook("OnChannelChat", irc.hooks.channelChat)
irc.register_hook("OnModeChange", irc.hooks.mode)
irc.register_hook("OnDisconnect", irc.hooks.disconnect)

View File

@ -33,8 +33,12 @@ end
-- Temporarily set require so that LuaIRC can access it
local old_require = require
require = ie.require
-- Silence warnings about `module` in `ltn12`.
local old_module = rawget(_G, "module")
rawset(_G, "module", ie.module)
local lib = ie.require("irc")
require = old_require
irc = {
version = "0.2.0",
@ -48,7 +52,38 @@ irc = {
}
-- Compatibility
mt_irc = irc
rawset(_G, "mt_irc", irc)
local getinfo = debug.getinfo
local warned = { }
local function warn_deprecated(k)
local info = getinfo(3)
local loc = info.source..":"..info.currentline
if warned[loc] then return end
warned[loc] = true
print("COLON: "..tostring(k))
minetest.log("warning", "Deprecated use of colon notation when calling"
.." method `"..tostring(k).."` at "..loc)
end
-- This is a hack.
setmetatable(irc, {
__newindex = function(t, k, v)
if type(v) == "function" then
local f = v
v = function(me, ...)
if rawequal(me, t) then
warn_deprecated(k)
return f(...)
else
return f(me, ...)
end
end
end
rawset(t, k, v)
end,
})
dofile(modpath.."/config.lua")
dofile(modpath.."/messages.lua")
@ -56,10 +91,15 @@ loadfile(modpath.."/hooks.lua")(ie)
dofile(modpath.."/callback.lua")
dofile(modpath.."/chatcmds.lua")
dofile(modpath.."/botcmds.lua")
-- Restore old (safe) functions
require = old_require
rawset(_G, "module", old_module)
if irc.config.enable_player_part then
dofile(modpath.."/player_part.lua")
else
setmetatable(irc.joined_players, {__index = function(index) return true end})
setmetatable(irc.joined_players, {__index = function() return true end})
end
minetest.register_privilege("irc_admin", {
@ -69,20 +109,20 @@ minetest.register_privilege("irc_admin", {
local stepnum = 0
minetest.register_globalstep(function(dtime) return irc:step(dtime) end)
minetest.register_globalstep(function(dtime) return irc.step(dtime) end)
function irc:step(dtime)
function irc.step()
if stepnum == 3 then
if self.config.auto_connect then
self:connect()
if irc.config.auto_connect then
irc.connect()
end
end
stepnum = stepnum + 1
if not self.connected then return end
if not irc.connected then return end
-- Hooks will manage incoming messages and errors
local good, err = xpcall(function() self.conn:think() end, debug.traceback)
local good, err = xpcall(function() irc.conn:think() end, debug.traceback)
if not good then
print(err)
return
@ -90,79 +130,89 @@ function irc:step(dtime)
end
function irc:connect()
if self.connected then
function irc.connect()
if irc.connected then
minetest.log("error", "IRC: Ignoring attempt to connect when already connected.")
return
end
self.conn = irc.lib.new({
nick = self.config.nick,
username = "Minetest",
realname = "Minetest",
irc.conn = irc.lib.new({
nick = irc.config.nick,
username = irc.config.username,
realname = irc.config.realname,
})
self:doHook(self.conn)
irc.doHook(irc.conn)
-- We need to swap the `require` function again since
-- LuaIRC `require`s `ssl` if `irc.secure` is true.
old_require = require
require = ie.require
local good, message = pcall(function()
self.conn:connect({
host = self.config.server,
port = self.config.port,
password = self.config.password,
timeout = self.config.timeout,
secure = self.config.secure
irc.conn:connect({
host = irc.config.server,
port = irc.config.port,
password = irc.config.password,
timeout = irc.config.timeout,
reconnect = irc.config.reconnect,
secure = irc.config.secure
})
end)
require = old_require
if not good then
minetest.log("error", ("IRC: Connection error: %s: %s -- Reconnecting in ten minutes...")
:format(self.config.server, message))
minetest.after(600, function() self:connect() end)
minetest.log("error", ("IRC: Connection error: %s: %s -- Reconnecting in %d seconds...")
:format(irc.config.server, message, irc.config.reconnect))
minetest.after(irc.config.reconnect, function() irc.connect() end)
return
end
if self.config.NSPass then
self:say("NickServ", "IDENTIFY "..self.config.NSPass)
if irc.config.NSPass then
irc.conn:queue(irc.msgs.privmsg(
"NickServ", "IDENTIFY "..irc.config.NSPass))
end
self.conn:join(self.config.channel, self.config.key)
self.connected = true
irc.conn:join(irc.config.channel, irc.config.key)
irc.connected = true
minetest.log("action", "IRC: Connected!")
minetest.chat_send_all("IRC: Connected!")
end
function irc:disconnect(message)
if self.connected then
--The OnDisconnect hook will clear self.connected and print a disconnect message
self.conn:disconnect(message)
function irc.disconnect(message)
if irc.connected then
--The OnDisconnect hook will clear irc.connected and print a disconnect message
irc.conn:disconnect(message)
end
end
function irc:say(to, message)
function irc.say(to, message)
if not message then
message = to
to = self.config.channel
to = irc.config.channel
end
to = to or self.config.channel
to = to or irc.config.channel
self:queue(irc.msgs.privmsg(to, message))
irc.queue(irc.msgs.privmsg(to, message))
end
function irc:reply(message)
if not self.last_from then
function irc.reply(message)
if not irc.last_from then
return
end
message = message:gsub("[\r\n%z]", " \\n ")
self:say(self.last_from, message)
irc.say(irc.last_from, message)
end
function irc:send(msg)
if not self.connected then return end
self.conn:send(msg)
function irc.send(msg)
if not irc.connected then return end
irc.conn:send(msg)
end
function irc:queue(msg)
if not self.connected then return end
self.conn:queue(msg)
function irc.queue(msg)
if not irc.connected then return end
irc.conn:queue(msg)
end

1
mods/irc/irc Submodule

@ -0,0 +1 @@
Subproject commit e49a52ede1a58ddd94854657bc5098b0ac5d0677

View File

@ -1,3 +0,0 @@
/gh-pages/
*~

View File

@ -1,15 +0,0 @@
language: lua
notifications:
email: false
env:
global:
- secure: "kFhU+DZjhq/KbDt0DIDWnlskXMa12miNelmhhy30fQGgVIdiibDGKMNGyLahWp8CnPu1DARb5AZWK2TDfARdnURT2pgcsG83M7bYIY6cR647BWjL7oAhJ6CYEzTWJTBjeUjpN/o4vIgfXSDR0c7vboDi7Xz8ilfrBujPL2Oi/og="
install:
- sudo apt-get -y update
- sudo apt-get -y install lua5.1 luadoc
script:
- ./push-luadoc.sh

View File

@ -1,26 +0,0 @@
--[[
Lua IRC library
Copyright (c) 2010 Jakob Ovrum
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.]]

View File

@ -1,19 +0,0 @@
[![Build Status](https://travis-ci.org/JakobOvrum/LuaIRC.svg?branch=master)](https://travis-ci.org/JakobOvrum/LuaIRC)
LuaIRC
============
IRC client library for Lua.
Dependencies
-------------
* [LuaSocket](http://w3.impa.br/~diego/software/luasocket/)
**Only required if you want to make use of the TLS support**
* [LuaSec](http://www.inf.puc-rio.br/~brunoos/luasec/)
Documentation
-------------
Documentation can be automatically generated by passing irc.luadoc (in doc/) to [LuaDoc](http://luadoc.luaforge.net/), or pre-generated documentation can be found in the 'gh-pages' branch, which can also be browsed [online](http://jakobovrum.github.com/LuaIRC/doc/modules/irc.html).

View File

@ -1,92 +0,0 @@
local msgs = require("irc.messages")
local meta = {}
function meta:send(msg, ...)
if type(msg) == "table" then
msg = msg:toRFC1459()
else
if select("#", ...) > 0 then
msg = msg:format(...)
end
end
self:invoke("OnSend", msg)
local bytes, err = self.socket:send(msg .. "\r\n")
if not bytes and err ~= "timeout" and err ~= "wantwrite" then
self:invoke("OnDisconnect", err, true)
self:shutdown()
error(err, errlevel)
end
end
function meta:queue(msg)
table.insert(self.messageQueue, msg)
end
local function verify(str, errLevel)
if str:find("^:") or str:find("%s%z") then
error(("malformed parameter '%s' to irc command"):format(str), errLevel)
end
return str
end
function meta:sendChat(target, msg)
-- Split the message into segments if it includes newlines.
for line in msg:gmatch("([^\r\n]+)") do
self:queue(msgs.privmsg(verify(target, 3), line))
end
end
function meta:sendNotice(target, msg)
-- Split the message into segments if it includes newlines.
for line in msg:gmatch("([^\r\n]+)") do
self:queue(msgs.notice(verify(target, 3), line))
end
end
function meta:join(channel, key)
self:queue(msgs.join(
verify(channel, 3),
key and verify(key, 3) or nil))
end
function meta:part(channel, reason)
channel = verify(channel, 3)
self:queue(msgs.part(channel, reason))
if self.track_users then
self.channels[channel] = nil
end
end
function meta:trackUsers(b)
self.track_users = b
if not b then
for k,v in pairs(self.channels) do
self.channels[k] = nil
end
end
end
function meta:setMode(t)
local target = t.target or self.nick
local mode = ""
local add, rem = t.add, t.remove
assert(add or rem, "table contains neither 'add' nor 'remove'")
if add then
mode = table.concat{"+", verify(add, 3)}
end
if rem then
mode = table.concat{mode, "-", verify(rem, 3)}
end
self:queue(msgs.mode(verify(target, 3), mode))
end
return meta

View File

@ -1,198 +0,0 @@
--- LuaIRC is a low-level IRC library for Lua.
-- All functions raise Lua exceptions on error.
--
-- Use <code>new</code> to create a new Connection object.<br/>
-- Example:<br/><br/>
--<code>
--require "irc"<br/>
--local sleep = require "socket".sleep<br/>
--<br/>
--local s = irc.new{nick = "example"}<br/>
--<br/>
--s:hook("OnChat", function(user, channel, message)<br/>
-- print(("[%s] %s: %s"):format(channel, user.nick, message))<br/>
--end)<br/>
--<br/>
--s:connect("irc.example.net")<br/>
--s:join("#example")<br/>
--<br/>
--while true do<br/>
-- s:think()<br/>
-- sleep(0.5)<br/>
--end<br/>
--</code>
module "irc"
--- Create a new Connection object. Use <code>irc:connect</code> to connect to a server.
-- @param user Table with fields <code>nick</code>, <code>username</code> and <code>realname</code>.
-- The <code>nick</code> field is required.
--
-- @return Returns a new Connection object.
-- @see Connection
function new(user)
--- Hook a function to an event.
-- @param name Name of event.
-- @param id Unique tag.
-- @param f Callback function. [defaults to <code>id</code>]
-- @see Hooks
function irc:hook(name, id, f)
--- Remove previous hooked callback.
-- @param name Name of event.
-- @param id Unique tag.
function irc:unhook(name, id)
--- Connect <code>irc</code> to an IRC server.
-- @param host Host address.
-- @param port Server port. [default 6667]
function irc:connect(host, port)
-- @param table Table of connection details
-- @see ConnectOptions
function irc:connect(table)
--- Disconnect <code>irc</code> from the server.
-- @param message Quit message.
function irc:disconnect(message)
--- Handle incoming data for <code>irc</code>, and invoke previously hooked callbacks based on new server input.
-- You should call this in some kind of main loop, or at least often enough to not time out.
function irc:think()
--- Look up user info.
-- @param nick Nick of user to query.
-- @return Table with fields <code>userinfo</code>, <code>node</code>, <code>channels</code> and <code>account</code>.
function irc:whois(nick)
--- Look up topic.
-- Use this to invoke the hooks OnTopic and OnTopicInfo at any time.
-- @param channel Channel to query.
function irc:topic(channel)
--- Send a IRC message to the server.
-- @param msg Message or raw line to send, excluding newline characters.
-- @param ... Format parameters for <code>msg</code>, with <code>string.format</code> semantics. [optional]
function irc:send(msg, ...)
--- Queue Message to be sent to the server.
-- @param msg Message to be sent.
function irc:queue(msg)
--- Send a message to a channel or user.
-- @param target Nick or channel to send to.
-- @param message Message text.
function irc:sendChat(target, message)
--- Send a notice to a channel or user.
-- @param target Nick or channel to send to.
-- @param message Notice text.
function irc:sendNotice(target, message)
--- Join a channel.
-- @param channel Channel to join.
-- @param key Channel key. [optional]
function irc:join(channel, key)
--- Leave a channel.
-- @param channel Channel to leave.
function irc:part(channel)
--- Turn user information tracking on or off. User tracking is enabled by default.
-- @param b Boolean whether or not to track user information.
function irc:trackUsers(b)
--- Add/remove modes for a channel or nick.
-- @param t Table with fields <code>target, nick, add</code> and/or <code>rem</code>. <code>target</code> or <code>nick</code>
-- specifies the user or channel to add/remove modes. <code>add</code> is a list of modes to add to the user or channel.
-- <code>rem</code> is a list of modes to remove from the user or channel.
-- @usage Example which sets +m (moderated) for #channel: <br/>
-- <code>irc:setMode{target = "#channel", add = "m"}</code>
function irc:setMode(t)
--internal
function irc:invoke(name, ...)
function irc:handle(msg)
function irc:shutdown()
--- Table with connection information.
-- @name ConnectOptions
-- @class table
-- @field host Server host name.
-- @field port Server port. [defaults to <code>6667</code>]
-- @field timeout Connect timeout. [defaults to <code>30</code>]
-- @field password Server password.
-- @field secure Boolean to enable TLS connection, pass a params table (described, [luasec]) to control
-- [luasec]: http://www.inf.puc-rio.br/~brunoos/luasec/reference.html
--- Class representing a connection.
-- @name Connection
-- @class table
-- @field authed Boolean indicating whether the connection has completed registration.
-- @field connected Whether the connection is currently connected.
-- @field motd The server's message of the day. Can be nil.
-- @field nick The current nickname.
-- @field realname The real name sent to the server.
-- @field username The username/ident sent to the server.
-- @field socket Raw socket used by the library.
-- @field supports What the server claims to support in it's ISUPPORT message.
--- Class representing an IRC message.
-- @name Message
-- @class table
-- @field args A list of the command arguments
-- @field command The IRC command
-- @field prefix The prefix of the message
-- @field raw A raw IRC line for this message
-- @field tags A table of IRCv3 tags
-- @field user A User object describing the sender of the message
-- Fields may be missing.
-- Messages have the following methods:
-- <ul>
-- <li><code>toRFC1459()</code> - Returns the message serialized in RFC 1459 format.</li>
-- </ul>
--- List of hooks you can use with irc:hook.
-- The parameter list describes the parameters passed to the callback function.
-- <ul>
-- <li><code>PreRegister()</code> - Usefull for requesting capabilities.</li>
-- <li><code>OnRaw(line)</code> - Any non false/nil return value assumes line handled and will not be further processed.</li>
-- <li><code>OnSend(line)</code></li>
-- <li><code>OnDisconnect(message, errorOccurred)</code></li>
-- <li><code>OnChat(user, channel, message)</code></li>
-- <li><code>OnNotice(user, channel, message)</code></li>
-- <li><code>OnJoin(user, channel)</code>*</li>
-- <li><code>OnPart(user, channel)</code>*</li>
-- <li><code>OnQuit(user, message)</code></li>
-- <li><code>NickChange(user, newnick, channel)</code>*†</li>
-- <li><code>NameList(channel, names)</code></li>
-- <li><code>OnTopic(channel, topic)</code></li>
-- <li><code>OnTopicInfo(channel, creator, timeCreated)</code></li>
-- <li><code>OnKick(channel, nick, kicker, reason)</code>* (kicker is a <code>user</code> table)</li>
-- <li><code>OnUserMode(modes)</code></li>
-- <li><code>OnChannelMode(user, channel, modes)</code></li>
-- <li><code>OnModeChange(user, target, modes, ...)</code>* ('...' contains mode options such as banmasks)</li>
-- <li><code>OnCapabilityList(caps)</code></li>
-- <li><code>OnCapabilityAvailable(cap, value)</code> Called only when a capability becomes available or changes.</li>
-- <li><code>OnCapabilitySet(cap, enabled)</code>*</li>
-- <li><code>DoX(msg)</code>* - 'X' is any IRC command or numeric with the first letter capitalized (eg, DoPing and Do001)</li>
-- </ul>
-- * Event also invoked for yourself.
-- † Channel passed only when user tracking is enabled
-- @name Hooks
-- @class table
--- Table with information about a user.
-- <ul>
-- <li><code>server</code> - Server name.</li>
-- <li><code>nick</code> - User nickname.</li>
-- <li><code>username</code> - User username.</li>
-- <li><code>host</code> - User hostname.</li>
-- <li><code>realname</code> - User real name.</li>
-- <li><code>access</code> - User access, available in channel-oriented callbacks. A table containing boolean fields for each access mode that the server supports. Eg: 'o', and 'v'.</li>
-- </ul>
-- Fields may be missing. To fill them in, enable user tracking and use irc:whois.
-- @name User
-- @class table

View File

@ -1,277 +0,0 @@
local util = require("irc.util")
local msgs = require("irc.messages")
local Message = msgs.Message
local handlers = {}
handlers["PING"] = function(conn, msg)
conn:send(Message({command="PONG", args=msg.args}))
end
local function requestWanted(conn, wanted)
local args = {}
for cap, value in pairs(wanted) do
if type(value) == "string" then
cap = cap .. "=" .. value
end
if not conn.capabilities[cap] then
table.insert(args, cap)
end
end
conn:queue(Message({
command = "CAP",
args = {"REQ", table.concat(args, " ")}
})
)
end
handlers["CAP"] = function(conn, msg)
local cmd = msg.args[2]
if not cmd then
return
end
if cmd == "LS" then
local list = msg.args[3]
local last = false
if list == "*" then
list = msg.args[4]
else
last = true
end
local avail = conn.availableCapabilities
local wanted = conn.wantedCapabilities
for item in list:gmatch("(%S+)") do
local eq = item:find("=", 1, true)
local k, v
if eq then
k, v = item:sub(1, eq - 1), item:sub(eq + 1)
else
k, v = item, true
end
if not avail[k] or avail[k] ~= v then
wanted[k] = conn:invoke("OnCapabilityAvailable", k, v)
end
avail[k] = v
end
if last then
if next(wanted) then
requestWanted(conn, wanted)
end
conn:invoke("OnCapabilityList", conn.availableCapabilities)
end
elseif cmd == "ACK" then
for item in msg.args[3]:gmatch("(%S+)") do
local enabled = (item:sub(1, 1) ~= "-")
local name = enabled and item or item:sub(2)
conn:invoke("OnCapabilitySet", name, enabled)
conn.capabilities[name] = enabled
end
end
end
handlers["001"] = function(conn, msg)
conn.authed = true
conn.nick = msg.args[1]
end
handlers["PRIVMSG"] = function(conn, msg)
conn:invoke("OnChat", msg.user, msg.args[1], msg.args[2])
end
handlers["NOTICE"] = function(conn, msg)
conn:invoke("OnNotice", msg.user, msg.args[1], msg.args[2])
end
handlers["JOIN"] = function(conn, msg)
local channel = msg.args[1]
if conn.track_users then
if msg.user.nick == conn.nick then
conn.channels[channel] = {users = {}}
else
conn.channels[channel].users[msg.user.nick] = msg.user
end
end
conn:invoke("OnJoin", msg.user, msg.args[1])
end
handlers["PART"] = function(conn, msg)
local channel = msg.args[1]
if conn.track_users then
if msg.user.nick == conn.nick then
conn.channels[channel] = nil
else
conn.channels[channel].users[msg.user.nick] = nil
end
end
conn:invoke("OnPart", msg.user, msg.args[1], msg.args[2])
end
handlers["QUIT"] = function(conn, msg)
if conn.track_users then
for chanName, chan in pairs(conn.channels) do
chan.users[msg.user.nick] = nil
end
end
conn:invoke("OnQuit", msg.user, msg.args[1], msg.args[2])
end
handlers["NICK"] = function(conn, msg)
local newNick = msg.args[1]
if conn.track_users then
for chanName, chan in pairs(conn.channels) do
local users = chan.users
local oldinfo = users[msg.user.nick]
if oldinfo then
users[newNick] = oldinfo
users[msg.user.nick] = nil
conn:invoke("NickChange", msg.user, newNick, chanName)
end
end
else
conn:invoke("NickChange", msg.user, newNick)
end
if msg.user.nick == conn.nick then
conn.nick = newNick
end
end
local function needNewNick(conn, msg)
local newnick = conn.nickGenerator(msg.args[2])
conn:queue(irc.msgs.nick(newnick))
end
-- ERR_ERRONEUSNICKNAME (Misspelt but remains for historical reasons)
handlers["432"] = needNewNick
-- ERR_NICKNAMEINUSE
handlers["433"] = needNewNick
-- ERR_UNAVAILRESOURCE
handlers["437"] = function(conn, msg)
if not conn.authed then
needNewNick(conn, msg)
end
end
-- RPL_ISUPPORT
handlers["005"] = function(conn, msg)
local arglen = #msg.args
-- Skip first and last parameters (nick and info)
for i = 2, arglen - 1 do
local item = msg.args[i]
local pos = item:find("=")
if pos then
conn.supports[item:sub(1, pos - 1)] = item:sub(pos + 1)
else
conn.supports[item] = true
end
end
end
-- RPL_MOTDSTART
handlers["375"] = function(conn, msg)
conn.motd = ""
end
-- RPL_MOTD
handlers["372"] = function(conn, msg)
-- MOTD lines have a "- " prefix, strip it.
conn.motd = conn.motd .. msg.args[2]:sub(3) .. '\n'
end
-- NAMES list
handlers["353"] = function(conn, msg)
local chanType = msg.args[2]
local channel = msg.args[3]
local names = msg.args[4]
if conn.track_users then
conn.channels[channel] = conn.channels[channel] or {users = {}, type = chanType}
local users = conn.channels[channel].users
for nick in names:gmatch("(%S+)") do
local access, name = util.parseNick(conn, nick)
users[name] = {access = access}
end
end
end
-- End of NAMES list
handlers["366"] = function(conn, msg)
if conn.track_users then
conn:invoke("NameList", msg.args[2], msg.args[3])
end
end
-- No topic
handlers["331"] = function(conn, msg)
conn:invoke("OnTopic", msg.args[2], nil)
end
handlers["TOPIC"] = function(conn, msg)
conn:invoke("OnTopic", msg.args[1], msg.args[2])
end
handlers["332"] = function(conn, msg)
conn:invoke("OnTopic", msg.args[2], msg.args[3])
end
-- Topic creation info
handlers["333"] = function(conn, msg)
conn:invoke("OnTopicInfo", msg.args[2], msg.args[3], tonumber(msg.args[4]))
end
handlers["KICK"] = function(conn, msg)
conn:invoke("OnKick", msg.args[1], msg.args[2], msg.user, msg.args[3])
end
-- RPL_UMODEIS
-- To answer a query about a client's own mode, RPL_UMODEIS is sent back
handlers["221"] = function(conn, msg)
conn:invoke("OnUserMode", msg.args[2])
end
-- RPL_CHANNELMODEIS
-- The result from common irc servers differs from that defined by the rfc
handlers["324"] = function(conn, msg)
conn:invoke("OnChannelMode", msg.args[2], msg.args[3])
end
handlers["MODE"] = function(conn, msg)
local target = msg.args[1]
local modes = msg.args[2]
local optList = {}
for i = 3, #msg.args do
table.insert(optList, msg.args[i])
end
if conn.track_users and target ~= conn.nick then
local add = true
local argNum = 1
util.updatePrefixModes(conn)
for c in modes:gmatch(".") do
if c == "+" then add = true
elseif c == "-" then add = false
elseif conn.modeprefix[c] then
local nick = optList[argNum]
argNum = argNum + 1
local user = conn.channels[target].users[nick]
user.access = user.access or {}
local access = user.access
access[c] = add
if c == "o" then access.op = add
elseif c == "v" then access.voice = add
end
end
end
end
conn:invoke("OnModeChange", msg.user, target, modes, unpack(optList))
end
handlers["ERROR"] = function(conn, msg)
conn:invoke("OnDisconnect", msg.args[1], true)
conn:shutdown()
error(msg.args[1], 3)
end
return handlers

View File

@ -1,257 +0,0 @@
local socket = require("socket")
local util = require("irc.util")
local handlers = require("irc.handlers")
local msgs = require("irc.messages")
local Message = msgs.Message
local meta = {}
meta.__index = meta
for k, v in pairs(require("irc.asyncoperations")) do
meta[k] = v
end
local meta_preconnect = {}
function meta_preconnect.__index(o, k)
local v = rawget(meta_preconnect, k)
if v == nil and meta[k] ~= nil then
error(("field '%s' is not accessible before connecting"):format(k), 2)
end
return v
end
meta.connected = true
meta_preconnect.connected = false
function new(data)
local o = {
nick = assert(data.nick, "Field 'nick' is required");
username = data.username or "lua";
realname = data.realname or "Lua owns";
nickGenerator = data.nickGenerator or util.defaultNickGenerator;
hooks = {};
track_users = true;
supports = {};
messageQueue = {};
lastThought = 0;
recentMessages = 0;
availableCapabilities = {};
wantedCapabilities = {};
capabilities = {};
}
assert(util.checkNick(o.nick), "Erroneous nickname passed to irc.new")
return setmetatable(o, meta_preconnect)
end
function meta:hook(name, id, f)
f = f or id
self.hooks[name] = self.hooks[name] or {}
self.hooks[name][id] = f
return id or f
end
meta_preconnect.hook = meta.hook
function meta:unhook(name, id)
local hooks = self.hooks[name]
assert(hooks, "no hooks exist for this event")
assert(hooks[id], "hook ID not found")
hooks[id] = nil
end
meta_preconnect.unhook = meta.unhook
function meta:invoke(name, ...)
local hooks = self.hooks[name]
if hooks then
for id, f in pairs(hooks) do
local ret = f(...)
if ret then
return ret
end
end
end
end
function meta_preconnect:connect(_host, _port)
local host, port, password, secure, timeout
if type(_host) == "table" then
host = _host.host
port = _host.port
timeout = _host.timeout
password = _host.password
secure = _host.secure
else
host = _host
port = _port
end
host = host or error("host name required to connect", 2)
port = port or 6667
local s = socket.tcp()
s:settimeout(timeout or 30)
assert(s:connect(host, port))
if secure then
local work, ssl = pcall(require, "ssl")
if not work then
error("LuaSec required for secure connections", 2)
end
local params
if type(secure) == "table" then
params = secure
else
params = {mode = "client", protocol = "tlsv1"}
end
s = ssl.wrap(s, params)
local success, errmsg = s:dohandshake()
if not success then
error(("could not make secure connection: %s"):format(errmsg), 2)
end
end
self.socket = s
setmetatable(self, meta)
self:invoke("PreRegister", self)
if password then
self:queue(Message({command="PASS", args={password}}))
end
self:queue(msgs.nick(self.nick))
self:queue(Message({command="USER", args={self.username, "0", "*", self.realname}}))
self.channels = {}
s:settimeout(0)
repeat
self:think()
socket.sleep(0.1)
until self.authed
end
function meta:disconnect(message)
message = message or "Bye!"
self:invoke("OnDisconnect", message, false)
self:send(msgs.quit(message))
self:shutdown()
end
function meta:shutdown()
self.socket:close()
setmetatable(self, meta_preconnect)
end
local function getline(self, errlevel)
local line, err = self.socket:receive("*l")
if not line and err ~= "timeout" and err ~= "wantread" then
self:invoke("OnDisconnect", err, true)
self:shutdown()
error(err, errlevel)
end
return line
end
function meta:think()
while true do
local line = getline(self, 3)
if line and #line > 0 then
if not self:invoke("OnRaw", line) then
self:handle(Message({raw=line}))
end
else
break
end
end
-- Handle outgoing message queue
local diff = socket.gettime() - self.lastThought
self.recentMessages = self.recentMessages - (diff * 2)
if self.recentMessages < 0 then
self.recentMessages = 0
end
for i = 1, #self.messageQueue do
if self.recentMessages > 4 then
break
end
self:send(table.remove(self.messageQueue, 1))
self.recentMessages = self.recentMessages + 1
end
self.lastThought = socket.gettime()
end
function meta:handle(msg)
local handler = handlers[msg.command]
if handler then
handler(self, msg)
end
self:invoke("Do" .. util.capitalize(msg.command), msg)
end
local whoisHandlers = {
["311"] = "userinfo";
["312"] = "node";
["319"] = "channels";
["330"] = "account"; -- Freenode
["307"] = "registered"; -- Unreal
}
function meta:whois(nick)
self:send(msgs.whois(nick))
local result = {}
while true do
local line = getline(self, 3)
if line then
local msg = Message({raw=line})
local handler = whoisHandlers[msg.command]
if handler then
result[handler] = msg.args
elseif msg.command == "318" then
break
else
self:handle(msg)
end
end
end
if result.account then
result.account = result.account[3]
elseif result.registered then
result.account = result.registered[2]
end
return result
end
function meta:topic(channel)
self:queue(msgs.topic(channel))
end
return {
new = new;
Message = Message;
msgs = msgs;
color = util.color;
bold = util.bold;
underline = util.underline;
}

View File

@ -1,207 +0,0 @@
-- Module table
local m = {}
local msg_meta = {}
msg_meta.__index = msg_meta
local function Message(opts)
opts = opts or {}
setmetatable(opts, msg_meta)
if opts.raw then
opts:fromRFC1459(opts.raw)
end
return opts
end
m.Message = Message
local tag_escapes = {
[";"] = "\\:",
[" "] = "\\s",
["\0"] = "\\0",
["\\"] = "\\\\",
["\r"] = "\\r",
["\n"] = "\\n",
}
local tag_unescapes = {}
for x, y in pairs(tag_escapes) do tag_unescapes[y] = x end
function msg_meta:toRFC1459()
local s = ""
if self.tags then
s = s.."@"
for key, value in pairs(self.tags) do
s = s..key
if value ~= true then
value = value:gsub("[; %z\\\r\n]", tag_escapes)
s = s.."="..value
end
s = s..";"
end
-- Strip trailing semicolon
s = s:sub(1, -2)
s = s.." "
end
s = s..self.command
local argnum = #self.args
for i = 1, argnum do
local arg = self.args[i]
local startsWithColon = (arg:sub(1, 1) == ":")
local hasSpace = arg:find(" ")
if i == argnum and (hasSpace or startsWithColon) then
s = s.." :"
else
assert(not hasSpace and not startsWithColon,
"Message arguments can not be "
.."serialized to RFC1459 format")
s = s.." "
end
s = s..arg
end
return s
end
local function parsePrefix(prefix)
local user = {}
user.nick, user.username, user.host = prefix:match("^(.+)!(.+)@(.+)$")
if not user.nick and prefix:find(".", 1, true) then
user.server = prefix
end
return user
end
function msg_meta:fromRFC1459(line)
-- IRCv3 tags
if line:sub(1, 1) == "@" then
self.tags = {}
local space = line:find(" ", 1, true)
-- For each semicolon-delimited section from after
-- the @ character to before the space character.
for tag in line:sub(2, space - 1):gmatch("([^;]+)") do
local eq = tag:find("=", 1, true)
if eq then
self.tags[tag:sub(1, eq - 1)] =
tag:sub(eq + 1):gsub("\\([:s0\\rn])", tag_unescapes)
else
self.tags[tag] = true
end
end
line = line:sub(space + 1)
end
if line:sub(1, 1) == ":" then
local space = line:find(" ", 1, true)
self.prefix = line:sub(2, space - 1)
self.user = parsePrefix(self.prefix)
line = line:sub(space + 1)
end
local pos
self.command, pos = line:match("(%S+)()")
line = line:sub(pos)
self.args = self.args or {}
for pos, param in line:gmatch("()(%S+)") do
if param:sub(1, 1) == ":" then
param = line:sub(pos + 1)
table.insert(self.args, param)
break
end
table.insert(self.args, param)
end
end
function m.privmsg(to, text)
return Message({command="PRIVMSG", args={to, text}})
end
function m.notice(to, text)
return Message({command="NOTICE", args={to, text}})
end
function m.action(to, text)
return Message({command="PRIVMSG", args={to, ("\x01ACTION %s\x01"):format(text)}})
end
function m.ctcp(command, to, args)
s = "\x01"..command
if args then
s = ' '..args
end
s = s..'\x01'
return Message({command="PRIVMSG", args={to, s}})
end
function m.kick(channel, target, reason)
return Message({command="KICK", args={channel, target, reason}})
end
function m.join(channel, key)
return Message({command="JOIN", args={channel, key}})
end
function m.part(channel, reason)
return Message({command="PART", args={channel, reason}})
end
function m.quit(reason)
return Message({command="QUIT", args={reason}})
end
function m.kill(target, reason)
return Message({command="KILL", args={target, reason}})
end
function m.kline(time, mask, reason, operreason)
local args = nil
if time then
args = {time, mask, reason..'|'..operreason}
else
args = {mask, reason..'|'..operreason}
end
return Message({command="KLINE", args=args})
end
function m.whois(nick, server)
local args = nil
if server then
args = {server, nick}
else
args = {nick}
end
return Message({command="WHOIS", args=args})
end
function m.topic(channel, text)
return Message({command="TOPIC", args={channel, text}})
end
function m.invite(channel, target)
return Message({command="INVITE", args={channel, target}})
end
function m.nick(nick)
return Message({command="NICK", args={nick}})
end
function m.mode(target, modes)
-- We have to split the modes parameter because the mode string and
-- each parameter are seperate arguments (The first command is incorrect)
-- MODE foo :+ov Nick1 Nick2
-- MODE foo +ov Nick1 Nick2
local mt = util.split(modes)
return Message({command="MODE", args={target, unpack(mt)}})
end
function m.cap(cmd, ...)
return Message({command="CAP", args={cmd, ...}})
end
return m

View File

@ -1,19 +0,0 @@
#!/bin/bash
if [ "$TRAVIS_REPO_SLUG" == "JakobOvrum/LuaIRC" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_BRANCH" == "master" ]; then
echo -e "Generating luadoc...\n"
git config --global user.email "travis@travis-ci.org"
git config --global user.name "travis-ci"
git clone --quiet --branch=gh-pages https://${GH_TOKEN}@github.com/${TRAVIS_REPO_SLUG} gh-pages > /dev/null
cd gh-pages
git rm -rf ./doc
sh ./generate.sh
git add -f ./doc
git commit -m "Lastest documentation on successful travis build $TRAVIS_BUILD_NUMBER auto-pushed to gh-pages"
git push -fq origin gh-pages > /dev/null
echo -e "Published luadoc to gh-pages.\n"
fi

View File

@ -1,52 +0,0 @@
local select = require("socket").select
local m = {}
local set = {}
set.__index = set
function m.new(t)
t.connections = {}
t.sockets = {}
return setmetatable(t, set)
end
function set:add(connection)
local socket = connection.socket
insert(self.sockets, socket)
self.connections[socket] = connection
insert(self.connections, connection)
end
function set:remove(connection)
local socket = connection.socket
self.connections[socket] = nil
for k, s in ipairs(self.sockets) do
if socket == s then
remove(self.sockets, k)
remove(self.connections, k)
break
end
end
end
function set:select()
local read, write, err = select(self.sockets, nil, self.timeout)
if read then
for k, socket in ipairs(read) do
read[k] = self.connections[socket]
end
end
return read, err
end
-- Select - but if it times out, it returns all connections.
function set:poll()
local read, err = self:select()
return err == "timeout" and self.connections or read
end
return m

View File

@ -1,120 +0,0 @@
-- Module table
local m = {}
function m.updatePrefixModes(conn)
if conn.prefixmode and conn.modeprefix then
return
end
conn.prefixmode = {}
conn.modeprefix = {}
if conn.supports.PREFIX then
local modes, prefixes = conn.supports.PREFIX:match("%(([^%)]*)%)(.*)")
for i = 1, #modes do
conn.prefixmode[prefixes:sub(i, i)] = modes:sub(i, i)
conn.modeprefix[ modes:sub(i, i)] = prefixes:sub(i, i)
end
else
conn.prefixmode['@'] = 'o'
conn.prefixmode['+'] = 'v'
conn.modeprefix['o'] = '@'
conn.modeprefix['v'] = '+'
end
end
function m.parseNick(conn, nick)
local access = {}
m.updatePrefixModes(conn)
local namestart = 1
for i = 1, #nick - 1 do
local c = nick:sub(i, i)
if conn.prefixmode[c] then
access[conn.prefixmode[c]] = true
else
namestart = i
break
end
end
access.op = access.o
access.voice = access.v
local name = nick:sub(namestart)
return access, name
end
-- mIRC markup scheme (de-facto standard)
m.color = {
black = 1,
blue = 2,
green = 3,
red = 4,
lightred = 5,
purple = 6,
brown = 7,
yellow = 8,
lightgreen = 9,
navy = 10,
cyan = 11,
lightblue = 12,
violet = 13,
gray = 14,
lightgray = 15,
white = 16
}
local colByte = string.char(3)
setmetatable(m.color, {__call = function(_, text, colornum)
colornum = (type(colornum) == "string" and
assert(color[colornum], "Invalid color '"..colornum.."'") or
colornum)
return table.concat{colByte, tostring(colornum), text, colByte}
end})
local boldByte = string.char(2)
function m.bold(text)
return boldByte..text..boldByte
end
local underlineByte = string.char(31)
function m.underline(text)
return underlineByte..text..underlineByte
end
function m.checkNick(nick)
return nick:find("^[a-zA-Z_%-%[|%]%^{|}`][a-zA-Z0-9_%-%[|%]%^{|}`]*$") ~= nil
end
function m.defaultNickGenerator(nick)
-- LuaBot -> LuaCot -> LuaCou -> ...
-- We change a random character rather than appending to the
-- nickname as otherwise the new nick could exceed the ircd's
-- maximum nickname length.
local randindex = math.random(1, #nick)
local randchar = string.sub(nick, randindex, randindex)
local b = string.byte(randchar)
b = b + 1
if b < 65 or b > 125 then
b = 65
end
-- Get the halves before and after the changed character
local first = string.sub(nick, 1, randindex - 1)
local last = string.sub(nick, randindex + 1, #nick)
nick = first .. string.char(b) .. last -- Insert the new charachter
return nick
end
function m.capitalize(text)
-- Converts first character to upercase and the rest to lowercase.
-- "PING" -> "Ping" | "hello" -> "Hello" | "123" -> "123"
return text:sub(1, 1):upper()..text:sub(2):lower()
end
function m.split(str, sep)
local t = {}
for s in str:gmatch("%S+") do
table.insert(t, s)
end
return t
end
return m

View File

@ -3,11 +3,15 @@
irc.msgs = irc.lib.msgs
function irc:sendLocal(message)
minetest.chat_send_all(message)
function irc.logChat(message)
minetest.log("action", "IRC CHAT: "..message)
end
function irc:playerMessage(name, message)
function irc.sendLocal(message)
minetest.chat_send_all(message)
irc.logChat(message)
end
function irc.playerMessage(name, message)
return ("<%s> %s"):format(name, message)
end

1
mods/irc/mod.conf Normal file
View File

@ -0,0 +1 @@
name = irc

View File

@ -2,68 +2,68 @@
-- See LICENSE.txt for details.
function irc:player_part(name)
if not self.joined_players[name] then
minetest.chat_send_player(name, "IRC: You are not in the channel.")
return
function irc.player_part(name)
if not irc.joined_players[name] then
return false, "You are not in the channel"
end
self.joined_players[name] = nil
minetest.chat_send_player(name, "IRC: You are now out of the channel.")
irc.joined_players[name] = nil
return true, "You left the channel"
end
function irc:player_join(name)
if self.joined_players[name] then
minetest.chat_send_player(name, "IRC: You are already in the channel.")
return
function irc.player_join(name)
if irc.joined_players[name] then
return false, "You are already in the channel"
end
self.joined_players[name] = true
minetest.chat_send_player(name, "IRC: You are now in the channel.")
irc.joined_players[name] = true
return true, "You joined the channel"
end
minetest.register_chatcommand("join", {
description = "Join the IRC channel",
privs = {shout=true},
func = function(name, param)
irc:player_join(name)
end
})
minetest.register_chatcommand("part", {
description = "Part the IRC channel",
privs = {shout=true},
func = function(name, param)
irc:player_part(name)
end
})
minetest.register_chatcommand("who", {
description = "Tell who is currently on the channel",
privs = {},
func = function(name, param)
local s = ""
for name, _ in pairs(irc.joined_players) do
s = s..", "..name
end
minetest.chat_send_player(name, "Players On Channel:"..s)
func = function(name)
return irc.player_join(name)
end
})
minetest.register_chatcommand("part", {
description = "Part the IRC channel",
privs = {shout=true},
func = function(name)
return irc.player_part(name)
end
})
minetest.register_chatcommand("who", {
description = "Tell who is currently on the channel",
privs = {},
func = function()
local out, n = { }, 0
for plname in pairs(irc.joined_players) do
n = n + 1
out[n] = plname
end
table.sort(out)
return true, "Players in channel: "..table.concat(out, ", ")
end
})
minetest.register_on_joinplayer(function(player)
local name = player:get_player_name()
irc.joined_players[name] = irc.config.auto_join
end)
minetest.register_on_leaveplayer(function(player)
local name = player:get_player_name()
irc.joined_players[name] = nil
end)
function irc:sendLocal(message)
for name, _ in pairs(self.joined_players) do
function irc.sendLocal(message)
for name, _ in pairs(irc.joined_players) do
minetest.chat_send_player(name, message)
end
irc.logChat(message)
end

75
mods/irc/settingtypes.txt Normal file
View File

@ -0,0 +1,75 @@
[Basic]
# Whether to automatically connect to the server on mod load.
# If false, you must use /irc_connect to connect.
irc.auto_connect (Auto-connect on load) bool true
# Nickname for the bot. May only contain characters A-Z, 0-9
# '{', '}', '[', ']', '|', '^', '-', or '_'.
irc.nick (Bot nickname) string Minetest
# Server to connect to.
irc.server (IRC server) string irc.freenode.net
# Server port.
# The standard IRC protocol port is 6667 for regular servers,
# or 6697 for SSL-enabled servers.
# If unsure, leave at 6667.
irc.port (IRC server port) int 6667 1 65535
# Channel the bot joins after connecting.
irc.channel (Channel to join) string ##mt-irc-mod
[Authentication]
# Password for authenticating to NickServ.
# Leave empty to not authenticate with NickServ.
irc.NSPass (NickServ password) string
# IRC server password.
# Leave empty for no password.
irc.password (Server password) string
# Password for joining the channel.
# Leave empty if your channel is not protected.
irc.key (Channel key) string
# Enable TLS connection.
# Requires LuaSEC <https://github.com/brunoos/luasec>.
irc.secure (Use TLS) bool false
# Username for SASL authentication.
# Leave empty to use the nickname.
irc.sasl.user (SASL username) string
# Password for SASL authentication.
# Leave empty to not authenticate via SASL.
irc.sasl.pass (SASL password) string
[Advanced]
# Enable this to make the bot send messages when players join
# or leave the game server.
irc.send_join_part (Send join and part messages) bool true
# Enable this to make the bot send messages when players are kicked.
irc.send_kicks (Send kick messages) bool false
# Underlying socket timeout in seconds.
irc.timeout (Timeout) int 60 1
# Time between reconnection attempts, in seconds.
irc.reconnect (Reconnect delay) int 600 1
# Prefix to use for bot commands.
irc.command_prefix (Command prefix) string
# Enable debug output.
irc.debug (Debug mode) bool false
# Whether to enable players joining and parting the channel.
irc.enable_player_part (Allow player join/part) bool true
# Whether to automatically show players in the channel when they join.
irc.auto_join (Auto join players) bool true

View File

@ -5,7 +5,7 @@ local mname = "memorandum"
-----------------------------------------------------------------------------------------------
-- { left , bottom , front , right , top , back }
local sheet = { -1/2 , -1/2 , -1/2 , 1/2 , -7/16 , 1/2 }
local info = 'On this piece of paper is written: "'
local info = '"'
local sign = '" Signed by '
minetest.register_craftitem(":default:paper", {

View File

@ -264,7 +264,7 @@ minetest.register_entity("painting:paintent", {
--check for brush.
local name = string.sub(puncher:get_wielded_item():get_name(), #"painting:brush_"+1)
if not colors[name] then -- Not one of the brushes; can't paint.
minetest.chat_send_all(name)
-- minetest.chat_send_all(name)
return
end

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

View File

@ -26,12 +26,12 @@ minetest.register_chatcommand("report", {
mod_list = table.concat(mods, ", ")
email.send_mail(name, minetest.setting_get("name"),
"Report: " .. param .. " (mods online: " .. mod_list .. ")")
irc:say(name .. " reports: " .. param .. " (mods online: " .. mod_list .. ")")
irc:say(name .. " sent a report! (mods online: " .. mod_list .. ")")
return true, "Reported. Moderators currently online: " .. mod_list
else
email.send_mail(name, minetest.setting_get("name"),
"Report: " .. param .. " (no mods online)")
irc:say(name .. " reports: " .. param .. " (no mods online)")
irc:say(name .. " sent a report! (no mods online)")
return true, "Reported. We'll get back to you."
end
end