Skip to content

Commit

Permalink
support any league year
Browse files Browse the repository at this point in the history
and eradicate all references to the bad year
  • Loading branch information
drcatdoctor committed Dec 16, 2020
1 parent fe1dae1 commit e8ef3b2
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 30 deletions.
23 changes: 11 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <name of a channel you want updates to go to>
!fcleague <league ID>
!fcleague <league ID> <league year>
!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

Expand All @@ -81,7 +79,7 @@ In ANY channel in your server that Fantasy Critic Bot is in:
Example:
```
!fcadd fantasy-critic
!fclogin [email protected] s3cr3tpa55w0rd abb1234f-44c0-2c7d-9901-80aa314d26f6 2020
!fclogin [email protected] s3cr3tpa55w0rd abb1234f-44c0-2c7d-9901-80aa314d26f6 2021
!fcstart
```

Expand All @@ -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

Expand All @@ -105,7 +103,7 @@ https://www.fantasycritic.games/league/YOUR-LEAGUE-ID-HERE/2020

* `!fcadd <channel name>`: Add a channel that should receive updates from fcbot.
* `!fcremove <channel name>`: Remove a channel from receiving updates.
* `!fcleague <league ID>`: Set this fcbot to monitor the given public league.
* `!fcleague <league ID> <league year>`: Set this fcbot to monitor the given public league.
* `!fclogin <email> <password> <league ID> <league year>`: Set this fcbot to monitor the given private league.
* `!fcstart`: Begin posting updates to added channels.
* `!fcstop`: Stop posting any updates.
Expand All @@ -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

Expand Down
5 changes: 2 additions & 3 deletions src/bot/FCMongo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 4 additions & 6 deletions src/bot/GuildWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
);
}

Expand All @@ -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[] {
Expand Down Expand Up @@ -347,10 +345,10 @@ export class GuildWorker {
}

private async getMGY(): Promise<_.Dictionary<FC.MasterGameYear>> {
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);
Expand Down
14 changes: 6 additions & 8 deletions src/bot/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import { FCMongo } from './FCMongo';

require('dotenv').config()

const GAME_YEAR = 2020;

export class FCBot {

discord: Discord.Client;
Expand Down Expand Up @@ -175,13 +173,13 @@ export class FCBot {
break;

case "!fcleague":
if (args.length != 1) {
this.send(channel, "Usage: !fcleague <leagueId>");
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 <leagueId> <leagueYear>");
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":
Expand All @@ -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":
Expand Down
2 changes: 1 addition & 1 deletion utils/check-oc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
Expand Down

0 comments on commit e8ef3b2

Please sign in to comment.