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 * ---------------------------------------------------
16 static FileReader *quotes = NULL;
22 /* $ModDesc: Provides random Quotes on Connect. */
26 class CommandRandquote : public Command
29 CommandRandquote (InspIRCd* Instance) : Command(Instance,"RANDQUOTE", 0, 0)
31 this->source = "m_randquote.so";
34 CmdResult Handle (const char** parameters, int pcntl, User *user)
39 if (q_file.empty() || quotes->Exists())
41 fsize = quotes->FileSize();
42 str = quotes->GetLine(rand() % fsize);
43 user->WriteServ("NOTICE %s :%s%s%s",user->nick,prefix.c_str(),str.c_str(),suffix.c_str());
47 user->WriteServ("NOTICE %s :Your administrator specified an invalid quotes file, please bug them about this.", user->nick);
55 /** Thrown by m_randquote
57 class RandquoteException : public ModuleException
60 const std::string err;
62 RandquoteException(const std::string &message) : err(message) { }
64 ~RandquoteException() throw () { }
66 virtual const char* GetReason()
72 class ModuleRandQuote : public Module
75 CommandRandquote* mycommand;
78 ModuleRandQuote(InspIRCd* Me)
82 conf = new ConfigReader(ServerInstance);
83 // Sort the Randomizer thingie..
86 q_file = conf->ReadValue("randquote","file",0);
87 prefix = conf->ReadValue("randquote","prefix",0);
88 suffix = conf->ReadValue("randquote","suffix",0);
94 RandquoteException e("m_randquote: Quotefile not specified - Please check your config.");
98 quotes = new FileReader(ServerInstance, q_file);
101 RandquoteException e("m_randquote: QuoteFile not Found!! Please check your config - module will not function.");
106 /* Hidden Command -- Mode clients assume /quote sends raw data to an IRCd >:D */
107 mycommand = new CommandRandquote(ServerInstance);
108 ServerInstance->AddCommand(mycommand);
112 void Implements(char* List)
114 List[I_OnUserConnect] = 1;
117 virtual ~ModuleRandQuote()
123 virtual Version GetVersion()
125 return Version(1,1,0,1,VF_VENDOR,API_VERSION);
128 virtual void OnUserConnect(User* user)
131 mycommand->Handle(NULL, 0, user);
135 MODULE_INIT(ModuleRandQuote)