summaryrefslogtreecommitdiff
path: root/src/modules/m_randquote.cpp
diff options
context:
space:
mode:
authorPeter Powell <petpow@saberuk.com>2013-05-17 05:46:51 +0100
committerattilamolnar <attilamolnar@hush.com>2013-05-27 00:15:30 +0200
commit244a65e8556328642350575c4a94ee8fc1b676b4 (patch)
tree97bf4ff8cf2621a28041a719bd8d766f44014c5b /src/modules/m_randquote.cpp
parentee641f3f229143940fbe359ac98863edfdf249ce (diff)
Clean up the FileReader class and all of the modules that use it.
- Modules which use this class will now have to catch a CoreException when opening files if they wish to ignore the failed loading of a file. - m_randquote has been cleaned up massively and the RANDQUOTE command has been removed as it was pretty much useless.
Diffstat (limited to 'src/modules/m_randquote.cpp')
-rw-r--r--src/modules/m_randquote.cpp63
1 files changed, 14 insertions, 49 deletions
diff --git a/src/modules/m_randquote.cpp b/src/modules/m_randquote.cpp
index 62d3022cf..8b9ffd6e9 100644
--- a/src/modules/m_randquote.cpp
+++ b/src/modules/m_randquote.cpp
@@ -25,73 +25,38 @@
#include "inspircd.h"
-static FileReader *quotes = NULL;
-
-std::string prefix;
-std::string suffix;
-
-/** Handle /RANDQUOTE
- */
-class CommandRandquote : public Command
-{
- public:
- CommandRandquote(Module* Creator) : Command(Creator,"RANDQUOTE", 0)
- {
- }
-
- CmdResult Handle (const std::vector<std::string>& parameters, User *user)
- {
- std::string str;
- int fsize;
-
- fsize = quotes->FileSize();
- str = quotes->GetLine(ServerInstance->GenRandomInt(fsize));
- user->WriteNotice(prefix + str + suffix);
-
- return CMD_SUCCESS;
- }
-};
-
class ModuleRandQuote : public Module
{
- CommandRandquote cmd;
- public:
- ModuleRandQuote()
- : cmd(this)
- {
- }
+ private:
+ std::string prefix;
+ std::string suffix;
+ std::vector<std::string> quotes;
+ public:
void init() CXX11_OVERRIDE
{
ConfigTag* conf = ServerInstance->Config->ConfValue("randquote");
-
- std::string q_file = conf->getString("file","quotes");
prefix = conf->getString("prefix");
suffix = conf->getString("suffix");
+ FileReader reader(conf->getString("file", "quotes"));
+ quotes = reader.GetVector();
- quotes = new FileReader(q_file);
- if (!quotes->Exists())
- {
- throw ModuleException("m_randquote: QuoteFile not Found!! Please check your config - module will not function.");
- }
- ServerInstance->Modules->AddService(cmd);
Implementation eventlist[] = { I_OnUserConnect };
ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
}
- ~ModuleRandQuote()
+ void OnUserConnect(LocalUser* user) CXX11_OVERRIDE
{
- delete quotes;
+ if (!quotes.empty())
+ {
+ unsigned long random = ServerInstance->GenRandomInt(quotes.size());
+ user->WriteNotice(prefix + quotes[random] + suffix);
+ }
}
Version GetVersion() CXX11_OVERRIDE
{
- return Version("Provides random quotes on connect.",VF_VENDOR);
- }
-
- void OnUserConnect(LocalUser* user) CXX11_OVERRIDE
- {
- cmd.Handle(std::vector<std::string>(), user);
+ return Version("Provides random quotes on connect.", VF_VENDOR);
}
};