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