]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_randquote.cpp
Use CommandBase::Params instead of std::vector<std::string>.
[user/henk/code/inspircd.git] / src / modules / m_randquote.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2010 Daniel De Graaf <danieldg@inspircd.org>
5  *   Copyright (C) 2007-2008 Robin Burchell <robin+git@viroteck.net>
6  *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
7  *   Copyright (C) 2003, 2006 Craig Edwards <craigedwards@brainbox.cc>
8  *   Copyright (C) 2005 Craig McLure <craig@chatspike.net>
9  *
10  * This file is part of InspIRCd.  InspIRCd is free software: you can
11  * redistribute it and/or modify it under the terms of the GNU General Public
12  * License as published by the Free Software Foundation, version 2.
13  *
14  * This program is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
17  * details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  */
22
23
24 #include "inspircd.h"
25
26 class ModuleRandQuote : public Module
27 {
28  private:
29         std::string prefix;
30         std::string suffix;
31         std::vector<std::string> quotes;
32
33  public:
34         void init() CXX11_OVERRIDE
35         {
36                 ConfigTag* conf = ServerInstance->Config->ConfValue("randquote");
37                 prefix = conf->getString("prefix");
38                 suffix = conf->getString("suffix");
39                 FileReader reader(conf->getString("file", "quotes"));
40                 quotes = reader.GetVector();
41         }
42
43         void OnUserConnect(LocalUser* user) CXX11_OVERRIDE
44         {
45                 if (!quotes.empty())
46                 {
47                         unsigned long random = ServerInstance->GenRandomInt(quotes.size());
48                         user->WriteNotice(prefix + quotes[random] + suffix);
49                 }
50         }
51
52         Version GetVersion() CXX11_OVERRIDE
53         {
54                 return Version("Provides random quotes on connect.", VF_VENDOR);
55         }
56 };
57
58 MODULE_INIT(ModuleRandQuote)