summaryrefslogtreecommitdiff
path: root/include/modules/global/service.h
blob: 01149d48e1b77c939ca6da805dc05637f2904418 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
 *
 * (C) 2011-2025 Anope Team
 * Contact us at team@anope.org
 *
 * Please read COPYING and README for further details.
 */

#pragma once

#define GLOBAL_NO_MESSAGE     _("You do not have any messages queued and did not specify a message to send.")
#define GLOBAL_QUEUE_CONFLICT _("You can not send a single message while you have messages queued.")

class GlobalService
	: public Service
{
public:
	GlobalService(Module *m)
		: Service(m, "GlobalService", "Global")
	{
	}

	/** Retrieves the bot which sends global messages unless otherwise specified. */
	virtual Reference<BotInfo> GetDefaultSender() const = 0;

	/** Clears any queued messages for the specified account.
	 * @param nc The account to clear queued messages for.
	 */
	virtual void ClearQueue(NickCore *nc) = 0;

	/** Retrieves the size of the messages queue for the specified user.
	 * @param nc The account to count queued messages for.
	 */
	inline size_t CountQueue(NickCore* nc) const
	{
		auto *q = GetQueue(nc);
		return q ? q->size() : 0;
	}

	/** Retrieves the messages queue for the specified user.
	 * @param nc The account to retrieve queued messages for.
	 */
	virtual const std::vector<Anope::string> *GetQueue(NickCore* nc) const = 0;

	/** Queues a message to be sent later.
	 * @param nc The account to queue the message for.
	 * @param message The message to queue.
	 * @return The new number of messages in the queue.
	 */
	virtual size_t Queue(NickCore *nc, const Anope::string &message) = 0;

	/** Sends a single message to all users on the network.
	 * @param message The message to send.
	 * @param source If non-nullptr then the source of the message.
	 * @param sender If non-nullptr then the bot to send the message from.
	 * @param server If non-nullptr then the server to send messages to.
	 * @return If the message was sent then true; otherwise, false.
	 */
	virtual bool SendSingle(const Anope::string &message, CommandSource *source = nullptr, BotInfo *sender = nullptr, Server *server = nullptr) = 0;

	/** Sends a message queue to all users on the network.
	 * @param source The source of the message.
	 * @param sender If non-nullptr then the bot to send the message from.
	 * @param server If non-nullptr then the server to send messages to.
	 * @return If the message queue was sent then true; otherwise, false.
	 */
	virtual bool SendQueue(CommandSource &source, BotInfo *sender = nullptr, Server *server = nullptr) = 0;

	/** Unqueues a message from the message queue.
	 * @param nc The account to unqueue the message from.
	 * @param idx The index of the item to remove.
	 * @return Whether the message was removed from the queue.
	 */
	virtual bool Unqueue(NickCore *nc, size_t idx) = 0;
};