テスト送信
This commit is contained in:
parent
4ae971fe8d
commit
0f30337fc3
3 changed files with 86 additions and 62 deletions
|
@ -7,6 +7,7 @@ import { format } from '../functions/format';
|
|||
import { deleteUser } from '../functions/users';
|
||||
import { updateScore } from '../functions/update-score';
|
||||
import { getScores } from '../functions/get-scores';
|
||||
import { send } from './send';
|
||||
|
||||
export default (): void => {
|
||||
cron.schedule('0 0 0 * * *', async () => {
|
||||
|
@ -15,31 +16,7 @@ export default (): void => {
|
|||
.getMany();
|
||||
for (const user of users) {
|
||||
try {
|
||||
const text = format(await getScores(user));
|
||||
await updateScore(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;
|
||||
}
|
||||
break;
|
||||
} else if (user.alertMode === 'notification') {
|
||||
console.log(`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;
|
||||
}
|
||||
} else {
|
||||
console.info(`will not send ${user.username}@${user.host}'s misshaialert`);
|
||||
}
|
||||
await send(user);
|
||||
} catch (e) {
|
||||
if (e.code === 'NO_SUCH_USER' || e.code === 'AUTHENTICATION_FAILED') {
|
||||
// ユーザーが削除されている場合、レコードからも消してとりやめ
|
||||
|
@ -51,6 +28,7 @@ export default (): void => {
|
|||
} finally {
|
||||
if (user.alertMode === 'note')
|
||||
await delay(3000);
|
||||
await updateScore(user);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue