1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * Inspire is copyright (C) 2002-2004 ChatSpike-Dev.
7 * <brain@chatspike.net>
8 * <Craig@chatspike.net>
10 * Written by Craig Edwards, Craig McLure, and others.
11 * This program is free but copyrighted software; see
12 * the file COPYING for details.
14 * ---------------------------------------------------
25 #include "helperfuncs.h"
28 FileReader *quotes = NULL;
30 std::string q_file = "";
31 std::string prefix = "";
32 std::string suffix = "";
34 /* $ModDesc: Provides random Quotes on Connect. */
36 class cmd_randquote : public command_t
39 cmd_randquote () : command_t("RANDQUOTE", 0, 0)
41 this->source = "m_randquote.so";
44 void Handle (char** parameters, int pcntl, userrec *user)
49 if (q_file == "" || quotes->Exists())
51 fsize = quotes->FileSize();
52 str = quotes->GetLine(rand() % fsize);
53 sprintf(buf,"NOTICE %s :%s%s%s",user->nick,prefix.c_str(),str.c_str(),suffix.c_str());
54 Srv->SendServ(user->fd, buf);
58 sprintf(buf, "NOTICE %s :Your administrator specified an invalid quotes file, please bug them about this.", user->nick);
59 Srv->SendServ(user->fd, buf);
66 class ModuleRandQuote : public Module
69 cmd_randquote* mycommand;
72 ModuleRandQuote(Server* Me)
76 conf = new ConfigReader;
77 // Sort the Randomizer thingie..
80 q_file = conf->ReadValue("randquote","file",0);
81 prefix = conf->ReadValue("randquote","prefix",0);
82 suffix = conf->ReadValue("randquote","suffix",0);
88 log(DEFAULT,"m_randquote: Quotefile not specified - Please check your config.");
92 quotes = new FileReader(q_file);
95 log(DEFAULT,"m_randquote: QuoteFile not Found!! Please check your config - module will not function.");
100 /* Hidden Command -- Mode clients assume /quote sends raw data to an IRCd >:D */
101 mycommand = new cmd_randquote();
102 Srv->AddCommand(mycommand);
106 void Implements(char* List)
108 List[I_OnUserConnect] = 1;
111 virtual ~ModuleRandQuote()
117 virtual Version GetVersion()
119 return Version(1,0,0,1,VF_VENDOR);
122 virtual void OnUserConnect(userrec* user)
125 mycommand->Handle(NULL, 0, user);
130 class ModuleRandQuoteFactory : public ModuleFactory
133 ModuleRandQuoteFactory()
137 ~ModuleRandQuoteFactory()
141 virtual Module * CreateModule(Server* Me)
143 return new ModuleRandQuote(Me);
149 extern "C" void * init_module( void )
151 return new ModuleRandQuoteFactory;