pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 1 | import log from '../utils/log.js' |
| 2 | import readConfig from '../utils/readConfig.js' |
| 3 | import convertCurlyBracketString from '../utils/convertCurlyBracketString.js' |
pineafan | 377794f | 2022-04-18 19:01:01 +0100 | [diff] [blame^] | 4 | import singleNotify from '../utils/singleNotify.js'; |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 5 | |
pineafan | 377794f | 2022-04-18 19:01:01 +0100 | [diff] [blame^] | 6 | export async function callback(interaction, member) { |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 7 | let config = await readConfig(member.guild.id); |
| 8 | |
| 9 | config.stats.forEach(async element => { |
| 10 | if (element.enabled) { |
| 11 | let string = element.text |
| 12 | if (!string) return |
| 13 | string = await convertCurlyBracketString(string, member.id, member.displayName, member.guild.name, member.guild.members) |
| 14 | |
| 15 | let channel = await member.client.channels.fetch(element.channel) |
| 16 | if (channel.guild.id !== member.guild.id) return |
pineafan | 377794f | 2022-04-18 19:01:01 +0100 | [diff] [blame^] | 17 | if (!channel) return await singleNotify(interaction.client, |
| 18 | "statsChannelDeleted", |
| 19 | member.guild.id, |
| 20 | "The stats channel has been deleted. Please set a new channel to use this feature.", |
| 21 | "Critical" |
| 22 | ) |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 23 | try { |
| 24 | await channel.edit({ name: string }) |
| 25 | } catch (err) { |
| 26 | console.error(err) |
| 27 | } |
| 28 | } |
| 29 | }); |
| 30 | } |