diff --git a/src/commands/confess.ts b/src/commands/confess.ts new file mode 100644 index 0000000..055b922 --- /dev/null +++ b/src/commands/confess.ts @@ -0,0 +1,88 @@ +import { + ApplicationCommandOptionType, + Attachment, + Colors, + CommandInteraction, + EmbedBuilder, + MessageFlags, + TextChannel, +} from "discord.js"; +import { Discord, Slash, SlashOption } from "discordx"; +import db from "../db"; +import { confessTable } from "../db/schema"; +import { eq } from "drizzle-orm"; + +@Discord() +export class Confession { + @Slash({ name: "confess-setup", description: "setup confessions" }) + async confessSetup( + @SlashOption({ + name: "log_channel", + description: "channel to send logs", + required: true, + type: ApplicationCommandOptionType.Channel, + }) + channel: TextChannel, + inter: CommandInteraction, + ) { + if (inter.guild?.ownerId != inter.user.id) { + return inter.reply("you aren't the owner silly!"); + } + await db.insert(confessTable).values({ + guild: inter.guildId!, + channel: channel.id, + }); + await inter.reply("confess setup done!"); + } + @Slash({ + name: "confess", + description: "confessions are LOGGED for moderation purposes.", + }) + async confess( + @SlashOption({ + name: "message", + description: "message to confess", + required: true, + type: ApplicationCommandOptionType.String, + }) + message: string, + @SlashOption({ + name: "attachment", + description: "submit an image attachment with the message :3", + required: false, + type: ApplicationCommandOptionType.Attachment, + }) + attachment: Attachment, + inter: CommandInteraction, + ) { + const embed = new EmbedBuilder() + .setTitle("A Confession!") + .setDescription(message) + .setFooter({ text: "Confessions" }) + .setColor(Colors.DarkRed); + + const logEmbed = new EmbedBuilder() + .setTitle(`Confession Log from ${inter.user.username}`) + .setDescription(message) + .setFooter({ text: "Confession Log" }); + + if (attachment) { + embed.setImage(attachment.url); + logEmbed.setImage(attachment.url); + } + + const channelRes = await db + .select() + .from(confessTable) + .where(eq(confessTable.guild, inter.guildId!)); + const channel = inter.client.channels.cache.get( + channelRes[0].channel, + ) as TextChannel; + await (inter.channel as TextChannel).send({ embeds: [embed] }); + await inter.reply({ + content: "Confession Sent", + flags: MessageFlags.Ephemeral, + }); + await channel.send({ embeds: [logEmbed] }); + } +} diff --git a/src/commands/intro-setup.ts b/src/commands/intro-setup.ts index 9ae24a5..e9c8826 100644 --- a/src/commands/intro-setup.ts +++ b/src/commands/intro-setup.ts @@ -33,6 +33,9 @@ export class Intro { set: { channel: channel.id }, setWhere: sql`guild = ${inter.guildId}`, }); - await inter.reply({content: "intro setup done!", flags: MessageFlags.Ephemeral}); + await inter.reply({ + content: "intro setup done!", + flags: MessageFlags.Ephemeral, + }); } } diff --git a/src/db/migrations/0004_keen_bedlam.sql b/src/db/migrations/0004_keen_bedlam.sql new file mode 100644 index 0000000..3e70bdf --- /dev/null +++ b/src/db/migrations/0004_keen_bedlam.sql @@ -0,0 +1,4 @@ +CREATE TABLE `confess` ( + `guild` text PRIMARY KEY NOT NULL, + `channel` text NOT NULL +); diff --git a/src/db/migrations/meta/0004_snapshot.json b/src/db/migrations/meta/0004_snapshot.json new file mode 100644 index 0000000..3def8ff --- /dev/null +++ b/src/db/migrations/meta/0004_snapshot.json @@ -0,0 +1,214 @@ +{ + "version": "6", + "dialect": "sqlite", + "id": "dea3a962-3fb8-4c45-90fa-baff2f53bfb2", + "prevId": "fb3b9c6d-7d3b-4651-b230-e163bf08b586", + "tables": { + "bye": { + "name": "bye", + "columns": { + "guild": { + "name": "guild", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "channel": { + "name": "channel", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "message": { + "name": "message", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "colonthree": { + "name": "colonthree", + "columns": { + "user": { + "name": "user", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "amount": { + "name": "amount", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "messages_count": { + "name": "messages_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "confess": { + "name": "confess", + "columns": { + "guild": { + "name": "guild", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "channel": { + "name": "channel", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "greets": { + "name": "greets", + "columns": { + "guild": { + "name": "guild", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "channel": { + "name": "channel", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "message": { + "name": "message", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "intro": { + "name": "intro", + "columns": { + "guild": { + "name": "guild", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "channel": { + "name": "channel", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "tickets": { + "name": "tickets", + "columns": { + "user": { + "name": "user", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "channel": { + "name": "channel", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "uptime": { + "name": "uptime", + "columns": { + "guild": { + "name": "guild", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "channel": { + "name": "channel", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "message": { + "name": "message", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + } + }, + "views": {}, + "enums": {}, + "_meta": { + "schemas": {}, + "tables": {}, + "columns": {} + }, + "internal": { + "indexes": {} + } +} diff --git a/src/db/migrations/meta/_journal.json b/src/db/migrations/meta/_journal.json index 52d4282..867b728 100644 --- a/src/db/migrations/meta/_journal.json +++ b/src/db/migrations/meta/_journal.json @@ -29,6 +29,13 @@ "when": 1742927150677, "tag": "0003_clumsy_mephistopheles", "breakpoints": true + }, + { + "idx": 4, + "version": "6", + "when": 1744606507294, + "tag": "0004_keen_bedlam", + "breakpoints": true } ] } diff --git a/src/db/schema.ts b/src/db/schema.ts index 6018e62..f318505 100644 --- a/src/db/schema.ts +++ b/src/db/schema.ts @@ -36,4 +36,9 @@ export const introTable = sqliteTable("intro", { channel: text().notNull(), }); +export const confessTable = sqliteTable("confess", { + guild: text().primaryKey(), + channel: text().notNull(), +}); + export type ColonThreeType = InferSelectModel; diff --git a/src/events/members.ts b/src/events/members.ts index b448257..da80913 100644 --- a/src/events/members.ts +++ b/src/events/members.ts @@ -28,11 +28,16 @@ export class MemberEvents { await member.roles.add(botRole); } } else { - if(Date.now() - member.user.createdAt.getTime() < 1000 * 60 * 60 * 24 * 7) { + if ( + Date.now() - member.user.createdAt.getTime() < + 1000 * 60 * 60 * 24 * 7 + ) { try { - await member.send("to protect against raids, bots, and other disturbances, accounts under a week old are kicked upon joining. please wait for your account to mature before rejoining.") - } catch(_) {} - await member.kick("account less than week old") + await member.send( + "to protect against raids, bots, and other disturbances, accounts under a week old are kicked upon joining. please wait for your account to mature before rejoining.", + ); + } catch (_) {} + await member.kick("account less than week old"); return; } await db.insert(colonTable).values({ diff --git a/src/events/ready.ts b/src/events/ready.ts index 2c531ed..a4d5957 100644 --- a/src/events/ready.ts +++ b/src/events/ready.ts @@ -2,7 +2,6 @@ import { Client, Discord, On, type ArgsOf } from "discordx"; import { underageCheck } from "../utils/underage"; import { bumpRemind } from "../utils/bump"; import { uptimeLoop } from "../utils/uptime-loop"; -import { introCheck } from "../utils/intro-check"; @Discord() export class Ready { @@ -20,6 +19,6 @@ export class Ready { } bumpRemind(client); uptimeLoop(client); - introCheck(client); + //introCheck(client); } } diff --git a/src/utils/intro-check.ts b/src/utils/intro-check.ts index 6d8667e..e9f58ce 100644 --- a/src/utils/intro-check.ts +++ b/src/utils/intro-check.ts @@ -10,6 +10,7 @@ export const introCheck = async (client: Client) => { for (const c of channelRes) { const channel = client.channels.cache.get(c.channel) as TextChannel; const guild = client.guilds.cache.get(c.guild); + await guild?.fetch(); const msgs = await channel.messages.fetch({ limit: 10 }); for (const m of msgs) { if (!guild?.members.cache.has(m[1].author.id)) {