1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2007 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
19 static FileReader *quotes = NULL;
21 std::string q_file = "";
22 std::string prefix = "";
23 std::string suffix = "";
25 /* $ModDesc: Provides random Quotes on Connect. */
29 class cmd_randquote : public command_t
32 cmd_randquote (InspIRCd* Instance) : command_t(Instance,"RANDQUOTE", 0, 0)
34 this->source = "m_randquote.so";
37 CmdResult Handle (const char** parameters, int pcntl, userrec *user)
42 if (q_file == "" || quotes->Exists())
44 fsize = quotes->FileSize();
45 str = quotes->GetLine(rand() % fsize);
46 user->WriteServ("NOTICE %s :%s%s%s",user->nick,prefix.c_str(),str.c_str(),suffix.c_str());
50 user->WriteServ("NOTICE %s :Your administrator specified an invalid quotes file, please bug them about this.", user->nick);
58 /** Thrown by m_randquote
60 class RandquoteException : public ModuleException
63 const std::string err;
65 RandquoteException(const std::string &message) : err(message) { }
67 ~RandquoteException() throw () { }
69 virtual const char* GetReason()
75 class ModuleRandQuote : public Module
78 cmd_randquote* mycommand;
81 ModuleRandQuote(InspIRCd* Me)
85 conf = new ConfigReader(ServerInstance);
86 // Sort the Randomizer thingie..
89 q_file = conf->ReadValue("randquote","file",0);
90 prefix = conf->ReadValue("randquote","prefix",0);
91 suffix = conf->ReadValue("randquote","suffix",0);
97 RandquoteException e("m_randquote: Quotefile not specified - Please check your config.");
101 quotes = new FileReader(ServerInstance, q_file);
102 if(!quotes->Exists())
104 RandquoteException e("m_randquote: QuoteFile not Found!! Please check your config - module will not function.");
109 /* Hidden Command -- Mode clients assume /quote sends raw data to an IRCd >:D */
110 mycommand = new cmd_randquote(ServerInstance);
111 ServerInstance->AddCommand(mycommand);
115 void Implements(char* List)
117 List[I_OnUserConnect] = 1;
120 virtual ~ModuleRandQuote()
126 virtual Version GetVersion()
128 return Version(1,1,0,1,VF_VENDOR,API_VERSION);
131 virtual void OnUserConnect(userrec* user)
134 mycommand->Handle(NULL, 0, user);
139 class ModuleRandQuoteFactory : public ModuleFactory
142 ModuleRandQuoteFactory()
146 ~ModuleRandQuoteFactory()
150 virtual Module * CreateModule(InspIRCd* Me)
152 return new ModuleRandQuote(Me);
158 extern "C" DllExport void * init_module( void )
160 return new ModuleRandQuoteFactory;