diff --git a/src/bot-commands/commands/danktimesbot-commands.ts b/src/bot-commands/commands/danktimesbot-commands.ts index 9d8d440..d95ff15 100644 --- a/src/bot-commands/commands/danktimesbot-commands.ts +++ b/src/bot-commands/commands/danktimesbot-commands.ts @@ -272,9 +272,9 @@ export class DankTimesBotCommands implements IDankTimesBotCommands { const recipient: User = chat.getOrCreateUser(recipientId, msg.reply_to_message?.from?.username); chat.alterUserScore(new AlterUserScoreArgs(user, -amount, AlterUserScoreArgs.DANKTIMESBOT_ORIGIN_NAME, - AlterUserScoreArgs.DONATION_GIVEN_REASON)); + AlterUserScoreArgs.DONATION_GIVEN_REASON, undefined, true)); amount = chat.alterUserScore(new AlterUserScoreArgs(recipient, amount, - AlterUserScoreArgs.DANKTIMESBOT_ORIGIN_NAME, AlterUserScoreArgs.DONATION_RECEIVED_REASON)); + AlterUserScoreArgs.DANKTIMESBOT_ORIGIN_NAME, AlterUserScoreArgs.DONATION_RECEIVED_REASON, undefined, true)); return `🎉 ${user.name} donated ${amount} internet points to ${recipient.name} 🎉`; } diff --git a/src/chat/alter-user-score-args.ts b/src/chat/alter-user-score-args.ts index 2be3046..69784a9 100644 --- a/src/chat/alter-user-score-args.ts +++ b/src/chat/alter-user-score-args.ts @@ -24,6 +24,7 @@ export class AlterUserScoreArgs { * not being caused by a plugin. * @param reason The reason for the score change, e.g. 'random.danktime' or 'hardcoremode.punishment'. * @param timestamp Optional timestamp of the score change. Used for hardmode punishment. + * @param immutable Disallows the score to be changed by a plugin. Default is false. */ constructor( public readonly user: User, @@ -31,5 +32,6 @@ export class AlterUserScoreArgs { public readonly nameOfOriginPlugin: string, public readonly reason: string, public readonly timestamp?: number, + public readonly immutable = false, ) {} } diff --git a/src/chat/chat.ts b/src/chat/chat.ts index 226963b..9763671 100644 --- a/src/chat/chat.ts +++ b/src/chat/chat.ts @@ -358,7 +358,7 @@ export class Chat { return 0; } const preEvent = new PreUserScoreChangedEventArguments(this, alterUserScoreArgs.user, alterUserScoreArgs.amount, - alterUserScoreArgs.reason, alterUserScoreArgs.nameOfOriginPlugin); + alterUserScoreArgs.reason, alterUserScoreArgs.nameOfOriginPlugin, alterUserScoreArgs.immutable); this.pluginHost.triggerEvent(PluginEvent.PreUserScoreChange, preEvent); const correctedAmount = alterUserScoreArgs.user.alterScore(preEvent.changeInScore, alterUserScoreArgs.timestamp); diff --git a/src/plugin-host/plugin-events/event-arguments/pre-user-score-changed-event-arguments.ts b/src/plugin-host/plugin-events/event-arguments/pre-user-score-changed-event-arguments.ts index b12e30c..d2c50b1 100644 --- a/src/plugin-host/plugin-events/event-arguments/pre-user-score-changed-event-arguments.ts +++ b/src/plugin-host/plugin-events/event-arguments/pre-user-score-changed-event-arguments.ts @@ -26,7 +26,7 @@ export class PreUserScoreChangedEventArguments extends PluginEventArguments { public set changeInScore(newChangeInScore: number) { if (isNaN(newChangeInScore)) { console.error(`Failed to set new score change for source '${this.nameOfOriginPlugin}' for reason '${this.reason}': not a number`); - } else { + } else if (!this.immutable) { this.myChangeInScore = newChangeInScore; } } @@ -41,8 +41,9 @@ export class PreUserScoreChangedEventArguments extends PluginEventArguments { * @param reason The reason for the score change, e.g. 'random.danktime' or 'hardcoremode.punishment'. * @param nameOfOriginPlugin The name of the plugin that is causing the score change, or empty if it is * not being caused by a plugin. + * @param immutable Disallows the score delta to be changed. */ - constructor(chat: Chat, user: User, changeInScore: number, reason: string, nameOfOriginPlugin: string) { + constructor(chat: Chat, user: User, changeInScore: number, reason: string, nameOfOriginPlugin: string, private immutable: boolean) { super(nameOfOriginPlugin, reason); this.chat = chat; this.user = user;