To create new wiki account, please join us on #znc at Libera.Chat and ask admins to create a wiki account for you. You can say thanks to spambots for this inconvenience.
Broadcast/Source: Difference between revisions
Jump to navigation
Jump to search
>Resistance Loaded source code from git repo specified on wiki page. |
>Efreak m Added github link. |
||
(2 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
This source is also available on [https://github.com/Efreak/ZNC-Modules/blob/master/broadcast.cpp GitHub]. | |||
<pre>/* | <pre>/* | ||
* Copyright (C) | * Copyright (C) 2010 Efreak. | ||
* | * | ||
* This program is free software; you can redistribute it and/or modify it | * 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 | * under the terms of the GNU General Public License version 2 as published | ||
* by the Free Software Foundation. | * by the Free Software Foundation. | ||
* | * | ||
* This | * 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 | |||
*/ | */ | ||
Line 71: | Line 74: | ||
}; | }; | ||
GLOBALMODULEDEFS(CBroadcastMod, "Broadcast with a prefix.");</pre> | GLOBALMODULEDEFS(CBroadcastMod, "Broadcast with a prefix. Version 0.01");</pre> | ||
[[Category:Modules/Code]] |
Latest revision as of 18:50, 31 August 2012
This source is also available on GitHub.
/* * 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");