Browse Source

IRCCommand:

* Added static member selected_server.
* Added static member active_server.
ExtraCommands:
* Converted all existing console/IRC commands to Generic commands.
* Added SelectGenericCommand.
* Added DeselectGenericCommand.
pull/3/head
JustinAJ 10 years ago
parent
commit
a1f29e2b87
  1. 15
      Bot/IRC_Bot.cpp
  2. 3
      Bot/IRC_Command.cpp
  3. 5
      Bot/IRC_Command.h
  4. 395
      ExtraCommands/ExtraCommands.cpp
  5. 20
      ExtraCommands/ExtraCommands.h
  6. BIN
      Release/Bot.lib
  7. BIN
      Release/Plugins/RenX.Core.lib

15
Bot/IRC_Bot.cpp

@ -47,7 +47,12 @@ IRC_Bot::IRC_Bot(const Jupiter::ReadableString &configSection) : Client(configSe
IRC_Bot::~IRC_Bot() IRC_Bot::~IRC_Bot()
{ {
while (IRC_Bot::commands.size()) delete IRC_Bot::commands.remove(0); if (IRCCommand::selected_server == this)
IRCCommand::selected_server = nullptr;
if (IRCCommand::active_server == this)
IRCCommand::active_server = IRCCommand::selected_server;
IRC_Bot::commands.emptyAndDelete();
} }
void IRC_Bot::addCommand(IRCCommand *cmd) void IRC_Bot::addCommand(IRCCommand *cmd)
@ -193,9 +198,13 @@ void IRC_Bot::OnChat(const Jupiter::ReadableString &channel, const Jupiter::Read
IRCCommand *cmd = IRC_Bot::getCommand(command); IRCCommand *cmd = IRC_Bot::getCommand(command);
if (cmd != nullptr) if (cmd != nullptr)
{ {
IRCCommand::active_server = this;
int cAccess = cmd->getAccessLevel(chan); int cAccess = cmd->getAccessLevel(chan);
if (cAccess >= 0 && Jupiter::IRC::Client::getAccessLevel(channel, nick) >= cAccess) cmd->trigger(this, channel, nick, parameters); if (cAccess >= 0 && Jupiter::IRC::Client::getAccessLevel(channel, nick) >= cAccess)
else this->sendNotice(nick, STRING_LITERAL_AS_REFERENCE("Access Denied.")); cmd->trigger(this, channel, nick, parameters);
else
this->sendNotice(nick, STRING_LITERAL_AS_REFERENCE("Access Denied."));
IRCCommand::active_server = IRCCommand::selected_server;
} }
} }
} }

3
Bot/IRC_Command.cpp

@ -53,6 +53,9 @@ IRCCommand::~IRCCommand()
IRCCommand::types.emptyAndDelete(); IRCCommand::types.emptyAndDelete();
} }
IRC_Bot *IRCCommand::active_server = nullptr;
IRC_Bot *IRCCommand::selected_server = nullptr;
// IRC Command Functions // IRC Command Functions
int IRCCommand::getAccessLevel() int IRCCommand::getAccessLevel()

5
Bot/IRC_Command.h

@ -145,6 +145,11 @@ public:
*/ */
virtual ~IRCCommand(); virtual ~IRCCommand();
/** Public members */
static IRC_Bot *active_server; /** Currently active IRC server */
static IRC_Bot *selected_server; /** Currently selected IRC server */
/** Private members */ /** Private members */
private: private:
int access; /** Default access level */ int access; /** Default access level */

395
ExtraCommands/ExtraCommands.cpp

