1
0
Fork 0
mirror of https://github.com/FrankerFaceZ/FrankerFaceZ.git synced 2025-06-28 15:27:43 +00:00

Cure cancer

This commit is contained in:
Fugiman 2015-08-09 23:32:29 -07:00
parent 96cc2ea787
commit 7b7af6169f
4 changed files with 287 additions and 10 deletions

140
script.js
View file

@ -2690,6 +2690,28 @@ var FFZ = window.FrankerFaceZ,
// Settings
// --------------------
FFZ.basic_settings.cure_cancer = {
type: "boolean",
category: "Chat",
name: "Cure Cancer",
help: "Destroys all cancerous chat messages before they can even be seen.",
get: function() {
return this.settings.remove_deleted &&
this.settings.remove_bot_ban_notices &&
+this.settings.chat_delay;
},
set: function(val) {
this.settings.set('remove_deleted', val);
this.settings.set('remove_bot_ban_notices', val);
this.settings.set('chat_delay', val ? ''+(+this.settings.chat_delay || 300) : '0');
}
};
FFZ.settings_info.minimal_chat = {
type: "boolean",
value: false,
@ -2730,6 +2752,28 @@ FFZ.settings_info.minimal_chat = {
};
FFZ.settings_info.chat_delay = {
type: "select",
options: {
0: "No Delay",
300: "Wait for bot auto-bans (300ms)",
1200: "Wait for human mods (1200ms)",
5000: " (5000ms)"
},
value: 0,
category: "Chat Appearance",
name: "Artificial Chat Delay",
help: "Delay messages allowing moderators to ban them before you see them.",
on_update: function (val) {
var delay_badge = document.querySelector('#ffz-stat-delay');
delay_badge.title = utils.number_commas(+val||300) + "ms of artifical chat delay added.";
delay_badge.classList.toggle('hidden', !+val);
}
};
FFZ.settings_info.remove_deleted = {
type: "boolean",
value: false,
@ -2777,6 +2821,16 @@ FFZ.settings_info.remove_deleted = {
};
FFZ.settings_info.remove_bot_ban_notices = {
type: "boolean",
value: false,
category: "Chat Filtering",
name: "Remove Bot Ban Notices",
help: "Remove messages from bots announcing who was banned for what reason and for how long.",
};
FFZ.settings_info.prevent_clear = {
type: "boolean",
value: false,
@ -5641,6 +5695,7 @@ FFZ.prototype._modify_rview = function(view) {
sub_badge = cont.querySelector('#ffz-stat-sub'),
slow_badge = cont.querySelector('#ffz-stat-slow'),
banned_badge = cont.querySelector('#ffz-stat-banned'),
delay_badge = cont.querySelector('#ffz-stat-delay'),
btn = cont.querySelector('button');
if ( f.has_bttv || ! f.settings.room_status ) {
@ -5696,11 +5751,23 @@ FFZ.prototype._modify_rview = function(view) {
jQuery(banned_badge).tipsy({gravity:"s", offset:15});
}
if ( ! delay_badge ) {
delay_badge = document.createElement('span');
delay_badge.className = 'ffz room-state stat float-right';
delay_badge.id = 'ffz-stat-delay';
delay_badge.innerHTML = 'DELAY';
delay_badge.title = "300ms of artifical chat delay added.";
cont.appendChild(delay_badge);
jQuery(delay_badge).tipsy({gravity:"s", offset:15});
}
r9k_badge.classList.toggle('hidden', !(room && room.get('r9k')));
sub_badge.classList.toggle('hidden', !(room && room.get('subsOnly')));
slow_badge.classList.toggle('hidden', !(room && room.get('slowMode')));
slow_badge.title = "This room is in slow mode. You may send messages every " + utils.number_commas(room && room.get('slow')||120) + " seconds.";
banned_badge.classList.toggle('hidden', !(room && room.get('ffz_banned')));
delay_badge.title = utils.number_commas(+f.settings.chat_delay||300) + "ms of artifical chat delay added.";
delay_badge.classList.toggle('hidden', !+f.settings.chat_delay);
if ( btn ) {
btn.classList.toggle('ffz-waiting', (room && room.get('slowWait') || 0));
@ -6338,6 +6405,7 @@ FFZ.prototype._modify_room = function(room) {
// Track which rooms the user is currently in.
init: function() {
this._super();
try {
f.add_room(this.id, this);
this.set("ffz_chatters", {});
@ -6348,6 +6416,7 @@ FFZ.prototype._modify_room = function(room) {
willDestroy: function() {
this._super();
try {
f.remove_room(this.id);
} catch(err) {
@ -6358,11 +6427,18 @@ FFZ.prototype._modify_room = function(room) {
clearMessages: function(user) {
var t = this;
if ( user ) {
if (!this.ffzRecentlyBanned)
this.ffzRecentlyBanned = [];
this.ffzRecentlyBanned.push(user);
while (this.ffzRecentlyBanned.length > 100)
this.ffzRecentlyBanned.shift();
var msgs = t.get('messages'),
total = msgs.get('length'),
i = total,
alternate;
// Delete visible messages
while(i--) {
var msg = msgs.get(i);
@ -6387,6 +6463,19 @@ FFZ.prototype._modify_room = function(room) {
}
}
// Delete pending messages
if (t.ffzPending) {
msgs = t.ffzPending;
i = msgs.length;
while(i--) {
var msg = msgs.get(i);
if ( msg.from !== user ) continue;
msg.ffz_deleted = true;
msg.deleted = !f.settings.prevent_clear;
msg.removed = f.settings.remove_deleted;
}
}
if ( f.settings.mod_card_history ) {
var room = f.rooms && f.rooms[t.get('id')],
user_history = room && room.user_history && room.user_history[user]
@ -6429,8 +6518,25 @@ FFZ.prototype._modify_room = function(room) {
messages.removeAt(0, len - limit);
},
// Artificial chat delay
pushMessage: function(msg) {
if ( this.shouldShowMessage(msg) ) {
if (+f.settings.chat_delay) {
if (!this.ffzPending)
this.ffzPending = [];
// uses black magic to ensure messages get flushed, but without a setInterval
if (!this.ffzPending.length)
setTimeout(this.ffzPendingFlush.bind(this), 100);
msg.time = Date.now();
this.ffzPending.push(msg);
} else {
this.ffzActualPushMessage(msg);
}
},
ffzActualPushMessage: function (msg) {
if ( this.shouldShowMessage(msg) && this.ffzShouldShowMessage(msg) ) {
this.get("messages").pushObject(msg);
this.trimMessages();
@ -6438,6 +6544,38 @@ FFZ.prototype._modify_room = function(room) {
}
},
ffzPendingFlush: function() {
var now = Date.now();
for (var i = 0, l = this.ffzPending.length; i < l; i++) {
var msg = this.ffzPending[i];
if (msg.removed) continue;
if (+f.settings.chat_delay + msg.time > now) break;
this.ffzActualPushMessage(msg);
}
this.ffzPending = this.ffzPending.slice(i);
// uses black magic to ensure messages get flushed, but without a setInterval
if (this.ffzPending.length)
setTimeout(this.ffzPendingFlush.bind(this), 100);
},
ffzShouldShowMessage: function (msg) {
if (f.settings.remove_bot_ban_notices && this.ffzRecentlyBanned) {
var banned = '(' + this.ffzRecentlyBanned.join('|') + ')';
var bots = {
'nightbot': '^' + banned,
'moobot': '\\(' + banned + '\\)',
'xanbot': '^' + banned,
};
if (msg.from in bots && (new RegExp(bots[msg.from])).test(msg.message)) {
return false;
}
}
return true;
},
addMessage: function(msg) {
if ( msg ) {
if ( ! f.settings.hosted_sub_notices && msg.style === 'notification' && HOSTED_SUB.test(msg.message) )