pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 1 | import convertCurlyBracketString from "../utils/convertCurlyBracketString.js"; |
| 2 | import singleNotify from "../utils/singleNotify.js"; |
| 3 | import client from "../utils/client.js"; |
pineafan | 708692b | 2022-07-24 22:16:22 +0100 | [diff] [blame] | 4 | |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 5 | interface PropSchema { |
| 6 | enabled: boolean; |
| 7 | name: string; |
| 8 | } |
pineafan | 708692b | 2022-07-24 22:16:22 +0100 | [diff] [blame] | 9 | |
| 10 | export async function callback(_, member) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 11 | const guild = await client.guilds.fetch(member.guild.id); |
| 12 | const config = await client.database.guilds.read(guild.id); |
pineafan | 708692b | 2022-07-24 22:16:22 +0100 | [diff] [blame] | 13 | Object.entries(config.getKey("stats")).forEach(async ([channel, props]) => { |
| 14 | if ((props as PropSchema).enabled) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 15 | let string = (props as PropSchema).name; |
| 16 | if (!string) return; |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 17 | string = await convertCurlyBracketString( |
| 18 | string, |
| 19 | member.id, |
| 20 | member.displayName, |
| 21 | guild.name, |
| 22 | guild.members |
| 23 | ); |
pineafan | 708692b | 2022-07-24 22:16:22 +0100 | [diff] [blame] | 24 | let fetchedChannel; |
| 25 | try { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 26 | fetchedChannel = await guild.channels.fetch(channel); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 27 | } catch (e) { |
| 28 | fetchedChannel = null; |
| 29 | } |
pineafan | 708692b | 2022-07-24 22:16:22 +0100 | [diff] [blame] | 30 | if (!fetchedChannel) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 31 | const deleted = config.getKey("stats")[channel]; |
| 32 | console.log(`stats.${channel}`); |
| 33 | console.log(guild.id); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 34 | await client.database.guilds.write( |
| 35 | guild.id, |
| 36 | null, |
| 37 | `stats.${channel}` |
| 38 | ); |
pineafan | 708692b | 2022-07-24 22:16:22 +0100 | [diff] [blame] | 39 | return singleNotify( |
| 40 | "statsChannelDeleted", |
| 41 | guild.id, |
pineafan | e23c4ec | 2022-07-27 21:56:27 +0100 | [diff] [blame] | 42 | "One or more of your stats channels have been deleted. Please use `/settings stats` if you wish to add the channel again.\n" + |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame^] | 43 | `The channels name was: ${deleted.name}`, |
pineafan | 708692b | 2022-07-24 22:16:22 +0100 | [diff] [blame] | 44 | "Critical" |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 45 | ); |
pineafan | 708692b | 2022-07-24 22:16:22 +0100 | [diff] [blame] | 46 | } |
| 47 | try { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 48 | await fetchedChannel.setName(string.slice(0, 100)); |
pineafan | 708692b | 2022-07-24 22:16:22 +0100 | [diff] [blame] | 49 | } catch (e) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 50 | console.error(e); |
pineafan | 708692b | 2022-07-24 22:16:22 +0100 | [diff] [blame] | 51 | } |
| 52 | } |
| 53 | }); |
| 54 | } |