diff --git a/commands/dominator.ts b/commands/dominator.ts index cb44ce1..bf9168d 100644 --- a/commands/dominator.ts +++ b/commands/dominator.ts @@ -75,7 +75,7 @@ async function execute(interaction: ChatInputCommandInteraction) { const triggerData = { communityID: interaction.guildId } as any; if (action != null && action != undefined) triggerData[`${attribute}_action`] = action; if (threshold != null && threshold != undefined) triggerData[`${attribute}_threshold`] = threshold; - await dominator!.update(triggerData); + await dominator.update(triggerData); } interaction.editReply({ embeds: [await embedDominator(await dominator.read(interaction.guildId!) as (MessageDominator | MemberDominator), attribute, interaction.client, interaction.guild!)] }); diff --git a/events/guildMemberAdd.ts b/events/guildMemberAdd.ts index 4f1ced0..75be8b8 100644 --- a/events/guildMemberAdd.ts +++ b/events/guildMemberAdd.ts @@ -14,30 +14,30 @@ export async function guildMemberAdd(member: GuildMember) { export async function moderateMember(member: GuildMember) { const [psychoPass, dominator] = await Promise.all([PsychoPasses.read(member.user.id), MemberDominators.read(member.guild.id)]); if (!psychoPass || !dominator) throw new Error("Psycho-Pass or Dominator undefined!"); - if (psychoPass!.messages < 25) return; + if (psychoPass.messages < 25) return; let maxAction = ACTIONS.indexOf("NOOP"); const reasons: Reason[] = []; for (const attribute of ATTRIBUTES) { - const score = psychoPass![attribute as keyof PsychoPass] as number; - const threshold = dominator![`${attribute}_threshold` as keyof MemberDominator] as number; + const score = psychoPass[attribute as keyof PsychoPass] as number; + const threshold = dominator[`${attribute}_threshold` as keyof MemberDominator] as number; if (score >= threshold) { - const action = dominator![`${attribute}_action` as keyof MemberDominator] as number; + const action = dominator[`${attribute}_action` as keyof MemberDominator] as number; maxAction = Math.max(maxAction, action); reasons.push({ attribute: attribute.toLowerCase(), score, threshold }); } } - if (psychoPass!.crime_coefficient >= 300) { - maxAction = Math.max(maxAction, dominator!.crime_coefficient_300_action); - reasons.unshift({ + if (psychoPass.crime_coefficient >= 300) { + maxAction = Math.max(maxAction, dominator.crime_coefficient_300_action); + reasons.push({ attribute: "Crime Coefficient", - score: psychoPass!.crime_coefficient, + score: psychoPass.crime_coefficient, threshold: 300 }); - } else if (psychoPass!.crime_coefficient >= 100) { - maxAction = Math.max(maxAction, dominator!.crime_coefficient_100_action); - reasons.unshift({ + } else if (psychoPass.crime_coefficient >= 100) { + maxAction = Math.max(maxAction, dominator.crime_coefficient_100_action); + reasons.push({ attribute: "Crime Coefficient", - score: psychoPass!.crime_coefficient, + score: psychoPass.crime_coefficient, threshold: 100 }); } diff --git a/events/messageCreate.ts b/events/messageCreate.ts index 73ecbe1..6b52d1b 100644 --- a/events/messageCreate.ts +++ b/events/messageCreate.ts @@ -17,16 +17,16 @@ export async function messageCreate(message: Message) { console.log(`@${message.author.username} (${message.author.id}) has sent a new message in Server: ${message.guild!.name} (${message.guildId!}) in Channel: ${(message.channel as TextChannel).name} (${message.channel.id})`); const [analysis, dominator] = await Promise.all([analyzeComment(message.content), MessageDominators.read(message.guildId!)]); if (!analysis || !dominator) throw new Error("messageCreate: MessageAnalysis or MessageDominator undefined!"); - analysis!.userID = message.author.id; - analysis!.communityID = message.guildId!; - ingestMessage(analysis!); + analysis.userID = message.author.id; + analysis.communityID = message.guildId!; + ingestMessage(analysis); let maxAction = ACTIONS.indexOf("NOOP"); const reasons: Reason[] = []; - for (const attribute in analysis!.attributeScores) { - const score = analysis!.attributeScores[attribute as keyof MessageAnalysis["attributeScores"]].summaryScore.value; - const threshold = dominator![`${attribute.toLowerCase()}_threshold` as keyof MessageDominator] as number; + for (const attribute in analysis.attributeScores) { + const score = analysis.attributeScores[attribute as keyof MessageAnalysis["attributeScores"]].summaryScore.value; + const threshold = dominator[`${attribute.toLowerCase()}_threshold` as keyof MessageDominator] as number; if (score >= threshold) { - const action = dominator![`${attribute.toLowerCase()}_action` as keyof MessageDominator] as number; + const action = dominator[`${attribute.toLowerCase()}_action` as keyof MessageDominator] as number; maxAction = Math.max(maxAction, action); reasons.push({ attribute: attribute.toLowerCase(), score, threshold }); } diff --git a/events/messageUpdate.ts b/events/messageUpdate.ts index 17b9e12..2bc36fb 100644 --- a/events/messageUpdate.ts +++ b/events/messageUpdate.ts @@ -17,16 +17,16 @@ export default async function messageUpdate(_: Message | PartialMessage, newMess console.log(`@${newMessage.author.username} (${newMessage.author.id}) has updated a message in Server: ${newMessage.guild!.name} (${newMessage.guildId!}) in Channel: ${(newMessage.channel as TextChannel).name} (${newMessage.channel.id})`); const [analysis, dominator] = await Promise.all([analyzeComment(newMessage.content), MessageDominators.read(newMessage.guildId!)]); if (!analysis || !dominator) throw new Error("messageUpdate: MessageAnalysis or MessageDominator undefined!"); - analysis!.userID = newMessage.author.id; - analysis!.communityID = newMessage.guildId!; - ingestMessage(analysis!); + analysis.userID = newMessage.author.id; + analysis.communityID = newMessage.guildId!; + ingestMessage(analysis); let maxAction = ACTIONS.indexOf("NOOP"); const reasons: Reason[] = []; - for (const attribute in analysis!.attributeScores) { - const score = analysis!.attributeScores[attribute as keyof MessageAnalysis["attributeScores"]].summaryScore.value; - const threshold = dominator![`${attribute.toLowerCase()}_threshold` as keyof MessageDominator] as number; + for (const attribute in analysis.attributeScores) { + const score = analysis.attributeScores[attribute as keyof MessageAnalysis["attributeScores"]].summaryScore.value; + const threshold = dominator[`${attribute.toLowerCase()}_threshold` as keyof MessageDominator] as number; if (score >= threshold) { - const action = dominator![`${attribute.toLowerCase()}_action` as keyof MessageDominator] as number; + const action = dominator[`${attribute.toLowerCase()}_action` as keyof MessageDominator] as number; maxAction = Math.max(maxAction, action); reasons.push({ attribute: attribute.toLowerCase(), score, threshold }); }