summaryrefslogtreecommitdiff
path: root/modules/commands/bs_bot.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'modules/commands/bs_bot.cpp')
-rw-r--r--modules/commands/bs_bot.cpp156
1 files changed, 93 insertions, 63 deletions
diff --git a/modules/commands/bs_bot.cpp b/modules/commands/bs_bot.cpp
index 977d4b72f..2413e6b6d 100644
--- a/modules/commands/bs_bot.cpp
+++ b/modules/commands/bs_bot.cpp
@@ -27,7 +27,7 @@ class CommandBSBot : public Command
if (BotInfo::Find(nick, true))
{
- source.Reply(_("Bot \002%s\002 already exists."), nick.c_str());
+ source.Reply(_("Bot \002{0}\002 already exists."), nick);
return;
}
@@ -35,19 +35,19 @@ class CommandBSBot : public Command
if (nick.length() > networkinfo->Get<unsigned>("nicklen"))
{
- source.Reply(_("Bot nicks may only be %d characters long."), networkinfo->Get<unsigned>("nicklen"));
+ source.Reply(_("Bot nicks may only be \002{0}\002 characters long."), networkinfo->Get<unsigned>("nicklen"));
return;
}
if (user.length() > networkinfo->Get<unsigned>("userlen"))
{
- source.Reply(_("Bot idents may only be %d characters long."), networkinfo->Get<unsigned>("userlen"));
+ source.Reply(_("Bot idents may only be \002{0}\002 characters long."), networkinfo->Get<unsigned>("userlen"));
return;
}
if (host.length() > networkinfo->Get<unsigned>("hostlen"))
{
- source.Reply(_("Bot hosts may only be %d characters long."), networkinfo->Get<unsigned>("hostlen"));
+ source.Reply(_("Bot hosts may only be \002{0}\002 characters long."), networkinfo->Get<unsigned>("hostlen"));
return;
}
@@ -73,17 +73,22 @@ class CommandBSBot : public Command
* if so. You need to drop the nick manually before you can use
* it as a bot nick from now on -GD
*/
- if (NickServ::FindNick(nick))
+ NickServ::Nick *na = NickServ::FindNick(nick);
+ if (na)
{
- source.Reply(NICK_ALREADY_REGISTERED, nick.c_str());
+ source.Reply(_("Nickname \002{0}\002 is already registered!"), na->nick);
return;
}
+ User *targ = User::Find(nick, true);
+ if (targ)
+ targ->Kill(Me, "Nickname is reserved for services");
+
BotInfo *bi = new BotInfo(nick, user, host, real);
Log(LOG_ADMIN, source, 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());
+ source.Reply(_("\002{0}!{1}@{2}\002 (\002{3}\002) added to the bot list."), bi->nick, bi->GetIdent(), bi->host, bi->realname);
this->OnBotCreate(&Event::BotCreate::OnBotCreate, bi);
}
@@ -105,13 +110,13 @@ class CommandBSBot : public Command
BotInfo *bi = BotInfo::Find(oldnick, true);
if (!bi)
{
- source.Reply(BOT_DOES_NOT_EXIST, oldnick.c_str());
+ source.Reply(_("Bot \002{0}\002 does not exist."), oldnick);
return;
}
if (bi->conf)
{
- source.Reply(_("Bot %s is not changeable."), bi->nick.c_str());
+ source.Reply(_("Bot \002{0}\002 is not changeable because it is configured in services configuration."), bi->nick.c_str());
return;
}
@@ -119,19 +124,19 @@ class CommandBSBot : public Command
if (nick.length() > networkinfo->Get<unsigned>("nicklen"))
{
- source.Reply(_("Bot nicks may only be %d characters long."), networkinfo->Get<unsigned>("nicklen"));
+ source.Reply(_("Bot nicknames may only be \002{0}\002 characters long."), networkinfo->Get<unsigned>("nicklen"));
return;
}
if (user.length() > networkinfo->Get<unsigned>("userlen"))
{
- source.Reply(_("Bot idents may only be %d characters long."), networkinfo->Get<unsigned>("userlen"));
+ source.Reply(_("Bot usernames may only be \002{0}\002 characters long."), networkinfo->Get<unsigned>("userlen"));
return;
}
if (host.length() > networkinfo->Get<unsigned>("hostlen"))
{
- source.Reply(_("Bot hosts may only be %d characters long."), networkinfo->Get<unsigned>("hostlen"));
+ source.Reply(_("Bot hostnames may only be \002{0}\002 characters long."), networkinfo->Get<unsigned>("hostlen"));
return;
}
@@ -140,33 +145,37 @@ class CommandBSBot : public Command
* 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))
+ if (nick.equals_cs(bi->nick)
+ && (user.empty() || user.equals_cs(bi->GetIdent()))
+ && (host.empty() || host.equals_cs(bi->host))
+ && (real.empty() || real.equals_cs(bi->realname)))
{
- source.Reply(_("Old info is equal to the new one."));
+ source.Reply(_("There is no difference between the current settings and the new settings."));
return;
}
if (!IRCD->IsNickValid(nick))
{
- source.Reply(_("Bot nicks may only contain valid nick characters."));
+ source.Reply(_("Bot nicknames may only contain valid nickname characters."));
return;
}
if (!user.empty() && !IRCD->IsIdentValid(user))
{
- source.Reply(_("Bot idents may only contain valid ident characters."));
+ source.Reply(_("Bot uesrnames may only contain valid username characters."));
return;
}
if (!host.empty() && !IRCD->IsHostValid(host))
{
- source.Reply(_("Bot hosts may only contain valid host characters."));
+ source.Reply(_("Bot hostnames may only contain valid hostname characters."));
return;
}
- if (!nick.equals_ci(bi->nick) && BotInfo::Find(nick, true))
+ BotInfo *newbi = BotInfo::Find(nick, true);
+ if (newbi && bi != newbi)
{
- source.Reply(_("Bot \002%s\002 already exists."), nick.c_str());
+ source.Reply(_("Bot \002{0}\002 already exists."), newbi->nick);
return;
}
@@ -176,9 +185,10 @@ class CommandBSBot : public Command
* if so. You need to drop the nick manually before you can use
* it as a bot nick from now on -GD
*/
- if (NickServ::FindNick(nick))
+ NickServ::Nick *na = NickServ::FindNick(nick);
+ if (na)
{
- source.Reply(NICK_ALREADY_REGISTERED, nick.c_str());
+ source.Reply(_("Nickname \002{0}\002 is already registered."), na->nick);
return;
}
@@ -199,11 +209,11 @@ class CommandBSBot : public Command
if (!nick.equals_cs(bi->nick))
bi->SetNewNick(nick);
- if (!user.empty() && !user.equals_cs(bi->GetIdent()))
+ if (!user.equals_cs(bi->GetIdent()))
bi->SetIdent(user);
- if (!host.empty() && !host.equals_cs(bi->host))
+ if (!host.equals_cs(bi->host))
bi->host = host;
- if (!real.empty() && !real.equals_cs(bi->realname))
+ if (real.equals_cs(bi->realname))
bi->realname = real;
if (!user.empty())
@@ -220,7 +230,7 @@ class CommandBSBot : public Command
}
}
- 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());
+ source.Reply(_("Bot \002{0}\002 has been changed to \002{1}!{2}@{3}\002 (\002{4}\002)."), oldnick, bi->nick, bi->GetIdent(), bi->host, bi->realname);
Log(LOG_ADMIN, source, this) << "CHANGE " << oldnick << " to " << bi->GetMask() << " " << bi->realname;
this->OnBotChange(&Event::BotChange::OnBotChange, bi);
@@ -239,13 +249,13 @@ class CommandBSBot : public Command
BotInfo *bi = BotInfo::Find(nick, true);
if (!bi)
{
- source.Reply(BOT_DOES_NOT_EXIST, nick.c_str());
+ source.Reply(_("Bot \002{0}\002 does not exist."), nick);
return;
}
if (bi->conf)
{
- source.Reply(_("Bot %s is not deletable."), bi->nick.c_str());
+ source.Reply(_("Bot \002{0}\002 is can not be deleted because it is configured in services configuration."), bi->nick);
return;
}
@@ -253,7 +263,7 @@ class CommandBSBot : public Command
Log(LOG_ADMIN, source, this) << "DEL " << bi->nick;
- source.Reply(_("Bot \002%s\002 has been deleted."), nick.c_str());
+ source.Reply(_("Bot \002{0}\002 has been deleted."), bi->nick);
delete bi;
}
@@ -261,9 +271,9 @@ class CommandBSBot : public Command
CommandBSBot(Module *creator) : Command(creator, "botserv/bot", 1, 6), OnBotCreate(creator, "OnBotCreate"), OnBotChange(creator, "OnBotChange"), OnBotDelete(creator, "OnBotDelete")
{
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"));
+ this->SetSyntax(_("\002ADD \037nicknae\037 \037username\037 \037hostname\037 \037realname\037\002"));
+ this->SetSyntax(_("\002CHANGE \037oldnickname\037 \037newnickname\037 [\037username\037 [\037hostname\037 [\037realname\037]]]\002"));
+ this->SetSyntax(_("\002DEL \037nickname\037\002"));
}
void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
@@ -271,20 +281,17 @@ class CommandBSBot : public Command
const Anope::string &cmd = params[0];
if (Anope::ReadOnly)
- {
- source.Reply(_("Sorry, bot modification is temporarily disabled."));
- return;
- }
+ source.Reply(_("Services are in read-only mode. Any changes made may not persist."));
if (cmd.equals_ci("ADD"))
{
- // ADD nick user host real - 5
if (!source.HasCommand("botserv/bot/add"))
{
- source.Reply(ACCESS_DENIED);
+ source.Reply(_("Access denied. You do not have access to the operator command \002{0}\002."), "botserv/bot/add");
return;
}
+ // ADD nick user host real - 5
if (params.size() < 5)
{
this->OnSyntaxError(source, "ADD");
@@ -296,7 +303,7 @@ class CommandBSBot : public Command
if (tempparams.size() >= 6)
tempparams[4] = tempparams[4] + " " + tempparams[5];
- return this->DoAdd(source, tempparams);
+ this->DoAdd(source, tempparams);
}
else if (cmd.equals_ci("CHANGE"))
{
@@ -304,7 +311,7 @@ class CommandBSBot : public Command
// but only oldn and newn are required
if (!source.HasCommand("botserv/bot/change"))
{
- source.Reply(ACCESS_DENIED);
+ source.Reply(_("Access denied. You do not have access to the operator command \002{0}\002."), "botserv/bot/change");
return;
}
@@ -314,14 +321,14 @@ class CommandBSBot : public Command
return;
}
- return this->DoChange(source, params);
+ this->DoChange(source, params);
}
else if (cmd.equals_ci("DEL"))
{
// DEL nick
if (!source.HasCommand("botserv/bot/del"))
{
- source.Reply(ACCESS_DENIED);
+ source.Reply(_("Access denied. You do not have access to the operator command \002{0}\002."), "botserv/bot/del");
return;
}
@@ -331,35 +338,58 @@ class CommandBSBot : public Command
return;
}
- return this->DoDel(source, params);
+ this->DoDel(source, params);
}
else
this->OnSyntaxError(source, "");
-
- return;
}
bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
- 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"
- " \n"
- "\002BOT CHANGE\002 allows to change the nickname, username, hostname\n"
- "or realname of a bot without actually having to delete it (and\n"
- "all the data associated with it).\n"
- " \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."));
+ if (subcommand.equals_ci("ADD"))
+ source.Reply(_("\002{command} ADD\002 adds a bot with the given \037nickname\037, \037username\037, \037hostname\037 and \037realname\037."
+ " You can not create a bot with a nickname that is currently registered. If an unregistered user is currently using the nick, they will be killed.\n"
+ " Once a bot is created, users will be able to assign the bot to their channels. This command requires the opererator privilege for command \002{0}\002."
+ "\n"
+ "Example:\n"
+ " {command} ADD Botox Botox services.anope.org Botox\n"
+ " Adds a service bot with nickname \"Botox\", username \"Botox\", hostname \"services.anope.org\", and realname \"Botox\" to the bot list."),
+ "botserv/bot/add", "command"_kw = source.command);
+ else if (subcommand.equals_ci("CHANGE"))
+ source.Reply(_("\002{command} CHANGE\002 allows changing the \037nickname\037, \037username\037, \037hostname\037 and \037realname\037 of bot \037oldnickname\037."
+ " If a new username, hostname, or realname is specified, then the bot \037nickname\037 will quit and rejoin all of its channels using the new mask."
+ " Otherwise, the bot simply change nick to \037newnickname\037. All settings on the bot, such as channels and no-bot, are retained."
+ " This command requires the operator privilege for command \002{0}\002."
+ "\n"
+ "Example:\n"
+ " {command} CHANGE Botox peer connection reset.by peer\n"
+ " Renames the bot \"Botox\" to \"peer\" with the given username, hostname, and realname."),
+ "botserv/bot/change", "command"_kw = source.command);
+ else if (subcommand.equals_ci("DEL"))
+ source.Reply(_("\002{command} DEL\002 removes the bot \037nickname\037 from the bot list. The bot will quit from any channels it is in, and will not be replaced."
+ " This command requires the operator privilege for command \002{0}\002.\n"
+ "\n"
+ "Example:\n"
+ " {command} DEL peer\n"
+ " Removes the bot \"peer\" from the bot list."),
+ "botserv/bot/del", "command"_kw = source.command);
+ else
+ {
+ source.Reply(_("Allows Services Operators to create, modify, and delete bots that users will be able to use on their channels."));
+
+ CommandInfo *help = source.service->FindCommand("generic/help");
+ if (help)
+ source.Reply(_("\n"
+ "The \002ADD\002 command adds a bot with the given \037nickname\037, \037username\037, \037hostname\037 and \037realname\037 to the bot list.\n"
+ "\002{msg}{service} {help} {command} ADD\002 for more information.\n"
+ "\n"
+ "The \002CHANGE\002 command allows changing the \037nickname\037, \037username\037, \037hostname\037 and \037realname\037 of bot \037oldnickname\037.\n"
+ "\002{msg}{service} {help} {command} CHANGE\002 for more information.\n"
+ "\n"
+ "The \002{command} DEL\002 removes the bot \037nickname\037 from the bot list.\n"
+ "\002{msg}{service} {help} {command} DEL\002 for more information."),
+ "msg"_kw = Config->StrictPrivmsg, "help"_kw = help->cname, "command"_kw = source.command);
+ }
return true;
}
};