0
0
Fork 0

コメント追加したり

This commit is contained in:
xeltica 2021-09-04 18:24:11 +09:00
parent 1c45e759c3
commit b9575d2c5b
22 changed files with 945 additions and 809 deletions

View file

@ -0,0 +1,55 @@
import { User } from '../models/entities/user';
import { format } from '../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;
}
};
/**
*
* @param text
* @param user
*/
const sendNoteAlert = async (text: string, user: User) => {
const res = await api<Record<string, unknown>>(user.host, 'notes/create', {
text,
visibility: user.visibility,
localOnly: user.localOnly,
remoteFollowersOnly: user.remoteFollowersOnly,
}, user.token);
if (res.error) {
throw res.error || res;
}
};
/**
*
* @param text
* @param user
*/
const sendNotificationAlert = async (text: string, user: User) => {
const res = await api(user.host, 'notifications/create', {
header: 'みす廃あらーと',
icon: 'https://i.imgur.com/B991yTl.png',
body: text,
}, user.token);
if (res.error) {
throw res.error || res;
}
};