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.

Version

From ZNC
Revision as of 16:41, 24 August 2012 by >Nero (Created page with "{{External Module}} Stores CTCP Replies and compares them with older ones for recognizing Users on IRC == Usage == Just do an CTCP VERSION request on other Users, *version wil...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Stores CTCP Replies and compares them with older ones for recognizing Users on IRC

Usage

Just do an CTCP VERSION request on other Users, *version will add an notice if the reply is know from formerly requests.

Commands

  • get <name>

Gets the stored Version of an user (Case insensitive)

  • del <name>

Deletes above

  • clear

Deletes all

  • list <search term>

Searches for substring in List or Lists all

Sourcecode

/*
 * Fuck that Copyright shit. Here is your Code. Do what you want.
 * Made by Nero
 */

#include "User.h"
#include "Nick.h"

class CVersion : public CModule
{
public:
	MODCONSTRUCTOR(CVersion)
	{
	}

	virtual ~CVersion()
	{
	}

	virtual EModRet OnCTCPReply(CNick& Nick, CString& sMessage) {
		if (sMessage.Equals("VERSION", false, 7)) {
			SetNV(Nick.GetNick().AsLower(),sMessage);
			CString sNicks = "";
			for (MCString::iterator it = BeginNV(); it != EndNV(); ++it) {
				if ((it->second).AsLower() == sMessage.AsLower() && it->first != Nick.GetNick().AsLower()) 
				sNicks = sNicks + it->first + " ";
			}
			if (sNicks.size()>2) {
				PutModNotice("VERSION: " + sNicks);
			}
		}
		return CONTINUE;
	}

	virtual EModRet OnStatusCommand(CString& sCommand) {
		CString sCmdName = sCommand.Token(0).AsLower();
		if (sCmdName == "rdata") {
			CString sName = sCommand.Token(1).AsLower();
			sCommand = GetNV(sName);
			return HALT;
		}
		return CONTINUE;
	}


	virtual void OnModCommand(const CString& sCommand) {
		CString sCmdName = sCommand.Token(0).AsLower();
		CString sArg = sCommand.Token(1,true).AsLower();
		if (sCmdName == "del") {
			DelNV(sCommand.Token(1).AsLower());
			PutModule("Deleted " + sCommand.Token(1));
		} else if (sCmdName == "get") {
			PutModule(GetNV(sArg));
			PutModule("--- End of List");
		} else if (sCmdName == "clear") {
			int i = 0;
			for (MCString::iterator it = BeginNV(); it != EndNV(); ++it) {
				DelNV(it->first);
				i++;
			}
			PutModule(CString(i) + " entries deleted");
		} else if (sCmdName == "list") {
			for (MCString::iterator it = BeginNV(); it != EndNV(); ++it) {
				if ((it->second).AsLower().find(sArg) != CString::npos || sArg.empty())
				PutModule("\002" + it->first + "\002: " + it->second);
			}
			PutModule("--- End of List");
		} else {
			PutModule("Commands: del <name>, get <name>, list, clear");
		}
	}
};

MODULEDEFS(CVersion, "Stores VERSION-Replies")