From 053128df5c36b80c35e8ec5483125305f8fc86ea Mon Sep 17 00:00:00 2001 From: Kevin Smith Date: Sat, 21 Jul 2012 20:31:16 +0100 Subject: Adding MUC kicking support to Swiftob bots diff --git a/Swiftob/LuaCommands.cpp b/Swiftob/LuaCommands.cpp index 8cc614d..27c44eb 100644 --- a/Swiftob/LuaCommands.cpp +++ b/Swiftob/LuaCommands.cpp @@ -298,6 +298,25 @@ int LuaCommands::get_software_version(lua_State *L) { return 1; } +int LuaCommands::muc_kick(lua_State *L) { + if (!lua_isstring(L, 2)) { + return luaL_error(L, "muc_kick requires a nick to kick"); + } + std::string nick = lua_tostring(L, 2); + if (!lua_isstring(L, 1)) { + return luaL_error(L, "muc_kick requires a muc to kick from"); + } + JID mucJID(lua_tostring(L, 1)); + MUC::ref muc = mucs_->getMUC(mucJID); + muc->kickOccupant(JID(mucJID.getNode(), mucJID.getDomain(), nick)); + return 0; +} + +static int l_muc_kick(lua_State *L) { + LuaCommands* commands = LuaCommands::commandsFromLua(L); + return commands->muc_kick(L); +} + static int l_store_setting(lua_State *L) { return LuaCommands::commandsFromLua(L)->store_setting(L); } @@ -399,6 +418,7 @@ void LuaCommands::loadScript(boost::filesystem::path filePath) { lua_register(lua, "swiftob_muc_input_to_jid", &l_muc_input_to_jid); lua_register(lua, "swiftob_store_setting", &l_store_setting); lua_register(lua, "swiftob_get_setting", &l_get_setting); + lua_register(lua, "swiftob_muc_kick", &l_muc_kick); int fileLoaded = luaL_dofile(lua, filePath.string().c_str()); if (fileLoaded == 0 ) { std::cout << "Loaded" << std::endl; diff --git a/Swiftob/LuaCommands.h b/Swiftob/LuaCommands.h index b82959e..97ea87c 100644 --- a/Swiftob/LuaCommands.h +++ b/Swiftob/LuaCommands.h @@ -72,6 +72,7 @@ class LuaCommands { int muc_input_to_jid(lua_State *L); int store_setting(lua_State *L); int get_setting(lua_State *L); + int muc_kick(lua_State *L); static LuaCommands* commandsFromLua(lua_State *L); static Storage* storageFromLua(lua_State *L); private: diff --git a/Swiftob/scripts/badWords.lua b/Swiftob/scripts/badWords.lua new file mode 100644 index 0000000..2c16214 --- /dev/null +++ b/Swiftob/scripts/badWords.lua @@ -0,0 +1,15 @@ +function bad_words(body, muc, nick, message) + words = {"sbwriel"} + print("Received line from '" .. nick .. "' in '" .. muc .. "':") + print(body) + + for _, word in pairs(words) do + if string.len(string.match(body, word)) > 0 then + --swiftob_reply_to(message, "Kicking "..nick.." for bad word "..word) + swiftob_muc_kick(muc, nick) + end + end +end + +swiftob_register_listener(bad_words) + -- cgit v0.10.2-6-g49f6