wip: ログ
This commit is contained in:
parent
d4c3673315
commit
0c3df4245d
9 changed files with 133 additions and 19 deletions
|
@ -1,6 +1,26 @@
|
|||
import { User } from '../models/entities/user';
|
||||
import { toSignedString } from '../../common/functions/to-signed-string';
|
||||
import {Count} from '../models/count';
|
||||
import {api} from '../services/misskey';
|
||||
import {Score} from '../../common/types/score';
|
||||
import {MiUser} from './update-score';
|
||||
|
||||
/**
|
||||
* ユーザーのスコアを取得します。
|
||||
* @param user ユーザー
|
||||
* @returns ユーザーのスコア
|
||||
*/
|
||||
export const getScores = async (user: User): Promise<Score> => {
|
||||
// TODO 毎回取ってくるのも微妙なので、ある程度キャッシュしたいかも
|
||||
const miUser = await api<MiUser>(user.host, 'users/show', { username: user.username }, user.token);
|
||||
|
||||
return {
|
||||
notesCount: miUser.notesCount,
|
||||
followingCount: miUser.followingCount,
|
||||
followersCount: miUser.followersCount,
|
||||
...getDelta(user, miUser),
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* ユーザーのスコア差分を取得します。
|
||||
|
|
|
@ -9,7 +9,7 @@ const RETRY_COUNT = 5;
|
|||
/**
|
||||
* Misskey APIを呼び出す
|
||||
*/
|
||||
export const api = async <T = Record<string, unknown>>(host: string, endpoint: string, arg: Record<string, unknown>, token?: string): Promise<T> => {
|
||||
export const api = async <T extends Record<string, unknown> = Record<string, unknown>>(host: string, endpoint: string, arg: Record<string, unknown>, token?: string): Promise<T> => {
|
||||
const a = { ...arg };
|
||||
if (token) {
|
||||
a.i = token;
|
||||
|
|
|
@ -1,5 +1,30 @@
|
|||
import { User } from '../models/entities/user';
|
||||
import { api } from './misskey';
|
||||
import {format} from '../../common/functions/format';
|
||||
import {getScores} from '../functions/get-scores';
|
||||
|
||||
|
||||
/**
|
||||
* アラートを送信する
|
||||
* @param user ユーザー
|
||||
*/
|
||||
export const sendAlert = async (user: User) => {
|
||||
const text = format(user, await getScores(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;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* ノートアラートを送信する
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue