Skip to content

Commit

Permalink
No one is one blocked message (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
zippy1981 committed Oct 30, 2023
1 parent c118812 commit ae0eab1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions __tests__/config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ describe('Tests the config module', () => {

expect(config).toEqual( {
'AllowConfigDump': false,
'DisableOneBlockedMessage': false,
'MessageFetchCount': 50,
'OneBlockedPercent': 1,
'ScoreDatabase': './score.db3',
Expand Down
5 changes: 5 additions & 0 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ const getConfig = () => {
*/
ScoreDatabase: process.env.SCORE_DATABASE ?? './score.db3',

/**
* Set to true via the environment variable DISABLE_ONE_BLOCKED_MESSAGE to disable the random one blocked mssage behavior.
*/
DisableOneBlockedMessage: process.env.DISABLE_ONE_BLOCKED_MESSAGE?.localeCompare('true', 'en', { sensitivity: 'base' }) === 0,

/**
* Percentage change of getting "who is one blocked message" for plebians who should be so lucky to be in
* the present of so much KIR.
Expand Down
6 changes: 4 additions & 2 deletions one-blocked-message.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ function isRealest(username) {
* @returns true if one blocked message gets sent, false otherwise.
*/
function oneBlockedMessage(initialQuery) {
const isARealOne = isRealest(initialQuery.author.username);
if (!config.DisableOneBlockedMessage) {
const isARealOne = isRealest(initialQuery.author.username);
const randomVal = Math.random() * 100;
const triggerPecentage = 100 - (isARealOne ? config.RealestOneBlockedPercent : config.OneBlockedPercent);
console.debug(`Random Value: ${randomVal} - Trigger: ${triggerPecentage}. User ${initialQuery.author.username} - Realest: ${isARealOne}.`);
Expand All @@ -25,8 +26,9 @@ function oneBlockedMessage(initialQuery) {
initialQuery.channel.send(initialQuery.author.toString() + ' who is one blocked message');
return true;
}
}

return false;
return false;
}

module.exports = {
Expand Down

0 comments on commit ae0eab1

Please sign in to comment.