]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_randquote.cpp
Stop hiding users when a prefix is set on them, fixes apparent desyncs
[user/henk/code/inspircd.git] / src / modules / m_randquote.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2010 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "inspircd.h"
15
16 static FileReader *quotes = NULL;
17
18 std::string prefix;
19 std::string suffix;
20
21 /* $ModDesc: Provides random Quotes on Connect. */
22
23 /** Handle /RANDQUOTE
24  */
25 class CommandRandquote : public Command
26 {
27  public:
28         CommandRandquote(Module* Creator) : Command(Creator,"RANDQUOTE", 0)
29         {
30         }
31
32         CmdResult Handle (const std::vector<std::string>& parameters, User *user)
33         {
34                 std::string str;
35                 int fsize;
36
37                 fsize = quotes->FileSize();
38                 str = quotes->GetLine(ServerInstance->GenRandomInt(fsize));
39                 user->WriteServ("NOTICE %s :%s%s%s",user->nick.c_str(),prefix.c_str(),str.c_str(),suffix.c_str());
40
41                 return CMD_SUCCESS;
42         }
43 };
44
45 class ModuleRandQuote : public Module
46 {
47  private:
48         CommandRandquote cmd;
49  public:
50         ModuleRandQuote()
51                 : cmd(this)
52         {
53         }
54
55         void init()
56         {
57                 ConfigTag* conf = ServerInstance->Config->ConfValue("randquote");
58
59                 std::string q_file = conf->getString("file","quotes");
60                 prefix = conf->getString("prefix");
61                 suffix = conf->getString("suffix");
62
63                 quotes = new FileReader(q_file);
64                 if (!quotes->Exists())
65                 {
66                         throw ModuleException("m_randquote: QuoteFile not Found!! Please check your config - module will not function.");
67                 }
68                 ServerInstance->AddCommand(&cmd);
69                 Implementation eventlist[] = { I_OnUserConnect };
70                 ServerInstance->Modules->Attach(eventlist, this, 1);
71         }
72
73
74         virtual ~ModuleRandQuote()
75         {
76                 delete quotes;
77         }
78
79         virtual Version GetVersion()
80         {
81                 return Version("Provides random Quotes on Connect.",VF_VENDOR);
82         }
83
84         virtual void OnUserConnect(LocalUser* user)
85         {
86                 cmd.Handle(std::vector<std::string>(), user);
87         }
88 };
89
90 MODULE_INIT(ModuleRandQuote)