summaryrefslogtreecommitdiff
path: root/modules/pseudoclients/botserv.cpp
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2012-10-08 20:58:47 -0400
committerAdam <Adam@anope.org>2012-10-08 20:58:47 -0400
commit3af786d4c97e8ee99ea122a5c058d82e6222f295 (patch)
tree750c5de0ec2c001b6366fd5137478e6944cdc296 /modules/pseudoclients/botserv.cpp
parente57b470e83fac205a354138b1daccec654214e39 (diff)
Fix fantasy !help & give it its own help header, not ChanServ's
Diffstat (limited to 'modules/pseudoclients/botserv.cpp')
-rw-r--r--modules/pseudoclients/botserv.cpp190
1 files changed, 105 insertions, 85 deletions
diff --git a/modules/pseudoclients/botserv.cpp b/modules/pseudoclients/botserv.cpp
index ec4bac11d..f165423fc 100644
--- a/modules/pseudoclients/botserv.cpp
+++ b/modules/pseudoclients/botserv.cpp
@@ -46,105 +46,106 @@ class BotServCore : public Module
Anope::string realbuf = msg;
- bool was_action = false;
if (realbuf.substr(0, 8).equals_ci("\1ACTION ") && realbuf[realbuf.length() - 1] == '\1')
{
realbuf.erase(0, 8);
realbuf.erase(realbuf.length() - 1);
- was_action = true;
+ return;
}
- if (realbuf.empty())
+ if (realbuf.empty() || !c->ci->botflags.HasFlag(BS_FANTASY))
return;
- /* Fantaisist commands */
- if (c->ci->botflags.HasFlag(BS_FANTASY) && (Config->BSFantasyCharacter.empty() || realbuf.find_first_of(Config->BSFantasyCharacter) == 0) && !was_action)
- {
- /* Strip off the fantasy character */
- if (!Config->BSFantasyCharacter.empty())
- realbuf.erase(realbuf.begin());
+ std::vector<Anope::string> params = BuildStringVector(realbuf);
- std::vector<Anope::string> params = BuildStringVector(realbuf);
+ if (!realbuf.find_first_of(c->ci->bi->nick))
+ params.erase(params.begin());
+ else if (Config->BSFantasyCharacter.empty())
+ ;
+ else if (!realbuf.find_first_of(Config->BSFantasyCharacter))
+ params[0].erase(params[0].begin());
+ else
+ return;
+
+ if (params.empty())
+ return;
- ServerConfig::fantasy_map::const_iterator it = Config->Fantasy.end();
- unsigned count = 0;
- for (unsigned max = params.size(); it == Config->Fantasy.end() && max > 0; --max)
- {
- Anope::string full_command;
- for (unsigned i = 0; i < max; ++i)
- full_command += " " + params[i];
- full_command.erase(full_command.begin());
+ CommandInfo::map::const_iterator it = Config->Fantasy.end();
+ unsigned count = 0;
+ for (unsigned max = params.size(); it == Config->Fantasy.end() && max > 0; --max)
+ {
+ Anope::string full_command;
+ for (unsigned i = 0; i < max; ++i)
+ full_command += " " + params[i];
+ full_command.erase(full_command.begin());
- ++count;
- it = Config->Fantasy.find(full_command);
- }
+ ++count;
+ it = Config->Fantasy.find(full_command);
+ }
- if (it == Config->Fantasy.end())
- return;
+ if (it == Config->Fantasy.end())
+ return;
- const CommandInfo &info = it->second;
- service_reference<Command> cmd("Command", info.name);
- if (!cmd)
- {
- Log(LOG_DEBUG) << "Fantasy command " << it->first << " exists for nonexistant service " << info.name << "!";
- return;
- }
+ const CommandInfo &info = it->second;
+ service_reference<Command> cmd("Command", info.name);
+ if (!cmd)
+ {
+ Log(LOG_DEBUG) << "Fantasy command " << it->first << " exists for nonexistant service " << info.name << "!";
+ return;
+ }
- for (unsigned i = 0, j = params.size() - (count - 1); i < j; ++i)
- params.erase(params.begin());
+ for (unsigned i = 0, j = params.size() - (count - 1); i < j; ++i)
+ params.erase(params.begin());
- while (cmd->MaxParams > 0 && params.size() > cmd->MaxParams)
- {
- params[cmd->MaxParams - 1] += " " + params[cmd->MaxParams];
- params.erase(params.begin() + cmd->MaxParams);
- }
+ while (cmd->MaxParams > 0 && params.size() > cmd->MaxParams)
+ {
+ params[cmd->MaxParams - 1] += " " + params[cmd->MaxParams];
+ params.erase(params.begin() + cmd->MaxParams);
+ }
- /* All ChanServ commands take the channel as a first parameter */
- if (cmd->name.find("chanserv/") == 0)
- params.insert(params.begin(), c->ci->name);
+ /* All ChanServ commands take the channel as a first parameter */
+ if (cmd->name.find("chanserv/") == 0 && !cmd->HasFlag(CFLAG_STRIP_CHANNEL))
+ params.insert(params.begin(), c->ci->name);
- // Command requires registered users only
- if (!cmd->HasFlag(CFLAG_ALLOW_UNREGISTERED) && !u->Account())
- return;
+ // Command requires registered users only
+ if (!cmd->HasFlag(CFLAG_ALLOW_UNREGISTERED) && !u->Account())
+ return;
- if (params.size() < cmd->MinParams)
- return;
+ if (params.size() < cmd->MinParams)
+ return;
- CommandSource source(u->nick, u, u->Account(), u);
- source.c = c;
- source.owner = c->ci->bi;
- source.service = c->ci->bi;
- source.command = it->first;
- source.permission = info.permission;
+ CommandSource source(u->nick, u, u->Account(), u, c->ci->bi);
+ source.c = c;
+ source.command = it->first;
+ source.permission = info.permission;
- EventReturn MOD_RESULT;
- if (c->ci->AccessFor(u).HasPriv("FANTASIA"))
- {
- FOREACH_RESULT(I_OnBotFantasy, OnBotFantasy(source, cmd, c->ci, params));
- }
- else
- {
- FOREACH_RESULT(I_OnBotNoFantasyAccess, OnBotNoFantasyAccess(source, cmd, c->ci, params));
- }
+ EventReturn MOD_RESULT;
+ if (c->ci->AccessFor(u).HasPriv("FANTASIA"))
+ {
+ FOREACH_RESULT(I_OnBotFantasy, OnBotFantasy(source, cmd, c->ci, params));
+ }
+ else
+ {
+ FOREACH_RESULT(I_OnBotNoFantasyAccess, OnBotNoFantasyAccess(source, cmd, c->ci, params));
+ }
- if (MOD_RESULT == EVENT_STOP || !c->ci->AccessFor(u).HasPriv("FANTASIA"))
- return;
+ if (MOD_RESULT == EVENT_STOP || !c->ci->AccessFor(u).HasPriv("FANTASIA"))
+ return;
- if (MOD_RESULT != EVENT_ALLOW && !info.permission.empty() && !source.HasCommand(info.permission))
- return;
+ if (MOD_RESULT != EVENT_ALLOW && !info.permission.empty() && !source.HasCommand(info.permission))
+ return;
- FOREACH_RESULT(I_OnPreCommand, OnPreCommand(source, cmd, params));
- if (MOD_RESULT == EVENT_STOP)
- return;
+ FOREACH_RESULT(I_OnPreCommand, OnPreCommand(source, cmd, params));
+ if (MOD_RESULT == EVENT_STOP)
+ return;
- dynamic_reference<User> user_reference(u);
- dynamic_reference<NickCore> nc_reference(u->Account());
- cmd->Execute(source, params);
+ dynamic_reference<User> user_reference(u);
+ dynamic_reference<NickCore> nc_reference(u->Account());
+ cmd->Execute(source, params);
- if (user_reference && nc_reference)
- {
- FOREACH_MOD(I_OnPostCommand, OnPostCommand(source, cmd, params));
- }
+ if (user_reference && nc_reference)
+ {
+ FOREACH_MOD(I_OnPostCommand, OnPostCommand(source, cmd, params));
}
}
@@ -200,24 +201,43 @@ class BotServCore : public Module
EventReturn OnPreHelp(CommandSource &source, const std::vector<Anope::string> &params) anope_override
{
- if (!params.empty() || source.owner->nick != Config->BotServ)
+ if (!params.empty())
return EVENT_CONTINUE;
- source.Reply(_("\002%s\002 allows you to have a bot on your own channel.\n"
- "It has been created for users that can't host or\n"
- "configure a bot, or for use on networks that don't\n"
- "allow user bots. Available commands are listed \n"
- "below; to use them, type \002%s%s \037command\037\002. For\n"
- "more information on a specific command, type\n"
- "\002%s%s %s \037command\037\002.\n "),
- Config->BotServ.c_str(), Config->UseStrictPrivMsgString.c_str(), Config->BotServ.c_str(),
- Config->UseStrictPrivMsgString.c_str(), Config->BotServ.c_str(), source.command.c_str());
+
+ if (source.c)
+ {
+ source.Reply(_("\2%s\2 allows you to execute \"fantasy\" commands in the channel.\n"
+ "Fantasy commands are tied to existing commands, usually on \2%s\2,\n"
+ "and provide a more convenient way to execute commands. Commands that\n"
+ "require a channel as a parameter will automatically have that parameter\n"
+ "given.\n"), source.service->nick.c_str(), Config->ChanServ.c_str());
+ if (!Config->BSFantasyCharacter.empty())
+ source.Reply(_(" \n"
+ "Fantasy commands may be prefixed with one of the following characters: %s\n"), Config->BSFantasyCharacter.c_str());
+ source.Reply(_(" \n"
+ "Available commands are:"));
+ }
+ else if (source.service->nick == Config->BotServ)
+ {
+ source.Reply(_("\002%s\002 allows you to have a bot on your own channel.\n"
+ "It has been created for users that can't host or\n"
+ "configure a bot, or for use on networks that don't\n"
+ "allow user bots. Available commands are listed \n"
+ "below; to use them, type \002%s%s \037command\037\002. For\n"
+ "more information on a specific command, type\n"
+ "\002%s%s %s \037command\037\002.\n "),
+ Config->BotServ.c_str(), Config->UseStrictPrivMsgString.c_str(), Config->BotServ.c_str(),
+ Config->UseStrictPrivMsgString.c_str(), Config->BotServ.c_str(), source.command.c_str());
+ }
+
return EVENT_CONTINUE;
}
void OnPostHelp(CommandSource &source, const std::vector<Anope::string> &params) anope_override
{
- if (!params.empty() || source.owner->nick != Config->BotServ)
+ if (!params.empty() || source.c || source.service->nick != Config->BotServ)
return;
+
source.Reply(_(" \n"
"Bot will join a channel whenever there is at least\n"
"\002%d\002 user(s) on it."), Config->BSMinUsers);