<commit_before>/*
 * Copyright (C) 2004-2010  See the AUTHORS file for details.
 *
 * 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.
 */

#include "Chan.h"
#include "Modules.h"
#include "User.h"

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

	void ClearAllBuffers() {
		const vector<CChan*>& vChans = GetUser()->GetChans();
		vector<CChan*>::const_iterator it;

		for (it = vChans.begin(); it != vChans.end(); ++it) {
			(*it)->ClearBuffer();
			// We force KeepBuffer on all channels since this module
			// doesnt make any sense without
			(*it)->SetKeepBuffer(true);
		}

	}

	virtual EModRet OnUserMsg(CString& sTarget, CString& sMessage) {
		ClearAllBuffers();
		return CONTINUE;
	}

	virtual EModRet OnUserCTCP(CString& sTarget, CString& sMessage) {
		ClearAllBuffers();
		return CONTINUE;
	}

	virtual EModRet OnUserAction(CString& sTarget, CString& sMessage) {
		ClearAllBuffers();
		return CONTINUE;
	}

	virtual EModRet OnUserNotice(CString& sTarget, CString& sMessage) {
		ClearAllBuffers();
		return CONTINUE;
	}

	virtual EModRet OnUserJoin(CString& sChannel, CString& sKey) {
		ClearAllBuffers();
		return CONTINUE;
	}

	virtual EModRet OnUserPart(CString& sChannel, CString& sMessage) {
		ClearAllBuffers();
		return CONTINUE;
	}

	virtual EModRet OnUserTopic(CString& sChannel, CString& sTopic) {
		ClearAllBuffers();
		return CONTINUE;
	}

	virtual void OnClientLogin() {
		ClearAllBuffers();
	}

	// No OnClientDisconnect(), disconnect could be coming from e.g. a timeout
};

MODULEDEFS(CClearBufferOnMsgMod, "Clear all channel buffers whenever the user does something")
<commit_msg>clearbufferonmsg: Skip detached chans<commit_after>/*
 * Copyright (C) 2004-2010  See the AUTHORS file for details.
 *
 * 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.
 */

#include "Chan.h"
#include "Modules.h"
#include "User.h"

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

	void ClearAllBuffers() {
		const vector<CChan*>& vChans = GetUser()->GetChans();
		vector<CChan*>::const_iterator it;

		for (it = vChans.begin(); it != vChans.end(); ++it) {
			// Skip detached channels, they weren't read yet
			if ((*it)->IsDetached())
				continue;

			(*it)->ClearBuffer();
			// We force KeepBuffer on all channels since this module
			// doesnt make any sense without
			(*it)->SetKeepBuffer(true);
		}

	}

	virtual EModRet OnUserMsg(CString& sTarget, CString& sMessage) {
		ClearAllBuffers();
		return CONTINUE;
	}

	virtual EModRet OnUserCTCP(CString& sTarget, CString& sMessage) {
		ClearAllBuffers();
		return CONTINUE;
	}

	virtual EModRet OnUserAction(CString& sTarget, CString& sMessage) {
		ClearAllBuffers();
		return CONTINUE;
	}

	virtual EModRet OnUserNotice(CString& sTarget, CString& sMessage) {
		ClearAllBuffers();
		return CONTINUE;
	}

	virtual EModRet OnUserJoin(CString& sChannel, CString& sKey) {
		ClearAllBuffers();
		return CONTINUE;
	}

	virtual EModRet OnUserPart(CString& sChannel, CString& sMessage) {
		ClearAllBuffers();
		return CONTINUE;
	}

	virtual EModRet OnUserTopic(CString& sChannel, CString& sTopic) {
		ClearAllBuffers();
		return CONTINUE;
	}

	virtual void OnClientLogin() {
		ClearAllBuffers();
	}

	// No OnClientDisconnect(), disconnect could be coming from e.g. a timeout
};

MODULEDEFS(CClearBufferOnMsgMod, "Clear all channel buffers whenever the user does something")

{'fraction_non_alphanumeric': 0.10960757780784844, 'fraction_numerical': 0.004871447902571042, 'mean_word_length': 4.541229385307346, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1864598', 'n_tokens_mistral': 1341, 'n_tokens_neox': 1221, 'n_words': 351}