emoji request

This commit is contained in:
mattyatea 2023-11-15 13:46:17 +09:00
parent d439dd66f9
commit 66bb2e15c8
1 changed files with 45 additions and 33 deletions

View File

@ -6,6 +6,7 @@ import { CustomEmojiService } from '@/core/CustomEmojiService.js';
import { ModerationLogService } from '@/core/ModerationLogService.js'; import { ModerationLogService } from '@/core/ModerationLogService.js';
import { ApiError } from '../../../error.js'; import { ApiError } from '../../../error.js';
import { MetaService } from '@/core/MetaService.js'; import { MetaService } from '@/core/MetaService.js';
import {DriveService} from "@/core/DriveService.js";
export const meta = { export const meta = {
tags: ['admin'], tags: ['admin'],
@ -53,11 +54,18 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
private metaService: MetaService, private metaService: MetaService,
private customEmojiService: CustomEmojiService, private customEmojiService: CustomEmojiService,
private moderationLogService: ModerationLogService, private moderationLogService: ModerationLogService,
private driveService: DriveService,
) { ) {
super(meta, paramDef, async (ps, me) => { super(meta, paramDef, async (ps, me) => {
const driveFile = await this.driveFilesRepository.findOneBy({ id: ps.fileId }); let driveFile;
let tmp = await this.driveFilesRepository.findOneBy({ id: ps.fileId });
if (tmp == null) throw new ApiError(meta.errors.noSuchFile);
if (driveFile == null) throw new ApiError(meta.errors.noSuchFile); try {
driveFile = await this.driveService.uploadFromUrl({ url: tmp.url , user: null, force: true });
} catch (e) {
throw new ApiError();
}
const emoji = await this.customEmojiService.add({ const emoji = await this.customEmojiService.add({
driveFile, driveFile,
@ -72,40 +80,44 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
roleIdsThatCanBeUsedThisEmojiAsReaction: [], roleIdsThatCanBeUsedThisEmojiAsReaction: [],
}); });
const {ApiBase,EmojiBotToken,DiscordWebhookUrl} = (await this.metaService.fetch()) const {ApiBase,EmojiBotToken,DiscordWebhookUrl} = (await this.metaService.fetch())
const data_disc = {"username": "絵文字追加通知ちゃん",
'content': if (EmojiBotToken){
'絵文字名 : :'+ ps.name +':\n' + const data_Miss = {
'カテゴリ : ' + ps.category + '\n'+ 'i': EmojiBotToken,
'ライセンス : '+ ps.license + '\n'+ 'text':
'タグ : '+ps.aliases+ '\n'+ '絵文字名 : :' + ps.name + ':\n' +
'追加したユーザー : ' + '@'+me.username + '\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)
})
} }
const data_Miss = { if (DiscordWebhookUrl){
'i': EmojiBotToken, const data_disc = {"username": "絵文字追加通知ちゃん",
'text': 'content':
'絵文字名 : :' + ps.name + ':\n' + '絵文字名 : :'+ ps.name +':\n' +
'カテゴリ : ' + ps.category + '\n' + 'カテゴリ : ' + ps.category + '\n'+
'ライセンス : ' + ps.license + '\n' + 'ライセンス : '+ ps.license + '\n'+
'タグ : ' + ps.aliases + '\n' + 'タグ : '+ps.aliases+ '\n'+
'追加したユーザー : ' + '@' + me.username + '\n' '追加したユーザー : ' + '@'+me.username + '\n'
}; }
await fetch(DiscordWebhookUrl, {
'method':'post',
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(data_disc),
})
}
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 { return {
id: emoji.id, id: emoji.id,