mirror of
https://github.com/FrankerFaceZ/FrankerFaceZ.git
synced 2025-06-27 21:05:53 +00:00
Merge branch 'master' into types
This commit is contained in:
commit
fed7d3e103
6 changed files with 101 additions and 3 deletions
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "frankerfacez",
|
"name": "frankerfacez",
|
||||||
"author": "Dan Salvato LLC",
|
"author": "Dan Salvato LLC",
|
||||||
"version": "4.60.0",
|
"version": "4.60.1",
|
||||||
"description": "FrankerFaceZ is a Twitch enhancement suite.",
|
"description": "FrankerFaceZ is a Twitch enhancement suite.",
|
||||||
"private": true,
|
"private": true,
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
|
|
|
@ -1268,6 +1268,11 @@ export default class Actions extends Module {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
addNotice(room, message) {
|
||||||
|
return this.resolve('site.chat').addNotice(room, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
sendMessage(room, message) {
|
sendMessage(room, message) {
|
||||||
return this.resolve('site.chat').sendMessage(room, message);
|
return this.resolve('site.chat').sendMessage(room, message);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
import { TranslatableError } from 'src/utilities/object';
|
||||||
import {createElement} from 'utilities/dom';
|
import {createElement} from 'utilities/dom';
|
||||||
|
|
||||||
|
|
||||||
|
@ -368,7 +369,11 @@ export const msg_delete = {
|
||||||
},
|
},
|
||||||
|
|
||||||
click(event, data) {
|
click(event, data) {
|
||||||
this.sendMessage(data.room.login, `/delete ${data.message_id}`);
|
const td = this.resolve('site.twitch_data');
|
||||||
|
return td.deleteChatMessage(data.room.id, data.message_id).catch(err => {
|
||||||
|
if ( err instanceof TranslatableError )
|
||||||
|
this.addNotice(data.room.login, this.i18n.t(err.i18n_key, err.message, err.data));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
16
src/utilities/mutations/delete-chat-message.gql
Normal file
16
src/utilities/mutations/delete-chat-message.gql
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
mutation FFZ_DeleteChatMessage($input: DeleteChatMessageInput!) {
|
||||||
|
deleteChatMessage(input: $input) {
|
||||||
|
responseCode
|
||||||
|
message {
|
||||||
|
id
|
||||||
|
sender {
|
||||||
|
id
|
||||||
|
login
|
||||||
|
displayName
|
||||||
|
}
|
||||||
|
content {
|
||||||
|
text
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -62,6 +62,33 @@ export function isValidShortcut(key: string) {
|
||||||
*/
|
*/
|
||||||
export const generateUUID = () => crypto.randomUUID();
|
export const generateUUID = () => crypto.randomUUID();
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An error that can be localized using the i18n module.
|
||||||
|
*/
|
||||||
|
export class TranslatableError extends Error {
|
||||||
|
|
||||||
|
i18n_key: string;
|
||||||
|
data: any;
|
||||||
|
|
||||||
|
constructor(message: string, key: string, data?: any) {
|
||||||
|
super(message);
|
||||||
|
this.i18n_key = key;
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
toString() {
|
||||||
|
const ffz = window.FrankerFaceZ?.get?.(),
|
||||||
|
i18n = ffz?.resolve?.('i18n');
|
||||||
|
|
||||||
|
if ( i18n && this.i18n_key )
|
||||||
|
return i18n.t(this.i18n_key, this.message, this.data);
|
||||||
|
|
||||||
|
return this.message;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a SHA-256 hash of a string. Uses {@link crypto.subtle.digest}
|
* Get a SHA-256 hash of a string. Uses {@link crypto.subtle.digest}
|
||||||
*
|
*
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
||||||
import Module from 'utilities/module';
|
import Module from 'utilities/module';
|
||||||
import {get, debounce} from 'utilities/object';
|
import {get, debounce, TranslatableError} from 'utilities/object';
|
||||||
|
|
||||||
const LANGUAGE_MATCHER = /^auto___lang_(\w+)$/;
|
const LANGUAGE_MATCHER = /^auto___lang_(\w+)$/;
|
||||||
|
|
||||||
|
@ -171,6 +171,51 @@ export default class TwitchData extends Module {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ========================================================================
|
||||||
|
// Chat
|
||||||
|
// ========================================================================
|
||||||
|
|
||||||
|
async deleteChatMessage(
|
||||||
|
channel_id/* :string*/,
|
||||||
|
message_id/* :string*/
|
||||||
|
) {
|
||||||
|
channel_id = String(channel_id);
|
||||||
|
|
||||||
|
const data = await this.mutate({
|
||||||
|
mutation: await import(/* webpackChunkName: 'queries' */ './mutations/delete-chat-message.gql'),
|
||||||
|
variables: {
|
||||||
|
input: {
|
||||||
|
channelID: channel_id,
|
||||||
|
messageID: message_id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const code = get('data.deleteChatMessage.responseCode', data);
|
||||||
|
|
||||||
|
if ( code === 'TARGET_IS_BROADCASTER' )
|
||||||
|
throw new TranslatableError(
|
||||||
|
"You cannot delete the broadcaster's messages.",
|
||||||
|
"chat.delete.forbidden.broadcaster"
|
||||||
|
);
|
||||||
|
|
||||||
|
if ( code === 'TARGET_IS_MODERATOR' )
|
||||||
|
throw new TranslatableError(
|
||||||
|
"You cannot delete messages from moderator {displayName}.",
|
||||||
|
"chat.delete.forbidden.moderator",
|
||||||
|
get('data.deleteChatMessage.message.sender', data)
|
||||||
|
);
|
||||||
|
|
||||||
|
if ( code !== 'SUCCESS' )
|
||||||
|
throw new TranslatableError(
|
||||||
|
"You don't have permission to delete messages.",
|
||||||
|
"chat.delete.forbidden"
|
||||||
|
);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// ========================================================================
|
// ========================================================================
|
||||||
// Users
|
// Users
|
||||||
// ========================================================================
|
// ========================================================================
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue