Skip to content

Commit

Permalink
Most of Mailbox implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
SunburntRock89 committed Oct 28, 2022
1 parent 1d3c5ec commit da24677
Show file tree
Hide file tree
Showing 22 changed files with 799 additions and 381 deletions.
737 changes: 402 additions & 335 deletions package-lock.json

Large diffs are not rendered by default.

28 changes: 14 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"test": "echo \"Error: we haven't set up testing yet.\" && exit 1",
"postinstall": "prisma generate",
"diagram": "prisma generate erd"
"diagram": "prisma generate erd"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -34,33 +34,33 @@
},
"dependencies": {
"@discoin/scambio": "^2.2.0",
"@prisma/client": "^4.4.0",
"bufferutil": "^4.0.6",
"dayjs": "^1.11.5",
"discord-api-types": "^0.37.11",
"discord.js": "^14.5.0",
"@prisma/client": "^4.5.0",
"bufferutil": "^4.0.7",
"dayjs": "^1.11.6",
"discord-api-types": "^0.37.15",
"discord.js": "^14.6.0",
"erlpack": "github:discordapp/erlpack",
"i18next": "^21.9.2",
"i18next": "^21.10.0",
"node-schedule": "^2.1.0",
"re2": "^1.17.7",
"url-regex-safe": "^3.0.0",
"utf-8-validate": "^5.0.9",
"utf-8-validate": "^5.0.10",
"uuid": "^9.0.0",
"winston": "^3.8.2",
"winston-daily-rotate-file": "^4.7.1",
"zlib-sync": "^0.1.7",
"zucc": "^0.1.2"
},
"devDependencies": {
"@mermaid-js/mermaid-cli": "^9.1.6",
"@mermaid-js/mermaid-cli": "^9.1.7",
"@tsconfig/node18": "^1.0.1",
"@types/node": "^18.7.23",
"@types/node": "^18.11.7",
"@types/uuid": "^8.3.4",
"@typescript-eslint/eslint-plugin": "^5.38.1",
"@typescript-eslint/parser": "^5.38.1",
"@typescript-eslint/eslint-plugin": "^5.41.0",
"@typescript-eslint/parser": "^5.41.0",
"cross-env": "^7.0.3",
"eslint": "^8.24.0",
"prisma": "^4.4.0",
"eslint": "^8.26.0",
"prisma": "^4.5.0",
"prisma-erd-generator": "^1.2.1",
"safe-regex": "^2.1.1",
"transformer": "^1.2.8",
Expand Down
25 changes: 23 additions & 2 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,25 @@ type numberVIP {
name String
}

type mailboxMessage {
id String
from String
message String
sent atAndBy
}

model Mailbox {
number String @id @map("_id")
autoreply String @default(value: "Sorry, I am currently unavailable. Please call again later.")
receiving Boolean @default(value: true)
messages mailboxMessage[]
numberDoc Numbers?
}

model Numbers {
number String @id @map("_id")
channelID String
Expand All @@ -35,12 +54,14 @@ model Numbers {
blocked String[]
contacts String[]
expiry DateTime
mentions String[]
mentions String[]
promote numberPromote?
vip numberVIP?
waiting Boolean @default(false)
createdAt DateTime @default(now())
mailbox Mailbox? @relation(fields: [number], references: [number])
outgoingCalls Calls[] @relation("to")
incomingCalls Calls[] @relation("from")
Expand All @@ -58,7 +79,7 @@ type atAndBy {
}

type onHold {
onHold Boolean
onHold Boolean
holdingSide String? // channel ID of holding side (maybe change this later)
}

Expand Down
9 changes: 5 additions & 4 deletions src/TODO
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
General:
logging everywhere (in the support guild)
Guild events if needed
611
Finish localization
411
** Rush Rollout ASAP **
Expand Down Expand Up @@ -36,9 +35,9 @@ upgrade
allow
backdoor
<!-- cinfo - standard command should be usable --- ensure tested -->
handover
<!-- handover - think we stopped using this -->

hold
<!-- hold - needs testing -->
<!-- ninfo - needs second page but otherwise complete -->
<!-- pay - please test -->
<!-- permcheck - superseded by red colour phone -->
Expand Down Expand Up @@ -76,4 +75,6 @@ stats
unvip

----- Pipe Dream -----
refactor command types to have their own specific classes, perhaps building in their own permission checking
refactor command types to have their own specific classes, perhaps building in their own permission checking
030x xxx xxxx formatting
i18next@latest
2 changes: 1 addition & 1 deletion src/commands/standard/call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export default class Call extends Command {

const embed = EmbedBuilder.from(this.t("twoThreeThree.baseEmbed", {
canAfford: this.account!.balance > 500 ? "canAfford" : "cantAfford",
}));
}) as APIEmbed);
embed
.setColor(isVIP ? this.config.colors.yellowbook : this.config.colors.info)
.setAuthor({
Expand Down
12 changes: 12 additions & 0 deletions src/commands/standard/convert.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Command from "../../internals/commandProcessor";
import discoin from "@discoin/scambio";

import auth from "../../config/auth";

const dClient = new discoin(auth.discoin.token, ["DTS"]);

export default class Convert extends Command {
async run(): Promise<void> {

}
}
30 changes: 30 additions & 0 deletions src/commands/standard/mailbox clear.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { ActionRowBuilder, ButtonBuilder, ButtonStyle } from "discord.js";
import Command from "../../internals/commandProcessor";

export default class MailboxClear extends Command {
async run(): Promise<void> {
const mailbox = await this.fetchMailbox();

if (mailbox.messages.length === 0) {
this.interaction.reply({
embeds: [this.client.errorEmbed("Your mailbox is already empty!")],
ephemeral: true,
});
return;
}

this.interaction.reply({
embeds: [this.client.warningEmbed("Are you sure you want to do this? Your messages cannot be recovered.")],
components: [
new ActionRowBuilder<ButtonBuilder>().addComponents([
new ButtonBuilder()
.setCustomId("mailbox-clear-confirm")
.setEmoji("👍")
.setLabel("Confirm")
.setStyle(ButtonStyle.Danger),
]),
],
ephemeral: true,
});
}
}
14 changes: 14 additions & 0 deletions src/commands/standard/mailbox messages.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { EmbedBuilder } from "discord.js";
import Command from "../../internals/commandProcessor";

export default class MailboxMessages extends Command {
async run(): Promise<void> {
const mailbox = await this.fetchMailbox();

const embed = new EmbedBuilder()
.setColor(this.config.colors.info)
.setTitle(`📬 You have ${mailbox.messages.length} messages.`);

if (mailbox.messages.length === 0) {}
}
}
37 changes: 37 additions & 0 deletions src/commands/standard/mailbox settings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { ActionRowBuilder } from "@discordjs/builders";
import { ModalBuilder, TextInputBuilder, TextInputStyle } from "discord.js";
import Command from "../../internals/commandProcessor";

export default class MailboxSettings extends Command {
async run(): Promise<void> {
const mailbox = await this.fetchMailbox();

const modal = new ModalBuilder()
.setCustomId("mailbox-settings-update")
.setTitle("Mailbox Settings")
.addComponents([
new ActionRowBuilder<TextInputBuilder>().addComponents([
new TextInputBuilder()
.setCustomId("autoreply")
.setValue(mailbox.autoreply)
.setLabel("Automatic Reply")
.setStyle(TextInputStyle.Short)
.setMinLength(0)
.setRequired(true),
]),
new ActionRowBuilder<TextInputBuilder>().addComponents([
new TextInputBuilder()
.setCustomId("active")
.setValue(mailbox.receiving ? "ON" : "OFF")
.setLabel("Message Receiving")
.setPlaceholder("ON/OFF")
.setRequired(true)
.setMinLength(2)
.setMaxLength(3)
.setStyle(TextInputStyle.Short),
]),
]);

this.interaction.showModal(modal);
}
}
34 changes: 34 additions & 0 deletions src/config/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,40 @@ const commands: Command[] = [
permissionLevel: PermissionLevel.none,
useType: CommandType.call,
},
{
name: "mailbox",
description: `Manage your store of messages.`,
options: [{
name: "clear",
description: "Clear all messages from mailbox",
type: ApplicationCommandOptionType.Subcommand,

permissionLevel: PermissionLevel.serverAdmin,
}, {
name: "messages",
description: "View all of the messages in your mailbox",
type: ApplicationCommandOptionType.Subcommand,

permissionLevel: PermissionLevel.none,
}, {
name: "remove",
description: "Remove a specific message from your mailbox",
type: ApplicationCommandOptionType.Subcommand,

permissionLevel: PermissionLevel.serverAdmin,
}, {
name: "settings",
description: "Change settings about your mailbox",
type: ApplicationCommandOptionType.Subcommand,

permissionLevel: PermissionLevel.serverAdmin,
}],

guildOnly: true,
numberRequired: true,
permissionLevel: PermissionLevel.none,
useType: CommandType.standard,
},
];

export default commands;
12 changes: 5 additions & 7 deletions src/events/interactionCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export default async(client: DTelClient, _interaction: Interaction): Promise<voi
case InteractionType.ModalSubmit: {
const typedInteraction = interaction as MessageComponentInteraction|ModalSubmitInteraction;

if (interaction.type === InteractionType.ModalSubmit && interaction.message?.interaction?.user.id != interaction.user.id) {
if (interaction.type === InteractionType.ModalSubmit && interaction.message?.interaction && interaction.message?.interaction?.user.id != interaction.user.id) {
interaction.reply(t("errors.wrongUser"));
return;
}
Expand Down Expand Up @@ -129,15 +129,13 @@ export default async(client: DTelClient, _interaction: Interaction): Promise<voi

toRunPath = `${__dirname}/../interactions/${commandName}`;

const subCommand = cmd.options?.find(o => o.type === ApplicationCommandOptionType.Subcommand) as SubcommandData | null;

if (subCommand) {
commandName = `${commandName} ${subCommand}`;
permissionLevel = subCommand.permissionLevel;
const subCommand = cmd.options?.filter(o => o.type === ApplicationCommandOptionType.Subcommand) as SubcommandData[];

if (subCommand.length > 0) {
commandName = `${split[0]} ${split[1]}`;
interactionName = split.slice(2, split.length).join("-");
interactionName = split[2];

permissionLevel = subCommand.find(c => c.name == split[1])?.permissionLevel || PermissionLevel.none;
toRunPath += `/${split[1]}`;
} else {
permissionLevel = commandData.permissionLevel;
Expand Down
22 changes: 22 additions & 0 deletions src/interactions/mailbox/clear/confirm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import ComponentProcessor from "../../../internals/componentProcessor";

export default class MailboxClearConfirm extends ComponentProcessor {
async run(): Promise<void> {
await this.db.mailbox.update({
where: {
number: this.number!.number,
},
data: {
messages: [],
},
});

this.interaction.reply({
embeds: [{
color: this.config.colors.success,
title: "📪 Cleared!",
description: "Your mailbox has been cleared.",
}],
});
}
}
25 changes: 25 additions & 0 deletions src/interactions/mailbox/send/initiate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { ModalBuilder, TextInputBuilder } from "@discordjs/builders";
import { ActionRowBuilder, TextInputStyle } from "discord.js";
import ComponentProcessor from "../../../internals/componentProcessor";

export default class MailboxSendInitiate extends ComponentProcessor {
async run(): Promise<void> {
const toSendNum = this.interaction.customId.replace("mailbox-send-initiate-", "");

const modal = new ModalBuilder()
.setTitle("Send a message")
.setCustomId(`mailbox-send-modal-${toSendNum}`)
.addComponents([
new ActionRowBuilder<TextInputBuilder>().addComponents([
new TextInputBuilder()
.setCustomId("message")
.setLabel("Message")
.setPlaceholder("Enter your message here")
.setStyle(TextInputStyle.Short)
.setRequired(true),
]),
]);

this.interaction.showModal(modal);
}
}
Loading

0 comments on commit da24677

Please sign in to comment.