pineafan | 708692b | 2022-07-24 22:16:22 +0100 | [diff] [blame] | 1 | import convertCurlyBracketString from '../utils/convertCurlyBracketString.js' |
| 2 | import singleNotify from '../utils/singleNotify.js'; |
| 3 | import client from '../utils/client.js'; |
| 4 | |
| 5 | interface PropSchema { enabled: boolean, name: string } |
| 6 | |
| 7 | export async function callback(_, member) { |
pineafan | 708692b | 2022-07-24 22:16:22 +0100 | [diff] [blame] | 8 | let guild = await client.guilds.fetch(member.guild.id) |
| 9 | let config = await client.database.guilds.read(guild.id); |
| 10 | Object.entries(config.getKey("stats")).forEach(async ([channel, props]) => { |
| 11 | if ((props as PropSchema).enabled) { |
| 12 | let string = (props as PropSchema).name |
| 13 | if (!string) return |
| 14 | string = await convertCurlyBracketString(string, member.id, member.displayName, guild.name, guild.members) |
| 15 | let fetchedChannel; |
| 16 | try { |
| 17 | fetchedChannel = await guild.channels.fetch(channel) |
| 18 | } catch (e) { fetchedChannel = null } |
| 19 | if (!fetchedChannel) { |
| 20 | return singleNotify( |
| 21 | "statsChannelDeleted", |
| 22 | guild.id, |
| 23 | "One or more of your stats channels have been deleted. Please open the settings menu to change this.", |
| 24 | "Critical" |
| 25 | ) |
| 26 | } |
| 27 | try { |
| 28 | await fetchedChannel.setName(string) |
| 29 | } catch (e) { |
| 30 | console.error(e) |
| 31 | } |
| 32 | } |
| 33 | }); |
| 34 | } |