リファクタとデザイン調整とresolve #1
This commit is contained in:
parent
41f40dd2c2
commit
219b15d9e6
17 changed files with 404 additions and 64 deletions
|
@ -5,24 +5,38 @@ import { Users } from '../models';
|
|||
import { api } from './misskey';
|
||||
import { format } from '../functions/format';
|
||||
import { deleteUser } from '../functions/users';
|
||||
import { updateScore } from '../functions/update-score';
|
||||
import { getScores } from '../functions/get-scores';
|
||||
|
||||
export default (): void => {
|
||||
cron.schedule('0 0 0 * * *', async () => {
|
||||
cron.schedule('50 45 0 * * *', async () => {
|
||||
const users = await Users.createQueryBuilder()
|
||||
.select()
|
||||
.getMany();
|
||||
for (const user of users) {
|
||||
try {
|
||||
const text = await format(user);
|
||||
|
||||
const res = await api<Record<string, unknown>>(user.host, 'notes/create', {
|
||||
text,
|
||||
visibility: 'home'
|
||||
}, user.token);
|
||||
if (res.error) {
|
||||
throw res.error;
|
||||
}
|
||||
await updateScore(user);
|
||||
const text = format(await getScores(user));
|
||||
|
||||
if (user.alertMode === 'note') {
|
||||
const res = await api<Record<string, unknown>>(user.host, 'notes/create', {
|
||||
text,
|
||||
visibility: 'specified'
|
||||
}, user.token);
|
||||
if (res.error) {
|
||||
throw res.error;
|
||||
}
|
||||
break;
|
||||
} else if (user.alertMode === '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;
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
if (e.code === 'NO_SUCH_USER' || e.code === 'AUTHENTICATION_FAILED') {
|
||||
// ユーザーが削除されている場合、レコードからも消してとりやめ
|
||||
|
@ -32,7 +46,8 @@ export default (): void => {
|
|||
console.error(e);
|
||||
}
|
||||
} finally {
|
||||
await delay(3000);
|
||||
if (user.alertMode === 'note')
|
||||
await delay(3000);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue