Skip to content

Commit

Permalink
remove unnecessary non-null assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
dragonejt committed Sep 23, 2023
1 parent e278774 commit f33a7fe
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 27 deletions.
2 changes: 1 addition & 1 deletion commands/dominator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ async function execute(interaction: ChatInputCommandInteraction) {
const triggerData = { communityID: interaction.guildId } as any;

Check warning on line 75 in commands/dominator.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type
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!)] });
Expand Down
24 changes: 12 additions & 12 deletions events/guildMemberAdd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
}
Expand Down
14 changes: 7 additions & 7 deletions events/messageCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
Expand Down
14 changes: 7 additions & 7 deletions events/messageUpdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
Expand Down

0 comments on commit f33a7fe

Please sign in to comment.