anope- supernets anope source code & configuration |
git clone git://git.acid.vegas/anope.git |
Log | Files | Refs | Archive | README |
bots.h (4216B)
1 /* 2 * 3 * (C) 2008-2011 Robin Burchell <w00t@inspircd.org> 4 * (C) 2008-2022 Anope Team <team@anope.org> 5 * 6 * Please read COPYING and README for further details. 7 */ 8 9 #ifndef BOTS_H 10 #define BOTS_H 11 12 #include "users.h" 13 #include "anope.h" 14 #include "serialize.h" 15 #include "commands.h" 16 17 18 typedef Anope::map<BotInfo *> botinfo_map; 19 20 extern CoreExport Serialize::Checker<botinfo_map> BotListByNick, BotListByUID; 21 22 /* A service bot (NickServ, ChanServ, a BotServ bot, etc). */ 23 class CoreExport BotInfo : public User, public Serializable 24 { 25 /* Channels this bot is assigned to */ 26 Serialize::Checker<std::set<ChannelInfo *> > channels; 27 public: 28 time_t created; 29 /* Last time this bot said something (via privmsg) */ 30 time_t lastmsg; 31 /* Map of actual command names -> service name/permission required */ 32 CommandInfo::map commands; 33 /* Modes the bot should have as configured in service:modes */ 34 Anope::string botmodes; 35 /* Channels the bot should be in as configured in service:channels */ 36 std::vector<Anope::string> botchannels; 37 /* Whether or not this bot is introduced to the network */ 38 bool introduced; 39 /* Bot can only be assigned by irc ops */ 40 bool oper_only; 41 /* Bot is defined in the configuration file */ 42 bool conf; 43 44 /** Create a new bot. 45 * @param nick The nickname to assign to the bot. 46 * @param user The ident to give the bot. 47 * @param host The hostname to give the bot. 48 * @param real The realname to give the bot. 49 * @param bmodes The modes to give the bot. 50 */ 51 BotInfo(const Anope::string &nick, const Anope::string &user = "", const Anope::string &host = "", const Anope::string &real = "", const Anope::string &bmodes = ""); 52 53 /** Destroy a bot, clearing up appropriately. 54 */ 55 virtual ~BotInfo(); 56 57 void Serialize(Serialize::Data &data) const; 58 static Serializable* Unserialize(Serializable *obj, Serialize::Data &); 59 60 void GenerateUID(); 61 62 void OnKill(); 63 64 /** Change the nickname for the bot. 65 * @param newnick The nick to change to 66 */ 67 void SetNewNick(const Anope::string &newnick); 68 69 /** Return the channels this bot is assigned to 70 */ 71 const std::set<ChannelInfo *> &GetChannels() const; 72 73 /** Assign this bot to a given channel, removing the existing assigned bot if one exists. 74 * @param u The user assigning the bot, or NULL 75 * @param ci The channel registration to assign the bot to. 76 */ 77 void Assign(User *u, ChannelInfo *ci); 78 79 /** Remove this bot from a given channel. 80 * @param u The user requesting the unassign, or NULL. 81 * @param ci The channel registration to remove the bot from. 82 */ 83 void UnAssign(User *u, ChannelInfo *ci); 84 85 /** Get the number of channels this bot is assigned to 86 */ 87 unsigned GetChannelCount() const; 88 89 /** Join this bot to a channel 90 * @param c The channel 91 * @param status The status the bot should have on the channel 92 */ 93 void Join(Channel *c, ChannelStatus *status = NULL); 94 95 /** Join this bot to a channel 96 * @param chname The channel name 97 * @param status The status the bot should have on the channel 98 */ 99 void Join(const Anope::string &chname, ChannelStatus *status = NULL); 100 101 /** Part this bot from a channel 102 * @param c The channel 103 * @param reason The reason we're parting 104 */ 105 void Part(Channel *c, const Anope::string &reason = ""); 106 107 /** Called when a user messages this bot 108 * @param u The user 109 * @param message The users' message 110 */ 111 virtual void OnMessage(User *u, const Anope::string &message); 112 113 /** Link a command name to a command in services 114 * @param cname The command name 115 * @param sname The service name 116 * @param permission Permission required to execute the command, if any 117 * @return The commandinfo for the newly created command 118 */ 119 CommandInfo& SetCommand(const Anope::string &cname, const Anope::string &sname, const Anope::string &permission = ""); 120 121 /** Get command info for a command 122 * @param cname The command name 123 * @return A struct containing service name and permission 124 */ 125 CommandInfo *GetCommand(const Anope::string &cname); 126 127 /** Find a bot by nick 128 * @param nick The nick 129 * @param nick_only True to only look by nick, and not by UID 130 * @return The bot, if it exists 131 */ 132 static BotInfo* Find(const Anope::string &nick, bool nick_only = false); 133 }; 134 135 #endif // BOTS_H