-
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ef76232
commit 4a126bd
Showing
23 changed files
with
1,194 additions
and
705 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { EmbedBuilder, User } from "discord.js"; | ||
import { PermissionLevel } from "../../interfaces/commandData"; | ||
import Command from "../../internals/commandProcessor"; | ||
|
||
export default class AddCredit extends Command { | ||
async run(): Promise<void> { | ||
const userID = this.interaction.options.getString("user", true); | ||
|
||
let user: User; | ||
try { | ||
user = await this.client.getUser(userID); | ||
} catch { | ||
this.targetUserNotFound(); | ||
return; | ||
} | ||
|
||
const perms = await this.client.getPerms(userID); | ||
|
||
if (userID === this.client.user.id) { | ||
this.interaction.reply({ | ||
ephemeral: true, | ||
embeds: [this.client.errorEmbed("I am *the* VIP, don't forget that!")], | ||
}); | ||
return; | ||
} else if (user.bot) { | ||
this.interaction.reply({ | ||
ephemeral: true, | ||
embeds: [this.client.errorEmbed("Not sure, but I think it'll break stuff", { title: "Probably shouldn't do that." })], | ||
}); | ||
return; | ||
} | ||
|
||
let account = await this.fetchAccount(userID); | ||
const monthsToAdd = this.interaction.options.getInteger("months", true); | ||
|
||
if (monthsToAdd < 0 && (account.vipMonthsRemaining + monthsToAdd) < 0) { | ||
this.interaction.reply({ | ||
ephemeral: true, | ||
embeds: [this.client.errorEmbed("That would make this user a negative VIP!", { title: "Are you insane?", footer: { text: "User does not have enough months to remove this many" } })], | ||
}); | ||
return; | ||
} | ||
|
||
account = await this.db.accounts.update({ | ||
where: { | ||
id: account.id, | ||
}, | ||
data: { | ||
vipMonthsRemaining: account.vipMonthsRemaining + monthsToAdd, | ||
}, | ||
}); | ||
|
||
const monthsAdded = monthsToAdd > 0; | ||
const addedOrRemoved = monthsAdded ? "Added" : "Removed"; | ||
|
||
const embed = EmbedBuilder.from({ | ||
color: this.config.colors.vip, | ||
title: `${addedOrRemoved} VIP months!`, | ||
description: `${addedOrRemoved} ${monthsToAdd} month${monthsToAdd == 1 ? "" : "s"} ${monthsAdded ? "to" : "from"} <@${userID}> (${userID})`, | ||
footer: { | ||
icon_url: this.interaction.user.displayAvatarURL(), | ||
text: `${this.interaction.user.tag} (${this.interaction.user.id})`, | ||
}, | ||
}).setTimestamp(new Date()); | ||
|
||
if (this.interaction.channelId != this.config.supportGuild.channels.management) { | ||
this.client.sendCrossShard({ | ||
embeds: [embed], | ||
}, this.config.supportGuild.channels.management); | ||
} | ||
|
||
this.interaction.reply({ | ||
embeds: [embed], | ||
}); | ||
|
||
user.send({ | ||
embeds: [{ | ||
color: this.config.colors.vip, | ||
title: monthsAdded ? "💸 You're a real VIP!" : "VIP Update", | ||
description: `A support member has ${addedOrRemoved.toLowerCase()} ${Math.abs(monthsToAdd).toLocaleString()} VIP month${monthsToAdd == 1 ? "" : "s"} ${monthsAdded ? "to" : "from"} your account.\nYou now have ${account.vipMonthsRemaining} month${monthsToAdd == 1 ? "" : "s"} remaining.\nCall \`*411\` to spend your VIP months.`, | ||
footer: { | ||
text: "Thank you for supporting DTel!", | ||
}, | ||
}], | ||
}).catch(() => null); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import Command from "../../internals/commandProcessor"; | ||
import config from "../../config/config"; | ||
import { APIEmbed } from "discord.js"; | ||
import { Numbers, Phonebook, Prisma } from "@prisma/client"; | ||
import CallCommand from "./call"; | ||
|
||
export default class RCall extends Command { | ||
async run(): Promise<void> { | ||
await this.interaction.deferReply(); | ||
|
||
let toCall: Numbers | null = null; | ||
|
||
let cycle = 0; | ||
// Presume the Phonebook always has at least 1 number | ||
while (!toCall) { | ||
cycle++; | ||
if (cycle > 100) { | ||
this.interaction.editReply("❌ Couldn't find a number to call."); | ||
return; | ||
} | ||
|
||
const randomEntry = (await this.db.phonebook.aggregateRaw({ | ||
pipeline: [{ | ||
$match: { | ||
number: { | ||
$ne: this.number!.number, | ||
}, // Don't get this channel's number | ||
}, | ||
}, { | ||
$sample: { | ||
size: 1, | ||
}, | ||
}], | ||
}) as unknown as Prisma.JsonObject[])[0]; | ||
|
||
|
||
const number = await this.db.numbers.findUnique({ | ||
where: { | ||
number: randomEntry._id as string, | ||
}, | ||
include: { | ||
incomingCalls: { | ||
where: { | ||
active: true, | ||
}, | ||
}, | ||
outgoingCalls: { | ||
where: { | ||
active: true, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
// If this number doesn't exist then delete it's Yellowbook entry and try again. | ||
if (!number) { | ||
await this.db.phonebook.delete({ | ||
where: { | ||
number: randomEntry._id as string, | ||
}, | ||
}); | ||
continue; | ||
} | ||
|
||
// Number is in a call, try again | ||
if (number?.outgoingCalls.length > 0 || number.incomingCalls.length > 0) continue; | ||
|
||
const channel = await this.client.getChannel(number.channelID); | ||
if (!channel) { | ||
await this.db.phonebook.delete({ | ||
where: { | ||
number: number.number, | ||
}, | ||
}); | ||
continue; | ||
} | ||
|
||
console.log(number.channelID); | ||
if (number.expiry < new Date() || (this.number?.blocked && this.number.blocked.includes(number.number))) continue; | ||
|
||
toCall = number; | ||
} | ||
|
||
this.interaction.editReply("☎️ Found a number! Dialling..."); | ||
|
||
CallCommand.call(this.interaction, toCall.number, this.number!, true); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.