summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiftob')
-rw-r--r--Swiftob/Commands.cpp54
-rw-r--r--Swiftob/Commands.h10
-rw-r--r--Swiftob/LuaCommands.cpp94
-rw-r--r--Swiftob/LuaCommands.h8
-rw-r--r--Swiftob/MUCs.cpp17
-rw-r--r--Swiftob/MUCs.h22
-rw-r--r--Swiftob/SConscript15
-rw-r--r--Swiftob/Storage.cpp4
-rw-r--r--Swiftob/Swiftob.cpp35
-rw-r--r--Swiftob/Swiftob.h3
-rw-r--r--Swiftob/Users.cpp2
-rw-r--r--Swiftob/Users.h10
-rw-r--r--Swiftob/linit.cpp1
-rw-r--r--Swiftob/scripts/badWords.lua15
-rw-r--r--Swiftob/scripts/irssiLogs.lua23
-rw-r--r--Swiftob/scripts/logAllMessages.lua6
16 files changed, 279 insertions, 40 deletions
diff --git a/Swiftob/Commands.cpp b/Swiftob/Commands.cpp
index cf24196..38e5f57 100644
--- a/Swiftob/Commands.cpp
+++ b/Swiftob/Commands.cpp
@@ -10,4 +10,5 @@
#include <iostream>
#include <boost/bind.hpp>
+#include <boost/algorithm/string.hpp>
#include <Swiften/Client/Client.h>
@@ -23,9 +24,18 @@ Commands::Commands(Users* users, Swift::Client* client, Storage* storage, MUCs*
}
-void Commands::resetCommands() {
+Commands::~Commands() {
+ clearCommands();
+}
+
+void Commands::clearCommands() {
foreach (NamedCommand command, commands_) {
delete command.second;
}
commands_.clear();
+
+}
+
+void Commands::resetCommands() {
+ clearCommands();
registerCommand("quit", Owner, "Quit the bot", boost::bind(&Commands::handleQuitCommand, this, _1, _2, _3));
registerCommand("help", Anyone, "Get help", boost::bind(&Commands::handleHelpCommand, this, _1, _2, _3));
@@ -33,4 +43,7 @@ void Commands::resetCommands() {
registerCommand("part", Owner, "Leave a MUC", boost::bind(&Commands::handlePartCommand, this, _1, _2, _3));
registerCommand("rehash", Owner, "Reload scripts", boost::bind(&Commands::handleRehashCommand, this, _1, _2, _3));
+ registerCommand("restart", Owner, "Restart bot", boost::bind(&Commands::handleRestartCommand, this, _1, _2, _3));
+ registerCommand("nick", Owner, "Change nick (requires restart)", boost::bind(&Commands::handleChangeNick, this, _1, _2, _3));
+ //registerCommand("owner", Owner, "Change owner settinsg", boost::bind(&Commands::handleChangeOwner, this, _1, _2, _3));
onReset();
}
@@ -42,4 +55,8 @@ void Commands::registerCommand(const std::string& name, RoleList roles, const st
}
+void Commands::registerListener(ListenerCallback listener) {
+ listeners_.push_back(listener);
+}
+
bool Commands::hasCommand(const std::string& name) {
return commands_.find(name) != commands_.end();
@@ -58,4 +75,10 @@ bool Commands::runCommand(const std::string& name, const std::string& params, Sw
}
+void Commands::runListeners(Swift::Message::ref message) {
+ foreach (ListenerCallback listener, listeners_) {
+ listener(message);
+ }
+}
+
bool Commands::roleIn(const Users::User::Role userRole, RoleList roleList) {
switch (roleList) {
@@ -67,4 +90,25 @@ bool Commands::roleIn(const Users::User::Role userRole, RoleList roleList) {
}
+void Commands::handleChangeNick(const std::string& /*command*/, const std::string& params, Swift::Message::ref message) {
+ std::string nick(params);
+ boost::algorithm::trim(nick);
+ if (nick.empty()) {
+ replyTo(message, "Current nick is '" + mucs_->getDefaultNick() + "'. Run the command with a new nick to change it.");
+ }
+ else {
+ if (mucs_->setDefaultNick(params)) {
+ replyTo(message, "Default nick now set to '" + nick + "' - restart the bot for this to take effect.");
+ }
+ else {
+ replyTo(message, "Can't set invalid nick '" + nick + "'.");
+ }
+ }
+}
+
+void Commands::handleChangeOwner(const std::string& /*command*/, const std::string& /*params*/, Swift::Message::ref /*message*/) {
+ /* Oh, right. I don't have user persistence coded yet.
+ * Probably not worth doing this until I have.*/
+}
+
void Commands::handleQuitCommand(const std::string& /*command*/, const std::string& /*params*/, Swift::Message::ref message) {
replyTo(message, "Shutting down");
@@ -85,4 +129,5 @@ void Commands::handleRehashCommand(const std::string& /*command*/, const std::st
std::cout << "Rehashing at the behest of " << message->getFrom().toString() << std::endl;
resetCommands();
+ listeners_.clear();
if (rehashError_.empty()) {
replyTo(message, "Rehash complete");
@@ -92,4 +137,11 @@ void Commands::handleRehashCommand(const std::string& /*command*/, const std::st
}
+void Commands::handleRestartCommand(const std::string& /*command*/, const std::string& /*params*/, Swift::Message::ref message) {
+ rehashError_ = "";
+ replyTo(message, "Restarting now.");
+ std::cout << "Restarting at the behest of " << message->getFrom().toString() << std::endl;
+ onRestartRequested();
+}
+
void Commands::handleJoinCommand(const std::string& /*command*/, const std::string& params, Swift::Message::ref message) {
Swift::JID room(params);
diff --git a/Swiftob/Commands.h b/Swiftob/Commands.h
index 8423252..d5aac2c 100644
--- a/Swiftob/Commands.h
+++ b/Swiftob/Commands.h
@@ -22,4 +22,5 @@ namespace Swift {
class Storage;
class Commands {
+ typedef boost::function<void(Swift::Message::ref)> ListenerCallback;
public:
enum RoleList {Anyone, Owner};
@@ -42,8 +43,11 @@ class Commands {
public:
Commands(Users* users, Swift::Client* client, Storage* storage, MUCs* mucs);
+ ~Commands();
bool hasCommand(const std::string&);
bool runCommand(const std::string& command, const std::string& params, Swift::Message::ref message);
+ void runListeners(Swift::Message::ref message);
void replyTo(Swift::Message::ref source, std::string replyBody, bool outOfMUC = false);
void registerCommand(const std::string& name, RoleList roles, const std::string& description, boost::function<void(const std::string& /*command*/, const std::string& /*params*/, Swift::Message::ref)> callback);
+ void registerListener(ListenerCallback);
void resetCommands();
void setRehashError(const std::string& error);
@@ -51,5 +55,7 @@ class Commands {
public:
boost::signal<void ()> onReset;
+ boost::signal<void ()> onRestartRequested;
private:
+ void clearCommands();
bool roleIn(const Users::User::Role userRole, RoleList roles);
void handleQuitCommand(const std::string& command, const std::string& params, Swift::Message::ref message);
@@ -60,6 +66,10 @@ class Commands {
void handlePartCommand(const std::string& /*command*/, const std::string& params, Swift::Message::ref message);
void handleRehashCommand(const std::string& command, const std::string& params, Swift::Message::ref message);
+ void handleRestartCommand(const std::string& command, const std::string& params, Swift::Message::ref message);
+ void handleChangeNick(const std::string& command, const std::string& params, Swift::Message::ref message);
+ void handleChangeOwner(const std::string& command, const std::string& params, Swift::Message::ref message);
private:
std::map<std::string, Command*> commands_;
+ std::vector<ListenerCallback> listeners_;
Users* users_;
Swift::Client* client_;
diff --git a/Swiftob/LuaCommands.cpp b/Swiftob/LuaCommands.cpp
index 9f99d82..0358f98 100644
--- a/Swiftob/LuaCommands.cpp
+++ b/Swiftob/LuaCommands.cpp
@@ -15,10 +15,41 @@
#include <Swiften/Client/Client.h>
#include <Swiften/Network/TimerFactory.h>
+#include <boost/filesystem/operations.hpp>
+#include <Swiften/Base/Path.h>
#include <Swiftob/Commands.h>
+#include <Swiften/Base/BoostFilesystemVersion.h>
+
#define LUA_COMMANDS "__Lua_Commands"
#define STORAGE "__Storage"
+static const luaL_Reg defaultLibraries[] = {
+ {"", luaopen_base},
+ {LUA_LOADLIBNAME, luaopen_package},
+ {LUA_TABLIBNAME, luaopen_table},
+ {LUA_IOLIBNAME, luaopen_io},
+ {LUA_OSLIBNAME, luaopen_os},
+ {LUA_STRLIBNAME, luaopen_string},
+ {LUA_MATHLIBNAME, luaopen_math},
+ {LUA_DBLIBNAME, luaopen_debug},
+ {NULL, NULL}
+};
+
+static void initialize(lua_State* L) {
+ lua_gc(L, LUA_GCSTOP, 0);
+ for (const luaL_Reg* lib = defaultLibraries; lib->func; lib++) {
+#if LUA_VERSION_NUM >= 502
+ luaL_requiref(L, lib->name, lib->func, 1);
+ lua_pop(L, 1);
+#else
+ lua_pushcfunction(L, lib->func);
+ lua_pushstring(L, lib->name);
+ lua_call(L, 1, 0);
+#endif
+ }
+ lua_gc(L, LUA_GCRESTART, 0);
+}
+
LuaCommands::LuaCommands(Commands* commands, const std::string& path, Client* client, TimerFactory* timerFactory, MUCs* mucs) : path_(path), scriptsPath_(boost::filesystem::path(path_) / "scripts") {
commands_ = commands;
@@ -43,4 +74,19 @@ void LuaCommands::registerCommands() {
}
+static int l_register_listener(lua_State *L) {
+ LuaCommands* commands = NULL;
+ lua_getfield(L, LUA_REGISTRYINDEX, LUA_COMMANDS);
+ commands = static_cast<LuaCommands*>(lua_touserdata(L, -1));
+ lua_pop(L, 1);
+ if (!lua_isfunction(L, 1)) {
+ return luaL_error(L, "register_listener parameter must be a callback function");
+ }
+ lua_pushvalue(L, 1);
+ int callbackIndex = luaL_ref(L, LUA_REGISTRYINDEX);
+ lua_pop(L, 1);
+ commands->getCommands()->registerListener(boost::bind(&LuaCommands::handleLuaListener, commands, callbackIndex, L, _1));
+ return 0;
+}
+
static int l_register_command(lua_State *L) {
LuaCommands* commands = NULL;
@@ -284,4 +330,23 @@ int LuaCommands::get_software_version(lua_State *L) {
}
+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);
@@ -314,4 +379,19 @@ int LuaCommands::get_setting(lua_State *L) {
}
+void LuaCommands::handleLuaListener(int callbackIndex, lua_State* L, Swift::Message::ref message) {
+ lua_rawgeti(L, LUA_REGISTRYINDEX, callbackIndex);
+ lua_pushstring(L, message->getBody().c_str());
+ lua_pushstring(L, message->getFrom().toBare().toString().c_str());
+ lua_pushstring(L, message->getFrom().getResource().c_str());
+ messageOntoStack(message, L);
+ int result = lua_pcall(L, 4, 0, 0);
+ if (result != 0) {
+ std::string error(lua_tostring(L, -1));
+ lua_pop(L, 1);
+ error = "Listener failed: " + error;
+ std::cout << error << std::endl;
+ }
+}
+
void LuaCommands::handleLuaCommand(int callbackIndex, lua_State* L, const std::string& command, const std::string& params, Swift::Message::ref message) {
lua_rawgeti(L, LUA_REGISTRYINDEX, callbackIndex);
@@ -353,15 +433,20 @@ void LuaCommands::messageOntoStack(Swift::Message::ref message, lua_State* L) {
void LuaCommands::loadScript(boost::filesystem::path filePath) {
std::cout << "Trying to load file from " << filePath << std::endl;
- lua_State* lua = lua_open();
- luaL_openlibs(lua);
+ lua_State* lua = luaL_newstate();
+ initialize(lua);
lua_pushlightuserdata(lua, this);
lua_setfield(lua, LUA_REGISTRYINDEX, LUA_COMMANDS);
- std::string filename(filePath.filename());
+#if BOOST_FILESYSTEM_VERSION == 2 // TODO: Delete this when boost 1.44 becomes a minimum requirement, and we no longer need v2
+ std::string filename = filePath.filename();
+#else
+ std::string filename = filePath.filename().string();
+#endif
filename += ".storage";
- boost::filesystem::path storagePath(boost::filesystem::path(path_) / filename);
+ boost::filesystem::path storagePath(boost::filesystem::path(path_) / stringToPath(filename));
Storage* storage = new Storage(storagePath);
lua_pushlightuserdata(lua, storage);
lua_setfield(lua, LUA_REGISTRYINDEX, STORAGE);
lua_register(lua, "swiftob_register_command", &l_register_command);
+ lua_register(lua, "swiftob_register_listener", &l_register_listener);
lua_register(lua, "swiftob_reply_to", &l_reply_to);
lua_register(lua, "swiftob_get_software_version", &l_get_software_version);
@@ -369,4 +454,5 @@ void LuaCommands::loadScript(boost::filesystem::path filePath) {
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 ) {
diff --git a/Swiftob/LuaCommands.h b/Swiftob/LuaCommands.h
index fc743ca..c5f959d 100644
--- a/Swiftob/LuaCommands.h
+++ b/Swiftob/LuaCommands.h
@@ -10,7 +10,5 @@
#include <vector>
-#include <lua.h>
-#include <lauxlib.h>
-#include <lualib.h>
+#include <lua.hpp>
#include <boost/filesystem/fstream.hpp>
#include <boost/noncopyable.hpp>
@@ -65,6 +63,7 @@ class LuaCommands {
LuaCommands(Commands* commands, const std::string& path, Client* client, TimerFactory* timerFactory, MUCs* mucs);
- /* Public but isn't really part of the API */
+ /* Public but aren't really part of the API */
void handleLuaCommand(int callbackIndex, lua_State* L, const std::string& command, const std::string& params, Message::ref message);
+ void handleLuaListener(int callbackIndex, lua_State* L, Message::ref message);
Commands* getCommands() {return commands_;}
int get_software_version(lua_State *L);
@@ -72,4 +71,5 @@ class LuaCommands {
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);
diff --git a/Swiftob/MUCs.cpp b/Swiftob/MUCs.cpp
index 695cbd9..aec821a 100644
--- a/Swiftob/MUCs.cpp
+++ b/Swiftob/MUCs.cpp
@@ -18,5 +18,8 @@
#include <Swiftob/Storage.h>
+using namespace Swift;
+
#define MUC_LIST_SETTING "muc_list"
+#define NICK "default_nick"
typedef std::pair<JID, MUC::ref> JIDMUCPair;
@@ -25,4 +28,8 @@ MUCs::MUCs(Client* client, Storage* storage) : defaultNick_("Kanchil+") {
client_ = client;
storage_ = storage;
+ std::string storedNick = storage_->getSetting(NICK);
+ if (!storedNick.empty()) {
+ defaultNick_ = storedNick;
+ }
client_->onConnected.connect(boost::bind(&MUCs::handleConnected, this));
}
@@ -119,2 +126,12 @@ MUC::ref MUCs::getMUC(const JID& room) {
return (mucs_.find(room) != mucs_.end()) ? mucs_[room] : MUC::ref();
}
+
+bool MUCs::setDefaultNick(const std::string& nick) {
+ JID testJID("alice", "wonderland.lit", nick);
+ if (testJID.isValid()) {
+ defaultNick_ = testJID.getResource();
+ storage_->saveSetting(NICK, defaultNick_);
+ return true;
+ }
+ return false;
+}
diff --git a/Swiftob/MUCs.h b/Swiftob/MUCs.h
index e727ec2..ecbb7a6 100644
--- a/Swiftob/MUCs.h
+++ b/Swiftob/MUCs.h
@@ -22,23 +22,23 @@ class MUC;
class Storage;
-using namespace Swift;
-
class MUCs {
public:
- MUCs(Client* client, Storage* storage);
- void join(const JID& room, boost::signal<void (const std::string&)>::slot_type successCallback, boost::function<void(const std::string& /*reason*/)> failureCallback);
- void part(const JID& room);
- bool contains(const JID& room);
- MUC::ref getMUC(const JID& room);
+ MUCs(Swift::Client* client, Storage* storage);
+ void join(const Swift::JID& room, boost::signal<void (const std::string&)>::slot_type successCallback, boost::function<void(const std::string& /*reason*/)> failureCallback);
+ void part(const Swift::JID& room);
+ bool contains(const Swift::JID& room);
+ Swift::MUC::ref getMUC(const Swift::JID& room);
+ const std::string& getDefaultNick() const {return defaultNick_;}
+ bool setDefaultNick(const std::string& nick);
private:
void handleConnected();
- void handleJoinFailed(const JID& room, ErrorPayload::ref error, boost::function<void(const std::string& /*reason*/)> failureCallback);
+ void handleJoinFailed(const Swift::JID& room, Swift::ErrorPayload::ref error, boost::function<void(const std::string& /*reason*/)> failureCallback);
void handleInitialJoinSuccess();
void handleInitialJoinFailure(const std::string&);
void save();
private:
- MUCRegistry registry_;
- std::map<JID, MUC::ref> mucs_;
- Client* client_;
+ Swift::MUCRegistry registry_;
+ std::map<Swift::JID, Swift::MUC::ref> mucs_;
+ Swift::Client* client_;
Storage* storage_;
std::string defaultNick_;
diff --git a/Swiftob/SConscript b/Swiftob/SConscript
index bb056bb..b78ade9 100644
--- a/Swiftob/SConscript
+++ b/Swiftob/SConscript
@@ -1,12 +1,17 @@
Import("env")
+if env["SCONS_STAGE"] == "build" and not GetOption("help") and not env.get("HAVE_LUA", 0) :
+ print "Warning: Lua was not found. Swiftob will not be built."
+ if "Sluift" in env["PROJECTS"] :
+ env["PROJECTS"].remove("Sluift")
-if env["SCONS_STAGE"] == "build":
+elif env["SCONS_STAGE"] == "build":
myenv = env.Clone()
- myenv.MergeFlags(myenv.get("LUA_FLAGS", {}))
- myenv.MergeFlags(myenv["SWIFTEN_FLAGS"])
- myenv.MergeFlags(myenv["SWIFTEN_DEP_FLAGS"])
+ # Too many compile warnings here at the moment
+ myenv.Replace(CXXFLAGS = [flag for flag in env["CXXFLAGS"] if flag != "-Weverything"])
+ myenv.UseFlags(myenv.get("LUA_FLAGS", {}))
+ myenv.UseFlags(myenv["SWIFTEN_FLAGS"])
+ myenv.UseFlags(myenv["SWIFTEN_DEP_FLAGS"])
sources = [
- "linit.cpp",
"Swiftob.cpp",
"Users.cpp",
diff --git a/Swiftob/Storage.cpp b/Swiftob/Storage.cpp
index 47d0619..5311d82 100644
--- a/Swiftob/Storage.cpp
+++ b/Swiftob/Storage.cpp
@@ -7,4 +7,6 @@
#include <Swiftob/Storage.h>
+#include <boost/filesystem/operations.hpp>
+
#include <Swiften/Base/String.h>
#include <Swiften/Base/ByteArray.h>
@@ -24,5 +26,5 @@ void Storage::load() {
if (boost::filesystem::exists(settingsPath_)) {
Swift::ByteArray data;
- Swift::readByteArrayFromFile(data, settingsPath_.string());
+ Swift::readByteArrayFromFile(data, settingsPath_);
foreach (std::string line, Swift::String::split(Swift::byteArrayToString(data), '\n')) {
std::pair<std::string, std::string> pair = Swift::String::getSplittedAtFirst(line, '\t');
diff --git a/Swiftob/Swiftob.cpp b/Swiftob/Swiftob.cpp
index 331e55e..1578e34 100644
--- a/Swiftob/Swiftob.cpp
+++ b/Swiftob/Swiftob.cpp
@@ -33,12 +33,12 @@ po::options_description Swiftob::getOptionsDescription() {
Swiftob::Swiftob(const po::variables_map& options) : options_(options), networkFactories_(&eventLoop_), quitting_(false) {
- std::string path;
- path = options["path"].as<std::string>();
+ path_ = options["path"].as<std::string>();
client_ = new Swift::Client(Swift::JID(options["jid"].as<std::string>()), options["password"].as<std::string>(), &networkFactories_);
- storage_ = new Storage(boost::filesystem::path(path) / "settings.txt");
- mucs_ = new MUCs(client_, storage_);
- users_ = new Users(client_, mucs_);
- commands_ = new Commands(users_, client_, storage_, mucs_);
- lua_ = new LuaCommands(commands_, path, client_, networkFactories_.getTimerFactory(), mucs_);
+ storage_ = new Storage(boost::filesystem::path(path_) / "settings.txt");
+ mucs_ = NULL;
+ users_ = NULL;
+ commands_ = NULL;
+ lua_ = NULL;
+ init();
client_->onConnected.connect(boost::bind(&Swiftob::handleConnected, this));
client_->onDisconnected.connect(boost::bind(&Swiftob::handleDisconnected, this, _1));
@@ -55,4 +55,21 @@ Swiftob::Swiftob(const po::variables_map& options) : options_(options), networkF
}
+void Swiftob::init() {
+ delete mucs_;
+ mucs_ = new MUCs(client_, storage_);
+ delete users_;
+ users_ = new Users(client_, mucs_);
+ delete commands_;
+ commands_ = new Commands(users_, client_, storage_, mucs_);
+ commands_->onRestartRequested.connect(boost::bind(&Swiftob::handleRestartRequested, this));
+ delete lua_;
+ lua_ = new LuaCommands(commands_, path_, client_, networkFactories_.getTimerFactory(), mucs_);
+}
+
+void Swiftob::handleRestartRequested() {
+ client_->disconnect();
+ init();
+}
+
void Swiftob::handleConnected() {
std::cout << "Connected" << std::endl;
@@ -88,4 +105,8 @@ void Swiftob::handleMessageReceived(Swift::Message::ref message) {
return;
}
+
+ /* Run through any full-message listeners */
+ commands_->runListeners(message);
+
/*Convert body into !command if it's not a MUC, and it misses the bang*/
std::string bangBody(body);
diff --git a/Swiftob/Swiftob.h b/Swiftob/Swiftob.h
index ad4e9b8..36091e4 100644
--- a/Swiftob/Swiftob.h
+++ b/Swiftob/Swiftob.h
@@ -33,4 +33,6 @@ class Swiftob {
~Swiftob();
private:
+ void init();
+ void handleRestartRequested();
void handleConnected();
void handleDisconnected(const boost::optional<Swift::ClientError>&);
@@ -46,4 +48,5 @@ class Swiftob {
bool quitting_;
Users* users_;
+ std::string path_;
Swift::Client* client_;
};
diff --git a/Swiftob/Users.cpp b/Swiftob/Users.cpp
index 09173cc..868efb0 100644
--- a/Swiftob/Users.cpp
+++ b/Swiftob/Users.cpp
@@ -14,4 +14,6 @@
#include <Swiftob/MUCs.h>
+using namespace Swift;
+
Users::Users(Client* client, MUCs* mucs) {
client_ = client;
diff --git a/Swiftob/Users.h b/Swiftob/Users.h
index 0acc330..a78beed 100644
--- a/Swiftob/Users.h
+++ b/Swiftob/Users.h
@@ -19,6 +19,4 @@ class Client;
class MUCs;
-using namespace Swift;
-
class Users {
public:
@@ -27,5 +25,5 @@ class Users {
/* If you add a role here, edit the role lists in Commands.cpp*/
enum Role {Unknown, Owner};
- User(const JID& jid, Role role) : jid_(jid), role_(role) {}
+ User(const Swift::JID& jid, Role role) : jid_(jid), role_(role) {}
Role getRole() {return role_;}
Swift::JID getJID() {return jid_;}
@@ -36,12 +34,12 @@ class Users {
public:
- Users(Client* client, MUCs* mucs);
+ Users(Swift::Client* client, MUCs* mucs);
void clearAll();
void addUser(const User& user);
- User::Role getRoleForSender(Message::ref message);
+ User::Role getRoleForSender(Swift::Message::ref message);
private:
std::vector<User> users_;
- Client* client_;
+ Swift::Client* client_;
MUCs* mucs_;
};
diff --git a/Swiftob/linit.cpp b/Swiftob/linit.cpp
deleted file mode 100644
index 13c5b09..0000000
--- a/Swiftob/linit.cpp
+++ /dev/null
@@ -1 +0,0 @@
-#include "../3rdParty/Lua/src/linit.c"
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)
+
diff --git a/Swiftob/scripts/irssiLogs.lua b/Swiftob/scripts/irssiLogs.lua
new file mode 100644
index 0000000..3cecd9d
--- /dev/null
+++ b/Swiftob/scripts/irssiLogs.lua
@@ -0,0 +1,23 @@
+function irssi_log_to_file(muc, line)
+ filename = muc:gsub("@", "_at_")
+ filename = filename:gsub("%.%.", "_")
+ filename = filename:gsub("/", "_")
+ filename = filename:gsub("\\", "_")
+ file = io.open(filename, "a+")
+ if file == nil then
+ io.close()
+ else
+ file:write(line)
+ file:write("\n")
+ file:close()
+ end
+
+end
+
+function irssi_log_message(body, muc, nick, message)
+ time = os.date("%H:%M")
+ irssi_log_to_file(muc, time.." <"..nick.."> "..body)
+end
+
+swiftob_register_listener(irssi_log_message)
+
diff --git a/Swiftob/scripts/logAllMessages.lua b/Swiftob/scripts/logAllMessages.lua
new file mode 100644
index 0000000..a14c0f3
--- /dev/null
+++ b/Swiftob/scripts/logAllMessages.lua
@@ -0,0 +1,6 @@
+function log_a_message(body, muc, nick, message)
+ print("Received line from '" .. nick .. "' in '" .. muc .. "':")
+ print(body)
+end
+
+swiftob_register_listener(log_a_message)