diff --git a/aurora/commands/alliance.ts b/aurora/commands/alliance.ts index 5761c986..f536f28e 100644 --- a/aurora/commands/alliance.ts +++ b/aurora/commands/alliance.ts @@ -459,7 +459,7 @@ export default { ]}).then(m => setTimeout(() => m.delete(), 10000)).catch(() => {}) const formattedArgs = fn.argsHelper(args, 2) - const nationsToRemove = formattedArgs.asArray() + const nationsToRemove = formattedArgs.asArray() as any[] const allianceIndex = alliances.findIndex(a => a.allianceName.toLowerCase() == allianceName.toLowerCase()) if (!nationsToRemove) { @@ -467,7 +467,9 @@ export default { return } + console.log(nationsToRemove.toString()) const len = nationsToRemove.length + for (let i = 0; i < len; i++) { const cur = nationsToRemove[i] @@ -484,9 +486,9 @@ export default { }) ]}).then(m => setTimeout(() => m.delete(), 10000)).catch(() => {}) } - - const foundAllianceNations = foundAlliance.nations - const lower = cur.toLowerCase() + + const foundAllianceNations = foundAlliance.nations as any[] + const lower = cur?.toLowerCase() const foundNation = foundAllianceNations.find(nation => nation.toLowerCase() == lower) const foundNationIndex = foundAllianceNations.findIndex(nation => nation.toLowerCase() == lower) diff --git a/aurora/slashcommands/unsubscribe.ts b/aurora/slashcommands/unsubscribe.ts index 00f685bf..ad4695b0 100644 --- a/aurora/slashcommands/unsubscribe.ts +++ b/aurora/slashcommands/unsubscribe.ts @@ -8,11 +8,12 @@ import { import * as fn from '../../bot/utils/fn.js' -import admin from "firebase-admin" -const FieldValue = admin.firestore.FieldValue +import { + getFirestore, FieldValue, DocumentReference +} from "firebase-admin/firestore" async function unsub( - subbedChannels: admin.firestore.DocumentReference, + subbedChannels: DocumentReference, interaction: ChatInputCommandInteraction, subTypeName: string ) { @@ -88,7 +89,9 @@ export default { invalidUsage.setFooter(fn.devsFooter(client)) ], ephemeral: true}) - const subsCollection = admin.firestore().collection("subs") + const db = getFirestore() + + const subsCollection = db.collection("subs") unsub(subsCollection.doc(comparator), interaction, comparator) }, data: new SlashCommandBuilder().setName("unsubscribe") diff --git a/bot/objects/AllianceModal.ts b/bot/objects/AllianceModal.ts index 9bdfc53c..12a88110 100644 --- a/bot/objects/AllianceModal.ts +++ b/bot/objects/AllianceModal.ts @@ -1,12 +1,19 @@ -import Discord from 'discord.js' +import { + type CommandInteractionOptionResolver, + type ModalSubmitInteraction, + type ChatInputCommandInteraction, + ModalBuilder, ActionRowBuilder, + TextInputBuilder, TextInputStyle +} from 'discord.js' + import cache from 'memory-cache' -const ParagraphStyle = Discord.TextInputStyle.Paragraph +const ParagraphStyle = TextInputStyle.Paragraph const optionals = ['flag', 'discord', 'fill', 'outline', 'full_name'] -const optLower = (opts: Discord.CommandInteractionOptionResolver, k: string) => +const optLower = (opts: CommandInteractionOptionResolver, k: string) => opts.getString(k).toLowerCase() -const fieldVal = (interaction: Discord.ModalSubmitInteraction, name: string) => +const fieldVal = (interaction: ModalSubmitInteraction, name: string) => interaction.fields.getField(name).value type Alliance = { @@ -24,23 +31,22 @@ type Alliance = { } } -class AllianceModal extends Discord.ModalBuilder { +class AllianceModal extends ModalBuilder { rows = [] required = false alliance: Alliance = null - constructor(id, title, alliance = null) { + constructor(id: string, title: string, alliance = null) { super({ customId: id, title, components: [] }) this.alliance = alliance this.required = !alliance ? true : false } - createRow = (id, label, placeholder = null, style = Discord.TextInputStyle.Short) => { - if (optionals.includes(id)) this.required = false - else this.required = true + createRow = (id: string, label: string, placeholder: string = null, style = TextInputStyle.Short) => { + this.required = !optionals.includes(id) - const comp = new Discord.TextInputBuilder() + const comp = new TextInputBuilder() .setCustomId(id) .setLabel(label) .setStyle(style) @@ -51,10 +57,10 @@ class AllianceModal extends Discord.ModalBuilder { comp.setPlaceholder(str) } - return new Discord.ActionRowBuilder().addComponents(comp) + return new ActionRowBuilder().addComponents(comp) } - show = (interaction: Discord.ChatInputCommandInteraction) => { + show = (interaction: ChatInputCommandInteraction) => { console.log(`Showing creation wizard for ${this.alliance.name}`) const key = interaction.member.user.id @@ -64,10 +70,10 @@ class AllianceModal extends Discord.ModalBuilder { return interaction.showModal(this) } - main = (options: Discord.CommandInteractionOptionResolver) => { + main = (options: CommandInteractionOptionResolver) => { this.rows = [ - this.createRow('nations', 'List of Nations', this.alliance?.nations, ParagraphStyle), - this.createRow('leaders', 'Leader(s)', this.alliance?.leaders, ParagraphStyle), + this.createRow('nations', 'List of Nations', this.alliance?.nations.join(", "), ParagraphStyle), + this.createRow('leaders', 'Leader(s)', this.alliance?.leaders.join(", "), ParagraphStyle), this.createRow('flag', 'Flag Image Link (Optional)', this.alliance?.imageURL), this.createRow('discord', 'Discord Invite Link (Optional)', this.alliance?.discordInvite), this.createRow('full_name', 'Full Name (Optional)', this.alliance?.fullName) @@ -79,7 +85,7 @@ class AllianceModal extends Discord.ModalBuilder { return this } - asObject = (interaction: Discord.ModalSubmitInteraction ) => { + asObject = (interaction: ModalSubmitInteraction ) => { const obj: any = { mapName: this.alliance.map, allianceName: this.alliance.name, @@ -87,9 +93,9 @@ class AllianceModal extends Discord.ModalBuilder { leaders: fieldVal(interaction, 'leaders') } - const fullName = fieldVal(interaction, 'full_name'), - discord = fieldVal(interaction, 'discord'), - flag = fieldVal(interaction, 'flag') + const fullName = fieldVal(interaction, 'full_name') + const discord = fieldVal(interaction, 'discord') + const flag = fieldVal(interaction, 'flag') if (fullName) obj.fullName = fullName if (discord) obj.discord = discord diff --git a/bot/utils/aurora.ts b/bot/utils/aurora.ts index 36b2dcb2..52d942f9 100644 --- a/bot/utils/aurora.ts +++ b/bot/utils/aurora.ts @@ -150,7 +150,7 @@ async function getAlliance(name: string) { return foundAlliance } -async function getAlliances(skipCache = false) { +async function getAlliances(skipCache = false): Promise { const cached = cache.get('aurora_alliances') const skip = !skipCache ? cached : null