1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd is copyright (C) 2002-2006 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 * ---------------------------------------------------
26 static FileReader *quotes = NULL;
28 std::string q_file = "";
29 std::string prefix = "";
30 std::string suffix = "";
32 /* $ModDesc: Provides random Quotes on Connect. */
34 class cmd_randquote : public command_t
37 cmd_randquote (InspIRCd* Instance) : command_t(Instance,"RANDQUOTE", 0, 0)
39 this->source = "m_randquote.so";
42 CmdResult Handle (const char** parameters, int pcntl, userrec *user)
47 if (q_file == "" || quotes->Exists())
49 fsize = quotes->FileSize();
50 str = quotes->GetLine(rand() % fsize);
51 sprintf(buf,"NOTICE %s :%s%s%s",user->nick,prefix.c_str(),str.c_str(),suffix.c_str());
52 user->WriteServ(std::string(buf));
56 sprintf(buf, "NOTICE %s :Your administrator specified an invalid quotes file, please bug them about this.", user->nick);
57 user->WriteServ(std::string(buf));
64 class RandquoteException : public ModuleException
69 RandquoteException(std::string message) : err(message) { }
71 virtual const char* GetReason()
73 return (char*)err.c_str();
77 class ModuleRandQuote : public Module
80 cmd_randquote* mycommand;
83 ModuleRandQuote(InspIRCd* Me)
87 conf = new ConfigReader(ServerInstance);
88 // Sort the Randomizer thingie..
91 q_file = conf->ReadValue("randquote","file",0);
92 prefix = conf->ReadValue("randquote","prefix",0);
93 suffix = conf->ReadValue("randquote","suffix",0);
99 RandquoteException e("m_randquote: Quotefile not specified - Please check your config.");
103 quotes = new FileReader(ServerInstance, q_file);
104 if(!quotes->Exists())
106 RandquoteException e("m_randquote: QuoteFile not Found!! Please check your config - module will not function.");
111 /* Hidden Command -- Mode clients assume /quote sends raw data to an IRCd >:D */
112 mycommand = new cmd_randquote(ServerInstance);
113 ServerInstance->AddCommand(mycommand);
117 void Implements(char* List)
119 List[I_OnUserConnect] = 1;
122 virtual ~ModuleRandQuote()
128 virtual Version GetVersion()
130 return Version(1,0,0,1,VF_VENDOR);
133 virtual void OnUserConnect(userrec* user)
136 mycommand->Handle(NULL, 0, user);
141 class ModuleRandQuoteFactory : public ModuleFactory
144 ModuleRandQuoteFactory()
148 ~ModuleRandQuoteFactory()
152 virtual Module * CreateModule(InspIRCd* Me)
154 return new ModuleRandQuote(Me);
160 extern "C" void * init_module( void )
162 return new ModuleRandQuoteFactory;