# HG changeset patch # User Kim Alvefur # Date 1290296249 -3600 # Node ID 45d31a4f9c5ae505f81e6420167dd4acdb2df34c # Parent 222b0b70baf322ba734e5aa58ccdeb918f90a241 plugins.bookmarks: Don't allow to bookmark the same room twice diff -r 222b0b70baf3 -r 45d31a4f9c5a plugins/bookmarks.lua --- a/plugins/bookmarks.lua Sat Nov 20 18:51:56 2010 +0100 +++ b/plugins/bookmarks.lua Sun Nov 21 00:37:29 2010 +0100 @@ -4,6 +4,8 @@ -- set allow_add_bookmarks = true; in config to enable the bookmark command function riddim.plugins.bookmarks(bot) + local my_bookmarks = {}; + bot.stream:add_plugin("private"); local function get_bookmarks(callback) @@ -39,10 +41,13 @@ local function join_bookmarked_rooms() get_bookmarks(function(storage) for i, room in ipairs(storage) do - if room.name == "conference" and room.attr.jid and room.attr.autojoin == "true" or room.attr.autojoin == "1" then - nick = room:get_child("nick"); - nick = nick and nick[1] or bot.config.nick; - bot:join_room(room.attr.jid, nick); + if room.name == "conference" and room.attr.jid then + my_bookmarks[room.attr.jid] = true; -- to know which rooms are bookmarked + if room.attr.autojoin == "true" or room.attr.autojoin == "1" then + nick = room:get_child("nick"); + nick = nick and nick[1] or bot.config.nick; + bot:join_room(room.attr.jid, nick); + end -- TODO Passwords -- Maybe get the hook in before the groupchat is loaded -- and add to the bot.config.autojoin variable? @@ -56,6 +61,9 @@ if bot.config.allow_add_bookmarks then bot:hook("commands/bookmark", function(command) local room = command.param and jid.bare(command.param) or command.room.jid; + if my_bookmarks[room] then return "Already bookmarked" end + my_bookmarks[room] = true; + add_bookmark({ jid = room, autojoin = "true" }, function() command:reply("Bookmarked " .. room) end); end); end