From 4f6b0ccf6b7aeb64ec9ae7968f01e77808d2087d Mon Sep 17 00:00:00 2001 From: mattyatea Date: Thu, 19 Oct 2023 01:16:11 +0900 Subject: [PATCH] emoji --- .../1697641012204-DiscordWebhookUrl.js | 11 +++++ .../migration/1697642704514-EmojiBotToken.js | 11 +++++ .../migration/1697645425687-BaseUrl.js | 15 +++++++ packages/backend/src/models/Meta.ts | 15 +++++++ .../api/endpoints/admin/emoji/add-draft.ts | 41 +++++++++++++++++-- .../src/server/api/endpoints/admin/meta.ts | 7 ++++ .../server/api/endpoints/admin/update-meta.ts | 13 +++++- .../frontend/src/components/MkEmojiPicker.vue | 2 +- .../src/pages/admin/other-settings.vue | 23 ++++++++++- 9 files changed, 132 insertions(+), 6 deletions(-) create mode 100644 packages/backend/migration/1697641012204-DiscordWebhookUrl.js create mode 100644 packages/backend/migration/1697642704514-EmojiBotToken.js create mode 100644 packages/backend/migration/1697645425687-BaseUrl.js diff --git a/packages/backend/migration/1697641012204-DiscordWebhookUrl.js b/packages/backend/migration/1697641012204-DiscordWebhookUrl.js new file mode 100644 index 0000000000..bde713177d --- /dev/null +++ b/packages/backend/migration/1697641012204-DiscordWebhookUrl.js @@ -0,0 +1,11 @@ +export class DiscordWebhookUrl1697641012204 { + name = 'DiscordWebhookUrl1697641012204' + + async up(queryRunner) { + await queryRunner.query(`ALTER TABLE "meta" ADD "DiscordWebhookUrl" character varying(1024)`); + } + + async down(queryRunner) { + await queryRunner.query(`ALTER TABLE "meta" DROP COLUMN "DiscordWebhookUrl"`); + } +} diff --git a/packages/backend/migration/1697642704514-EmojiBotToken.js b/packages/backend/migration/1697642704514-EmojiBotToken.js new file mode 100644 index 0000000000..8e284ede41 --- /dev/null +++ b/packages/backend/migration/1697642704514-EmojiBotToken.js @@ -0,0 +1,11 @@ +export class EmojiBotToken1697642704514 { + name = 'EmojiBotToken1697642704514' + + async up(queryRunner) { + await queryRunner.query(`ALTER TABLE "meta" ADD "EmojiBotToken" character varying(1024)`); + } + + async down(queryRunner) { + await queryRunner.query(`ALTER TABLE "meta" DROP COLUMN "EmojiBotToken"`); + } +} diff --git a/packages/backend/migration/1697645425687-BaseUrl.js b/packages/backend/migration/1697645425687-BaseUrl.js new file mode 100644 index 0000000000..1d1020b1cf --- /dev/null +++ b/packages/backend/migration/1697645425687-BaseUrl.js @@ -0,0 +1,15 @@ +export class BaseUrl1697645425687 { + name = 'BaseUrl1697645425687' + + async up(queryRunner) { + await queryRunner.query(`ALTER TABLE "meta" ADD "ApiBase" character varying(1024)`); + await queryRunner.query(`ALTER TABLE "meta" ALTER COLUMN "preservedUsernames" SET DEFAULT '{ "admin", "administrator", "root", "system", "maintainer", "host", "mod", "moderator", "owner", "superuser", "staff", "auth", "i", "me", "everyone", "all", "mention", "mentions", "example", "user", "users", "account", "accounts", "official", "help", "helps", "support", "supports", "info", "information", "informations", "announce", "announces", "announcement", "announcements", "notice", "notification", "notifications", "dev", "developer", "developers", "tech", "misskey" }'`); + await queryRunner.query(`ALTER TABLE "flash" ALTER COLUMN "visibility" SET NOT NULL`); + } + + async down(queryRunner) { + await queryRunner.query(`ALTER TABLE "flash" ALTER COLUMN "visibility" DROP NOT NULL`); + await queryRunner.query(`ALTER TABLE "meta" ALTER COLUMN "preservedUsernames" SET DEFAULT '{admin,administrator,root,system,maintainer,host,mod,moderator,owner,superuser,staff,auth,i,me,everyone,all,mention,mentions,example,user,users,account,accounts,official,help,helps,support,supports,info,information,informations,announce,announces,announcement,announcements,notice,notification,notifications,dev,developer,developers,tech,misskey}'`); + await queryRunner.query(`ALTER TABLE "meta" DROP COLUMN "ApiBase"`); + } +} diff --git a/packages/backend/src/models/Meta.ts b/packages/backend/src/models/Meta.ts index 23ae513ede..babec97980 100644 --- a/packages/backend/src/models/Meta.ts +++ b/packages/backend/src/models/Meta.ts @@ -196,11 +196,26 @@ export class MiMeta { }) public enableRecaptcha: boolean; + @Column('varchar', { + length: 1024, + nullable: true, + }) + public DiscordWebhookUrl: string | null; + @Column('varchar', { + length: 1024, + nullable: true, + }) + public EmojiBotToken: string | null; @Column('varchar', { length: 1024, nullable: true, }) public recaptchaSiteKey: string | null; + @Column('varchar', { + length: 1024, + nullable: true, + }) + public ApiBase: string | null; @Column('varchar', { length: 1024, diff --git a/packages/backend/src/server/api/endpoints/admin/emoji/add-draft.ts b/packages/backend/src/server/api/endpoints/admin/emoji/add-draft.ts index 53f3f54941..aae6f6df39 100644 --- a/packages/backend/src/server/api/endpoints/admin/emoji/add-draft.ts +++ b/packages/backend/src/server/api/endpoints/admin/emoji/add-draft.ts @@ -5,7 +5,7 @@ import { DI } from '@/di-symbols.js'; import { CustomEmojiService } from '@/core/CustomEmojiService.js'; import { ModerationLogService } from '@/core/ModerationLogService.js'; import { ApiError } from '../../../error.js'; - +import { MetaService } from '@/core/MetaService.js'; export const meta = { tags: ['admin'], @@ -46,12 +46,12 @@ export const paramDef = { // eslint-disable-next-line import/no-default-export @Injectable() export default class extends Endpoint { + constructor( @Inject(DI.driveFilesRepository) private driveFilesRepository: DriveFilesRepository, - + private metaService: MetaService, private customEmojiService: CustomEmojiService, - private moderationLogService: ModerationLogService, ) { super(meta, paramDef, async (ps, me) => { @@ -71,6 +71,41 @@ export default class extends Endpoint { localOnly: ps.localOnly ?? false, roleIdsThatCanBeUsedThisEmojiAsReaction: [], }); + const {ApiBase,EmojiBotToken,DiscordWebhookUrl} = (await this.metaService.fetch()) + const data_disc = {"username": "絵文字追加通知ちゃん", + 'content': + '絵文字名 : :'+ ps.name +':\n' + + 'カテゴリ : ' + ps.category + '\n'+ + 'ライセンス : '+ ps.license + '\n'+ + 'タグ : '+ps.aliases+ '\n'+ + '追加したユーザー : ' + '@'+me.username + '\n' + } + + const data_Miss = { + 'i': EmojiBotToken, + 'text': + '絵文字名 : :' + ps.name + ':\n' + + 'カテゴリ : ' + ps.category + '\n' + + 'ライセンス : ' + ps.license + '\n' + + 'タグ : ' + ps.aliases + '\n' + + '追加したユーザー : ' + '@' + me.username + '\n' + }; + + await fetch(ApiBase+'/notes/create', { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body:JSON.stringify( data_Miss) + }) + + await fetch(DiscordWebhookUrl, { + 'method':'post', + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify(data_disc), + }) return { id: emoji.id, diff --git a/packages/backend/src/server/api/endpoints/admin/meta.ts b/packages/backend/src/server/api/endpoints/admin/meta.ts index f294934344..4b0d16b666 100644 --- a/packages/backend/src/server/api/endpoints/admin/meta.ts +++ b/packages/backend/src/server/api/endpoints/admin/meta.ts @@ -311,6 +311,10 @@ export const meta = { type: 'number', optional: false, nullable: false, }, + DiscordWebhookUrl: { + type: 'string', + optional: false, nullable: true, + }, }, }, } as const; @@ -424,6 +428,9 @@ export default class extends Endpoint { // eslint- perUserHomeTimelineCacheMax: instance.perUserHomeTimelineCacheMax, perUserListTimelineCacheMax: instance.perUserListTimelineCacheMax, notesPerOneAd: instance.notesPerOneAd, + DiscordWebhookUrl: instance.DiscordWebhookUrl, + EmojiBotToken: instance.EmojiBotToken, + ApiBase: instance.ApiBase }; }); } diff --git a/packages/backend/src/server/api/endpoints/admin/update-meta.ts b/packages/backend/src/server/api/endpoints/admin/update-meta.ts index f05819b186..adf6680d50 100644 --- a/packages/backend/src/server/api/endpoints/admin/update-meta.ts +++ b/packages/backend/src/server/api/endpoints/admin/update-meta.ts @@ -81,6 +81,7 @@ export const paramDef = { }, }, summalyProxy: { type: 'string', nullable: true }, + DiscordWebhookUrl:{ type: 'string', nullable: true}, deeplAuthKey: { type: 'string', nullable: true }, deeplIsPro: { type: 'boolean' }, enableEmail: { type: 'boolean' }, @@ -132,6 +133,8 @@ export const paramDef = { type: 'string', }, }, + EmojiBotToken:{ type: 'string', nullable: true}, + ApiBase:{ type: 'string',nullable:true} }, required: [], } as const; @@ -175,7 +178,15 @@ export default class extends Endpoint { // eslint- if (ps.themeColor !== undefined) { set.themeColor = ps.themeColor; } - + if (ps.DiscordWebhookUrl !== undefined){ + set.DiscordWebhookUrl = ps.DiscordWebhookUrl + } + if (ps.EmojiBotToken !== undefined){ + set.EmojiBotToken = ps.EmojiBotToken + } + if (ps.ApiBase !== undefined){ + set.ApiBase = ps.ApiBase + } if (ps.mascotImageUrl !== undefined) { set.mascotImageUrl = ps.mascotImageUrl; } diff --git a/packages/frontend/src/components/MkEmojiPicker.vue b/packages/frontend/src/components/MkEmojiPicker.vue index 9533463591..36a9e5c892 100644 --- a/packages/frontend/src/components/MkEmojiPicker.vue +++ b/packages/frontend/src/components/MkEmojiPicker.vue @@ -181,7 +181,7 @@ watch(q, () => { const searchCustom = () => { const max = 100; - const emojis = customEmojis.value.filter(emoji => !emoji.draft);; + const emojis = customEmojis.value.filter(emoji => !emoji.draft); const matches = new Set(); const exactMatch = emojis.find(emoji => emoji.name === newQ); diff --git a/packages/frontend/src/pages/admin/other-settings.vue b/packages/frontend/src/pages/admin/other-settings.vue index 7574c9d7d9..5cf90f49f9 100644 --- a/packages/frontend/src/pages/admin/other-settings.vue +++ b/packages/frontend/src/pages/admin/other-settings.vue @@ -36,6 +36,18 @@ SPDX-License-Identifier: AGPL-3.0-only + + + + + + + + + + + + @@ -51,18 +63,24 @@ import { fetchInstance } from '@/instance.js'; import { i18n } from '@/i18n.js'; import { definePageMetadata } from '@/scripts/page-metadata.js'; import MkSwitch from '@/components/MkSwitch.vue'; +import MkInput from "@/components/MkInput.vue"; let enableServerMachineStats: boolean = $ref(false); let enableIdenticonGeneration: boolean = $ref(false); let enableChartsForRemoteUser: boolean = $ref(false); let enableChartsForFederatedInstances: boolean = $ref(false); - +let DiscordWebhookUrl: string | null = $ref(null); +let EmojiBotToken: string | null = $ref(null); +let ApiBase:string | null = $ref(null) async function init() { const meta = await os.api('admin/meta'); enableServerMachineStats = meta.enableServerMachineStats; enableIdenticonGeneration = meta.enableIdenticonGeneration; enableChartsForRemoteUser = meta.enableChartsForRemoteUser; enableChartsForFederatedInstances = meta.enableChartsForFederatedInstances; + DiscordWebhookUrl = meta.DiscordWebhookUrl; + EmojiBotToken = meta.EmojiBotToken; + ApiBase = meta.ApiBase; } function save() { @@ -71,6 +89,9 @@ function save() { enableIdenticonGeneration, enableChartsForRemoteUser, enableChartsForFederatedInstances, + DiscordWebhookUrl, + EmojiBotToken, + ApiBase }).then(() => { fetchInstance(); });