Skip to content

Commit

Permalink
Merge pull request #527 from aternosorg/complete
Browse files Browse the repository at this point in the history
remove markdown from bad-word/auto-response autocompletions
  • Loading branch information
JulianVennen authored Nov 2, 2022
2 parents 3b087d7 + 0ca04fb commit 550fafa
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,21 @@ export default class CompletingAutoResponseCommand extends SubCommand {
}

for (const response of autoResponses.values()) {
let name = `[${response.id}] `;
if (response.global) {
name += 'global';
}
else {
name += response.channels.map(channel => {
channel = (/** @type {import('discord.js').Guild} */ interaction.guild)
.channels.cache.get(channel);
return '#' + (channel?.name ?? 'unknown');
}).join(', ');
}
name += ` ${response.trigger.type}: ${response.trigger.asContentString()}`;

options.push({
name: response.getOverview().slice(0, AUTOCOMPLETE_NAME_LIMIT),
name: name.slice(0, AUTOCOMPLETE_NAME_LIMIT),
value: response.id
});
}
Expand Down
15 changes: 14 additions & 1 deletion src/commands/settings/bad-word/CompletingBadWordCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,21 @@ export default class CompletingBadWordCommand extends SubCommand {
}

for (const word of badWords.values()) {
let name = `[${word.id}] `;
if (word.global) {
name += 'global';
}
else {
name += word.channels.map(channel => {
channel = (/** @type {import('discord.js').Guild} */ interaction.guild)
.channels.cache.get(channel);
return '#' + (channel?.name ?? 'unknown');
}).join(', ');
}
name += ` ${word.trigger.type}: ${word.trigger.asContentString()}`;

options.push({
name: word.getOverview().slice(0, AUTOCOMPLETE_NAME_LIMIT),
name: name.slice(0, AUTOCOMPLETE_NAME_LIMIT),
value: word.id
});
}
Expand Down
16 changes: 16 additions & 0 deletions src/discord/ChannelWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,22 @@ export default class ChannelWrapper {
this.channel = channel;
}

/**
* @param {import("discord.js").Snowflake} id
* @return {Promise<ChannelWrapper>}
*/
static async fetch(id) {
try {
return new this(await bot.client.channels.fetch(id));
}
catch (e) {
if ([RESTJSONErrorCodes.UnknownChannel, RESTJSONErrorCodes.MissingAccess].includes(e.code)) {
return null;
}
throw e;
}
}

sendable() {
if (!SENDABLE_CHANNEL_TYPES.includes(this.channel.type)) {
return false;
Expand Down

0 comments on commit 550fafa

Please sign in to comment.