pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 1 | import convertCurlyBracketString from '../utils/convertCurlyBracketString.js' |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 2 | import singleNotify from '../utils/singleNotify.js'; |
| 3 | import client from '../utils/client.js'; |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 4 | |
| 5 | export async function callback(_, member) { |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 6 | let config = await client.database.read(member.guild.id); |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 7 | |
| 8 | config.stats.forEach(async element => { |
| 9 | if (element.enabled) { |
| 10 | let string = element.text |
| 11 | if (!string) return |
| 12 | string = await convertCurlyBracketString(string, member.id, member.displayName, member.guild.name, member.guild.members) |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 13 | let channel; |
| 14 | try { |
| 15 | channel = await member.client.channels.fetch(element.channel) |
| 16 | } catch (error) { channel = null } |
| 17 | if (!channel) { |
| 18 | return singleNotify( |
| 19 | "statsChannelDeleted", |
| 20 | member.guild.id, |
| 21 | "One or more of your stats channels have been deleted. Please open the settings menu to change this.", |
| 22 | "Critical" |
| 23 | ) |
| 24 | } |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 25 | if (channel.guild.id !== member.guild.id) return |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 26 | try { |
| 27 | await channel.edit({ name: string }) |
| 28 | } catch (err) { |
| 29 | console.error(err) |
| 30 | } |
| 31 | } |
| 32 | }); |
pineafan | 6702cef | 2022-06-13 17:52:37 +0100 | [diff] [blame] | 33 | } |