From e66063e6304538d34c40460ca0aa2be5ddb6bdec Mon Sep 17 00:00:00 2001 From: Adam Date: Fri, 5 Aug 2011 05:35:31 -0400 Subject: Rewrote the example configurations and split them up into seperate files for each pseudo client. Also reorganized how the modules are stored, and made most of the old "extra" modules "core" --- modules/commands/bs_assign.cpp | 168 +++++ modules/commands/bs_badwords.cpp | 331 ++++++++++ modules/commands/bs_bot.cpp | 414 ++++++++++++ modules/commands/bs_botlist.cpp | 91 +++ modules/commands/bs_control.cpp | 158 +++++ modules/commands/bs_info.cpp | 244 +++++++ modules/commands/bs_kick.cpp | 1011 +++++++++++++++++++++++++++++ modules/commands/bs_set.cpp | 307 +++++++++ modules/commands/cs_access.cpp | 915 ++++++++++++++++++++++++++ modules/commands/cs_akick.cpp | 564 ++++++++++++++++ modules/commands/cs_appendtopic.cpp | 117 ++++ modules/commands/cs_ban.cpp | 109 ++++ modules/commands/cs_clearusers.cpp | 83 +++ modules/commands/cs_clone.cpp | 186 ++++++ modules/commands/cs_drop.cpp | 102 +++ modules/commands/cs_enforce.cpp | 215 ++++++ modules/commands/cs_entrymsg.cpp | 224 +++++++ modules/commands/cs_flags.cpp | 455 +++++++++++++ modules/commands/cs_getkey.cpp | 80 +++ modules/commands/cs_info.cpp | 142 ++++ modules/commands/cs_invite.cpp | 102 +++ modules/commands/cs_kick.cpp | 91 +++ modules/commands/cs_list.cpp | 136 ++++ modules/commands/cs_mode.cpp | 364 +++++++++++ modules/commands/cs_modes.cpp | 431 ++++++++++++ modules/commands/cs_register.cpp | 193 ++++++ modules/commands/cs_saset.cpp | 74 +++ modules/commands/cs_saset_noexpire.cpp | 81 +++ modules/commands/cs_set.cpp | 74 +++ modules/commands/cs_set_bantype.cpp | 98 +++ modules/commands/cs_set_description.cpp | 89 +++ modules/commands/cs_set_founder.cpp | 105 +++ modules/commands/cs_set_keeptopic.cpp | 94 +++ modules/commands/cs_set_misc.cpp | 110 ++++ modules/commands/cs_set_opnotice.cpp | 93 +++ modules/commands/cs_set_peace.cpp | 93 +++ modules/commands/cs_set_persist.cpp | 180 +++++ modules/commands/cs_set_private.cpp | 93 +++ modules/commands/cs_set_restricted.cpp | 91 +++ modules/commands/cs_set_secure.cpp | 94 +++ modules/commands/cs_set_securefounder.cpp | 95 +++ modules/commands/cs_set_secureops.cpp | 92 +++ modules/commands/cs_set_signkick.cpp | 104 +++ modules/commands/cs_set_successor.cpp | 119 ++++ modules/commands/cs_set_topiclock.cpp | 92 +++ modules/commands/cs_suspend.cpp | 158 +++++ modules/commands/cs_sync.cpp | 63 ++ modules/commands/cs_tban.cpp | 116 ++++ modules/commands/cs_topic.cpp | 84 +++ modules/commands/cs_unban.cpp | 94 +++ modules/commands/cs_xop.cpp | 880 +++++++++++++++++++++++++ modules/commands/gl_global.cpp | 64 ++ modules/commands/help.cpp | 130 ++++ modules/commands/hs_del.cpp | 107 +++ modules/commands/hs_group.cpp | 80 +++ modules/commands/hs_list.cpp | 137 ++++ modules/commands/hs_off.cpp | 67 ++ modules/commands/hs_on.cpp | 77 +++ modules/commands/hs_request.cpp | 424 ++++++++++++ modules/commands/hs_set.cpp | 236 +++++++ modules/commands/ms_cancel.cpp | 77 +++ modules/commands/ms_check.cpp | 89 +++ modules/commands/ms_del.cpp | 163 +++++ modules/commands/ms_ignore.cpp | 110 ++++ modules/commands/ms_info.cpp | 219 +++++++ modules/commands/ms_list.cpp | 168 +++++ modules/commands/ms_read.cpp | 195 ++++++ modules/commands/ms_rsend.cpp | 106 +++ modules/commands/ms_send.cpp | 70 ++ modules/commands/ms_sendall.cpp | 74 +++ modules/commands/ms_set.cpp | 313 +++++++++ modules/commands/ms_staff.cpp | 71 ++ modules/commands/ns_access.cpp | 195 ++++++ modules/commands/ns_ajoin.cpp | 239 +++++++ modules/commands/ns_alist.cpp | 96 +++ modules/commands/ns_cert.cpp | 231 +++++++ modules/commands/ns_drop.cpp | 130 ++++ modules/commands/ns_getemail.cpp | 82 +++ modules/commands/ns_getpass.cpp | 79 +++ modules/commands/ns_ghost.cpp | 122 ++++ modules/commands/ns_group.cpp | 305 +++++++++ modules/commands/ns_identify.cpp | 93 +++ modules/commands/ns_info.cpp | 173 +++++ modules/commands/ns_list.cpp | 169 +++++ modules/commands/ns_logout.cpp | 97 +++ modules/commands/ns_recover.cpp | 132 ++++ modules/commands/ns_register.cpp | 355 ++++++++++ modules/commands/ns_release.cpp | 110 ++++ modules/commands/ns_resetpass.cpp | 152 +++++ modules/commands/ns_saset.cpp | 173 +++++ modules/commands/ns_saset_noexpire.cpp | 76 +++ modules/commands/ns_sendpass.cpp | 108 +++ modules/commands/ns_set.cpp | 158 +++++ modules/commands/ns_set_autoop.cpp | 107 +++ modules/commands/ns_set_email.cpp | 186 ++++++ modules/commands/ns_set_greet.cpp | 108 +++ modules/commands/ns_set_hide.cpp | 149 +++++ modules/commands/ns_set_kill.cpp | 149 +++++ modules/commands/ns_set_language.cpp | 121 ++++ modules/commands/ns_set_message.cpp | 114 ++++ modules/commands/ns_set_misc.cpp | 126 ++++ modules/commands/ns_set_private.cpp | 114 ++++ modules/commands/ns_set_secure.cpp | 114 ++++ modules/commands/ns_status.cpp | 94 +++ modules/commands/ns_suspend.cpp | 160 +++++ modules/commands/ns_update.cpp | 70 ++ modules/commands/os_akill.cpp | 464 +++++++++++++ modules/commands/os_chankill.cpp | 120 ++++ modules/commands/os_config.cpp | 217 +++++++ modules/commands/os_defcon.cpp | 663 +++++++++++++++++++ modules/commands/os_forbid.cpp | 342 ++++++++++ modules/commands/os_forbid.h | 37 ++ modules/commands/os_ignore.cpp | 350 ++++++++++ modules/commands/os_ignore.h | 39 ++ modules/commands/os_jupe.cpp | 79 +++ modules/commands/os_kick.cpp | 83 +++ modules/commands/os_kill.cpp | 72 ++ modules/commands/os_list.cpp | 187 ++++++ modules/commands/os_login.cpp | 97 +++ modules/commands/os_mode.cpp | 109 ++++ modules/commands/os_modinfo.cpp | 245 +++++++ modules/commands/os_module.cpp | 202 ++++++ modules/commands/os_news.cpp | 450 +++++++++++++ modules/commands/os_news.h | 39 ++ modules/commands/os_noop.cpp | 94 +++ modules/commands/os_oline.cpp | 83 +++ modules/commands/os_oper.cpp | 219 +++++++ modules/commands/os_reload.cpp | 72 ++ modules/commands/os_session.cpp | 749 +++++++++++++++++++++ modules/commands/os_session.h | 32 + modules/commands/os_set.cpp | 261 ++++++++ modules/commands/os_shutdown.cpp | 117 ++++ modules/commands/os_stats.cpp | 224 +++++++ modules/commands/os_svsnick.cpp | 92 +++ modules/commands/os_sxline.cpp | 807 +++++++++++++++++++++++ modules/commands/os_update.cpp | 56 ++ 136 files changed, 24964 insertions(+) create mode 100644 modules/commands/bs_assign.cpp create mode 100644 modules/commands/bs_badwords.cpp create mode 100644 modules/commands/bs_bot.cpp create mode 100644 modules/commands/bs_botlist.cpp create mode 100644 modules/commands/bs_control.cpp create mode 100644 modules/commands/bs_info.cpp create mode 100644 modules/commands/bs_kick.cpp create mode 100644 modules/commands/bs_set.cpp create mode 100644 modules/commands/cs_access.cpp create mode 100644 modules/commands/cs_akick.cpp create mode 100644 modules/commands/cs_appendtopic.cpp create mode 100644 modules/commands/cs_ban.cpp create mode 100644 modules/commands/cs_clearusers.cpp create mode 100644 modules/commands/cs_clone.cpp create mode 100644 modules/commands/cs_drop.cpp create mode 100644 modules/commands/cs_enforce.cpp create mode 100644 modules/commands/cs_entrymsg.cpp create mode 100644 modules/commands/cs_flags.cpp create mode 100644 modules/commands/cs_getkey.cpp create mode 100644 modules/commands/cs_info.cpp create mode 100644 modules/commands/cs_invite.cpp create mode 100644 modules/commands/cs_kick.cpp create mode 100644 modules/commands/cs_list.cpp create mode 100644 modules/commands/cs_mode.cpp create mode 100644 modules/commands/cs_modes.cpp create mode 100644 modules/commands/cs_register.cpp create mode 100644 modules/commands/cs_saset.cpp create mode 100644 modules/commands/cs_saset_noexpire.cpp create mode 100644 modules/commands/cs_set.cpp create mode 100644 modules/commands/cs_set_bantype.cpp create mode 100644 modules/commands/cs_set_description.cpp create mode 100644 modules/commands/cs_set_founder.cpp create mode 100644 modules/commands/cs_set_keeptopic.cpp create mode 100644 modules/commands/cs_set_misc.cpp create mode 100644 modules/commands/cs_set_opnotice.cpp create mode 100644 modules/commands/cs_set_peace.cpp create mode 100644 modules/commands/cs_set_persist.cpp create mode 100644 modules/commands/cs_set_private.cpp create mode 100644 modules/commands/cs_set_restricted.cpp create mode 100644 modules/commands/cs_set_secure.cpp create mode 100644 modules/commands/cs_set_securefounder.cpp create mode 100644 modules/commands/cs_set_secureops.cpp create mode 100644 modules/commands/cs_set_signkick.cpp create mode 100644 modules/commands/cs_set_successor.cpp create mode 100644 modules/commands/cs_set_topiclock.cpp create mode 100644 modules/commands/cs_suspend.cpp create mode 100644 modules/commands/cs_sync.cpp create mode 100644 modules/commands/cs_tban.cpp create mode 100644 modules/commands/cs_topic.cpp create mode 100644 modules/commands/cs_unban.cpp create mode 100644 modules/commands/cs_xop.cpp create mode 100644 modules/commands/gl_global.cpp create mode 100644 modules/commands/help.cpp create mode 100644 modules/commands/hs_del.cpp create mode 100644 modules/commands/hs_group.cpp create mode 100644 modules/commands/hs_list.cpp create mode 100644 modules/commands/hs_off.cpp create mode 100644 modules/commands/hs_on.cpp create mode 100644 modules/commands/hs_request.cpp create mode 100644 modules/commands/hs_set.cpp create mode 100644 modules/commands/ms_cancel.cpp create mode 100644 modules/commands/ms_check.cpp create mode 100644 modules/commands/ms_del.cpp create mode 100644 modules/commands/ms_ignore.cpp create mode 100644 modules/commands/ms_info.cpp create mode 100644 modules/commands/ms_list.cpp create mode 100644 modules/commands/ms_read.cpp create mode 100644 modules/commands/ms_rsend.cpp create mode 100644 modules/commands/ms_send.cpp create mode 100644 modules/commands/ms_sendall.cpp create mode 100644 modules/commands/ms_set.cpp create mode 100644 modules/commands/ms_staff.cpp create mode 100644 modules/commands/ns_access.cpp create mode 100644 modules/commands/ns_ajoin.cpp create mode 100644 modules/commands/ns_alist.cpp create mode 100644 modules/commands/ns_cert.cpp create mode 100644 modules/commands/ns_drop.cpp create mode 100644 modules/commands/ns_getemail.cpp create mode 100644 modules/commands/ns_getpass.cpp create mode 100644 modules/commands/ns_ghost.cpp create mode 100644 modules/commands/ns_group.cpp create mode 100644 modules/commands/ns_identify.cpp create mode 100644 modules/commands/ns_info.cpp create mode 100644 modules/commands/ns_list.cpp create mode 100644 modules/commands/ns_logout.cpp create mode 100644 modules/commands/ns_recover.cpp create mode 100644 modules/commands/ns_register.cpp create mode 100644 modules/commands/ns_release.cpp create mode 100644 modules/commands/ns_resetpass.cpp create mode 100644 modules/commands/ns_saset.cpp create mode 100644 modules/commands/ns_saset_noexpire.cpp create mode 100644 modules/commands/ns_sendpass.cpp create mode 100644 modules/commands/ns_set.cpp create mode 100644 modules/commands/ns_set_autoop.cpp create mode 100644 modules/commands/ns_set_email.cpp create mode 100644 modules/commands/ns_set_greet.cpp create mode 100644 modules/commands/ns_set_hide.cpp create mode 100644 modules/commands/ns_set_kill.cpp create mode 100644 modules/commands/ns_set_language.cpp create mode 100644 modules/commands/ns_set_message.cpp create mode 100644 modules/commands/ns_set_misc.cpp create mode 100644 modules/commands/ns_set_private.cpp create mode 100644 modules/commands/ns_set_secure.cpp create mode 100644 modules/commands/ns_status.cpp create mode 100644 modules/commands/ns_suspend.cpp create mode 100644 modules/commands/ns_update.cpp create mode 100644 modules/commands/os_akill.cpp create mode 100644 modules/commands/os_chankill.cpp create mode 100644 modules/commands/os_config.cpp create mode 100644 modules/commands/os_defcon.cpp create mode 100644 modules/commands/os_forbid.cpp create mode 100644 modules/commands/os_forbid.h create mode 100644 modules/commands/os_ignore.cpp create mode 100644 modules/commands/os_ignore.h create mode 100644 modules/commands/os_jupe.cpp create mode 100644 modules/commands/os_kick.cpp create mode 100644 modules/commands/os_kill.cpp create mode 100644 modules/commands/os_list.cpp create mode 100644 modules/commands/os_login.cpp create mode 100644 modules/commands/os_mode.cpp create mode 100644 modules/commands/os_modinfo.cpp create mode 100644 modules/commands/os_module.cpp create mode 100644 modules/commands/os_news.cpp create mode 100644 modules/commands/os_news.h create mode 100644 modules/commands/os_noop.cpp create mode 100644 modules/commands/os_oline.cpp create mode 100644 modules/commands/os_oper.cpp create mode 100644 modules/commands/os_reload.cpp create mode 100644 modules/commands/os_session.cpp create mode 100644 modules/commands/os_session.h create mode 100644 modules/commands/os_set.cpp create mode 100644 modules/commands/os_shutdown.cpp create mode 100644 modules/commands/os_stats.cpp create mode 100644 modules/commands/os_svsnick.cpp create mode 100644 modules/commands/os_sxline.cpp create mode 100644 modules/commands/os_update.cpp (limited to 'modules/commands') diff --git a/modules/commands/bs_assign.cpp b/modules/commands/bs_assign.cpp new file mode 100644 index 000000000..803368994 --- /dev/null +++ b/modules/commands/bs_assign.cpp @@ -0,0 +1,168 @@ +/* BotServ core functions + * + * (C) 2003-2011 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + * + * Based on the original code of Epona by Lara. + * Based on the original code of Services by Andy Church. + */ + +/*************************************************************************/ + +#include "module.h" + +class CommandBSAssign : public Command +{ + public: + CommandBSAssign(Module *creator) : Command(creator, "botserv/assign", 2, 2) + { + this->SetDesc(_("Assigns a bot to a channel")); + this->SetSyntax(_("\037channel\037 \037nick\037")); + } + + void Execute(CommandSource &source, const std::vector ¶ms) + { + const Anope::string &chan = params[0]; + const Anope::string &nick = params[1]; + + User *u = source.u; + + if (readonly) + { + source.Reply(BOT_ASSIGN_READONLY); + return; + } + + ChannelInfo *ci = cs_findchan(params[0]); + if (ci == NULL) + { + source.Reply(CHAN_X_NOT_REGISTERED, params[0].c_str()); + return; + } + + BotInfo *bi = findbot(nick); + if (!bi) + { + source.Reply(BOT_DOES_NOT_EXIST, nick.c_str()); + return; + } + + if (ci->botflags.HasFlag(BS_NOBOT) || (!ci->HasPriv(u, CA_ASSIGN) && !u->HasPriv("botserv/administration"))) + { + source.Reply(ACCESS_DENIED); + return; + } + + if (bi->HasFlag(BI_PRIVATE) && !u->HasCommand("botserv/botserv/assign/private")) + { + source.Reply(ACCESS_DENIED); + return; + } + + if (ci->bi == bi) + { + source.Reply(_("Bot \002%s\002 is already assigned to channel \002%s\002."), ci->bi->nick.c_str(), chan.c_str()); + return; + } + + bool override = !ci->HasPriv(u, CA_ASSIGN); + Log(override ? LOG_OVERRIDE : LOG_COMMAND, u, this, ci) << "for " << bi->nick; + + bi->Assign(u, ci); + source.Reply(_("Bot \002%s\002 has been assigned to %s."), bi->nick.c_str(), ci->name.c_str()); + } + + bool OnHelp(CommandSource &source, const Anope::string &subcommand) + { + this->SendSyntax(source); + source.Reply(" "); + source.Reply(_("Assigns a bot pointed out by nick to the channel chan. You\n" + "can then configure the bot for the channel so it fits\n" + "your needs.")); + return true; + } +}; + +class CommandBSUnassign : public Command +{ + public: + CommandBSUnassign(Module *creator) : Command(creator, "botserv/unassign", 1, 1) + { + this->SetDesc(_("Unassigns a bot from a channel")); + this->SetSyntax(_("\037channel\037 \037nick\037")); + } + + void Execute(CommandSource &source, const std::vector ¶ms) + { + User *u = source.u; + + if (readonly) + { + source.Reply(BOT_ASSIGN_READONLY); + return; + } + + ChannelInfo *ci = cs_findchan(params[0]); + if (ci == NULL) + { + source.Reply(CHAN_X_NOT_REGISTERED, params[0].c_str()); + return; + } + + if (!u->HasPriv("botserv/administration") && !ci->HasPriv(u, CA_ASSIGN)) + { + source.Reply(ACCESS_DENIED); + return; + } + + if (!ci->bi) + { + source.Reply(BOT_NOT_ASSIGNED); + return; + } + + if (ci->HasFlag(CI_PERSIST) && !ModeManager::FindChannelModeByName(CMODE_PERM)) + { + source.Reply(_("You can not unassign bots while persist is set on the channel.")); + return; + } + + bool override = !ci->HasPriv(u, CA_ASSIGN); + Log(override ? LOG_OVERRIDE : LOG_COMMAND, u, this, ci) << "for " << ci->bi->nick; + + ci->bi->UnAssign(u, ci); + source.Reply(_("There is no bot assigned to %s anymore."), ci->name.c_str()); + } + + bool OnHelp(CommandSource &source, const Anope::string &subcommand) + { + this->SendSyntax(source); + source.Reply(" "); + source.Reply(_("Unassigns a bot from a channel. When you use this command,\n" + "the bot won't join the channel anymore. However, bot\n" + "configuration for the channel is kept, so you will always\n" + "be able to reassign a bot later without have to reconfigure\n" + "it entirely.")); + return true; + } +}; + +class BSAssign : public Module +{ + CommandBSAssign commandbsassign; + CommandBSUnassign commandbsunassign; + + public: + BSAssign(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, CORE), + commandbsassign(this), commandbsunassign(this) + { + this->SetAuthor("Anope"); + + ModuleManager::RegisterService(&commandbsassign); + ModuleManager::RegisterService(&commandbsunassign); + } +}; + +MODULE_INIT(BSAssign) diff --git a/modules/commands/bs_badwords.cpp b/modules/commands/bs_badwords.cpp new file mode 100644 index 000000000..a27dca2d4 --- /dev/null +++ b/modules/commands/bs_badwords.cpp @@ -0,0 +1,331 @@ +/* BotServ core functions + * + * (C) 2003-2011 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + * + * Based on the original code of Epona by Lara. + * Based on the original code of Services by Andy Church. + */ + +/*************************************************************************/ + +#include "module.h" + +class BadwordsListCallback : public NumberList +{ + CommandSource &source; + ChannelInfo *ci; + bool SentHeader; + public: + BadwordsListCallback(CommandSource &_source, ChannelInfo *_ci, const Anope::string &list) : NumberList(list, false), source(_source), ci(_ci), SentHeader(false) + { + } + + ~BadwordsListCallback() + { + if (!SentHeader) + source.Reply(_("No matching entries on %s bad words list."), ci->name.c_str()); + } + + void HandleNumber(unsigned Number) + { + if (!Number || Number > ci->GetBadWordCount()) + return; + + if (!SentHeader) + { + SentHeader = true; + source.Reply(_("Bad words list for %s:\n" + " Num Word Type"), ci->name.c_str()); + } + + DoList(source, Number - 1, ci->GetBadWord(Number - 1)); + } + + static void DoList(CommandSource &source, unsigned Number, BadWord *bw) + { + source.Reply(_(" %3d %-30s %s"), Number + 1, bw->word.c_str(), bw->type == BW_SINGLE ? "(SINGLE)" : (bw->type == BW_START ? "(START)" : (bw->type == BW_END ? "(END)" : ""))); + } +}; + +class BadwordsDelCallback : public NumberList +{ + CommandSource &source; + ChannelInfo *ci; + Command *c; + unsigned Deleted; + bool override; + public: + BadwordsDelCallback(CommandSource &_source, ChannelInfo *_ci, Command *_c, const Anope::string &list) : NumberList(list, true), source(_source), ci(_ci), c(_c), Deleted(0), override(false) + { + if (!ci->HasPriv(source.u, CA_BADWORDS) && source.u->HasPriv("botserv/administration")) + this->override = true; + } + + ~BadwordsDelCallback() + { + if (!Deleted) + source.Reply(_("No matching entries on %s bad words list."), ci->name.c_str()); + else if (Deleted == 1) + source.Reply(_("Deleted 1 entry from %s bad words list."), ci->name.c_str()); + else + source.Reply(_("Deleted %d entries from %s bad words list."), Deleted, ci->name.c_str()); + } + + void HandleNumber(unsigned Number) + { + if (!Number || Number > ci->GetBadWordCount()) + return; + + Log(override ? LOG_OVERRIDE : LOG_COMMAND, source.u, c, ci) << "DEL " << ci->GetBadWord(Number - 1)->word; + ++Deleted; + ci->EraseBadWord(Number - 1); + } +}; + +class CommandBSBadwords : public Command +{ + private: + void DoList(CommandSource &source, ChannelInfo *ci, const Anope::string &word) + { + bool override = !ci->HasPriv(source.u, CA_BADWORDS); + Log(override ? LOG_OVERRIDE : LOG_COMMAND, source.u, this, ci) << "LIST"; + + if (!ci->GetBadWordCount()) + source.Reply(_("%s bad words list is empty."), ci->name.c_str()); + else if (!word.empty() && word.find_first_not_of("1234567890,-") == Anope::string::npos) + { + BadwordsListCallback list(source, ci, word); + list.Process(); + } + else + { + bool SentHeader = false; + + for (unsigned i = 0, end = ci->GetBadWordCount(); i < end; ++i) + { + BadWord *bw = ci->GetBadWord(i); + + if (!word.empty() && !Anope::Match(bw->word, word)) + continue; + + if (!SentHeader) + { + SentHeader = true; + source.Reply(_("Bad words list for %s:\n" + " Num Word Type"), ci->name.c_str()); + + } + + BadwordsListCallback::DoList(source, i, bw); + } + + if (!SentHeader) + source.Reply(_("No matching entries on %s bad words list."), ci->name.c_str()); + } + + return; + } + + void DoAdd(CommandSource &source, ChannelInfo *ci, const Anope::string &word) + { + size_t pos = word.rfind(' '); + BadWordType type = BW_ANY; + Anope::string realword = word; + + if (pos != Anope::string::npos) + { + Anope::string opt = word.substr(pos + 1); + if (!opt.empty()) + { + if (opt.equals_ci("SINGLE")) + type = BW_SINGLE; + else if (opt.equals_ci("START")) + type = BW_START; + else if (opt.equals_ci("END")) + type = BW_END; + } + realword = word.substr(0, pos); + } + + if (ci->GetBadWordCount() >= Config->BSBadWordsMax) + { + source.Reply(_("Sorry, you can only have %d bad words entries on a channel."), Config->BSBadWordsMax); + return; + } + + for (unsigned i = 0, end = ci->GetBadWordCount(); i < end; ++i) + { + BadWord *bw = ci->GetBadWord(i); + + if (!bw->word.empty() && ((Config->BSCaseSensitive && realword.equals_cs(bw->word)) || (!Config->BSCaseSensitive && realword.equals_ci(bw->word)))) + { + source.Reply(_("\002%s\002 already exists in %s bad words list."), bw->word.c_str(), ci->name.c_str()); + return; + } + } + + bool override = !ci->HasPriv(source.u, CA_BADWORDS); + Log(override ? LOG_OVERRIDE : LOG_COMMAND, source.u, this, ci) << "ADD " << realword; + ci->AddBadWord(realword, type); + + source.Reply(_("\002%s\002 added to %s bad words list."), realword.c_str(), ci->name.c_str()); + + return; + } + + void DoDelete(CommandSource &source, ChannelInfo *ci, const Anope::string &word) + { + /* Special case: is it a number/list? Only do search if it isn't. */ + if (!word.empty() && isdigit(word[0]) && word.find_first_not_of("1234567890,-") == Anope::string::npos) + { + BadwordsDelCallback list(source, ci, this, word); + list.Process(); + } + else + { + unsigned i, end; + BadWord *badword; + + for (i = 0, end = ci->GetBadWordCount(); i < end; ++i) + { + badword = ci->GetBadWord(i); + + if (word.equals_ci(badword->word)) + break; + } + + if (i == end) + { + source.Reply(_("\002%s\002 not found on %s bad words list."), word.c_str(), ci->name.c_str()); + return; + } + + bool override = !ci->HasPriv(source.u, CA_BADWORDS); + Log(override ? LOG_OVERRIDE : LOG_COMMAND, source.u, this, ci) << "DEL " << badword->word; + + source.Reply(_("\002%s\002 deleted from %s bad words list."), badword->word.c_str(), ci->name.c_str()); + + ci->EraseBadWord(i); + } + + return; + } + + void DoClear(CommandSource &source, ChannelInfo *ci) + { + bool override = !ci->HasPriv(source.u, CA_BADWORDS); + Log(override ? LOG_OVERRIDE : LOG_COMMAND, source.u, this, ci) << "CLEAR"; + + ci->ClearBadWords(); + source.Reply(_("Bad words list is now empty.")); + return; + } + public: + CommandBSBadwords(Module *creator) : Command(creator, "botserv/badwords", 2, 3) + { + this->SetDesc(_("Maintains bad words list")); + this->SetSyntax(_("\037channel\037 ADD \037word\037 [\037SINGLE\037 | \037START\037 | \037END\037]")); + this->SetSyntax(_("\037channel\037 DEL {\037word\037 | \037entry-num\037 | \037list\037}")); + this->SetSyntax(_("\037channel\037 LIST [\037mask\037 | \037list\037]")); + this->SetSyntax(_("\037channel\037 CLEAR")); + } + + void Execute(CommandSource &source, const std::vector ¶ms) + { + const Anope::string &cmd = params[1]; + const Anope::string &word = params.size() > 2 ? params[2] : ""; + User *u = source.u; + bool need_args = cmd.equals_ci("LIST") || cmd.equals_ci("CLEAR"); + + if (!need_args && word.empty()) + { + this->OnSyntaxError(source, cmd); + return; + } + + ChannelInfo *ci = cs_findchan(params[0]); + if (ci == NULL) + { + source.Reply(CHAN_X_NOT_REGISTERED, params[0].c_str()); + return; + } + + + if (!ci->HasPriv(u, CA_BADWORDS) && (!need_args || !u->HasPriv("botserv/administration"))) + { + source.Reply(ACCESS_DENIED); + return; + } + + if (readonly) + { + source.Reply(_("Sorry, channel bad words list modification is temporarily disabled.")); + return; + } + + if (cmd.equals_ci("ADD")) + return this->DoAdd(source, ci, word); + else if (cmd.equals_ci("DEL")) + return this->DoDelete(source, ci, word); + else if (cmd.equals_ci("LIST")) + return this->DoList(source, ci, word); + else if (cmd.equals_ci("CLEAR")) + return this->DoClear(source, ci); + else + this->OnSyntaxError(source, ""); + } + + bool OnHelp(CommandSource &source, const Anope::string &subcommand) + { + this->SendSyntax(source); + source.Reply(" "); + source.Reply(_("Maintains the \002bad words list\002 for a channel. The bad\n" + "words list determines which words are to be kicked\n" + "when the bad words kicker is enabled. For more information,\n" + "type \002%s%s HELP KICK %s\002.\n" + " \n" + "The \002ADD\002 command adds the given word to the\n" + "badword list. If SINGLE is specified, a kick will be\n" + "done only if a user says the entire word. If START is \n" + "specified, a kick will be done if a user says a word\n" + "that starts with \037word\037. If END is specified, a kick\n" + "will be done if a user says a word that ends with\n" + "\037word\037. If you don't specify anything, a kick will\n" + "be issued every time \037word\037 is said by a user.\n" + " \n"), Config->UseStrictPrivMsgString.c_str(), source.owner->nick.c_str(), source.command.c_str()); + source.Reply(_("The \002DEL\002 command removes the given word from the\n" + "bad words list. If a list of entry numbers is given, those\n" + "entries are deleted. (See the example for LIST below.)\n" + " \n" + "The \002LIST\002 command displays the bad words list. If\n" + "a wildcard mask is given, only those entries matching the\n" + "mask are displayed. If a list of entry numbers is given,\n" + "only those entries are shown; for example:\n" + " \002#channel LIST 2-5,7-9\002\n" + " Lists bad words entries numbered 2 through 5 and\n" + " 7 through 9.\n" + " \n" + "The \002CLEAR\002 command clears all entries of the\n" + "bad words list.")); + return true; + } +}; + +class BSBadwords : public Module +{ + CommandBSBadwords commandbsbadwords; + + public: + BSBadwords(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, CORE), + commandbsbadwords(this) + { + this->SetAuthor("Anope"); + + ModuleManager::RegisterService(&commandbsbadwords); + } +}; + +MODULE_INIT(BSBadwords) diff --git a/modules/commands/bs_bot.cpp b/modules/commands/bs_bot.cpp new file mode 100644 index 000000000..7500d1926 --- /dev/null +++ b/modules/commands/bs_bot.cpp @@ -0,0 +1,414 @@ +/* BotServ core functions + * + * (C) 2003-2011 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + * + * Based on the original code of Epona by Lara. + * Based on the original code of Services by Andy Church. + */ + +/*************************************************************************/ + +#include "module.h" + +class CommandBSBot : public Command +{ + private: + void DoAdd(CommandSource &source, const std::vector ¶ms) + { + const Anope::string &nick = params[1]; + const Anope::string &user = params[2]; + const Anope::string &host = params[3]; + const Anope::string &real = params[4]; + BotInfo *bi; + + if (findbot(nick)) + { + source.Reply(_("Bot \002%s\002 already exists."), nick.c_str()); + return; + } + + if (nick.length() > Config->NickLen) + { + source.Reply(_("Bot Nicks may only contain valid nick characters.")); + return; + } + + if (user.length() > Config->UserLen) + { + source.Reply(_("Bot Idents may only contain %d characters."), Config->UserLen); + return; + } + + if (host.length() > Config->HostLen) + { + source.Reply(_("Bot Hosts may only contain %d characters."), Config->HostLen); + return; + } + + /* Check the nick is valid re RFC 2812 */ + if (isdigit(nick[0]) || nick[0] == '-') + { + source.Reply(_("Bot Nicks may only contain valid nick characters.")); + return; + } + + for (unsigned i = 0, end = nick.length(); i < end && i < Config->NickLen; ++i) + if (!isvalidnick(nick[i])) + { + source.Reply(_("Bot Nicks may only contain valid nick characters.")); + return; + } + + /* check for hardcored ircd forbidden nicks */ + if (!ircdproto->IsNickValid(nick)) + { + source.Reply(_("Bot Nicks may only contain valid nick characters.")); + return; + } + + /* Check the host is valid re RFC 2812 */ + if (!isValidHost(host, 3)) + { + source.Reply(_("Bot Hosts may only contain valid host characters.")); + return; + } + + for (unsigned i = 0, end = user.length(); i < end && i < Config->UserLen; ++i) + if (!isalnum(user[i])) + { + source.Reply(_("Bot Idents may only contain valid characters."), Config->UserLen); + return; + } + + /* We check whether the nick is registered, and inform the user + * if so. You need to drop the nick manually before you can use + * it as a bot nick from now on -GD + */ + if (findnick(nick)) + { + source.Reply(NICK_ALREADY_REGISTERED, nick.c_str()); + return; + } + + bi = new BotInfo(nick, user, host, real); + + Log(LOG_ADMIN, source.u, this) << "ADD " << bi->GetMask() << " " << bi->realname; + + source.Reply(_("%s!%s@%s (%s) added to the bot list."), bi->nick.c_str(), bi->GetIdent().c_str(), bi->host.c_str(), bi->realname.c_str()); + + FOREACH_MOD(I_OnBotCreate, OnBotCreate(bi)); + return; + } + + void DoChange(CommandSource &source, const std::vector ¶ms) + { + const Anope::string &oldnick = params[1]; + const Anope::string &nick = params.size() > 2 ? params[2] : ""; + const Anope::string &user = params.size() > 3 ? params[3] : ""; + const Anope::string &host = params.size() > 4 ? params[4] : ""; + const Anope::string &real = params.size() > 5 ? params[5] : ""; + BotInfo *bi; + + if (oldnick.empty() || nick.empty()) + { + this->OnSyntaxError(source, "CHANGE"); + return; + } + + if (!(bi = findbot(oldnick))) + { + source.Reply(BOT_DOES_NOT_EXIST, oldnick.c_str()); + return; + } + + if (!oldnick.equals_ci(nick) && nickIsServices(oldnick, false)) + { + source.Reply(BOT_DOES_NOT_EXIST, oldnick.c_str()); + return; + } + + if (nick.length() > Config->NickLen) + { + source.Reply(_("Bot Nicks may only contain valid nick characters.")); + return; + } + + if (!user.empty() && user.length() > Config->UserLen) + { + source.Reply(_("Bot Idents may only contain %d characters."), Config->UserLen); + return; + } + + if (!host.empty() && host.length() > Config->HostLen) + { + source.Reply(_("Bot Hosts may only contain %d characters."), Config->HostLen); + return; + } + + if (!oldnick.equals_ci(nick) && nickIsServices(nick, false)) + { + source.Reply(BOT_DOES_NOT_EXIST, oldnick.c_str()); + return; + } + + /* Checks whether there *are* changes. + * Case sensitive because we may want to change just the case. + * And we must finally check that the nick is not already + * taken by another bot. + */ + if (nick.equals_cs(bi->nick) && (!user.empty() ? user.equals_cs(bi->GetIdent()) : 1) && (!host.empty() ? host.equals_cs(bi->host) : 1) && (!real.empty() ? real.equals_cs(bi->realname) : 1)) + { + source.Reply(_("Old info is equal to the new one.")); + return; + } + + /* Check the nick is valid re RFC 2812 */ + if (isdigit(nick[0]) || nick[0] == '-') + { + source.Reply(_("Bot Nicks may only contain valid nick characters.")); + return; + } + + for (unsigned i = 0, end = nick.length(); i < end && i < Config->NickLen; ++i) + if (!isvalidnick(nick[i])) + { + source.Reply(_("Bot Nicks may only contain valid nick characters.")); + return; + } + + /* check for hardcored ircd forbidden nicks */ + if (!ircdproto->IsNickValid(nick)) + { + source.Reply(_("Bot Nicks may only contain valid nick characters.")); + return; + } + + if (!host.empty() && !isValidHost(host, 3)) + { + source.Reply(_("Bot Hosts may only contain valid host characters.")); + return; + } + + if (!user.empty()) + for (unsigned i = 0, end = user.length(); i < end && i < Config->UserLen; ++i) + if (!isalnum(user[i])) + { + source.Reply(_("Bot Idents may only contain valid characters."), Config->UserLen); + return; + } + + if (!nick.equals_ci(bi->nick) && findbot(nick)) + { + source.Reply(_("Bot \002%s\002 already exists."), nick.c_str()); + return; + } + + if (!nick.equals_ci(bi->nick)) + { + /* We check whether the nick is registered, and inform the user + * if so. You need to drop the nick manually before you can use + * it as a bot nick from now on -GD + */ + if (findnick(nick)) + { + source.Reply(NICK_ALREADY_REGISTERED, nick.c_str()); + return; + } + + /* The new nick is really different, so we remove the Q line for the old nick. */ + if (ircd->sqline) + { + XLine x(bi->nick); + ircdproto->SendSQLineDel(&x); + } + + /* Add a Q line for the new nick */ + XLine x(nick, "Reserved for services"); + ircdproto->SendSQLine(NULL, &x); + } + + if (!user.empty()) + ircdproto->SendQuit(bi, "Quit: Be right back"); + else + { + ircdproto->SendChangeBotNick(bi, nick); + } + + if (!nick.equals_cs(bi->nick)) + bi->SetNewNick(nick); + + if (!user.empty() && !user.equals_cs(bi->GetIdent())) + bi->SetIdent(user); + if (!host.empty() && !host.equals_cs(bi->host)) + bi->host = host; + if (!real.empty() && !real.equals_cs(bi->realname)) + bi->realname = real; + + if (!user.empty()) + { + ircdproto->SendClientIntroduction(bi, ircd->pseudoclient_mode); + bi->RejoinAll(); + } + + source.Reply(_("Bot \002%s\002 has been changed to %s!%s@%s (%s)"), oldnick.c_str(), bi->nick.c_str(), bi->GetIdent().c_str(), bi->host.c_str(), bi->realname.c_str()); + Log(LOG_ADMIN, source.u, this) << "CHANGE " << oldnick << " to " << bi->GetMask() << " " << bi->realname; + + FOREACH_MOD(I_OnBotChange, OnBotChange(bi)); + return; + } + + void DoDel(CommandSource &source, const std::vector ¶ms) + { + const Anope::string &nick = params[1]; + BotInfo *bi; + + if (nick.empty()) + { + this->OnSyntaxError(source, "DEL"); + return; + } + + if (!(bi = findbot(nick))) + { + source.Reply(BOT_DOES_NOT_EXIST, nick.c_str()); + return; + } + + if (nickIsServices(nick, false)) + { + source.Reply(BOT_DOES_NOT_EXIST, nick.c_str()); + return; + } + + FOREACH_MOD(I_OnBotDelete, OnBotDelete(bi)); + + Log(LOG_ADMIN, source.u, this) << "DEL " << bi->nick; + + source.Reply(_("Bot \002%s\002 has been deleted."), nick.c_str()); + delete bi; + return; + } + public: + CommandBSBot(Module *creator) : Command(creator, "botserv/bot", 1, 6) + { + this->SetDesc(_("Maintains network bot list")); + this->SetSyntax(_("\002ADD \037nick\037 \037user\037 \037host\037 \037real\037\002")); + this->SetSyntax(_("\002CHANGE \037oldnick\037 \037newnick\037 [\037user\037 [\037host\037 [\037real\037]]]\002")); + this->SetSyntax(_("\002DEL \037nick\037\002")); + } + + void Execute(CommandSource &source, const std::vector ¶ms) + { + const Anope::string &cmd = params[0]; + User *u = source.u; + + if (readonly) + { + source.Reply(_("Sorry, bot modification is temporarily disabled.")); + return; + } + + if (cmd.equals_ci("ADD")) + { + // ADD nick user host real - 5 + if (!u->HasCommand("botserv/bot/add")) + { + source.Reply(ACCESS_DENIED); + return; + } + + if (params.size() < 5) + { + this->OnSyntaxError(source, "ADD"); + return; + } + + std::vector tempparams = params; + // ADD takes less params than CHANGE, so we need to take 6 if given and append it with a space to 5. + if (tempparams.size() >= 6) + tempparams[4] = tempparams[4] + " " + tempparams[5]; + + return this->DoAdd(source, tempparams); + } + else if (cmd.equals_ci("CHANGE")) + { + // CHANGE oldn newn user host real - 6 + // but only oldn and newn are required + if (!u->HasCommand("botserv/bot/change")) + { + source.Reply(ACCESS_DENIED); + return; + } + + if (params.size() < 3) + { + this->OnSyntaxError(source, "CHANGE"); + return; + } + + return this->DoChange(source, params); + } + else if (cmd.equals_ci("DEL")) + { + // DEL nick + if (!u->HasCommand("botserv/bot/del")) + { + source.Reply(ACCESS_DENIED); + return; + } + + if (params.size() < 1) + { + this->OnSyntaxError(source, "DEL"); + return; + } + + return this->DoDel(source, params); + } + else + this->OnSyntaxError(source, ""); + + return; + } + + bool OnHelp(CommandSource &source, const Anope::string &subcommand) + { + this->SendSyntax(source); + source.Reply(" "); + source.Reply(_("Allows Services Operators to create, modify, and delete\n" + "bots that users will be able to use on their own\n" + "channels.\n" + " \n" + "\002BOT ADD\002 adds a bot with the given nickname, username,\n" + "hostname and realname. Since no integrity checks are done \n" + "for these settings, be really careful.\n" + "\002BOT CHANGE\002 allows to change nickname, username, hostname\n" + "or realname of a bot without actually delete it (and all\n" + "the data associated with it).\n" + "\002BOT DEL\002 removes the given bot from the bot list. \n" + " \n" + "\002Note\002: you cannot create a bot that has a nick that is\n" + "currently registered. If an unregistered user is currently\n" + "using the nick, they will be killed.")); + return true; + } +}; + +class BSBot : public Module +{ + CommandBSBot commandbsbot; + + public: + BSBot(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, CORE), + commandbsbot(this) + { + this->SetAuthor("Anope"); + + ModuleManager::RegisterService(&commandbsbot); + } +}; + +MODULE_INIT(BSBot) diff --git a/modules/commands/bs_botlist.cpp b/modules/commands/bs_botlist.cpp new file mode 100644 index 000000000..ee7e4d2d8 --- /dev/null +++ b/modules/commands/bs_botlist.cpp @@ -0,0 +1,91 @@ +/* BotServ core functions + * + * (C) 2003-2011 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + * + * Based on the original code of Epona by Lara. + * Based on the original code of Services by Andy Church. + */ + +/*************************************************************************/ + +#include "module.h" + +class CommandBSBotList : public Command +{ + public: + CommandBSBotList(Module *creator) : Command(creator, "botserv/botlist", 0, 0) + { + this->SetDesc(_("Lists available bots")); + this->SetSyntax(""); + } + + void Execute(CommandSource &source, const std::vector ¶ms) + { + User *u = source.u; + unsigned count = 0; + + for (Anope::insensitive_map::const_iterator it = BotListByNick.begin(), it_end = BotListByNick.end(); it != it_end; ++it) + { + BotInfo *bi = it->second; + + if (!bi->HasFlag(BI_PRIVATE)) + { + if (!count) + source.Reply(_("Bot list:")); + ++count; + source.Reply(" %-15s (%s@%s)", bi->nick.c_str(), bi->GetIdent().c_str(), bi->host.c_str()); + } + } + + if (u->HasCommand("botserv/botserv/botlist") && count < BotListByNick.size()) + { + source.Reply(_("Bots reserved to IRC operators:")); + + for (Anope::insensitive_map::const_iterator it = BotListByNick.begin(), it_end = BotListByNick.end(); it != it_end; ++it) + { + BotInfo *bi = it->second; + + if (bi->HasFlag(BI_PRIVATE)) + { + source.Reply(" %-15s (%s@%s)", bi->nick.c_str(), bi->GetIdent().c_str(), bi->host.c_str()); + ++count; + } + } + } + + if (!count) + source.Reply(_("There are no bots available at this time.\n" + "Ask a Services Operator to create one!")); + else + source.Reply(_("%d bots available."), count); + + return; + } + + bool OnHelp(CommandSource &source, const Anope::string &subcommand) + { + this->SendSyntax(source); + source.Reply(" "); + source.Reply(_("Lists all available bots on this network.")); + return true; + } +}; + +class BSBotList : public Module +{ + CommandBSBotList commandbsbotlist; + + public: + BSBotList(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, CORE), + commandbsbotlist(this) + { + this->SetAuthor("Anope"); + + ModuleManager::RegisterService(&commandbsbotlist); + } +}; + +MODULE_INIT(BSBotList) diff --git a/modules/commands/bs_control.cpp b/modules/commands/bs_control.cpp new file mode 100644 index 000000000..16a5b372a --- /dev/null +++ b/modules/commands/bs_control.cpp @@ -0,0 +1,158 @@ +/* BotServ core functions + * + * (C) 2003-2011 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + * + * Based on the original code of Epona by Lara. + * Based on the original code of Services by Andy Church. + */ + +/*************************************************************************/ + +#include "module.h" + +class CommandBSSay : public Command +{ + public: + CommandBSSay(Module *creator) : Command(creator, "botserv/say", 2, 2) + { + this->SetDesc(_("Makes the bot say the given text on the given channel")); + this->SetSyntax(_("\037channel\037 \037text\037")); + } + + void Execute(CommandSource &source, const std::vector ¶ms) + { + const Anope::string &text = params[1]; + + User *u = source.u; + + ChannelInfo *ci = cs_findchan(params[0]); + if (ci == NULL) + { + source.Reply(CHAN_X_NOT_REGISTERED, params[0].c_str()); + return; + } + + if (!ci->HasPriv(u, CA_SAY)) + { + source.Reply(ACCESS_DENIED); + return; + } + + if (!ci->bi) + { + source.Reply(BOT_NOT_ASSIGNED); + return; + } + + if (!ci->c || !ci->c->FindUser(ci->bi)) + { + source.Reply(BOT_NOT_ON_CHANNEL, ci->name.c_str()); + return; + } + + if (text[0] == '\001') + { + this->OnSyntaxError(source, ""); + return; + } + + ircdproto->SendPrivmsg(ci->bi, ci->name, "%s", text.c_str()); + ci->bi->lastmsg = Anope::CurTime; + + // XXX need a way to find if someone is overriding this + Log(LOG_COMMAND, u, this, ci) << text; + + return; + } + + bool OnHelp(CommandSource &source, const Anope::string &subcommand) + { + this->SendSyntax(source); + source.Reply(" "); + source.Reply(_("Makes the bot say the given text on the given channel.")); + return true; + } +}; + +class CommandBSAct : public Command +{ + public: + CommandBSAct(Module *creator) : Command(creator, "botserv/act", 2, 2) + { + this->SetDesc(_("Makes the bot do the equivalent of a \"/me\" command")); + this->SetSyntax(_("\037channel\037 \037text\037")); + } + + void Execute(CommandSource &source, const std::vector ¶ms) + { + User *u = source.u; + Anope::string message = params[1]; + + ChannelInfo *ci = cs_findchan(params[0]); + if (ci == NULL) + { + source.Reply(CHAN_X_NOT_REGISTERED, params[0].c_str()); + return; + } + + if (!ci->HasPriv(u, CA_SAY)) + { + source.Reply(ACCESS_DENIED); + return; + } + + if (!ci->bi) + { + source.Reply(BOT_NOT_ASSIGNED); + return; + } + + if (!ci->c || !ci->c->FindUser(ci->bi)) + { + source.Reply(BOT_NOT_ON_CHANNEL, ci->name.c_str()); + return; + } + + size_t i = 0; + while ((i = message.find(1)) && i != Anope::string::npos) + message.erase(i, 1); + + ircdproto->SendAction(ci->bi, ci->name, "%s", message.c_str()); + ci->bi->lastmsg = Anope::CurTime; + + // XXX Need to be able to find if someone is overriding this. + Log(LOG_COMMAND, u, this, ci) << message; + + return; + } + + bool OnHelp(CommandSource &source, const Anope::string &subcommand) + { + this->SendSyntax(source); + source.Reply(" "); + source.Reply(_("Makes the bot do the equivalent of a \"/me\" command\n" + "on the given channel using the given text.")); + return true; + } +}; + +class BSControl : public Module +{ + CommandBSSay commandbssay; + CommandBSAct commandbsact; + + public: + BSControl(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, CORE), + commandbssay(this), commandbsact(this) + { + this->SetAuthor("Anope"); + + ModuleManager::RegisterService(&commandbssay); + ModuleManager::RegisterService(&commandbsact); + } +}; + +MODULE_INIT(BSControl) diff --git a/modules/commands/bs_info.cpp b/modules/commands/bs_info.cpp new file mode 100644 index 000000000..b48a0b296 --- /dev/null +++ b/modules/commands/bs_info.cpp @@ -0,0 +1,244 @@ +/* BotServ core functions + * + * (C) 2003-2011 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + * + * Based on the original code of Epona by Lara. + * Based on the original code of Services by Andy Church. + * + * + */ +/*************************************************************************/ + +#include "module.h" + +class CommandBSInfo : public Command +{ + private: + void send_bot_channels(CommandSource &source, BotInfo *bi) + { + Anope::string buf; + for (registered_channel_map::const_iterator it = RegisteredChannelList.begin(), it_end = RegisteredChannelList.end(); it != it_end; ++it) + { + ChannelInfo *ci = it->second; + + if (ci->bi == bi) + { + if (buf.length() + ci->name.length() > 300) + { + source.Reply("%s", buf.c_str()); + buf.clear(); + } + buf += " " + ci->name + " "; + } + } + + if (!buf.empty()) + source.Reply("%s", buf.c_str()); + return; + } + public: + CommandBSInfo(Module *creator) : Command(creator, "botserv/info", 1, 1) + { + this->SetDesc(_("Allows you to see BotServ information about a channel or a bot")); + this->SetSyntax(_("\002INFO {\037chan\037 | \037nick\037}\002")); + } + + void Execute(CommandSource &source, const std::vector ¶ms) + { + const Anope::string &query = params[0]; + + bool need_comma = false; + char buf[BUFSIZE], *end; + + User *u = source.u; + BotInfo *bi = findbot(query); + ChannelInfo *ci; + if (bi) + { + source.Reply(_("Information for bot \002%s\002:"), bi->nick.c_str()); + source.Reply(_(" Mask : %s@%s"), bi->GetIdent().c_str(), bi->host.c_str()); + source.Reply(_(" Real name : %s"), bi->realname.c_str()); + source.Reply(_(" Created : %s"), do_strftime(bi->created).c_str()); + source.Reply(_(" Options : %s"), bi->HasFlag(BI_PRIVATE) ? _("Private") : _("None")); + source.Reply(_(" Used on : %d channel(s)"), bi->chancount); + + if (u->HasPriv("botserv/administration")) + this->send_bot_channels(source, bi); + } + else if ((ci = cs_findchan(query))) + { + if (!ci->HasPriv(u, CA_FOUNDER) && !u->HasPriv("botserv/administration")) + { + source.Reply(ACCESS_DENIED); + return; + } + + source.Reply(CHAN_INFO_HEADER, ci->name.c_str()); + if (ci->bi) + source.Reply(_(" Bot nick : %s"), ci->bi->nick.c_str()); + else + source.Reply(_(" Bot nick : not assigned yet.")); + + if (ci->botflags.HasFlag(BS_KICK_BADWORDS)) + { + if (ci->ttb[TTB_BADWORDS]) + source.Reply(_(" Bad words kicker : %s (%d kick(s) to ban)"), ENABLED, ci->ttb[TTB_BADWORDS]); + else + source.Reply(_(" Bad words kicker : %s"), ENABLED); + } + else + source.Reply(_(" Bad words kicker : %s"), DISABLED); + if (ci->botflags.HasFlag(BS_KICK_BOLDS)) + { + if (ci->ttb[TTB_BOLDS]) + source.Reply(_(" Bolds kicker : %s (%d kick(s) to ban)"), ENABLED, ci->ttb[TTB_BOLDS]); + else + source.Reply(_(" Bolds kicker : %s"), ENABLED); + } + else + source.Reply(_(" Bolds kicker : %s"), DISABLED); + if (ci->botflags.HasFlag(BS_KICK_CAPS)) + { + if (ci->ttb[TTB_CAPS]) + source.Reply(_(" Caps kicker : %s (%d kick(s) to ban; minimum %d/%d%%)"), ENABLED, ci->ttb[TTB_CAPS], ci->capsmin, ci->capspercent); + else + source.Reply(_(" Caps kicker : %s (minimum %d/%d%%)"), ENABLED, ci->capsmin, ci->capspercent); + } + else + source.Reply(_(" Caps kicker : %s"), DISABLED); + if (ci->botflags.HasFlag(BS_KICK_COLORS)) + { + if (ci->ttb[TTB_COLORS]) + source.Reply(_(" Colors kicker : %s (%d kick(s) to ban)"), ENABLED, ci->ttb[TTB_COLORS]); + else + source.Reply(_(" Colors kicker : %s"), ENABLED); + } + else + source.Reply(_(" Colors kicker : %s"), DISABLED); + if (ci->botflags.HasFlag(BS_KICK_FLOOD)) + { + if (ci->ttb[TTB_FLOOD]) + source.Reply(_(" Flood kicker : %s (%d kick(s) to ban; %d lines in %ds)"), ENABLED, ci->ttb[TTB_FLOOD], ci->floodlines, ci->floodsecs); + else + source.Reply(_(" Flood kicker : %s (%d lines in %ds)"), ENABLED, ci->floodlines, ci->floodsecs); + } + else + source.Reply(_(" Flood kicker : %s"), DISABLED); + if (ci->botflags.HasFlag(BS_KICK_REPEAT)) + { + if (ci->ttb[TTB_REPEAT]) + source.Reply(_(" Repeat kicker : %s (%d kick(s) to ban; %d times)"), ENABLED, ci->ttb[TTB_REPEAT], ci->repeattimes); + else + source.Reply(_(" Repeat kicker : %s (%d times)"), ENABLED, ci->repeattimes); + } + else + source.Reply(_(" Repeat kicker : %s"), DISABLED); + if (ci->botflags.HasFlag(BS_KICK_REVERSES)) + { + if (ci->ttb[TTB_REVERSES]) + source.Reply(_(" Reverses kicker : %s (%d kick(s) to ban)"), ENABLED, ci->ttb[TTB_REVERSES]); + else + source.Reply(_(" Reverses kicker : %s"), ENABLED); + } + else + source.Reply(_(" Reverses kicker : %s"), DISABLED); + if (ci->botflags.HasFlag(BS_KICK_UNDERLINES)) + { + if (ci->ttb[TTB_UNDERLINES]) + source.Reply(_(" Underlines kicker : %s (%d kick(s) to ban)"), ENABLED, ci->ttb[TTB_UNDERLINES]); + else + source.Reply(_(" Underlines kicker : %s"), ENABLED); + } + else + source.Reply(_(" Underlines kicker : %s"), DISABLED); + if (ci->botflags.HasFlag(BS_KICK_ITALICS)) + { + if (ci->ttb[TTB_ITALICS]) + source.Reply(_(" Italics kicker : %s (%d kick(s) to ban)"), ENABLED, ci->ttb[TTB_ITALICS]); + else + source.Reply(_(" Italics kicker : %s"), ENABLED); + } + else + source.Reply(_(" Italics kicker : %s"), DISABLED); + if (ci->botflags.HasFlag(BS_KICK_AMSGS)) + { + if (ci->ttb[TTB_AMSGS]) + source.Reply(_(" AMSG kicker : %s (%d kick(s) to ban)"), ENABLED, ci->ttb[TTB_AMSGS]); + else + source.Reply(_(" AMSG kicker : %s"), ENABLED); + } + else + source.Reply(_(" AMSG kicker : %s"), DISABLED); + + if (ci->botflags.HasFlag(BS_MSG_PRIVMSG)) + source.Reply(_(" Fantasy reply : %s"), "PRIVMSG"); + else if (ci->botflags.HasFlag(BS_MSG_NOTICE)) + source.Reply(_(" Fantasy reply : %s"), "NOTICE"); + else if (ci->botflags.HasFlag(BS_MSG_NOTICEOPS)) + source.Reply(_(" Fantasy reply : %s"), "NOTICEOPS"); + + end = buf; + *end = 0; + if (ci->botflags.HasFlag(BS_DONTKICKOPS)) + { + end += snprintf(end, sizeof(buf) - (end - buf), "%s", _("Ops protection")); + need_comma = true; + } + if (ci->botflags.HasFlag(BS_DONTKICKVOICES)) + { + end += snprintf(end, sizeof(buf) - (end - buf), "%s%s", need_comma ? ", " : "", _("Voices protection")); + need_comma = true; + } + if (ci->botflags.HasFlag(BS_FANTASY)) + { + end += snprintf(end, sizeof(buf) - (end - buf), "%s%s", need_comma ? ", " : "", _("Fantasy")); + need_comma = true; + } + if (ci->botflags.HasFlag(BS_GREET)) + { + end += snprintf(end, sizeof(buf) - (end - buf), "%s%s", need_comma ? ", " : "", _("Greet")); + need_comma = true; + } + if (ci->botflags.HasFlag(BS_NOBOT)) + { + end += snprintf(end, sizeof(buf) - (end - buf), "%s%s", need_comma ? ", " : "", _("No bot")); + need_comma = true; + } + source.Reply(_(" Options : %s"), *buf ? buf : _("None")); + } + else + source.Reply(_("\002%s\002 is not a valid bot or registered channel."), query.c_str()); + return; + } + + bool OnHelp(CommandSource &source, const Anope::string &subcommand) + { + this->SendSyntax(source); + source.Reply(" "); + source.Reply(_("Allows you to see %s information about a channel or a bot.\n" + "If the parameter is a channel, then you'll get information\n" + "such as enabled kickers. If the parameter is a nick,\n" + "you'll get information about a bot, such as creation\n" + "time or number of channels it is on."), source.owner->nick.c_str()); + return true; + } +}; + +class BSInfo : public Module +{ + CommandBSInfo commandbsinfo; + + public: + BSInfo(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, CORE), + commandbsinfo(this) + { + this->SetAuthor("Anope"); + + ModuleManager::RegisterService(&commandbsinfo); + } +}; + +MODULE_INIT(BSInfo) diff --git a/modules/commands/bs_kick.cpp b/modules/commands/bs_kick.cpp new file mode 100644 index 000000000..3f433f773 --- /dev/null +++ b/modules/commands/bs_kick.cpp @@ -0,0 +1,1011 @@ +/* BotServ core functions + * + * (C) 2003-2011 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + * + * Based on the original code of Epona by Lara. + * Based on the original code of Services by Andy Church. + * + * + */ +/*************************************************************************/ + +#include "module.h" + +class CommandBSKick : public Command +{ + public: + CommandBSKick(Module *creator) : Command(creator, "botserv/kick", 3, 6) + { + this->SetDesc(_("Configures kickers")); + this->SetSyntax(_("\037channel\037 \037option\037 {\037ON|\037} [\037settings\037]")); + } + + void Execute(CommandSource &source, const std::vector ¶ms) + { + const Anope::string &chan = params[0]; + const Anope::string &option = params[1]; + const Anope::string &value = params[2]; + const Anope::string &ttb = params.size() > 3 ? params[3] : ""; + + User *u = source.u; + ChannelInfo *ci = cs_findchan(params[0]); + + if (readonly) + source.Reply(_("Sorry, kicker configuration is temporarily disabled.")); + else if (ci == NULL) + source.Reply(CHAN_X_NOT_REGISTERED, params[0].c_str()); + else if (chan.empty() || option.empty() || value.empty()) + this->OnSyntaxError(source, ""); + else if (!value.equals_ci("ON") && !value.equals_ci("OFF")) + this->OnSyntaxError(source, ""); + else if (!ci->HasPriv(u, CA_SET) && !u->HasPriv("botserv/administration")) + source.Reply(ACCESS_DENIED); + else if (!ci->bi) + source.Reply(BOT_NOT_ASSIGNED); + else + { + bool override = !ci->HasPriv(u, CA_SET); + Log(override ? LOG_OVERRIDE : LOG_COMMAND, u, this, ci) << option << " " << value; + + if (option.equals_ci("BADWORDS")) + { + if (value.equals_ci("ON")) + { + if (!ttb.empty()) + { + try + { + ci->ttb[TTB_BADWORDS] = convertTo(ttb); + if (ci->ttb[TTB_BADWORDS] < 0) + throw ConvertException(); + } + catch (const ConvertException &) + { + /* reset the value back to 0 - TSL */ + ci->ttb[TTB_BADWORDS] = 0; + source.Reply(_("\002%s\002 cannot be taken as times to ban."), ttb.c_str()); + return; + } + } + else + ci->ttb[TTB_BADWORDS] = 0; + + ci->botflags.SetFlag(BS_KICK_BADWORDS); + if (ci->ttb[TTB_BADWORDS]) + source.Reply(_("Bot will now kick \002bad words\002, and will place a ban after \n" + "%d kicks for the same user. Use the BADWORDS command\n" + "to add or remove a bad word."), ci->ttb[TTB_BADWORDS]); + else + source.Reply(_("Bot will now kick \002bad words\002. Use the BADWORDS command\n" + "to add or remove a bad word.")); + } + else + { + ci->botflags.UnsetFlag(BS_KICK_BADWORDS); + source.Reply(_("Bot won't kick \002bad words\002 anymore.")); + } + } + else if (option.equals_ci("BOLDS")) + { + if (value.equals_ci("ON")) + { + if (!ttb.empty()) + { + try + { + ci->ttb[TTB_BOLDS] = convertTo(ttb); + if (ci->ttb[TTB_BOLDS] < 0) + throw ConvertException(); + } + catch (const ConvertException &) + { + ci->ttb[TTB_BOLDS] = 0; + source.Reply(_("\002%s\002 cannot be taken as times to ban."), ttb.c_str()); + return; + } + } + else + ci->ttb[TTB_BOLDS] = 0; + ci->botflags.SetFlag(BS_KICK_BOLDS); + if (ci->ttb[TTB_BOLDS]) + source.Reply(_("Bot will now kick \002bolds\002, and will place a ban after\n%d kicks to the same user."), ci->ttb[TTB_BOLDS]); + else + source.Reply(_("Bot will now kick \002bolds\002.")); + } + else + { + ci->botflags.UnsetFlag(BS_KICK_BOLDS); + source.Reply(_("Bot won't kick \002bolds\002 anymore.")); + } + } + else if (option.equals_ci("CAPS")) + { + if (value.equals_ci("ON")) + { + Anope::string min = params.size() > 4 ? params[4] : ""; + Anope::string percent = params.size() > 5 ? params[5] : ""; + + if (!ttb.empty()) + { + try + { + ci->ttb[TTB_CAPS] = convertTo(ttb); + if (ci->ttb[TTB_CAPS] < 0) + throw ConvertException(); + } + catch (const ConvertException &) + { + ci->ttb[TTB_CAPS] = 0; + source.Reply(_("\002%s\002 cannot be taken as times to ban."), ttb.c_str()); + return; + } + } + else + ci->ttb[TTB_CAPS] = 0; + + ci->capsmin = 10; + try + { + ci->capsmin = convertTo(min); + } + catch (const ConvertException &) { } + if (ci->capsmin < 1) + ci->capsmin = 10; + + ci->capspercent = 25; + try + { + ci->capspercent = convertTo(percent); + } + catch (const ConvertException &) { } + if (ci->capspercent < 1 || ci->capspercent > 100) + ci->capspercent = 25; + + ci->botflags.SetFlag(BS_KICK_CAPS); + if (ci->ttb[TTB_CAPS]) + source.Reply(_("Bot will now kick \002caps\002 (they must constitute at least\n" + "%d characters and %d%% of the entire message), and will \n" + "place a ban after %d kicks for the same user."), ci->capsmin, ci->capspercent, ci->ttb[TTB_CAPS]); + else + source.Reply(_("Bot will now kick \002caps\002 (they must constitute at least\n" + "%d characters and %d%% of the entire message)."), ci->capsmin, ci->capspercent); + } + else + { + ci->botflags.UnsetFlag(BS_KICK_CAPS); + source.Reply(_("Bot won't kick \002caps\002 anymore.")); + } + } + else if (option.equals_ci("COLORS")) + { + if (value.equals_ci("ON")) + { + if (!ttb.empty()) + { + try + { + ci->ttb[TTB_COLORS] = convertTo(ttb); + if (ci->ttb[TTB_COLORS] < 1) + throw ConvertException(); + } + catch (const ConvertException &) + { + ci->ttb[TTB_COLORS] = 0; + source.Reply(_("\002%s\002 cannot be taken as times to ban."), ttb.c_str()); + return; + } + } + else + ci->ttb[TTB_COLORS] = 0; + + ci->botflags.SetFlag(BS_KICK_COLORS); + if (ci->ttb[TTB_COLORS]) + source.Reply(_("Bot will now kick \002colors\002, and will place a ban after %d\nkicks for the same user."), ci->ttb[TTB_COLORS]); + else + source.Reply(_("Bot will now kick \002colors\002.")); + } + else + { + ci->botflags.UnsetFlag(BS_KICK_COLORS); + source.Reply(_("Bot won't kick \002colors\002 anymore.")); + } + } + else if (option.equals_ci("FLOOD")) + { + if (value.equals_ci("ON")) + { + Anope::string lines = params.size() > 4 ? params[4] : ""; + Anope::string secs = params.size() > 5 ? params[5] : ""; + + if (!ttb.empty()) + { + try + { + ci->ttb[TTB_FLOOD] = convertTo(ttb); + if (ci->ttb[TTB_FLOOD] < 1) + throw ConvertException(); + } + catch (const ConvertException &) + { + ci->ttb[TTB_FLOOD] = 0; + source.Reply(_("\002%s\002 cannot be taken as times to ban."), ttb.c_str()); + return; + } + } + else + ci->ttb[TTB_FLOOD] = 0; + + ci->floodlines = 6; + try + { + ci->floodlines = convertTo(lines); + } + catch (const ConvertException &) { } + if (ci->floodlines < 2) + ci->floodlines = 6; + + ci->floodsecs = 10; + try + { + ci->floodsecs = convertTo(secs); + } + catch (const ConvertException &) { } + if (ci->floodsecs < 1) + ci->floodsecs = 10; + if (ci->floodsecs > Config->BSKeepData) + ci->floodsecs = Config->BSKeepData; + + ci->botflags.SetFlag(BS_KICK_FLOOD); + if (ci->ttb[TTB_FLOOD]) + source.Reply(_("Bot will now kick \002flood\002 (%d lines in %d seconds and\nwill place a ban after %d kicks for the same user."), ci->floodlines, ci->floodsecs, ci->ttb[TTB_FLOOD]); + else + source.Reply(_("Bot will now kick \002flood\002 (%d lines in %d seconds)."), ci->floodlines, ci->floodsecs); + } + else + { + ci->botflags.UnsetFlag(BS_KICK_FLOOD); + source.Reply(_("Bot won't kick \002flood\002 anymore.")); + } + } + else if (option.equals_ci("REPEAT")) + { + if (value.equals_ci("ON")) + { + Anope::string times = params.size() > 4 ? params[4] : ""; + + if (!ttb.empty()) + { + try + { + ci->ttb[TTB_REPEAT] = convertTo(ttb); + if (ci->ttb[TTB_REPEAT] < 0) + throw ConvertException(); + } + catch (const ConvertException &) + { + ci->ttb[TTB_REPEAT] = 0; + source.Reply(_("\002%s\002 cannot be taken as times to ban."), ttb.c_str()); + ret