Skip to content

Instantly share code, notes, and snippets.

@kylef
Created September 19, 2011 15:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kylef/1226767 to your computer and use it in GitHub Desktop.
Save kylef/1226767 to your computer and use it in GitHub Desktop.
CraftIRC ZNC Module
#include "Modules.h"
#include "Chan.h"
class CCraftIRC : public CModule {
public:
MODCONSTRUCTOR(CCraftIRC) {
AddHelpCommand();
AddCommand("Alias", static_cast<CModCommand::ModCmdFunc>(&CCraftIRC::AliasCommand), "username [nick]");
AddCommand("Nick", static_cast<CModCommand::ModCmdFunc>(&CCraftIRC::NickCommand), "nick", "Set the nickname the CraftIRC bot uses.");
}
void AliasCommand(const CString& sLine) {
if (sLine.Token(2).empty()) {
DelNV(sLine.Token(1));
PutModule(sLine.Token(1) + " alias deleted.");
} else {
SetNV(sLine.Token(1), sLine.Token(2));
PutModule(sLine.Token(1) + " aliased to " + sLine.Token(2));
}
}
void NickCommand(const CString& sLine) {
SetNV("::NICK::", sLine.Token(1));
PutModule("CraftIRC nick has been set to " + sLine.Token(1));
}
~CCraftIRC() {}
virtual EModRet OnChanMsg(CNick& Nick, CChan& Channel, CString& sMessage) {
CString sNick = sMessage.Token(0);
if (Nick.GetNick().Equals(GetNV("::NICK::")) && sNick.Left(1).Equals("(") && sNick.Right(1).Equals(")")) {
sNick.Trim("()");
CNick *pNick = NULL;
if (!GetNV(sNick).empty()) {
pNick = Channel.FindNick(GetNV(sNick));
}
if (!pNick) {
pNick = Channel.FindNick(sNick);
}
if (pNick) {
PutUser(":" + pNick->GetNickMask() + " PRIVMSG " + Channel.GetName() + " :" + sMessage.Token(1, true));
return HALT;
}
}
return CONTINUE;
}
};
#ifndef NETWORKMODULEDEFS
#define NETWORKMODULEDEFS MODULEDEFS
#endif
NETWORKMODULEDEFS(CCraftIRC, "Craft IRC bot")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment