forked from Efreak/ZNC-Modules
-
Notifications
You must be signed in to change notification settings - Fork 0
/
broadcast.cpp
75 lines (61 loc) · 2.22 KB
/
broadcast.cpp
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
/*
* Copyright (C) 2010 Efreak.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published
* by the Free Software Foundation.
*
* If any other changes are made, update the version number to the latest ZNC
* version to reflect it, please. This makes things easier to know what
* version it works with; If you want to contribute code, let me know via IRC
* and I'll add you as a contributor on GitHub.
* -Efreak
*/
#include "znc.h"
#include "User.h"
using std::map;
class CBroadcastMod : public CGlobalModule {
public:
GLOBALMODCONSTRUCTOR(CBroadcastMod) {}
virtual ~CBroadcastMod() {}
virtual bool OnLoad(const CString& sArgs, CString& sErrorMsg) {
if(!sArgs.empty())
bcprefix=sArgs + " "; //used for the broadcast prefix. Basically just grab all the arguments.
else bcprefix="ZNC Global Message: ";
return true;
}
virtual void OnModCommand(const CString& sLine) {
CString sCommand = sLine.Token(0).AsLower();
if (!GetUser()->IsAdmin()) { //so far all these commands are administrative.
PutModule("Access denied"); //maybe a module name change is in order.
return;
}
/*
* Broadcast
*/
if (sCommand == "global"||sCommand=="broadcast") {
CString message=bcprefix + sLine.Token(1,true);
CZNC::Get().Broadcast(message);
} else if (sCommand=="set") {
bcprefix=sLine.Token(1,true);
} else if (sCommand=="show"||sCommand=="set") {
PutModule("Prefix set to '" + bcprefix + "'.");
}
/*
* Help command (todo: implement token-based help)
*/
else {
//Broadcast
PutModule("Broadcast: This module includes a broadcast command that prefixes a word(s) to the beginning of the");
PutModule(" message. Prefix defaults to 'ZNC Global Message: ', and can be changed by the arguments.");
PutModule("Commands:");
PutModule(" broadcast - broadcast specified message with the set prefix");
PutModule(" set - set the prefix to the following text. May be replaced during a rehash or restart.");
PutModule(" show - show the current prefix.");
}
}
protected:
private:
CString bcprefix;
};
GLOBALMODULEDEFS(CBroadcastMod, "Broadcast with a prefix. Version 0.01");