move promptMessage to invoker wrapper

This commit is contained in:
Erik 2022-04-26 19:46:10 +03:00
parent 93885114a9
commit b93e8d9c4b
Signed by: Navy.gif
GPG Key ID: 811EC0CD80E7E5FB
5 changed files with 33 additions and 33 deletions

View File

@ -84,36 +84,6 @@ class InteractionWrapper {
}); });
} }
async promptMessage(str, opts = {}) {
if (typeof str === 'string') {
if (opts.emoji) str = `${Emojis[opts.emoji]} ${str}`;
if (opts.reply) str = `<@!${this.author.id}> ${str}`;
}
const data = {
content: str,
files: opts.files,
embeds: opts.embed ? [opts.embed] : [],
disableMentions: opts.disableMentions
};
if (opts.editInteraction) await this.editReply(data);
else await this.channel.send(data).then((msg) => {
if (opts.delete) msg.delete();
});
return this.channel.awaitMessages({
filter: (m) => m.author.id === this.user.id, max: 1, time: opts.time * 1000 || 30_000, errors: ['time']
})
.then((collected) => {
return collected.first();
})
.catch((error) => { //eslint-disable-line no-unused-vars, handle-callback-err
return null;
});
}
replyEmbed(embed) { replyEmbed(embed) {
if (!embed.color) embed.color = 619452; if (!embed.color) embed.color = 619452;
return this.reply({ embeds: [embed] }); return this.reply({ embeds: [embed] });

View File

@ -80,6 +80,36 @@ class InvokerWrapper {
return this.target.deferReply(options); return this.target.deferReply(options);
} }
async promptMessage(str, opts = {}) {
if (typeof str === 'string') {
if (opts.emoji) str = `${Emojis[opts.emoji]} ${str}`;
if (opts.reply) str = `<@!${this.author.id}> ${str}`;
}
const data = {
content: str,
files: opts.files,
embeds: opts.embed ? [opts.embed] : [],
disableMentions: opts.disableMentions
};
if (opts.editReply) await this.editReply(data);
else await this.channel.send(data).then((msg) => {
if (opts.delete) msg.delete();
});
return this.channel.awaitMessages({
filter: (m) => m.author.id === this.user.id, max: 1, time: opts.time * 1000 || 30_000, errors: ['time']
})
.then((collected) => {
return collected.first();
})
.catch((error) => { //eslint-disable-line no-unused-vars, handle-callback-err
return null;
});
}
async reply(options = {}) { async reply(options = {}) {
if (typeof options === 'string') options = { content: options }; if (typeof options === 'string') options = { content: options };

View File

@ -43,7 +43,7 @@ class ImportCommand extends SlashCommand {
// TODO split into settings and modlogs // TODO split into settings and modlogs
const { MONGODB_HOST, MONGODB_USERNAME, MONGODB_PASSWORD } = process.env; const { MONGODB_HOST, MONGODB_USERNAME, MONGODB_PASSWORD } = process.env;
const migrator = new SettingsMigrator(guild, { const migrator = new SettingsMigrator(this.client, guild, {
host: MONGODB_HOST, host: MONGODB_HOST,
username: MONGODB_USERNAME, username: MONGODB_USERNAME,
password: MONGODB_PASSWORD, password: MONGODB_PASSWORD,

View File

@ -143,7 +143,7 @@ class WordFilterSetting extends FilterSetting {
const response = await interaction.promptMessage( const response = await interaction.promptMessage(
interaction.format('SETTING_WORDFILTER_ACTION_ADD_TRIGGERS'), interaction.format('SETTING_WORDFILTER_ACTION_ADD_TRIGGERS'),
{ time: 60 * 1000, editInteraction: true } { time: 60 * 1000, editReply: true }
); );
if (!response) { if (!response) {
if (actions.find((ac) => ac.trigger === 'generic')) return { if (actions.find((ac) => ac.trigger === 'generic')) return {

View File

@ -176,7 +176,7 @@ class Setting extends Component {
if (!message.length && !index && !embed) throw new Error('Must declare either message, index or embeds'); if (!message.length && !index && !embed) throw new Error('Must declare either message, index or embeds');
const response = await interaction.promptMessage( const response = await interaction.promptMessage(
index ? interaction.format(index, params) : message, index ? interaction.format(index, params) : message,
{ time, editInteraction: true, embed } { time, editReply: true, embed }
); );
if (!response) return { error: true, message: interaction.format('ERR_TIMEOUT') }; if (!response) return { error: true, message: interaction.format('ERR_TIMEOUT') };