Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add way for plugin to update points even after game has ended #740

Merged
merged 1 commit into from
Jun 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions scripts/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,16 @@ export async function updateData(url: string, file = "./sample/data1.json") {
settings.file = file;
}
// Gets the data. Note that the last match points are ignored and calculated using total points
const [newTransfer, countdown, players, clubs] = await plugins[url](
settings,
{
players: await connection.query("SELECT * FROM players WHERE league=?", [
league,
]),
clubs: await connection.query("SELECT * FROM clubs"),
timestamp: parseInt(lastUpdate[0].value2),
transferOpen: oldTransfer,
},
).catch((e) => {
const [newTransfer, countdown, players, clubs, run_settings] = await plugins[
url
](settings, {
players: await connection.query("SELECT * FROM players WHERE league=?", [
league,
]),
clubs: await connection.query("SELECT * FROM clubs"),
timestamp: parseInt(lastUpdate[0].value2),
transferOpen: oldTransfer,
}).catch((e) => {
console.error(
`Error - Failed to get data for ${league}(if this happens to often something is wrong) with error ${e}`,
);
Expand Down Expand Up @@ -302,7 +301,10 @@ export async function updateData(url: string, file = "./sample/data1.json") {
);
}
// Updates player stats if the game is running and has not ended for too long yet
if (clubDone && !gameDone) {
if (
clubDone &&
(!gameDone || !!run_settings?.update_points_after_game_end)
) {
// Calculate all the values if they need to be calculated for last_match and total_points
if (total_points === undefined) {
await connection.query(
Expand Down
15 changes: 12 additions & 3 deletions types/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,27 @@ export interface clubs {
teamScore?: number; // This is the score of the team
opponentScore?: number; // This is the score of the opponent
league: string; // This is the name of the league
home?: boolean; // This is if it is home or away
home?: boolean; // This is if it is home or away, If not set it is chosen at random so that there is only one home team in a game
}

// These are the types for the data getter functions
export type result = [boolean, number, players[], clubs[]];
export type result = [
boolean,
number,
players[],
clubs[],
{
update_points_after_game_end?: boolean; // Set this to true if you want the plugin to be able to change points even after the game has ended
[key: string]: unknown;
}?, // This is an optional paramater added in 1.20.0 for settings
];
type dataGetter = (
settings: { [key: string]: string },
past_data: {
players: players[];
clubs: clubs[];
timestamp: number;
transferOpen: boolean;
transferOpen: boolean; // This was added in version 1.20.0. If this is required you must set 1.20.0 as the min version.
[key: string]: unknown;
},
) => Promise<result>;
Expand Down