0
0
Fork 0
This commit is contained in:
Xeltica 2021-01-30 01:48:00 +09:00
parent 2e253f52bc
commit 2b71549feb
7 changed files with 90 additions and 44 deletions

View file

@ -9,32 +9,44 @@ import { AlertMode } from '../types/AlertMode';
import { Users } from '../models';
import { send } from './send';
import { api } from './misskey';
import * as Store from '../store';
export default (): void => {
cron.schedule('0 0 0 * * *', async () => {
Store.dispatch({
nowCalculating: true,
});
const users = await Users.find({
alertMode: Not<AlertMode>('nothing'),
});
for (const user of users) {
const miUser = await api<MiUser & { error: unknown }>(user.host, 'users/show', { username: user.username }, user.token);
try {
const miUser = await api<MiUser & { error: unknown }>(user.host, 'users/show', { username: user.username }, user.token);
if (miUser.error) throw miUser.error;
await updateRating(user, miUser);
await send(user);
} catch (e) {
if (e.code === 'NO_SUCH_USER' || e.code === 'AUTHENTICATION_FAILED') {
// ユーザーが削除されている場合、レコードからも消してとりやめ
console.info(`${user.username}@${user.host} is deleted, so delete this user from the system`);
await deleteUser(user.username, user.host);
} else {
console.error(`${e.name}: ${e.message}`);
}
} finally {
await updateScore(user, miUser);
if (user.alertMode === 'note')
await delay(3000);
await updateScore(user, miUser);
} catch (e) {
if (e.code) {
if (e.code === 'NO_SUCH_USER' || e.code === 'AUTHENTICATION_FAILED') {
// ユーザーが削除されている場合、レコードからも消してとりやめ
console.info(`${user.username}@${user.host} is deleted, so delete this user from the system`);
await deleteUser(user.username, user.host);
} else {
console.error(`Misskey Error: ${JSON.stringify(e)}`);
}
} else {
// おそらく通信エラー
console.error(`Unknown error: ${e.name} ${e.message}`);
}
}
}
Store.dispatch({
nowCalculating: false,
});
});
};