@ -20,267 +20,374 @@
#include "ExtraCommands.h" #include "ExtraCommands.h"
#include "IRC_Bot.h" #include "IRC_Bot.h"
// Raw Console Command using namespace Jupiter::literals;
RawConsoleCommand::RawConsoleCommand() // Select Command
SelectGenericCommand::SelectGenericCommand()
{ {
this->addTrigger(STRING_LITERAL_AS_REFERENCE("raw")); this->addTrigger("select"_jrs);
this->addTrigger(STRING_LITERAL_AS_REFERENCE("sendraw")); this->addTrigger("ircselect"_jrs);
} }
void RawConsoleCommand::trigger(const Jupiter::ReadableString &parameters) GenericCommand::ResponseLine *SelectGenericCommand::trigger(const Jupiter::ReadableString &parameters)
{ {
if (parameters.wordCount(WHITESPACE) < 2) if (parameters.isEmpty())
puts("Error: Too few parameters.");
else
{ {
Jupiter::ReferenceString network = Jupiter::ReferenceString::getWord(parameters, 0, WHITESPACE); if (IRCCommand::selected_server == nullptr)
Jupiter::ReferenceString message = Jupiter::ReferenceString::gotoWord(parameters, 1, WHITESPACE); return new GenericCommand::ResponseLine("No IRC server is currently selected."_jrs, GenericCommand::DisplayType::PublicSuccess);
size_t total = 0; return new GenericCommand::ResponseLine(IRCCommand::selected_server->getConfigSection() + " is currently selected."_jrs, GenericCommand::DisplayType::PublicSuccess);
for (size_t i = 0; i < serverManager->size(); i++)
{
IRC_Bot *server = serverManager->getServer(i);
if (server->getConfigSection().matchi(network))
{
server->send(message);
total++;
}
}
printf("%u packets sent." ENDL, total);
} }
if (IRCCommand::active_server == IRCCommand::selected_server)
IRCCommand::active_server = nullptr;
IRCCommand::selected_server = serverManager->getServer(parameters);
if (IRCCommand::selected_server == nullptr)
return new GenericCommand::ResponseLine("Error: IRC server \""_jrs + parameters + "\" not found. No IRC server is currently selected."_jrs, GenericCommand::DisplayType::PublicError);
if (IRCCommand::active_server == nullptr)
IRCCommand::active_server = IRCCommand::selected_server;
return new GenericCommand::ResponseLine(IRCCommand::selected_server->getConfigSection() + " is now selected."_jrs, GenericCommand::DisplayType::PublicSuccess);
} }
const Jupiter::ReadableString &RawConsoleCommand::getHelp(const Jupiter::ReadableString &) const Jupiter::ReadableString &SelectGenericCommand::getHelp(const Jupiter::ReadableString &)
{ {
static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Syntax: raw <network> <message>"); static Jupiter::ReferenceString defaultHelp = "Selects an IRC server if specified, responds with the currently selected server otherwise. Syntax: select [server]"_jrs;
return defaultHelp; return defaultHelp;
} }
CONSOLE_COMMAND_INIT(RawConsoleCommand) GENERIC_COMMAND_INIT(SelectGenericCommand)
GENERIC_COMMAND_AS_CONSOLE_COMMAND(SelectGenericCommand)
GENERIC_COMMAND_AS_IRC_COMMAND_ACCESS_CREATE(SelectGenericCommand, 4)
// Message Console Command // Deselect Command
MessageConsoleCommand::MessageConsoleCommand() DeselectGenericCommand::DeselectGenericCommand()
{ {
this->addTrigger(STRING_LITERAL_AS_REFERENCE("ircmsg")); this->addTrigger("deselect"_jrs);
this->addTrigger(STRING_LITERAL_AS_REFERENCE("message")); this->addTrigger("ircdeselect"_jrs);
this->addTrigger(STRING_LITERAL_AS_REFERENCE("privmsg")); this->addTrigger("dselect"_jrs);
this->addTrigger("ircdselect"_jrs);
this->addTrigger("unselect"_jrs);
this->addTrigger("ircunselect"_jrs);
} }
void MessageConsoleCommand::trigger(const Jupiter::ReadableString &parameters) GenericCommand::ResponseLine *DeselectGenericCommand::trigger(const Jupiter::ReadableString &parameters)
{ {
if (parameters.wordCount(WHITESPACE) < 3) if (IRCCommand::selected_server == nullptr)
puts("Error: Too few parameters."); return new GenericCommand::ResponseLine("No IRC server is currently selected."_jrs, GenericCommand::DisplayType::PublicSuccess);
GenericCommand::ResponseLine *ret = new GenericCommand::ResponseLine(IRCCommand::selected_server->getConfigSection() + " has been deselected."_jrs, GenericCommand::DisplayType::PublicSuccess);
IRCCommand::selected_server = nullptr;
IRCCommand::active_server = IRCCommand::selected_server;
return ret;
}
const Jupiter::ReadableString &DeselectGenericCommand::getHelp(const Jupiter::ReadableString &)
{
static Jupiter::ReferenceString defaultHelp = "Deselects the currently selected IRC server. Syntax: deselect"_jrs;
return defaultHelp;
}
GENERIC_COMMAND_INIT(DeselectGenericCommand)
GENERIC_COMMAND_AS_CONSOLE_COMMAND(DeselectGenericCommand)
GENERIC_COMMAND_AS_IRC_COMMAND_ACCESS_CREATE(DeselectGenericCommand, 4)
// Raw Command
RawGenericCommand::RawGenericCommand()
{
this->addTrigger("raw"_jrs);
this->addTrigger("sendraw"_jrs);
}
GenericCommand::ResponseLine *RawGenericCommand::trigger(const Jupiter::ReadableString &parameters)
{
IRC_Bot *server;
if (IRCCommand::selected_server != nullptr)
server = IRCCommand::selected_server;
else if (IRCCommand::active_server != nullptr)
server = IRCCommand::active_server;
else else
{ return new GenericCommand::ResponseLine("Error: No IRC server is currently selected."_jrs, GenericCommand::DisplayType::PublicError);
Jupiter::ReferenceString network = Jupiter::ReferenceString::getWord(parameters, 0, WHITESPACE);
Jupiter::ReferenceString channel = Jupiter::ReferenceString::getWord(parameters, 1, WHITESPACE);
Jupiter::ReferenceString message = Jupiter::ReferenceString::gotoWord(parameters, 2, WHITESPACE);
size_t total = 0; if (parameters.isEmpty())
for (size_t i = 0; i < serverManager->size(); i++) return new GenericCommand::ResponseLine("Error: Too few parameters. Syntax: raw <message>"_jrs, GenericCommand::DisplayType::PrivateError);
{
IRC_Bot *server = serverManager->getServer(i); server->send(parameters);
if (server->getConfigSection().matchi(network)) return new GenericCommand::ResponseLine("Data has been successfully sent to server."_jrs, GenericCommand::DisplayType::PublicSuccess);
{
server->sendMessage(channel, message);
total++;
}
}
printf("%u messages sent." ENDL, total);
}
} }
const Jupiter::ReadableString &MessageConsoleCommand::getHelp(const Jupiter::ReadableString &) const Jupiter::ReadableString &RawGenericCommand::getHelp(const Jupiter::ReadableString &)
{ {
static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Sends a message to an IRC user/channel, on a specified network (accepts wildcards). Syntax: msg <network> <destination> <message>"); static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Sends a line of data to the selected IRC server. Syntax: raw <message>");
return defaultHelp; return defaultHelp;
} }
CONSOLE_COMMAND_INIT(MessageConsoleCommand) GENERIC_COMMAND_INIT(RawGenericCommand)
GENERIC_COMMAND_AS_CONSOLE_COMMAND(RawGenericCommand)
GENERIC_COMMAND_AS_IRC_COMMAND_ACCESS_CREATE(RawGenericCommand, 5)
// Message Command
IRCMessageGenericCommand::IRCMessageGenericCommand()
{
this->addTrigger("ircmsg"_jrs);
this->addTrigger("ircmessage"_jrs);
this->addTrigger("privmsg"_jrs);
}
GenericCommand::ResponseLine *IRCMessageGenericCommand::trigger(const Jupiter::ReadableString &parameters)
{
IRC_Bot *server;
if (IRCCommand::selected_server != nullptr)
server = IRCCommand::selected_server;
else if (IRCCommand::active_server != nullptr)
server = IRCCommand::active_server;
else
return new GenericCommand::ResponseLine("Error: No IRC server is currently selected."_jrs, GenericCommand::DisplayType::PublicError);
if (parameters.wordCount(WHITESPACE) < 3)
return new GenericCommand::ResponseLine("Error: Too few parameters. Syntax: ircmsg <destination> <message>"_jrs, GenericCommand::DisplayType::PrivateError);
server->sendMessage(Jupiter::ReferenceString::getWord(parameters, 0, WHITESPACE), Jupiter::ReferenceString::gotoWord(parameters, 1, WHITESPACE));
return new GenericCommand::ResponseLine("Message successfully sent."_jrs, GenericCommand::DisplayType::PublicSuccess);
}
const Jupiter::ReadableString &IRCMessageGenericCommand::getHelp(const Jupiter::ReadableString &)
{
static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Sends a message to an IRC user or channel on the selected IRC server. Syntax: ircmsg <destination> <message>");
return defaultHelp;
}
GENERIC_COMMAND_INIT(IRCMessageGenericCommand)
GENERIC_COMMAND_AS_CONSOLE_COMMAND(IRCMessageGenericCommand)
GENERIC_COMMAND_AS_IRC_COMMAND_ACCESS_CREATE(IRCMessageGenericCommand, 5)
// Join Command // Join Command
void JoinIRCCommand::create() JoinGenericCommand::JoinGenericCommand()
{ {
this->addTrigger(STRING_LITERAL_AS_REFERENCE("Join")); this->addTrigger("Join"_jrs);
this->setAccessLevel(3);
} }
void JoinIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString &channel, const Jupiter::ReadableString &nick, const Jupiter::ReadableString &parameters) GenericCommand::ResponseLine *JoinGenericCommand::trigger(const Jupiter::ReadableString &parameters)
{ {
if (parameters.isNotEmpty()) IRC_Bot *server;
{ if (IRCCommand::selected_server != nullptr)
if (parameters.wordCount(WHITESPACE) == 1) server = IRCCommand::selected_server;
source->joinChannel(parameters); else if (IRCCommand::active_server != nullptr)
else source->joinChannel(Jupiter::ReferenceString::getWord(parameters, 0, WHITESPACE), Jupiter::ReferenceString::gotoWord(parameters, 1, WHITESPACE)); server = IRCCommand::active_server;
} else
else source->sendNotice(nick, STRING_LITERAL_AS_REFERENCE("Error: Too Few Parameters. Syntax: join <channel> [password]")); return new GenericCommand::ResponseLine("Error: No IRC server is currently selected."_jrs, GenericCommand::DisplayType::PublicError);
if (parameters.isEmpty())
return new GenericCommand::ResponseLine("Error: Too Few Parameters. Syntax: join <channel> [password]"_jrs, GenericCommand::DisplayType::PublicError);
if (parameters.wordCount(WHITESPACE) == 1)
server->joinChannel(parameters);
else
server->joinChannel(Jupiter::ReferenceString::getWord(parameters, 0, WHITESPACE), Jupiter::ReferenceString::gotoWord(parameters, 1, WHITESPACE));
return new GenericCommand::ResponseLine("Request to join channel has been sent."_jrs, GenericCommand::DisplayType::PublicSuccess);
} }
const Jupiter::ReadableString &JoinIRCCommand::getHelp(const Jupiter::ReadableString &) const Jupiter::ReadableString &JoinGenericCommand::getHelp(const Jupiter::ReadableString &)
{ {
static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Joins a channel. Syntax: join <Channel>"); static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Joins a channel. Syntax: join <channel> [password]");
return defaultHelp; return defaultHelp;
} }
IRC_COMMAND_INIT(JoinIRCCommand) GENERIC_COMMAND_INIT(JoinGenericCommand)
GENERIC_COMMAND_AS_CONSOLE_COMMAND(JoinGenericCommand)
GENERIC_COMMAND_AS_IRC_COMMAND_ACCESS_CREATE(JoinGenericCommand, 3)
// Part Command // Part Command
void PartIRCCommand::create() PartGenericCommand::PartGenericCommand()
{ {
this->addTrigger(STRING_LITERAL_AS_REFERENCE("Part")); this->addTrigger("Part"_jrs);
this->setAccessLevel(3);
} }
void PartIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString &channel, const Jupiter::ReadableString &nick, const Jupiter::ReadableString &parameters) GenericCommand::ResponseLine *PartGenericCommand::trigger(const Jupiter::ReadableString &parameters)
{ {
if (parameters.isNotEmpty()) IRC_Bot *server;
{ if (IRCCommand::selected_server != nullptr)
if (parameters.wordCount(WHITESPACE) == 1) server = IRCCommand::selected_server;
source->partChannel(parameters); else if (IRCCommand::active_server != nullptr)
else source->partChannel(Jupiter::ReferenceString::getWord(parameters, 0, WHITESPACE), Jupiter::ReferenceString::gotoWord(parameters, 1, WHITESPACE)); server = IRCCommand::active_server;
} else
else source->partChannel(channel); return new GenericCommand::ResponseLine("Error: No IRC server is currently selected."_jrs, GenericCommand::DisplayType::PublicError);
if (parameters.isEmpty())
return new GenericCommand::ResponseLine("Error: Too few parameters. Syntax: part <channel> [message]"_jrs, GenericCommand::DisplayType::PublicError);
if (parameters.wordCount(WHITESPACE) == 1)
server->partChannel(parameters);
else
server->partChannel(Jupiter::ReferenceString::getWord(parameters, 0, WHITESPACE), Jupiter::ReferenceString::gotoWord(parameters, 1, WHITESPACE));
return new GenericCommand::ResponseLine("Part command successfuly sent."_jrs, GenericCommand::DisplayType::PublicSuccess);
} }
const Jupiter::ReadableString &PartIRCCommand::getHelp(const Jupiter::ReadableString &) const Jupiter::ReadableString &PartGenericCommand::getHelp(const Jupiter::ReadableString &)
{ {
static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Parts from a channel. Syntax: part [channel=here] [message=empty]"); static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Parts from a channel. Syntax: part <channel> [message]");
return defaultHelp; return defaultHelp;
} }
IRC_COMMAND_INIT(PartIRCCommand) GENERIC_COMMAND_INIT(PartGenericCommand)
GENERIC_COMMAND_AS_CONSOLE_COMMAND(PartGenericCommand)
GENERIC_COMMAND_AS_IRC_COMMAND_ACCESS_CREATE(PartGenericCommand, 3)
// Info Command // DebugInfo Command
void InfoIRCCommand::create() DebugInfoGenericCommand::DebugInfoGenericCommand()
{ {
this->addTrigger(STRING_LITERAL_AS_REFERENCE("info")); this->addTrigger("debuginfo"_jrs);
this->setAccessLevel(4);
} }
void InfoIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString &channel, const Jupiter::ReadableString &nick, const Jupiter::ReadableString &parameters) GenericCommand::ResponseLine *DebugInfoGenericCommand::trigger(const Jupiter::ReadableString &parameters)
{ {
Jupiter::String msg; IRC_Bot *server;
msg.format("Prefixes: %.*s", source->getPrefixes().size(), source->getPrefixes().ptr()); if (IRCCommand::selected_server != nullptr)
source->sendMessage(channel, msg); server = IRCCommand::selected_server;
msg.format("Prefix Modes: %.*s", source->getPrefixModes().size(), source->getPrefixModes().ptr()); else if (IRCCommand::active_server != nullptr)
source->sendMessage(channel, msg); server = IRCCommand::active_server;
msg.format("Outputing data for %u channels...", source->getChannelCount()); else
source->sendMessage(channel, msg); return new GenericCommand::ResponseLine("Error: No IRC server is currently selected."_jrs, GenericCommand::DisplayType::PublicError);
for (unsigned int a = 0; a < source->getChannelCount(); a++)
Jupiter::IRC::Client::Channel *chan;
Jupiter::IRC::Client::User *user;
GenericCommand::ResponseLine *ret = new GenericCommand::ResponseLine("Prefixes: "_jrs + server->getPrefixes(), GenericCommand::DisplayType::PublicSuccess);
GenericCommand::ResponseLine *line = new GenericCommand::ResponseLine("Prefix Modes: "_jrs + server->getPrefixModes(), GenericCommand::DisplayType::PublicSuccess);
ret->next = line;
line->next = new GenericCommand::ResponseLine(Jupiter::StringS::Format("Outputting data for %u channels...", server->getChannelCount()), GenericCommand::DisplayType::PublicSuccess);
line = line->next;
for (unsigned int index = 0; index < server->getChannelCount(); ++index)
{ {
Jupiter::IRC::Client::Channel *chan = source->getChannel(a); chan = server->getChannel(index);
if (chan != nullptr) if (chan != nullptr)
{ {
msg.format("Channel %.*s - Type: %d", chan->getName().size(), chan->getName().ptr(), chan->getType()); line->next = new GenericCommand::ResponseLine(Jupiter::StringS::Format("Channel %.*s - Type: %d", chan->getName().size(), chan->getName().ptr(), chan->getType()), GenericCommand::DisplayType::PublicSuccess);
source->sendMessage(channel, msg); line = line->next;
for (unsigned int b = 0; b < chan->getUserCount(); b++) for (unsigned int j = 0; j != chan->getUserCount(); ++j)
{ {
Jupiter::IRC::Client::Channel::User *chanUser = chan->getUser(b); user = chan->getUser(j)->getUser();
Jupiter::IRC::Client::User *user = chanUser->getUser(); line->next = new GenericCommand::ResponseLine(Jupiter::StringS::Format("User %.*s!%.*s@%.*s (prefix: %c) of channel %.*s (of %u shared)", user->getNickname().size(), user->getNickname().ptr(), user->getUsername().size(), user->getUsername().ptr(), user->getHostname().size(), user->getHostname().ptr(), chan->getUserPrefix(j) ? chan->getUserPrefix(j) : ' ', chan->getName().size(), chan->getName().ptr(), user->getChannelCount()), GenericCommand::DisplayType::PublicSuccess);
msg.format("PRIVMSG %.*s :User %.*s!%.*s@%.*s (prefix: %c) of channel %.*s (of %u shared)" ENDL, channel.size(), channel.ptr(), user->getNickname().size(), user->getNickname().ptr(), user->getUsername().size(), user->getUsername().ptr(), user->getHostname().size(), user->getHostname().ptr(), chan->getUserPrefix(b) ? chan->getUserPrefix(b) : ' ', chan->getName().size(), chan->getName().ptr(), user->getChannelCount()); line = line->next;
source->send(msg);
} }
} }
} }
return ret;
} }
const Jupiter::ReadableString &InfoIRCCommand::getHelp(const Jupiter::ReadableString &) const Jupiter::ReadableString &DebugInfoGenericCommand::getHelp(const Jupiter::ReadableString &)
{ {
static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "TEMPORARY COMMAND - Spits out some info about channels. Syntax: info"); static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "DEBUG COMMAND - Spits out some information about channels. Syntax: debuginfo");
return defaultHelp; return defaultHelp;
} }
IRC_COMMAND_INIT(InfoIRCCommand) GENERIC_COMMAND_INIT(DebugInfoGenericCommand)
GENERIC_COMMAND_AS_CONSOLE_COMMAND(DebugInfoGenericCommand)
GENERIC_COMMAND_AS_IRC_COMMAND_ACCESS_CREATE(DebugInfoGenericCommand, 4)
// Exit command // Exit command
void ExitIRCCommand::create() ExitGenericCommand::ExitGenericCommand()
{ {
this->addTrigger(STRING_LITERAL_AS_REFERENCE("exit")); this->addTrigger("exit"_jrs);
this->setAccessLevel(5);
} }
void ExitIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString &channel, const Jupiter::ReadableString &nick, const Jupiter::ReadableString &parameters) GenericCommand::ResponseLine *ExitGenericCommand::trigger(const Jupiter::ReadableString &parameters)
{ {
source->sendMessage(channel, STRING_LITERAL_AS_REFERENCE("Bye!"));
exit(0); exit(0);
} }
const Jupiter::ReadableString &ExitIRCCommand::getHelp(const Jupiter::ReadableString &) const Jupiter::ReadableString &ExitGenericCommand::getHelp(const Jupiter::ReadableString &)
{ {
static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Closes the bot's application process. Syntax: exit"); static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Closes the bot's application process. Syntax: exit");
return defaultHelp; return defaultHelp;
} }
IRC_COMMAND_INIT(ExitIRCCommand) GENERIC_COMMAND_INIT(ExitGenericCommand)
GENERIC_COMMAND_AS_CONSOLE_COMMAND(ExitGenericCommand)
GENERIC_COMMAND_AS_IRC_COMMAND_ACCESS_CREATE(ExitGenericCommand, 5)
// IRC Connect command // IRC Connect command
void IRCConnectIRCCommand::create() IRCConnectGenericCommand::IRCConnectGenericCommand()
{ {
this->addTrigger(STRING_LITERAL_AS_REFERENCE("IRCConnect")); this->addTrigger("IRCConnect"_jrs);
this->addTrigger(STRING_LITERAL_AS_REFERENCE("IRCReconnect")); this->addTrigger("IRCReconnect"_jrs);
this->setAccessLevel(5);
} }
void IRCConnectIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString &channel, const Jupiter::ReadableString &nick, const Jupiter::ReadableString &parameters) GenericCommand::ResponseLine *IRCConnectGenericCommand::trigger(const Jupiter::ReadableString &parameters)
{ {
if (parameters == nullptr) if (parameters.isEmpty())
source->disconnect(STRING_LITERAL_AS_REFERENCE("Connect command used; reconnecting..."), false);
else
{ {
IRC_Bot *server = serverManager->getServer(parameters); IRC_Bot *server;
if (server != nullptr) if (IRCCommand::selected_server != nullptr)
{ server = IRCCommand::selected_server;
source->sendMessage(channel, STRING_LITERAL_AS_REFERENCE("Warning: Server already exists. Severing connection...")); else if (IRCCommand::active_server != nullptr)
server->disconnect(true); server = IRCCommand::active_server;
} else
if (serverManager->addServer(parameters)) return new GenericCommand::ResponseLine("Error: No IRC server is currently selected."_jrs, GenericCommand::DisplayType::PublicError);
source->sendMessage(channel, STRING_LITERAL_AS_REFERENCE("Connection successfully established; server added to server list."));
else source->sendMessage(channel, STRING_LITERAL_AS_REFERENCE("Error: Unable to find configuration settings for server, or connection refused.")); server->disconnect("Connect command used; reconnecting..."_jrs, false);
return new GenericCommand::ResponseLine("Disconnected from IRC server."_jrs, GenericCommand::DisplayType::PublicSuccess);
}
IRC_Bot *server = serverManager->getServer(parameters);
if (server != nullptr)
{
server->disconnect("Connect command used; reconnecting..."_jrs, false);
return new GenericCommand::ResponseLine("Disconnected from IRC server."_jrs, GenericCommand::DisplayType::PublicSuccess);
} }
if (serverManager->addServer(parameters))
return new GenericCommand::ResponseLine("Connection successfully established; server added to server list."_jrs, GenericCommand::DisplayType::PublicSuccess);
return new GenericCommand::ResponseLine("Error: Unable to find configuration settings for server, or connection refused."_jrs, GenericCommand::DisplayType::PublicError);
} }
const Jupiter::ReadableString &IRCConnectIRCCommand::getHelp(const Jupiter::ReadableString &) const Jupiter::ReadableString &IRCConnectGenericCommand::getHelp(const Jupiter::ReadableString &)
{ {
static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Connects/reconnects to an IRC server, based on config entry. Syntax: IRCConnect [server=here]"); static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Connects/reconnects to an IRC server, based on config entry. Syntax: IRCConnect [server=here]");
return defaultHelp; return defaultHelp;
} }
IRC_COMMAND_INIT(IRCConnectIRCCommand) GENERIC_COMMAND_INIT(IRCConnectGenericCommand)
GENERIC_COMMAND_AS_CONSOLE_COMMAND(IRCConnectGenericCommand)
GENERIC_COMMAND_AS_IRC_COMMAND_ACCESS_CREATE(IRCConnectGenericCommand, 5)
// IRC Disconnect command // IRC Disconnect command
void IRCDisconnectIRCCommand::create() IRCDisconnectGenericCommand::IRCDisconnectGenericCommand()
{ {
this->addTrigger(STRING_LITERAL_AS_REFERENCE("IRCDisconnect")); this->addTrigger("IRCDisconnect"_jrs);
this->setAccessLevel(5);
} }
void IRCDisconnectIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString &channel, const Jupiter::ReadableString &nick, const Jupiter::ReadableString &parameters) GenericCommand::ResponseLine *IRCDisconnectGenericCommand::trigger(const Jupiter::ReadableString &parameters)
{ {
if (parameters.isEmpty()) IRC_Bot *server;
source->disconnect(STRING_LITERAL_AS_REFERENCE("Disconnect command used"), true); if (IRCCommand::selected_server != nullptr)
server = IRCCommand::selected_server;
else if (IRCCommand::active_server != nullptr)
server = IRCCommand::active_server;
else else
{ return new GenericCommand::ResponseLine("Error: No IRC server is currently selected."_jrs, GenericCommand::DisplayType::PublicError);
IRC_Bot *server = serverManager->getServer(parameters);
if (server == nullptr) server->disconnect("Disconnect command used."_jrs, true);
source->sendNotice(nick, STRING_LITERAL_AS_REFERENCE("Error: Server not found.")); return new GenericCommand::ResponseLine("Disconnected from server."_jrs, GenericCommand::DisplayType::PublicSuccess);
else server->disconnect(STRING_LITERAL_AS_REFERENCE("Disconnect command used remotely"), true);
}
} }
const Jupiter::ReadableString &IRCDisconnectIRCCommand::getHelp(const Jupiter::ReadableString &) const Jupiter::ReadableString &IRCDisconnectGenericCommand::getHelp(const Jupiter::ReadableString &)
{ {
static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Disconnects from an IRC server, based on config entry. Syntax: IRCDisconnect [server=here]"); static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Disconnects from an IRC server, based on config entry. Syntax: IRCDisconnect");
return defaultHelp; return defaultHelp;
} }
IRC_COMMAND_INIT(IRCDisconnectIRCCommand) GENERIC_COMMAND_INIT(IRCDisconnectGenericCommand)
GENERIC_COMMAND_AS_CONSOLE_COMMAND(IRCDisconnectGenericCommand)
GENERIC_COMMAND_AS_IRC_COMMAND_ACCESS_CREATE(IRCDisconnectGenericCommand, 5)
// Plugin instantiation and entry point. // Plugin instantiation and entry point.
FunCommandsPlugin pluginInstance; FunCommandsPlugin pluginInstance;

