0
0
Fork 0
This commit is contained in:
Xeltica 2020-08-04 16:43:13 +09:00
parent a0f6dabbdf
commit f06fcc2056
17 changed files with 194 additions and 25 deletions

34
src/worker.ts Normal file
View file

@ -0,0 +1,34 @@
import cron from 'node-cron';
import { Users } from './models';
import { api } from './misskey';
import { format } from './format';
import { deleteUser } from './users';
export default (): void => {
cron.schedule('0 0 0 * * *', async () => {
const users = await Users.createQueryBuilder()
.select()
.getMany();
for (const user of users) {
try {
const text = await format(user);
const res = await api<any>(user.host, 'notes/create', {
text,
visibility: 'home'
}, user.token);
if (res.error) {
throw res.error;
}
} 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);
}
}
}
});
};