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:47, 24 August 2012 by >Nero
(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.

Coded by User:Nero. Feel free to contact me.

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

Example

[18:45:04] >draggy< CTCP VERSION
[18:45:05] <*version> (notice) VERSION: fsb wee
[18:45:05] <draggy> (notice) VERSION irssi v0.8.15

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") { // If other Modueles are requesting a VERSION string
			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")