From e8ef3b2de8ac78ba6acf8d64576841a3b095a529 Mon Sep 17 00:00:00 2001 From: drcatdoctor Date: Tue, 15 Dec 2020 19:47:17 -0500 Subject: [PATCH] support any league year and eradicate all references to the bad year --- README.md | 23 +++++++++++------------ src/bot/FCMongo.ts | 5 ++--- src/bot/GuildWorker.ts | 10 ++++------ src/bot/main.ts | 14 ++++++-------- utils/check-oc.js | 2 +- 5 files changed, 24 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index 3d5c891..20cc0e7 100644 --- a/README.md +++ b/README.md @@ -50,24 +50,22 @@ You can !fcadd multiple channels if you want. ### Setup with a public league -***Note: this currently only works with 2020 public leagues. To fix very soon.*** - In ANY channel in your server that Fantasy Critic Bot is in: ``` !fcadd - !fcleague + !fcleague !fcstart ``` Example: ``` !fcadd fantasy-critic - !fcleague abb1234f-44c0-2c7d-9901-80aa314d26f6 + !fcleague abb1234f-44c0-2c7d-9901-80aa314d26f6 2021 !fcstart ``` -You can find your league ID in the URL of your league's page. -https://www.fantasycritic.games/league/YOUR-LEAGUE-ID-HERE/2020 +You can find your league ID (and year) in the URL of your league's page. +https://www.fantasycritic.games/league/YOUR-LEAGUE-ID-HERE/YEAR ### Setup with a private league @@ -81,7 +79,7 @@ In ANY channel in your server that Fantasy Critic Bot is in: Example: ``` !fcadd fantasy-critic - !fclogin supergreg@gmail.com s3cr3tpa55w0rd abb1234f-44c0-2c7d-9901-80aa314d26f6 2020 + !fclogin supergreg@gmail.com s3cr3tpa55w0rd abb1234f-44c0-2c7d-9901-80aa314d26f6 2021 !fcstart ``` @@ -90,8 +88,8 @@ You can do it in a private channel, you can delete the message after you send it. Sorry. This bot was just for me at first. Hopefully this will improve soon. It should be in a PM or something. -You can find your league ID in the URL of your league's page. -https://www.fantasycritic.games/league/YOUR-LEAGUE-ID-HERE/2020 +You can find your league ID (and year) in the URL of your league's page. +https://www.fantasycritic.games/league/YOUR-LEAGUE-ID-HERE/YEAR ## Command list @@ -105,7 +103,7 @@ https://www.fantasycritic.games/league/YOUR-LEAGUE-ID-HERE/2020 * `!fcadd `: Add a channel that should receive updates from fcbot. * `!fcremove `: Remove a channel from receiving updates. - * `!fcleague `: Set this fcbot to monitor the given public league. + * `!fcleague `: Set this fcbot to monitor the given public league. * `!fclogin `: Set this fcbot to monitor the given private league. * `!fcstart`: Begin posting updates to added channels. * `!fcstop`: Stop posting any updates. @@ -114,9 +112,10 @@ https://www.fantasycritic.games/league/YOUR-LEAGUE-ID-HERE/2020 ## FAQ -### What happens with 2021 public leagues, once they exist?? +### Why does it sometimes report news twice? + +It's an intermittent bug, it will go away. I will fix it some day. I think it's something to do with memcache. -Unsupported for now, but it will be a small change once 2021 leagues are here. I will get to it then. ### It's broken aahhh diff --git a/src/bot/FCMongo.ts b/src/bot/FCMongo.ts index 74b1eef..0e55a40 100644 --- a/src/bot/FCMongo.ts +++ b/src/bot/FCMongo.ts @@ -12,11 +12,10 @@ export class FCMongo { COLLECTION_NAME = "fcbotdev"; constructor() { - // have to support both because of a weird heroku thing. (MONGODB_URI will be auto-deleted in heroku environments in November 2020 due to mLab discontinuing service, it's a whole thing.) - const mongo_uri = process.env.MONGO_URI || process.env.MONGODB_URI; + const mongo_uri = process.env.MONGO_URI; if (!mongo_uri) { - console.log("No MONGODB_URI set, no mongo for you"); + console.log("No MONGO_URI set, no mongo for you"); } else { this.mongo = new Mongo.MongoClient(mongo_uri, { useUnifiedTopology: true, diff --git a/src/bot/GuildWorker.ts b/src/bot/GuildWorker.ts index c2297e5..b0f656a 100644 --- a/src/bot/GuildWorker.ts +++ b/src/bot/GuildWorker.ts @@ -14,8 +14,6 @@ import { FCMemcache } from './FCMemcache' import { FCMongo } from './FCMongo' import { FCBot } from "./main"; -const GAME_YEAR = 2020; - export interface WorkerSaveState { guildId: string, fcAuth: any, @@ -278,7 +276,7 @@ export class GuildWorker { if (!this.lastMasterGameYear) this.lastMasterGameYear = await this.memcache.getLongLived( - FCMemcache.masterGameYearKey(GAME_YEAR) + FCMemcache.masterGameYearKey(this.league.year) ); } @@ -288,7 +286,7 @@ export class GuildWorker { this.memcache.setLongLived(FCMemcache.leagueActionsKey(this.league), this.lastLeagueActions); } - this.memcache.setLongLived(FCMemcache.masterGameYearKey(GAME_YEAR), this.lastMasterGameYear); + this.memcache.setLongLived(FCMemcache.masterGameYearKey(this.league.year), this.lastMasterGameYear); } private updatesForLeagueYear(newLeagueYear: FC.LeagueYear): string[] { @@ -347,10 +345,10 @@ export class GuildWorker { } private async getMGY(): Promise<_.Dictionary> { - const memKey = FCMemcache.masterGameYearKey(GAME_YEAR); + const memKey = FCMemcache.masterGameYearKey(this.league.year); var newMGYRaw: FC.MasterGameYear[] = await this.memcache.getLive(memKey); if (!newMGYRaw) { - newMGYRaw = await this.fc.getMasterGameYear(GAME_YEAR); + newMGYRaw = await this.fc.getMasterGameYear(this.league.year); this.memcache.setLive(memKey, newMGYRaw); } return _.keyBy(newMGYRaw, game => game.masterGameID); diff --git a/src/bot/main.ts b/src/bot/main.ts index 52cefbf..8d874d3 100644 --- a/src/bot/main.ts +++ b/src/bot/main.ts @@ -6,8 +6,6 @@ import { FCMongo } from './FCMongo'; require('dotenv').config() -const GAME_YEAR = 2020; - export class FCBot { discord: Discord.Client; @@ -175,13 +173,13 @@ export class FCBot { break; case "!fcleague": - if (args.length != 1) { - this.send(channel, "Usage: !fcleague "); - this.send(channel, "Your league ID is in the url for the league page - https://www.fantasycritic.games/league/YOUR-LEAGUE-ID-HERE/2020") + if (args.length != 2) { + this.send(channel, "Usage: !fcleague "); + this.send(channel, "Your league ID is in the url for the league page - https://www.fantasycritic.games/league/YOUR-LEAGUE-ID-HERE/YEAR") return; } - worker.setLeague(args[0], GAME_YEAR); - this.send(channel, "OK"); + worker.setLeague(args[0], Number(args[1])); + this.send(channel, "Now tracking league " + args[0] + " for league year " + args[1] + "."); break; case "!fclogin": @@ -191,7 +189,7 @@ export class FCBot { await worker.doFCLogin(args[0], args[1]); worker.setLeague(args[2], Number(args[3])); - this.send(channel, "OK"); + this.send(channel, "Now tracking league " + args[2] + " for league year " + args[3] + "."); break; case "!fcadminhelp": diff --git a/utils/check-oc.js b/utils/check-oc.js index fe1ed3e..c9276e7 100644 --- a/utils/check-oc.js +++ b/utils/check-oc.js @@ -32,7 +32,7 @@ async function getAllGamesForYear(year) { return allGames; } -getAllGamesForYear(2020).then( function (gamesArray) { +getAllGamesForYear(2021).then( function (gamesArray) { gamesArray.forEach(function (game) { console.log( `${game.id}: ${game.name} - ${game.firstReleaseDate}`