summaryrefslogtreecommitdiff
path: root/include/bots.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/bots.h')
-rw-r--r--include/bots.h118
1 files changed, 85 insertions, 33 deletions
diff --git a/include/bots.h b/include/bots.h
index 711e2b78e..ca2f5f64f 100644
--- a/include/bots.h
+++ b/include/bots.h
@@ -1,45 +1,44 @@
/*
+ * Anope IRC Services
*
- * (C) 2008-2011 Robin Burchell <w00t@inspircd.org>
- * (C) 2008-2017 Anope Team <team@anope.org>
+ * Copyright (C) 2008-2011 Robin Burchell <w00t@inspircd.org>
+ * Copyright (C) 2008-2017 Anope Team <team@anope.org>
*
- * Please read COPYING and README for further details.
+ * This file is part of Anope. Anope is free software; you can
+ * redistribute it and/or modify it under the terms of the GNU
+ * General Public License as published by the Free Software
+ * Foundation, version 2.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see see <http://www.gnu.org/licenses/>.
*/
-#ifndef BOTS_H
-#define BOTS_H
+#pragma once
#include "users.h"
#include "anope.h"
#include "serialize.h"
#include "commands.h"
-
-
-typedef Anope::map<BotInfo *> botinfo_map;
-
-extern CoreExport Serialize::Checker<botinfo_map> BotListByNick, BotListByUID;
+#include "config.h"
/* A service bot (NickServ, ChanServ, a BotServ bot, etc). */
-class CoreExport BotInfo : public User, public Serializable
+class CoreExport ServiceBot : public LocalUser
{
- /* Channels this bot is assigned to */
- Serialize::Checker<std::set<ChannelInfo *> > channels;
public:
- time_t created;
- /* Last time this bot said something (via privmsg) */
- time_t lastmsg;
+ /* Underlying botinfo for this bot */
+ Serialize::Reference<BotInfo> bi;
/* Map of actual command names -> service name/permission required */
CommandInfo::map commands;
/* Modes the bot should have as configured in service:modes */
Anope::string botmodes;
- /* Channels the bot should be in as configured in service:channels */
- std::vector<Anope::string> botchannels;
/* Whether or not this bot is introduced to the network */
- bool introduced;
- /* Bot can only be assigned by irc ops */
- bool oper_only;
- /* Bot is defined in the configuration file */
- bool conf;
+ bool introduced = false;
+ Logger logger;
/** Create a new bot.
* @param nick The nickname to assign to the bot.
@@ -48,14 +47,11 @@ class CoreExport BotInfo : public User, public Serializable
* @param real The realname to give the bot.
* @param bmodes The modes to give the bot.
*/
- BotInfo(const Anope::string &nick, const Anope::string &user = "", const Anope::string &host = "", const Anope::string &real = "", const Anope::string &bmodes = "");
+ ServiceBot(const Anope::string &nick, const Anope::string &user = "", const Anope::string &host = "", const Anope::string &real = "", const Anope::string &bmodes = "");
/** Destroy a bot, clearing up appropriately.
*/
- virtual ~BotInfo();
-
- void Serialize(Serialize::Data &data) const;
- static Serializable* Unserialize(Serializable *obj, Serialize::Data &);
+ virtual ~ServiceBot();
void GenerateUID();
@@ -68,19 +64,19 @@ class CoreExport BotInfo : public User, public Serializable
/** Return the channels this bot is assigned to
*/
- const std::set<ChannelInfo *> &GetChannels() const;
+ std::vector<ChanServ::Channel *> GetChannels() const;
/** Assign this bot to a given channel, removing the existing assigned bot if one exists.
* @param u The user assigning the bot, or NULL
* @param ci The channel registration to assign the bot to.
*/
- void Assign(User *u, ChannelInfo *ci);
+ void Assign(User *u, ChanServ::Channel *ci);
/** Remove this bot from a given channel.
* @param u The user requesting the unassign, or NULL.
* @param ci The channel registration to remove the bot from.
*/
- void UnAssign(User *u, ChannelInfo *ci);
+ void UnAssign(User *u, ChanServ::Channel *ci);
/** Get the number of channels this bot is assigned to
*/
@@ -124,12 +120,68 @@ class CoreExport BotInfo : public User, public Serializable
*/
CommandInfo *GetCommand(const Anope::string &cname);
+ CommandInfo *FindCommand(const Anope::string &service);
+
/** Find a bot by nick
* @param nick The nick
* @param nick_only True to only look by nick, and not by UID
* @return The bot, if it exists
*/
- static BotInfo* Find(const Anope::string &nick, bool nick_only = false);
+ static ServiceBot* Find(const Anope::string &nick, bool nick_only = false);
+};
+
+class BotInfo : public Serialize::Object
+{
+ friend class BotInfoType;
+
+ Serialize::Storage<Anope::string> nick, user, host, realname;
+ Serialize::Storage<time_t> created;
+ Serialize::Storage<bool> operonly;
+
+ public:
+ static constexpr const char *const NAME = "botinfo";
+
+ ServiceBot *bot = nullptr;
+ Configuration::Block *conf = nullptr;
+
+ using Serialize::Object::Object;
+
+ void Delete() override;
+
+ void SetNick(const Anope::string &);
+ Anope::string GetNick();
+
+ void SetUser(const Anope::string &);
+ Anope::string GetUser();
+
+ void SetHost(const Anope::string &);
+ Anope::string GetHost();
+
+ void SetRealName(const Anope::string &);
+ Anope::string GetRealName();
+
+ void SetCreated(const time_t &);
+ time_t GetCreated();
+
+ void SetOperOnly(const bool &);
+ bool GetOperOnly();
+};
+
+class BotInfoType : public Serialize::Type<BotInfo>
+{
+ public:
+ Serialize::Field<BotInfo, Anope::string> nick, user, host, realname;
+ Serialize::Field<BotInfo, time_t> created;
+ Serialize::Field<BotInfo, bool> operonly;
+
+ BotInfoType() : Serialize::Type<BotInfo>(nullptr)
+ , nick(this, "nick", &BotInfo::nick)
+ , user(this, "user", &BotInfo::user)
+ , host(this, "host", &BotInfo::host)
+ , realname(this, "realname", &BotInfo::realname)
+ , created(this, "created", &BotInfo::created)
+ , operonly(this, "operonly", &BotInfo::operonly)
+ {
+ }
};
-#endif // BOTS_H