0
0
Fork 0

アラート機能の全面的な書き直し

close #67
This commit is contained in:
Xeltica 2023-02-23 19:37:10 +09:00
parent 6cecc7bec7
commit d2b3b4b9e7
13 changed files with 207 additions and 118 deletions

View file

@ -1,36 +1,12 @@
import { User } from '../models/entities/user';
import { format } from '../../common/functions/format';
import { getScores } from '../functions/get-scores';
import { api } from './misskey';
/**
*
* @param user
*/
export const sendAlert = async (user: User) => {
const text = format(await getScores(user), user);
switch (user.alertMode) {
case 'note':
await sendNoteAlert(text, user);
break;
case 'notification':
await sendNotificationAlert(text, user);
break;
case 'both':
await Promise.all([
sendNotificationAlert(text, user),
sendNoteAlert(text, user),
]);
break;
}
};
/**
*
* @param text
* @param user
*/
const sendNoteAlert = async (text: string, user: User) => {
export const sendNoteAlert = async (text: string, user: User) => {
const res = await api<Record<string, unknown>>(user.host, 'notes/create', {
text,
visibility: user.visibility,
@ -48,9 +24,9 @@ const sendNoteAlert = async (text: string, user: User) => {
* @param text
* @param user
*/
const sendNotificationAlert = async (text: string, user: User) => {
export const sendNotificationAlert = async (text: string, user: User) => {
const res = await api(user.host, 'notifications/create', {
header: 'みす廃あらーと',
header: 'Misskey Tools',
icon: 'https://i.imgur.com/B991yTl.png',
body: text,
}, user.token);