You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

172 lines
5.3 KiB

11 years ago
/**
* Copyright (C) 2014-2015 Justin James.
11 years ago
*
* This license must be preserved.
* Any applications, libraries, or code which make any use of any
* component of this program must not be commercial, unless explicit
* permission is granted from the original author. The use of this
* program for non-profit purposes is permitted.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* In the event that this license restricts you from making desired use of this program, contact the original author.
* Written by Justin James <justin.aj@hotmail.com>
*/
#include <cstring>
#include "Jupiter/Functions.h"
#include "Jupiter/Socket.h"
#include "Jupiter/CString.h"
#include "FunCommands.h"
#include "IRC_Bot.h"
using namespace Jupiter::literals;
11 years ago
// 8ball
void EightBallIRCCommand::create()
{
this->addTrigger("8ball"_jrs);
this->addTrigger("8balls"_jrs);
this->addTrigger("eightBall"_jrs);
11 years ago
}
void EightBallIRCCommand::trigger(IRC_Bot *source, const Jupiter::ReadableString &channel, const Jupiter::ReadableString &nick, const Jupiter::ReadableString &parameters)
{
Jupiter::StringS msg;
unsigned short r = rand() % 20;
switch (r)
{
case 0:
msg.set("No."_jrs);
11 years ago
break;
case 1:
msg.set("Yes."_jrs);
11 years ago
break;
case 2:
msg.set("Maybe."_jrs);
11 years ago
break;
case 3:
msg.set("Seven."_jrs);
11 years ago
break;
case 4:
msg.set("Consider counseling."_jrs);
11 years ago
break;
case 5:
msg.set("Look into a realationship. A real one."_jrs);
11 years ago
break;
case 6:
msg.set("Quit asking me these deep questions, before I get deeply into you."_jrs);
11 years ago
break;
case 7:
msg.set("Fuck you."_jrs);
11 years ago
break;
case 8:
msg.set("Fuck me."_jrs);
11 years ago
break;
case 9:
msg.set("Good thing I bend that way. ;)"_jrs);
11 years ago
break;
case 10:
msg.format("Hai %.*s ;)", nick.size(), nick.ptr());
break;
case 11:
msg.format("Let's ban %.*s!", nick.size(), nick.ptr());
break;
case 12:
msg.format("Sorry %.*s, but your IQ must be at least %d for me to care.", nick.size(), nick.ptr(), rand() % 50);
break;
case 13:
msg.set("Ask me those kind of questions in #Jail"_jrs);
11 years ago
break;
case 14:
msg.set("I don't talk to slut-mongers."_jrs);
11 years ago
break;
case 15:
msg.set("I only talk to slut-mongers."_jrs);
11 years ago
break;
case 16:
msg.set("Nuclear launch detected."_jrs);
11 years ago
break;
case 17:
msg.set("404 - Not found."_jrs);
11 years ago
break;
case 18:
msg.set("I hurr u liek mudkipz?"_jrs);
11 years ago
break;
case 19:
msg.set("Walk this way, babycakes ;)"_jrs);
11 years ago
break;
default:
msg.set("Nothingness. You suck. Go rot."_jrs);
11 years ago
break;
}
source->sendMessage(channel, msg);
}
const Jupiter::ReadableString &EightBallIRCCommand::getHelp(const Jupiter::ReadableString &)
{
static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Accurately answers your question 60% of the time, EVERY time. Syntax: 8ball [question]");
return defaultHelp;
}
IRC_COMMAND_INIT(EightBallIRCCommand)
// Resolve Command
ResolveGenericCommand::ResolveGenericCommand()
11 years ago
{
this->addTrigger("resolve"_jrs);
11 years ago
}
GenericCommand::ResponseLine *ResolveGenericCommand::trigger(const Jupiter::ReadableString &parameters)
11 years ago
{
unsigned int count = parameters.wordCount(WHITESPACE);
if (count <= 1)
return new GenericCommand::ResponseLine("Error: Too few parameters. Syntax: resolve <hostname|ip> <address>"_jrs, GenericCommand::DisplayType::PrivateError);
Jupiter::ReferenceString command = Jupiter::ReferenceString::getWord(parameters, 0, WHITESPACE);
if (command.equalsi("hostname"_jrs) || command.equalsi("host"_jrs))
{
Jupiter::ReferenceString resolved = Jupiter::Socket::resolveHostname(Jupiter::CStringS::gotoWord(parameters, 1, WHITESPACE).c_str(), 0);
if (resolved.isEmpty())
return new GenericCommand::ResponseLine("Error: Unable to resolve."_jrs, GenericCommand::DisplayType::PublicError);
return new GenericCommand::ResponseLine(resolved, GenericCommand::DisplayType::PublicSuccess);
}
else if (command.equalsi("ip"_jrs))
11 years ago
{
Jupiter::ReferenceString resolved = Jupiter::Socket::resolveAddress(Jupiter::CStringS::gotoWord(parameters, 1, WHITESPACE).c_str(), 0);
if (resolved.isEmpty())
return new GenericCommand::ResponseLine("Error: Unable to resolve."_jrs, GenericCommand::DisplayType::PublicError);
return new GenericCommand::ResponseLine(resolved, GenericCommand::DisplayType::PublicSuccess);
11 years ago
}
return new GenericCommand::ResponseLine("Error: Invalid type. You can only resolve hostnames and IP addresses."_jrs, GenericCommand::DisplayType::PrivateError);
11 years ago
}
const Jupiter::ReadableString &ResolveGenericCommand::getHelp(const Jupiter::ReadableString &parameters)
11 years ago
{
static STRING_LITERAL_AS_NAMED_REFERENCE(defaultHelp, "Resolves an IP address or hostname. Syntax: resolve <hostname|ip> <address>");
static STRING_LITERAL_AS_NAMED_REFERENCE(hostHelp, "Resolves a hostname to an IP address. Syntax: resolve hostname <address>");
static STRING_LITERAL_AS_NAMED_REFERENCE(ipHelp, "Reverse-resolves an IP address to a hostname. Syntax: resolve ip <address>");
if (parameters.equalsi("hostname"_jrs) || parameters.equalsi("host"_jrs))
11 years ago
return hostHelp;
if (parameters.equalsi("ip"_jrs))
11 years ago
return ipHelp;
return defaultHelp;
}
GENERIC_COMMAND_INIT(ResolveGenericCommand)
11 years ago
// Plugin instantiation and entry point.
ExtraCommandsPlugin pluginInstance;
extern "C" __declspec(dllexport) Jupiter::Plugin *getPlugin()
{
return &pluginInstance;
}