diff --git a/src/main.js b/src/main.js index 490d3538..1c2c2367 100644 --- a/src/main.js +++ b/src/main.js @@ -149,7 +149,7 @@ ${typeof x[1] === 'string' ? x[1] : JSON.stringify(x[1], null, 4)}` FrankerFaceZ.Logger = Logger; const VER = FrankerFaceZ.version_info = { - major: 4, minor: 0, revision: 0, extra: '-rc17', + major: 4, minor: 0, revision: 0, extra: '-rc18', commit: __git_commit__, build: __webpack_hash__, toString: () => diff --git a/src/modules/chat/actions/index.jsx b/src/modules/chat/actions/index.jsx index c0fcd622..a7b7de2d 100644 --- a/src/modules/chat/actions/index.jsx +++ b/src/modules/chat/actions/index.jsx @@ -6,12 +6,14 @@ import Module from 'utilities/module'; import {has, maybe_call, deep_copy} from 'utilities/object'; -import {ClickOutside} from 'utilities/dom'; +import {createElement, ClickOutside} from 'utilities/dom'; import Tooltip from 'utilities/tooltip'; import * as ACTIONS from './types'; import * as RENDERERS from './renderers'; +import { transformPhrase } from 'src/i18n'; +const VAR_REPLACE = /\{\{(.*?)(?:\|(.*?))?\}\}/g; export default class Actions extends Module { constructor(...args) { @@ -24,6 +26,25 @@ export default class Actions extends Module { this.actions = {}; this.renderers = {}; + this.settings.add('chat.actions.reasons', { + default: [ + {v: {text: 'One-Man Spam', i18n: 'chat.reasons.spam'}}, + {v: {text: 'Posting Bad Links', i18n: 'chat.reasons.links'}}, + {v: {text: 'Ban Evasion', i18n: 'chat.reasons.evasion'}}, + {v: {text: 'Threats / Personal Info', i18n: 'chat.reasons.personal'}}, + {v: {text: 'Hate / Harassment', i18n: 'chat.reasons.hate'}}, + {v: {text: 'Ignoring Broadcaster / Moderators', i18n: 'chat.reason.ignore'}} + ], + + type: 'array_merge', + always_inherit: true, + + ui: { + path: 'Chat > Actions > Reasons', + component: 'chat-reasons', + } + }); + this.settings.add('chat.actions.inline', { // Filter out actions process: (ctx, val) => @@ -42,7 +63,7 @@ export default class Actions extends Module { type: 'array_merge', ui: { - path: 'Chat > In-Line Actions @{"description": "Here, you can define custom actions that will appear along messages in chat. If you aren\'t seeing an action you\'ve defined here in chat, please make sure that you have enabled Mod Icons in the chat settings menu."}', + path: 'Chat > Actions > In-Line @{"description": "Here, you can define custom actions that will appear along messages in chat. If you aren\'t seeing an action you\'ve defined here in chat, please make sure that you have enabled Mod Icons in the chat settings menu."}', component: 'chat-actions', context: ['user', 'room', 'message'], inline: true, @@ -149,6 +170,79 @@ export default class Actions extends Module { } + replaceVariables(text, data) { + return transformPhrase( + text, + data, + this.i18n.locale, + VAR_REPLACE, + {} + ); + } + + + renderInlineReasons(data, t, tip) { + const reasons = this.parent.context.get('chat.actions.reasons'), + reason_elements = [], + room = this.parent.getRoom(data.room.id, data.room.login, true), + rules = room && room.rules; + + if ( ! reasons && ! rules ) { + tip.hide(); + return null; + } + + const click_fn = reason => e => { + tip.hide(); + data.definition.click.call(this, e, Object.assign({reason}, data)); + e.preventDefault(); + return false; + }; + + for(const reason of reasons) { + const text = this.replaceVariables(reason.i18n ? this.i18n.t(reason.i18n, reason.text) : reason.text, data); + + reason_elements.push(