diff --git a/.gitignore b/.gitignore index a14702c..6f30be5 100644 --- a/.gitignore +++ b/.gitignore @@ -32,3 +32,5 @@ report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json # Finder (MacOS) folder config .DS_Store + +bump.json \ No newline at end of file diff --git a/env.d.ts b/env.d.ts index 1d0fe11..6da2bf8 100644 --- a/env.d.ts +++ b/env.d.ts @@ -6,5 +6,6 @@ module "bun" { GUILD: string; BAD_ROLE: string; BOT_ROLE: string; + BOT_CHANNEL: string; } } \ No newline at end of file diff --git a/src/events/messages.ts b/src/events/messages.ts index 5061753..821d7a8 100644 --- a/src/events/messages.ts +++ b/src/events/messages.ts @@ -1,6 +1,7 @@ -import { Discord, On, type ArgsOf } from "discordx"; +import { Client, Discord, On, type ArgsOf } from "discordx"; import { snipeObject } from ".."; import { sleep } from "../utils/underage"; +import { bumpRemind } from "../utils/bump"; @Discord() export class MessageEvents { @@ -10,14 +11,27 @@ export class MessageEvents { snipeObject.content = msg.content; } @On({ event: "messageCreate" }) - async messageCreate([msg]: ArgsOf<"messageCreate">) { + async messageCreate([msg]: ArgsOf<"messageCreate">, client: Client) { + if (msg.author.id == msg.client.user.id) return; + const linkRegex = /instagram\.com\/([^\s?]+)/; + if (linkRegex.test(msg.content)) { + let fixedLink = msg.content.match(linkRegex); + if (fixedLink) { + const linkMsg = fixedLink[0] + .replace("instagram.com/", "insta.ananas.moe/") + .replace("www.instagram.com/", "insta.ananas.moe/"); + await msg.channel.send("https://" + linkMsg); + await msg.suppressEmbeds(); + } + } if (msg.embeds.length > 0) { if (msg.embeds[0].description?.includes("Bump done!")) { await msg.channel.send( "thanks for bumping <3 I'll send a reminder in 2 hours :3", ); - await sleep(1000 * 60 * 120); - await msg.channel.send("it's time to bump again!"); + const f = Bun.file("bump.json"); + await f.write(JSON.stringify({ bump: Date.now() })); + bumpRemind(client); } } } diff --git a/src/events/ready.ts b/src/events/ready.ts index af05058..a37d6bf 100644 --- a/src/events/ready.ts +++ b/src/events/ready.ts @@ -1,5 +1,6 @@ import { Client, Discord, On, type ArgsOf } from "discordx"; import { underageCheck } from "../utils/underage"; +import { bumpRemind } from "../utils/bump"; @Discord() export class Ready { @@ -9,8 +10,12 @@ export class Ready { await client.initApplicationCommands(); await client.guilds.fetch(); const members = client.guilds.cache.get(Bun.env.GUILD!)?.members; - if (members) { - await underageCheck(members); + if (!(await Bun.file("bump.json").exists())) { + await Bun.write("bump.json", "{}"); } + if (members) { + underageCheck(members); + } + bumpRemind(client); } } diff --git a/src/utils/bump.ts b/src/utils/bump.ts new file mode 100644 index 0000000..a80ef0d --- /dev/null +++ b/src/utils/bump.ts @@ -0,0 +1,20 @@ +import type { Client } from "discordx"; +import type { TextChannel } from "discord.js"; +import { sleep } from "./underage"; + +export const bumpRemind = async (client: Client) => { + while (true) { + await sleep(5000); + const f = await Bun.file("bump.json").text(); + const data = JSON.parse(f); + if (data["bump"]) { + if (Date.now() - data["bump"] >= 60 * 120) { + const channel = client.channels.cache.get( + Bun.env.BOT_CHANNEL, + ) as TextChannel; + await channel.send("it's time to bump again!"); + return; + } + } + } +};