parent
6cecc7bec7
commit
d2b3b4b9e7
13 changed files with 207 additions and 118 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue