Skip to content

Commit

Permalink
add clickable league link in fcscore
Browse files Browse the repository at this point in the history
and staticify urls and paths in FC.Client
  • Loading branch information
drcatdoctor committed Jan 4, 2021
1 parent 00a506c commit 36a9f89
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
7 changes: 5 additions & 2 deletions src/bot/GuildWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,12 @@ export class GuildWorker {
`**${Math.round(pl.totalFantasyPoints * 100) / 100} points**`;
}
}));
var embed = new Discord.MessageEmbed();
const embed = new Discord.MessageEmbed();
embed.setDescription(strings.join('\n'));
embed.setTitle("Fantasy Critic Score Report");

const user1 = leagueYear.players[0].user;
embed.setTitle(user1.leagueName);
embed.setURL(FC.Client.leagueUrl(this.league.id, this.league.year));
embed.setColor("ffcc00");
channel.send(embed);
}
Expand Down
35 changes: 22 additions & 13 deletions src/fc/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import _ = require("lodash");
import rp = require('request-promise');
import { EventEmitter } from "events";
import { League, LeagueYear, LeagueAction, MasterGameYear } from "./main";
import { stringify } from "querystring";

const request_options = {
headers: {
Expand All @@ -12,24 +13,32 @@ const request_options = {
};

export class Client extends EventEmitter {
private readonly BASE_URL = "https://www.fantasycritic.games/api";
private readonly PATH_GET_LEAGUE_YEAR = '/League/GetLeagueYear';
private readonly PATH_GET_LEAGUE_ACTIONS = '/League/GetLeagueActions';
private readonly PATH_GET_MASTER_GAME_YEAR = '/game/MasterGameYear';
private readonly PATH_POST_LOGIN = '/account/login';
private readonly PATH_POST_REFRESH = '/token/refresh';
static readonly SITE_URL = "https://www.fantasycritic.games";

private static readonly BASE_API_URL = Client.SITE_URL + "/api";
private static readonly PATH_GET_LEAGUE_YEAR = '/League/GetLeagueYear';
private static readonly PATH_GET_LEAGUE_ACTIONS = '/League/GetLeagueActions';
private static readonly PATH_GET_MASTER_GAME_YEAR = '/game/MasterGameYear';
private static readonly PATH_POST_LOGIN = '/account/login';
private static readonly PATH_POST_REFRESH = '/token/refresh';

auth: {
token: string;
refreshToken: string;
};

static leagueUrl(leagueID: string, year: number) {
return Client.SITE_URL + "/league/" + leagueID + "/" + year.toString();
}

async login(emailAddress: string, password: string) {
const params = {
emailAddress: emailAddress,
password: password
};
console.log("Logging in to FC");
const jsonbody = await rp.post(_.defaults({
url: this.BASE_URL + this.PATH_POST_LOGIN,
url: Client.BASE_API_URL + Client.PATH_POST_LOGIN,
body: params,
simple: true
}, request_options));
Expand All @@ -46,7 +55,7 @@ export class Client extends EventEmitter {
refreshToken: this.auth.refreshToken
};
const jsonbody = await rp.post(_.defaults({
url: this.BASE_URL + this.PATH_POST_REFRESH,
url: Client.BASE_API_URL + Client.PATH_POST_REFRESH,
body: params,
simple: true
}, request_options));
Expand All @@ -57,7 +66,7 @@ export class Client extends EventEmitter {
var self = this; // needed for functions because typescript is insane
if (this.auth) {
const getPromise = rp.get(_.defaults({
url: this.BASE_URL + path,
url: Client.BASE_API_URL + path,
qs: queryStringParams,
simple: false,
resolveWithFullResponse: true,
Expand All @@ -81,7 +90,7 @@ export class Client extends EventEmitter {
else {
// try it?
const getPromise = rp.get(_.defaults({
url: this.BASE_URL + path,
url: Client.BASE_API_URL + path,
qs: queryStringParams,
simple: false,
resolveWithFullResponse: true,
Expand All @@ -100,18 +109,18 @@ export class Client extends EventEmitter {
}
}
async getLeagueYear(league: League): Promise<LeagueYear> {
return this.get(this.PATH_GET_LEAGUE_YEAR, {
return this.get(Client.PATH_GET_LEAGUE_YEAR, {
leagueID: league.id,
year: league.year
});
}
async getLeagueActions(league: League): Promise<LeagueAction[]> {
return this.get(this.PATH_GET_LEAGUE_ACTIONS, {
return this.get(Client.PATH_GET_LEAGUE_ACTIONS, {
leagueID: league.id,
year: league.year
});
}
async getMasterGameYear(year: number): Promise<MasterGameYear[]> {
return this.get(this.PATH_GET_MASTER_GAME_YEAR + "/" + String(year));
return this.get(Client.PATH_GET_MASTER_GAME_YEAR + "/" + String(year));
}
}

0 comments on commit 36a9f89

Please sign in to comment.