Skip to content

Commit

Permalink
style: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
eve0415 committed Nov 4, 2023
1 parent 95b3aba commit b48a0c1
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 33 deletions.
1 change: 1 addition & 0 deletions build.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import { join } from 'path';
import { cwd } from 'process';

import { build } from 'esbuild';

build({
Expand Down
72 changes: 39 additions & 33 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,49 @@
import { error, log } from 'console';
import { env, exit } from 'process';
import { Client, Partials, SnowflakeUtil, TextChannel } from 'discord.js';
import { DateTime, Interval } from 'luxon';
import { error, log } from "console";
import { env, exit } from "process";

import { Client, Partials, SnowflakeUtil, TextChannel } from "discord.js";
import { DateTime, Interval } from "luxon";

const { WATCH_CHANNEL } = env;

new Client({ intents: ['Guilds'], partials: [Partials.GuildMember] })
.on('ready', async client => {
const channel = await client.channels.fetch(`${WATCH_CHANNEL}`);
if (!channel) {
error('No channel found');
exit(1);
}
if (!(channel instanceof TextChannel)) {
error('Select TextChannel');
exit(1);
}
await new Client({ intents: ["Guilds"], partials: [Partials.GuildMember] })
.on("ready", async (client) => {
const channel = await client.channels.fetch(`${WATCH_CHANNEL}`);
if (!channel) {
error("No channel found");
exit(1);
}
if (!(channel instanceof TextChannel)) {
error("Select TextChannel");
exit(1);
}

log('I am ready to remove all messages!');
log("I am ready to remove all messages!");

task(channel).catch(error);
task(channel).catch(error);

setInterval(() => {
task(channel).catch(error);
}, 1000 * 60 * 60);
})
.login();
setInterval(() => {
task(channel).catch(error);
}, 1000 * 60 * 60);
})
.login();

async function task(channel: TextChannel) {
const messages = await channel.messages.fetch({
limit: 100,
cache: false,
before: SnowflakeUtil.generate({ timestamp: DateTime.now().setZone('Asia/Tokyo').minus({ hour: 23 }).toMillis() }).toString(),
const messages = await channel.messages.fetch({
limit: 100,
cache: false,
before: SnowflakeUtil.generate({
timestamp: DateTime.now()
.setZone("Asia/Tokyo")
.minus({ hour: 23 })
.toMillis(),
}).toString(),
});
messages
.filter((message) => !message.pinned)
.forEach((message) => {
setTimeout(() => {
message.delete().catch(console.error);
}, Interval.fromDateTimes(DateTime.now(), DateTime.fromJSDate(message.createdAt).plus({ day: 1 })).toDuration("millisecond").milliseconds);
});
messages
.filter(message => !message.pinned)
.forEach(message => {
setTimeout(() => {
message.delete().catch(console.error);
}, Interval.fromDateTimes(DateTime.now(), DateTime.fromJSDate(message.createdAt).plus({ day: 1 })).toDuration('millisecond').milliseconds);
});
}

0 comments on commit b48a0c1

Please sign in to comment.