Skip to content

Instantly share code, notes, and snippets.

@jamesbarnett
Last active March 12, 2020 07:17
Show Gist options
  • Save jamesbarnett/df311373375bdac3e6d923b2dd6183a8 to your computer and use it in GitHub Desktop.
Save jamesbarnett/df311373375bdac3e6d923b2dd6183a8 to your computer and use it in GitHub Desktop.
Filters out F-Bombs from e-chat
var lastWarningTimestamp = null;
var delayInterval = 15; // The interval in seconds
var languageViolationLedger = {};
var checkLastWarning = function(msg) {
console.log("lastWarningTimestamp: " + lastWarningTimestamp + ", Date.now() " + Date.now() / 1000);
if (Date.now() / 1000 - lastWarningTimestamp > delayInterval) {
CometdRoom.sendMessage(msg);
lastWarningTimestamp = Date.now() / 1000;
}
};
var fBombFilter = function(x) {
var message = x.data.messageBody.toUpperCase();
if (message.includes('FUCK')) {
CometdModerator.removeAccountMessages(x.data.userUuid);
checkLastWarning("Language please, " + x.data.username + ", no F-Bombs here.");
} else if (message.includes('NIGGER') || message.includes('NIGGA')) {
CometdModerator.removeAccountMessages(x.data.userUuid);
checkLastWarning("Language please, " + x.data.username + ", no N-words here.");
}
};
/*
* To stop this filter type into the console, $.cometd.removeListener(fBombFilterListener);
*/
var fBombFilterListener = $.cometd.addListener('/chatroom/message/add/*', fBombFilter);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment