blob: 7301a60c186e2f719cbc04a14b65d1186abc9a50 [file] [log] [blame]
import convertCurlyBracketString from "../utils/convertCurlyBracketString.js";
import singleNotify from "../utils/singleNotify.js";
import client from "../utils/client.js";
interface PropSchema { enabled: boolean, name: string }
export async function callback(_, member) {
const guild = await client.guilds.fetch(member.guild.id);
const config = await client.database.guilds.read(guild.id);
Object.entries(config.getKey("stats")).forEach(async ([channel, props]) => {
if ((props as PropSchema).enabled) {
let string = (props as PropSchema).name;
if (!string) return;
string = await convertCurlyBracketString(string, member.id, member.displayName, guild.name, guild.members);
let fetchedChannel;
try {
fetchedChannel = await guild.channels.fetch(channel);
} catch (e) { fetchedChannel = null; }
if (!fetchedChannel) {
const deleted = config.getKey("stats")[channel];
console.log(`stats.${channel}`);
console.log(guild.id);
await client.database.guilds.write(guild.id, null, `stats.${channel}`);
return singleNotify(
"statsChannelDeleted",
guild.id,
"One or more of your stats channels have been deleted. Please use `/settings stats` if you wish to add the channel again.\n" +
`The channels name was: ${deleted.name}`,
"Critical"
);
}
try {
await fetchedChannel.setName(string.slice(0, 100));
} catch (e) {
console.error(e);
}
}
});
}