0
0
Fork 0
misskey-tools/src/services/send.ts
2020-09-16 00:39:47 +09:00

30 lines
No EOL
1,007 B
TypeScript

import { User } from '../models/entities/user';
import { format } from '../functions/format';
import { getScores } from '../functions/get-scores';
import { api } from './misskey';
export const send = async (user: User): Promise<void> => {
const text = format(await getScores(user));
if (user.alertMode === 'note') {
console.info(`send ${user.username}@${user.host}'s misshaialert as a note`);
const res = await api<Record<string, unknown>>(user.host, 'notes/create', {
text,
}, user.token);
if (res.error) {
throw res.error || res;
}
} else if (user.alertMode === 'notification') {
console.info(`send ${user.username}@${user.host}'s misshaialert as a notification`);
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;
}
} else {
console.info(`will not send ${user.username}@${user.host}'s misshaialert`);
}
};