1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2009 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/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(Module* Creator) : Command(Creator,"RANDQUOTE", 0)
33 CmdResult Handle (const std::vector<std::string>& parameters, User *user)
38 if (q_file.empty() || quotes->Exists())
40 fsize = quotes->FileSize();
41 str = quotes->GetLine(rand() % fsize);
42 user->WriteServ("NOTICE %s :%s%s%s",user->nick.c_str(),prefix.c_str(),str.c_str(),suffix.c_str());
46 user->WriteServ("NOTICE %s :Your administrator specified an invalid quotes file, please bug them about this.", user->nick.c_str());
54 class ModuleRandQuote : public Module
60 ModuleRandQuote(InspIRCd* Me)
61 : Module(Me), cmd(this)
64 conf = new ConfigReader(ServerInstance);
65 // Sort the Randomizer thingie..
66 srand(ServerInstance->Time());
68 q_file = conf->ReadValue("randquote","file",0);
69 prefix = conf->ReadValue("randquote","prefix",0);
70 suffix = conf->ReadValue("randquote","suffix",0);
74 throw ModuleException("m_randquote: Quotefile not specified - Please check your config.");
77 quotes = new FileReader(ServerInstance, q_file);
80 throw ModuleException("m_randquote: QuoteFile not Found!! Please check your config - module will not function.");
84 /* Hidden Command -- Mode clients assume /quote sends raw data to an IRCd >:D */
85 ServerInstance->AddCommand(&cmd);
87 Implementation eventlist[] = { I_OnUserConnect };
88 ServerInstance->Modules->Attach(eventlist, this, 1);
92 virtual ~ModuleRandQuote()
98 virtual Version GetVersion()
100 return Version("$Id$",VF_VENDOR,API_VERSION);
103 virtual void OnUserConnect(User* user)
105 cmd.Handle(std::vector<std::string>(), user);
109 MODULE_INIT(ModuleRandQuote)