20
ExtraCommands/ExtraCommands.h

@ -1,5 +1,5 @@
/** /**
* Copyright (C) 2014 Justin James. * Copyright (C) 2014-2015 Justin James.
* *
* This license must be preserved. * This license must be preserved.
* Any applications, libraries, or code which make any use of any * Any applications, libraries, or code which make any use of any
@ -31,13 +31,15 @@ private:
STRING_LITERAL_AS_NAMED_REFERENCE(name, "ExtraCommands"); STRING_LITERAL_AS_NAMED_REFERENCE(name, "ExtraCommands");
}; };
GENERIC_CONSOLE_COMMAND(RawConsoleCommand) GENERIC_GENERIC_COMMAND(SelectGenericCommand)
GENERIC_CONSOLE_COMMAND(MessageConsoleCommand) GENERIC_GENERIC_COMMAND(DeselectGenericCommand)
GENERIC_IRC_COMMAND(JoinIRCCommand) GENERIC_GENERIC_COMMAND(RawGenericCommand)
GENERIC_IRC_COMMAND(PartIRCCommand) GENERIC_GENERIC_COMMAND(IRCMessageGenericCommand)
GENERIC_IRC_COMMAND(InfoIRCCommand) GENERIC_GENERIC_COMMAND(JoinGenericCommand)
GENERIC_IRC_COMMAND(ExitIRCCommand) GENERIC_GENERIC_COMMAND(PartGenericCommand)
GENERIC_IRC_COMMAND(IRCConnectIRCCommand) GENERIC_GENERIC_COMMAND(DebugInfoGenericCommand)
GENERIC_IRC_COMMAND(IRCDisconnectIRCCommand) GENERIC_GENERIC_COMMAND(ExitGenericCommand)
GENERIC_GENERIC_COMMAND(IRCConnectGenericCommand)
GENERIC_GENERIC_COMMAND(IRCDisconnectGenericCommand)
#endif // _EXTRACOMMANDS_H_HEADER #endif // _EXTRACOMMANDS_H_HEADER

BIN
Release/Bot.lib

Binary file not shown.

BIN
Release/Plugins/RenX.Core.lib

Binary file not shown.
Loading…
Cancel
Save