Compare commits

...

7 Commits

Author SHA1 Message Date
j 0b7c389875 starting money 2024-04-04 23:11:50 -04:00
j 3ad1191f98 typo 2024-04-04 23:11:33 -04:00
j 7651df9d3b cleanup 2024-04-04 23:11:18 -04:00
j cac2faf2e3 Redid build script, made a cleaning script to remove old builds 2024-04-04 23:11:08 -04:00
j 8c5701e6bb Fixed typo in name 2024-04-04 23:10:31 -04:00
j 7c993cabaf Will retry on network error 2024-04-04 23:10:22 -04:00
j 33577a7b24 Cleanup 2024-04-04 23:10:03 -04:00
8 changed files with 26 additions and 100 deletions

35
package-lock.json generated
View File

@ -1,5 +1,5 @@
{
"name": "CrossTalkPM",
"name": "OregonTrail",
"lockfileVersion": 2,
"requires": true,
"packages": {
@ -15,6 +15,7 @@
"ioredis": "^5.3.2",
"path": "^0.12.7",
"qs": "^6.11.2",
"rimraf": "^3.0.2",
"sqlite": "^5.1.1",
"sqlite3": "^5.1.7"
},
@ -213,8 +214,7 @@
"node_modules/balanced-match": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz",
"integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==",
"devOptional": true
"integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw=="
},
"node_modules/base64-js": {
"version": "1.5.1",
@ -262,7 +262,6 @@
"version": "1.1.11",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
"integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==",
"devOptional": true,
"dependencies": {
"balanced-match": "^1.0.0",
"concat-map": "0.0.1"
@ -415,8 +414,7 @@
"node_modules/concat-map": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
"integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==",
"devOptional": true
"integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg=="
},
"node_modules/console-control-strings": {
"version": "1.1.0",
@ -679,8 +677,7 @@
"node_modules/fs.realpath": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
"integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==",
"devOptional": true
"integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw=="
},
"node_modules/function-bind": {
"version": "1.1.2",
@ -745,7 +742,6 @@
"version": "7.2.3",
"resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz",
"integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==",
"devOptional": true,
"dependencies": {
"fs.realpath": "^1.0.0",
"inflight": "^1.0.4",
@ -929,7 +925,6 @@
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz",
"integrity": "sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==",
"devOptional": true,
"dependencies": {
"once": "^1.3.0",
"wrappy": "1"
@ -1107,7 +1102,6 @@
"version": "3.1.2",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz",
"integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==",
"devOptional": true,
"dependencies": {
"brace-expansion": "^1.1.7"
},
@ -1391,7 +1385,6 @@
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",
"integrity": "sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg==",
"devOptional": true,
"engines": {
"node": ">=0.10.0"
}
@ -1555,7 +1548,6 @@
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz",
"integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==",
"optional": true,
"dependencies": {
"glob": "^7.1.3"
},
@ -2252,8 +2244,7 @@
"balanced-match": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz",
"integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==",
"devOptional": true
"integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw=="
},
"base64-js": {
"version": "1.5.1",
@ -2287,7 +2278,6 @@
"version": "1.1.11",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
"integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==",
"devOptional": true,
"requires": {
"balanced-match": "^1.0.0",
"concat-map": "0.0.1"
@ -2399,8 +2389,7 @@
"concat-map": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
"integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==",
"devOptional": true
"integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg=="
},
"console-control-strings": {
"version": "1.1.0",
@ -2586,8 +2575,7 @@
"fs.realpath": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
"integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==",
"devOptional": true
"integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw=="
},
"function-bind": {
"version": "1.1.2",
@ -2637,7 +2625,6 @@
"version": "7.2.3",
"resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz",
"integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==",
"devOptional": true,
"requires": {
"fs.realpath": "^1.0.0",
"inflight": "^1.0.4",
@ -2765,7 +2752,6 @@
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz",
"integrity": "sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==",
"devOptional": true,
"requires": {
"once": "^1.3.0",
"wrappy": "1"
@ -2906,7 +2892,6 @@
"version": "3.1.2",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz",
"integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==",
"devOptional": true,
"requires": {
"brace-expansion": "^1.1.7"
}
@ -3123,8 +3108,7 @@
"path-is-absolute": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",
"integrity": "sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg==",
"devOptional": true
"integrity": "sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg=="
},
"prebuild-install": {
"version": "7.1.1",
@ -3249,7 +3233,6 @@
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz",
"integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==",
"optional": true,
"requires": {
"glob": "^7.1.3"
}

View File

@ -10,6 +10,7 @@
"ioredis": "^5.3.2",
"path": "^0.12.7",
"qs": "^6.11.2",
"rimraf": "^3.0.2",
"sqlite": "^5.1.1",
"sqlite3": "^5.1.7"
},
@ -19,8 +20,9 @@
"typescript": "^5.3.3"
},
"scripts": {
"build": "tsc && copyfiles -u 3 \"src/db/migrations/*.sql\" dist/db/migrations && copyfiles -u 3 \"src/db/seed/*.sql\" dist/db/seed && copyfiles -u 2 \"src/messages/*.txt\" dist/messages",
"start": "node dist/index.js",
"clean": "rimraf dist/*.js dist/db/migrations dist/messages",
"build": "npm run clean && tsc && copyfiles -u 3 \"src/db/migrations/*.sql\" dist/db/migrations && copyfiles -u 3 \"src/db/seed/*.sql\" dist/db/seed && copyfiles -u 2 \"src/messages/*.txt\" dist/messages",
"start": "npm run build && node dist/index.js",
"test": "tsc -p tsconfig.tests.json"
}
}
}

View File

@ -1,4 +1,4 @@
CREATE TABLE IF NOT EXISTS gameState (
CREATE TABLE IF NOT EXISTS game_state (
authorId INTEGER PRIMARY KEY,
data TEXT NOT NULL,
active BOOLEAN NOT NULL DEFAULT TRUE

View File

@ -251,7 +251,7 @@ class GameFlow {
// If not enough money, return an error message
return {
success: false,
errorMessage: `⚠️ You do not have enough money for ${selectedWeapon.name}. You have $${this.gameState.cashLeftAfterInitialPurchases} remaining.`
errorMessage: `⚠️ You do not have enough money for the ${selectedWeapon.name}. You have $${this.gameState.cashLeftAfterInitialPurchases} remaining.`
};
}

View File

@ -38,7 +38,7 @@ class GameState {
hostilityOfRidersFactor: number = 0;
shootingWordSelector: string = '';
shootingWordVariations: string[] = [];
cashLeftAfterInitialPurchases: number = 0;
cashLeftAfterInitialPurchases: number = 800;
tacticsChoiceWhenAttacked: number = 0;
actionChoiceForEachTurn: number = 0;
fortOptionFlag: boolean = false;

View File

@ -6,7 +6,6 @@ import rDramaSession from './rdrama/session/SessionManager';
import { DatabaseInitializer } from './db/initializeDatabase';
import RedisSessionManager from './redis/session/SessionManager';
import { Comment } from './rdrama/models/Comment';
import { CommentParser } from './rdrama/services/CommentParser';
// Import other necessary services or configurations

View File

@ -88,8 +88,16 @@ class SessionManager {
}
private retryCondition(error: AxiosError): boolean {
// Check for network errors (e.g., socket hang up)
const isNetworkError = !error.response && Boolean(error.code); // No response and error.code is truthy indicates a network error
// Check for specific HTTP status codes
const status = error.response?.status ?? 0;
return status === 429 || status >= 500;
const isRateLimitError = status === 429;
const isServerError = status >= 500;
// Retry on network errors, rate limit errors, or server errors
return isNetworkError || isRateLimitError || isServerError;
}

View File

@ -1,66 +0,0 @@
import dotenv from 'dotenv';
import { RedditService } from '../reddit/services/Reddit';
import { DatabaseService } from '../db/services/Database';
// Load environment variables from .env file
dotenv.config();
/**
* Determines whether a user should be notified based on various criteria.
*
* This function checks a Reddit user's information against a set of conditions
* defined by environment variables and user attributes. These conditions include
* whether the user is a moderator, an employee, accepts private messages, has
* karma below a certain threshold, and has not been notified before.
*
* @param {string} username - The Reddit username of the user to check.
* @returns {Promise<boolean>} - A promise that resolves to `true` if the user meets
* the criteria for notification, otherwise `false`.
*
* @throws {Error} Throws an error if there's a problem fetching user information
* from Reddit or checking the user's notification status in the database.
*
* @example
* // Example of checking if a user should be notified
* shouldNotifyUser('exampleUser').then(shouldNotify => {
* if (shouldNotify) {
* console.log('User should be notified.');
* } else {
* console.log('User should not be notified.');
* }
* }).catch(error => {
* console.error('Error checking if user should be notified:', error);
* });
*
* @example
* // Environment variables used in this function
* // .env file
* EXCLUDE_MODS=true
* EXCLUDE_EMPLOYEES=true
* KARMA_THRESHOLD=100000
*
* These environment variables control the behavior of the function, such as whether
* to exclude moderators or employees from notifications, and the karma threshold for
* notifications.
*/
export async function shouldNotifyUser(username: string): Promise<boolean> {
const userInfo = await RedditService.getUserInfo(username);
if (!userInfo) return false;
const { is_mod, is_employee, accept_pms, total_karma } = userInfo.data;
const excludeMods = process.env.EXCLUDE_MODS !== 'false'; // Defaults to true unless explicitly set to 'false'
const excludeEmployees = process.env.EXCLUDE_EMPLOYEES !== 'false'; // Defaults to true unless explicitly set to 'false'
const notifyAcceptPms = accept_pms !== false; // Notify if accept_pms is true or undefined
const karmaThreshold = parseInt(process.env.KARMA_THRESHOLD || '100000', 10);
const hasBeenNotifiedBefore = await DatabaseService.userMentionExists(username);
const meetsCriteria =
(!excludeMods || !is_mod) && // Notify unless we're excluding mods and the user is a mod
(!excludeEmployees || !is_employee) && // Notify unless we're excluding employees and the user is an employee
notifyAcceptPms &&
total_karma < karmaThreshold &&
!hasBeenNotifiedBefore;
return meetsCriteria;
}