-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: rework hub management as modal doesn't support SelectMenu anymor…
…e (sadge)
- Loading branch information
Showing
6 changed files
with
402 additions
and
100 deletions.
There are no files selected for viewing
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,113 @@ | ||
'use strict'; | ||
|
||
const { MessageMentions : { ChannelsPattern }, channelMention } = require('discord.js'); | ||
|
||
const { Interaction, Util } = require('../../../core'); | ||
|
||
class Hub extends Interaction { | ||
|
||
constructor() { | ||
|
||
super('hub', { category : 'voice' }); | ||
} | ||
|
||
static get interactions() { | ||
|
||
return { | ||
editDefaultSize : { method : 'editDefaultSize', customId : 'voice:hub:edit_default_size' }, | ||
|
||
setDefaultSize : { method : 'setDefaultSize', customId : 'voice:hub:set_default_size' }, | ||
setDefaultType : { method : 'setDefaultType', customId : 'voice:hub:set_default_type' } | ||
}; | ||
} | ||
|
||
/** | ||
* @param {import('discord.js').MessageComponentInteraction} interaction | ||
* @param {function(hub : Hub) : Promise<Hub|null>} handler | ||
*/ | ||
async handle(interaction, handler) { | ||
|
||
const { HubService } = this.services(); | ||
|
||
if (!interaction.guildId) { | ||
|
||
return null; | ||
} | ||
|
||
const hubId = interaction.message.content.match(ChannelsPattern)?.groups?.id; | ||
|
||
if (!hubId) { | ||
|
||
return; | ||
} | ||
|
||
let hub = await HubService.getHub(interaction.guildId, hubId); | ||
|
||
if (!hub) { | ||
|
||
return; | ||
} | ||
|
||
hub = await handler(hub); | ||
|
||
if (hub) { | ||
|
||
await HubService.update(hub); | ||
setTimeout(() => interaction.deleteReply(), Util.SECOND * 5); | ||
} | ||
} | ||
|
||
/** | ||
* @param {import('discord.js').ButtonInteraction} interaction | ||
**/ | ||
editDefaultSize(interaction) { | ||
|
||
const { HubView } = this.views(); | ||
|
||
return this.handle(interaction, async (hub) => { | ||
|
||
await interaction.reply(HubView.editDefaultSize(hub)); | ||
}); | ||
} | ||
|
||
/** ***************************************************************************** **/ | ||
|
||
/** | ||
* @param {import('discord.js').MentionableSelectMenuInteraction} interaction | ||
**/ | ||
setDefaultSize(interaction) { | ||
|
||
return this.handle(interaction, async (hub) => { | ||
|
||
hub.config.defaultSize = parseInt(interaction.values.pop(), 10); | ||
|
||
if (isNaN(hub.config.defaultSize)) { | ||
|
||
await interaction.reply({ content : `Invalid default size ❌`, ephemeral : true }); | ||
|
||
return; | ||
} | ||
|
||
await interaction.reply({ content : `Changed default size for ${ channelMention(hub.channel.id) } ✅`, ephemeral : true }); | ||
|
||
return hub; | ||
}); | ||
} | ||
|
||
/** | ||
* @param {import('discord.js').SelectMenuInteraction} interaction | ||
**/ | ||
setDefaultType(interaction) { | ||
|
||
return this.handle(interaction, async (hub) => { | ||
|
||
hub.config.defaultType = interaction.values.pop(); | ||
|
||
await interaction.reply({ content : `Changed default size for ${ channelMention(hub.channel.id) } ✅`, ephemeral : true }); | ||
|
||
return hub; | ||
}); | ||
} | ||
} | ||
|
||
module.exports = Hub; |
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.