From 6971b1aebce0ca1eea6f1b61f34e46df82e09e84 Mon Sep 17 00:00:00 2001 From: Sayak Mukhopadhyay Date: Sun, 16 Jul 2017 21:09:13 +0530 Subject: [PATCH] Changed all commands to use the EliteBGS API instead of local DB --- src/db/index.ts | 6 +- src/db/interfaces/faction.ts | 39 --- src/db/interfaces/index.ts | 2 - src/db/interfaces/system.ts | 47 ---- src/db/models/faction.ts | 21 -- src/db/models/index.ts | 2 - src/db/models/models.ts | 4 +- src/db/models/system.ts | 21 -- src/db/schemas/faction.ts | 50 ---- src/db/schemas/index.ts | 2 - src/db/schemas/system.ts | 58 ---- src/modules/discord/client.ts | 3 +- src/modules/discord/commands/bgsReport.ts | 247 ------------------ src/modules/discord/commands/factionStatus.ts | 163 ++++++++---- src/modules/discord/commands/index.ts | 1 - .../discord/commands/monitorFactions.ts | 24 +- .../discord/commands/monitorSystems.ts | 24 +- src/modules/discord/commands/systemStatus.ts | 170 ++++++++---- src/modules/eddn/eddn.ts | 69 ----- src/modules/eddn/schemas/blackmarket.ts | 40 --- src/modules/eddn/schemas/commodity.ts | 60 ----- src/modules/eddn/schemas/index.ts | 21 -- src/modules/eddn/schemas/journal.ts | 161 ------------ src/modules/eddn/schemas/outfitting.ts | 36 --- src/modules/eddn/schemas/shipyard.ts | 36 --- src/server.ts | 3 - 26 files changed, 229 insertions(+), 1081 deletions(-) delete mode 100644 src/db/interfaces/faction.ts delete mode 100644 src/db/interfaces/system.ts delete mode 100644 src/db/models/faction.ts delete mode 100644 src/db/models/system.ts delete mode 100644 src/db/schemas/faction.ts delete mode 100644 src/db/schemas/system.ts delete mode 100644 src/modules/discord/commands/bgsReport.ts delete mode 100644 src/modules/eddn/eddn.ts delete mode 100644 src/modules/eddn/schemas/blackmarket.ts delete mode 100644 src/modules/eddn/schemas/commodity.ts delete mode 100644 src/modules/eddn/schemas/index.ts delete mode 100644 src/modules/eddn/schemas/journal.ts delete mode 100644 src/modules/eddn/schemas/outfitting.ts delete mode 100644 src/modules/eddn/schemas/shipyard.ts diff --git a/src/db/index.ts b/src/db/index.ts index b5f9375..33fd9e0 100644 --- a/src/db/index.ts +++ b/src/db/index.ts @@ -17,9 +17,9 @@ import * as mongoose from 'mongoose'; import { DBSecrets } from '../secrets'; -import { guildSchema, systemSchema, factionSchema } from './schemas'; +import { guildSchema } from './schemas'; -import { IModel, IGuildModel, ISystemModel, IFactionModel } from './models'; +import { IModel, IGuildModel } from './models'; export class DB { private options: mongoose.ConnectionOptions; @@ -79,8 +79,6 @@ export class DB { createModels(): void { this.model.guild = mongoose.model("Guild", guildSchema); - this.model.system = mongoose.model("System", systemSchema); - this.model.faction = mongoose.model("Faction", factionSchema); } } diff --git a/src/db/interfaces/faction.ts b/src/db/interfaces/faction.ts deleted file mode 100644 index 12823b3..0000000 --- a/src/db/interfaces/faction.ts +++ /dev/null @@ -1,39 +0,0 @@ -/* - * KodeBlox Copyright 2017 Sayak Mukhopadhyay - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http: //www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -export interface IFaction { - faction_name: string, - faction_name_lower: string, - created_at: Date, - updated_at: Date, - faction_government: string, - faction_presence: [{ - system_name: string, - system_name_lower: string, - updated_at: Date, - influence: number, - state: string, - isControlling: boolean, - pending_states: [{ - state: string, - trend: number - }], - recovering_states: [{ - state: string, - trend: number - }], - }] -} diff --git a/src/db/interfaces/index.ts b/src/db/interfaces/index.ts index 45b2c0c..ce5035c 100644 --- a/src/db/interfaces/index.ts +++ b/src/db/interfaces/index.ts @@ -15,5 +15,3 @@ */ export * from './guild'; -export * from './system'; -export * from './faction'; diff --git a/src/db/interfaces/system.ts b/src/db/interfaces/system.ts deleted file mode 100644 index a7bc995..0000000 --- a/src/db/interfaces/system.ts +++ /dev/null @@ -1,47 +0,0 @@ -/* - * KodeBlox Copyright 2017 Sayak Mukhopadhyay - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http: //www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -export interface ISystem { - system_name: string, - system_name_lower: string, - created_at: Date, - updated_at: Date, - system_faction: string, - system_faction_lower: string, - faction_state: string, - system_allegiance: string, - system_economy: string, - system_government: string, - system_security: string, - factions: [{ - faction_name: string, - faction_name_lower: string, - updated_at: Date, - faction_state: string, - faction_government: string, - faction_influence: number, - faction_pending_states: [{ - state: string, - trend: number - }], - faction_recovering_states: [{ - state: string, - trend: number - }] - }], - powers: string[], - powerplay_state: string -} diff --git a/src/db/models/faction.ts b/src/db/models/faction.ts deleted file mode 100644 index e405726..0000000 --- a/src/db/models/faction.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * KodeBlox Copyright 2017 Sayak Mukhopadhyay - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http: //www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { Document } from 'mongoose'; -import { IFaction } from '../interfaces'; - -export interface IFactionModel extends Document, IFaction { -} diff --git a/src/db/models/index.ts b/src/db/models/index.ts index 6ebfdf6..1783d02 100644 --- a/src/db/models/index.ts +++ b/src/db/models/index.ts @@ -16,5 +16,3 @@ export * from './models'; export * from './guild'; -export * from './system'; -export * from './faction'; diff --git a/src/db/models/models.ts b/src/db/models/models.ts index d472d2d..63e5e78 100644 --- a/src/db/models/models.ts +++ b/src/db/models/models.ts @@ -15,10 +15,8 @@ */ import { Model } from 'mongoose'; -import { IGuildModel, ISystemModel, IFactionModel } from './'; +import { IGuildModel } from './'; export interface IModel { guild: Model; - system: Model; - faction: Model; } diff --git a/src/db/models/system.ts b/src/db/models/system.ts deleted file mode 100644 index ca3ff9d..0000000 --- a/src/db/models/system.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * KodeBlox Copyright 2017 Sayak Mukhopadhyay - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http: //www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { Document } from 'mongoose'; -import { ISystem } from '../interfaces'; - -export interface ISystemModel extends Document, ISystem { -} diff --git a/src/db/schemas/faction.ts b/src/db/schemas/faction.ts deleted file mode 100644 index 3835a70..0000000 --- a/src/db/schemas/faction.ts +++ /dev/null @@ -1,50 +0,0 @@ -/* - * KodeBlox Copyright 2017 Sayak Mukhopadhyay - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http: //www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { Schema } from 'mongoose'; - -export let factionSchema: Schema = new Schema({ - faction_name: { - type: String, - unique: true - }, - faction_name_lower: String, - created_at: { - type: Date, - default: Date.now - }, - updated_at: Date, - faction_government: String, - faction_presence: [{ - _id: false, - system_name: String, - system_name_lower: String, - updated_at: Date, - influence: Number, - state: String, - isControlling: Boolean, - pending_states: [{ - _id: false, - state: String, - trend: Number - }], - recovering_states: [{ - _id: false, - state: String, - trend: Number - }], - }] -}); diff --git a/src/db/schemas/index.ts b/src/db/schemas/index.ts index 45b2c0c..ce5035c 100644 --- a/src/db/schemas/index.ts +++ b/src/db/schemas/index.ts @@ -15,5 +15,3 @@ */ export * from './guild'; -export * from './system'; -export * from './faction'; diff --git a/src/db/schemas/system.ts b/src/db/schemas/system.ts deleted file mode 100644 index d58d336..0000000 --- a/src/db/schemas/system.ts +++ /dev/null @@ -1,58 +0,0 @@ -/* - * KodeBlox Copyright 2017 Sayak Mukhopadhyay - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http: //www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { Schema } from 'mongoose'; - -export let systemSchema: Schema = new Schema({ - system_name: { - type: String, - unique: true - }, - system_name_lower: String, - created_at: { - type: Date, - default: Date.now - }, - updated_at: Date, - system_faction: String, - system_faction_lower: String, - faction_state: String, - system_allegiance: String, - system_economy: String, - system_government: String, - system_security: String, - factions: [{ - _id: false, - faction_name: String, - faction_name_lower: String, - updated_at: Date, - faction_state: String, - faction_government: String, - faction_influence: Number, - faction_pending_states: [{ - _id: false, - state: String, - trend: Number - }], - faction_recovering_states: [{ - _id: false, - state: String, - trend: Number - }] - }], - powers: [String], - powerplay_state: String -}); diff --git a/src/modules/discord/client.ts b/src/modules/discord/client.ts index 0bcaac4..2dacbb8 100644 --- a/src/modules/discord/client.ts +++ b/src/modules/discord/client.ts @@ -17,7 +17,7 @@ import * as discord from 'discord.js'; import { DiscordSecrets } from '../../secrets'; import { Responses } from './responseDict'; -import { Hi, Help, MyGuild, BGSRole, AdminRoles, ForbiddenRoles, BGSChannel, MonitorSystems, MonitorFactions, SystemStatus, FactionStatus, BGSReport } from './commands'; +import { Hi, Help, MyGuild, BGSRole, AdminRoles, ForbiddenRoles, BGSChannel, MonitorSystems, MonitorFactions, SystemStatus, FactionStatus } from './commands'; export class DiscordClient { public client: discord.Client; @@ -71,6 +71,5 @@ export class DiscordClient { this.commandsMap.set("monitorfactions", MonitorFactions); this.commandsMap.set("systemstatus", SystemStatus); this.commandsMap.set("factionstatus", FactionStatus); - this.commandsMap.set("bgsreport", BGSReport); } } diff --git a/src/modules/discord/commands/bgsReport.ts b/src/modules/discord/commands/bgsReport.ts deleted file mode 100644 index c04b37a..0000000 --- a/src/modules/discord/commands/bgsReport.ts +++ /dev/null @@ -1,247 +0,0 @@ -/* - * KodeBlox Copyright 2017 Sayak Mukhopadhyay - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http: //www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import * as discord from 'discord.js'; -import App from '../../../server'; -import { Responses } from '../responseDict'; -import { DB } from '../../../db/index'; -import { Access } from './../access'; - -export class BGSReport { - db: DB; - constructor() { - this.db = App.db; - } - exec(message: discord.Message, commandArguments: string): void { - let argsArray: string[] = []; - if (commandArguments.length !== 0) { - argsArray = commandArguments.split(" "); - } - if (argsArray.length > 0) { - let command = argsArray[0].toLowerCase(); - if (this[command]) { - this[command](message, argsArray); - } else { - message.channel.send(Responses.getResponse(Responses.NOTACOMMAND)); - } - } else { - message.channel.send(Responses.getResponse(Responses.NOPARAMS)); - } - } - - get(message: discord.Message, argsArray: string[]): void { - Access.has(message.member, [Access.ADMIN, Access.BGS, Access.FORBIDDEN]) - .then(() => { - if (argsArray.length === 1) { - let guildId = message.guild.id; - this.db.model.guild.findOne({ guild_id: guildId }) - .then(guild => { - if (guild) { - let primaryFactions = []; - let secondaryFactions = []; - guild.monitor_factions.forEach(faction => { - if (faction.primary) { - primaryFactions.push(faction.faction_name); - } else { - secondaryFactions.push(faction.faction_name); - } - }); - let primarySystems = []; - let secondarySystems = [] - guild.monitor_systems.forEach(system => { - if (system.primary) { - primarySystems.push(system.system_name); - } else { - secondarySystems.push(system.system_name); - } - }); - this.db.model.faction.find({ faction_name_lower: { $in: primaryFactions } }) - .then(factions => { - if (factions) { - let embed = new discord.RichEmbed(); - embed.setTitle("BGS REPORT"); - embed.setColor([255, 100, 255]); - factions.forEach(faction => { - let factionAcronym = this.acronym(faction.faction_name); - embed.addField(faction.faction_name, "------------", false); - let factionPromiseArray = []; - faction.faction_presence.forEach((faction) => { - let systemReport = ""; - systemReport += `Current ${factionAcronym} Influence : ${(faction.influence * 100).toFixed(1)}%\n`; - systemReport += `Current ${factionAcronym} State : ${faction.state}\n`; - let pendingStates: string = ""; - if (faction.pending_states.length === 0) { - pendingStates = "None"; - } else { - faction.pending_states.forEach((pendingState, index, factionPendingStates) => { - let trend = this.getTrendIcon(pendingState.trend); - pendingStates = `${pendingStates}${pendingState.state}${trend}`; - if (index !== factionPendingStates.length - 1) { - pendingStates = `${pendingStates}, ` - } - }); - } - systemReport += `Pending ${factionAcronym} States : ${pendingStates}\n`; - secondaryFactions.forEach(otherFaction => { - factionPromiseArray.push( - new Promise((resolve, reject) => { - this.db.model.faction.findOne({ faction_name_lower: otherFaction }) - .then(otherFaction => { - if (otherFaction) { - let systems = otherFaction.faction_presence; - let indexOfSystem = systems.findIndex(x => x.system_name === faction.system_name); - if (indexOfSystem !== -1) { - let factionAcronym = this.acronym(otherFaction.faction_name); - let otherSystem = otherFaction.faction_presence[indexOfSystem]; - systemReport += `Current ${factionAcronym} Influence : ${(otherSystem.influence * 100).toFixed(1)}% (Currently in ${otherSystem.state})\n`; - } - } - resolve(systemReport); - }) - .catch(err => { - reject(err); - }); - }) - ); - }); - console.log(factionPromiseArray); - Promise.all(factionPromiseArray) - .then(systemReport => { - embed.addField(faction.system_name, systemReport); - }) - .catch(err => { - console.log(err); - }) - }); - }); - embed.setTimestamp(new Date()); - message.channel.send({ embed }) - .catch(err => { - console.log(err); - }); - } else { - message.channel.send(Responses.getResponse(Responses.FAIL)) - .then(() => { - message.channel.send("You don't have any factions under monitoring"); - }) - .catch(err => { - console.log(err); - }); - } - }); - } else { - message.channel.send(Responses.getResponse(Responses.FAIL)) - .then(() => { - message.channel.send("Your guild is not set yet"); - }) - .catch(err => { - console.log(err); - }); - } - - }); - - // this.db.model.system.findOne( - // { system_name_lower: systemName }) - // .then(system => { - // if (system) { - // let embed = new discord.RichEmbed(); - // embed.setTitle("SYSTEM STATUS"); - // embed.setColor([255, 0, 255]); - // if (system.faction_state === null) { - // system.faction_state = "None"; - // } - // embed.addField(system.system_name, system.faction_state, false); - // system.factions.forEach((faction) => { - // let factionDetail = ""; - // factionDetail += `State : ${faction.faction_state}\n`; - // factionDetail += `Influence : ${(faction.faction_influence * 100).toFixed(1)}%\n`; - // let pendingStates: string = ""; - // if (faction.faction_pending_states.length === 0) { - // pendingStates = "None"; - // } else { - // faction.faction_pending_states.forEach((pendingState, index, factionPendingStates) => { - // let trend = this.getTrendIcon(pendingState.trend); - // pendingStates = `${pendingStates}${pendingState.state}${trend}`; - // if (index !== factionPendingStates.length - 1) { - // pendingStates = `${pendingStates}, ` - // } - // }); - // } - // factionDetail += `Pending States : ${pendingStates}\n`; - // let recoveringStates: string = ""; - // if (faction.faction_recovering_states.length === 0) { - // recoveringStates = "None"; - // } else { - // faction.faction_recovering_states.forEach((recoveringState, index, factionRecoveringState) => { - // let trend = this.getTrendIcon(recoveringState.trend); - // recoveringStates = `${recoveringStates}${recoveringState.state}${trend}`; - // if (index !== factionRecoveringState.length - 1) { - // recoveringStates = `${recoveringStates}, ` - // } - // }) - // } - // factionDetail += `Recovering States : ${recoveringStates}`; - // let factionName = faction.faction_name; - // if (system.system_faction === factionName) { - // factionName += "* CONTROLLING FACTION"; - // } - // embed.addField(factionName, factionDetail, false) - // }); - // embed.setTimestamp(new Date()); - // message.channel.send({ embed }) - // .catch(err => { - // console.log(err); - // }); - // } else { - // message.channel.send(Responses.getResponse(Responses.FAIL)) - // .then(() => { - // message.channel.send("System is not monitored"); - // }) - // .catch(err => { - // console.log(err); - // }); - // } - // }) - // .catch(err => { - // message.channel.send(Responses.getResponse(Responses.FAIL)); - // console.log(err); - // }) - } else { - message.channel.send(Responses.getResponse(Responses.TOOMANYPARAMS)); - } - }) - .catch(() => { - message.channel.send(Responses.getResponse(Responses.INSUFFICIENTPERMS)); - }) - } - - private getTrendIcon(trend: number): string { - if (trend > 0) { - return "⬆️"; - } else if (trend < 0) { - return "⬇️"; - } else { - return "↔️"; - } - } - - private acronym(text) { - return text - .split(/\s/) - .reduce((accumulator, word) => accumulator + word.charAt(0), ''); - } -} diff --git a/src/modules/discord/commands/factionStatus.ts b/src/modules/discord/commands/factionStatus.ts index cdd7604..09c1f7f 100644 --- a/src/modules/discord/commands/factionStatus.ts +++ b/src/modules/discord/commands/factionStatus.ts @@ -15,6 +15,7 @@ */ import * as discord from 'discord.js'; +import * as request from 'request'; import App from '../../../server'; import { Responses } from '../responseDict'; import { DB } from '../../../db/index'; @@ -48,69 +49,123 @@ export class FactionStatus { if (argsArray.length >= 2) { let factionName: string = argsArray.slice(1).join(" ").toLowerCase(); - this.db.model.faction.findOne( - { faction_name_lower: factionName }) - .then(faction => { - if (faction) { + let requestOptions = { + url: "http://elitebgs.kodeblox.com/api/ebgs/v1/factions", + method: "GET", + auth: { + 'user': 'guest', + 'pass': 'secret', + 'sendImmediately': true + }, + qs: { name: factionName } + } + + request(requestOptions, (error, response, body) => { + if (!error && response.statusCode == 200) { + let responseData: string = body; + if (responseData.length === 2) { + message.channel.send(Responses.getResponse(Responses.FAIL)) + .then(() => { + message.channel.send("Faction not found"); + }) + .catch(err => { + console.log(err); + }); + } else { + let responseObject: object = JSON.parse(responseData); + let factionName = responseObject[0].name; + let factionNameLower = responseObject[0].name_lower; + let government = responseObject[0].government; + let presence = responseObject[0].faction_presence; let embed = new discord.RichEmbed(); embed.setTitle("FACTION STATUS"); - embed.setColor([255, 100, 255]); - embed.addField(faction.faction_name, faction.faction_government, false); - faction.faction_presence.forEach((faction) => { - let factionDetail = ""; - factionDetail += `State : ${faction.state}\n`; - factionDetail += `Influence : ${(faction.influence * 100).toFixed(1)}%\n`; - let pendingStates: string = ""; - if (faction.pending_states.length === 0) { - pendingStates = "None"; - } else { - faction.pending_states.forEach((pendingState, index, factionPendingStates) => { - let trend = this.getTrendIcon(pendingState.trend); - pendingStates = `${pendingStates}${pendingState.state}${trend}`; - if (index !== factionPendingStates.length - 1) { - pendingStates = `${pendingStates}, ` - } - }); + embed.setColor([255, 0, 255]); + embed.addField(factionName, government, false); + let historyPromises = []; + presence.forEach((system) => { + let requestOptions = { + url: "http://elitebgs.kodeblox.com/api/ebgs/v1/factions", + method: "GET", + auth: { + 'user': 'guest', + 'pass': 'secret', + 'sendImmediately': true + }, + qs: { + name: factionNameLower, + system: system.system_name_lower + } } - factionDetail += `Pending States : ${pendingStates}\n`; - let recoveringStates: string = ""; - if (faction.recovering_states.length === 0) { - recoveringStates = "None"; - } else { - faction.recovering_states.forEach((recoveringState, index, factionRecoveringState) => { - let trend = this.getTrendIcon(recoveringState.trend); - recoveringStates = `${recoveringStates}${recoveringState.state}${trend}`; - if (index !== factionRecoveringState.length - 1) { - recoveringStates = `${recoveringStates}, ` + historyPromises.push(new Promise((resolve, reject) => { + request(requestOptions, (error, response, body) => { + if (!error && response.statusCode == 200) { + let responseData: string = body; + if (responseData.length === 2) { + resolve([system.system_name, "Faction status not found"]); + } else { + let responseObject: object = JSON.parse(responseData); + let systemName = responseObject[0].history[0].system; + let systemNameLower = responseObject[0].history[0].system_lower; + let state = responseObject[0].history[0].state; + let influence = responseObject[0].history[0].influence; + let pendingStatesArray = responseObject[0].history[0].pending_states; + let recoveringStatesArray = responseObject[0].history[0].recovering_states; + + let factionDetail = ""; + factionDetail += `State : ${state}\n`; + factionDetail += `Influence : ${(influence * 100).toFixed(1)}%\n`; + + let pendingStates: string = ""; + if (pendingStatesArray.length === 0) { + pendingStates = "None"; + } else { + pendingStatesArray.forEach((pendingState, index, factionPendingStates) => { + let trend = this.getTrendIcon(pendingState.trend); + pendingStates = `${pendingStates}${pendingState.state}${trend}`; + if (index !== factionPendingStates.length - 1) { + pendingStates = `${pendingStates}, ` + } + }); + } + factionDetail += `Pending States : ${pendingStates}\n`; + let recoveringStates: string = ""; + if (recoveringStatesArray.length === 0) { + recoveringStates = "None"; + } else { + recoveringStatesArray.forEach((recoveringState, index, factionRecoveringState) => { + let trend = this.getTrendIcon(recoveringState.trend); + recoveringStates = `${recoveringStates}${recoveringState.state}${trend}`; + if (index !== factionRecoveringState.length - 1) { + recoveringStates = `${recoveringStates}, ` + } + }) + } + factionDetail += `Recovering States : ${recoveringStates}`; + resolve([systemName, factionDetail]); + } } }) - } - factionDetail += `Recovering States : ${recoveringStates}`; - let systemName = faction.system_name; - // if (system.system_faction === factionName) { - // factionName += "* CONTROLLING FACTION"; - // } - embed.addField(systemName, factionDetail, false) - }); - embed.setTimestamp(new Date()); - message.channel.send({ embed }) - .catch(err => { - console.log(err); - }); - } else { - message.channel.send(Responses.getResponse(Responses.FAIL)) - .then(() => { - message.channel.send("Faction is not monitored"); + })); + }) + + Promise.all(historyPromises) + .then(fields => { + fields.forEach(field => { + embed.addField(field[0], field[1]); + }) + embed.setTimestamp(new Date()); + message.channel.send({ embed }) + .catch(err => { + console.log(err); + }); }) .catch(err => { + message.channel.send(Responses.getResponse(Responses.FAIL)); console.log(err); - }); + }) } - }) - .catch(err => { - message.channel.send(Responses.getResponse(Responses.FAIL)); - console.log(err); - }) + } + }) } else { message.channel.send(Responses.getResponse(Responses.NOPARAMS)); } diff --git a/src/modules/discord/commands/index.ts b/src/modules/discord/commands/index.ts index ff4feb9..f4f6be7 100644 --- a/src/modules/discord/commands/index.ts +++ b/src/modules/discord/commands/index.ts @@ -25,4 +25,3 @@ export * from './monitorSystems'; export * from './monitorFactions'; export * from './systemStatus'; export * from './factionStatus'; -export * from './bgsReport'; diff --git a/src/modules/discord/commands/monitorFactions.ts b/src/modules/discord/commands/monitorFactions.ts index a193d28..c43083a 100644 --- a/src/modules/discord/commands/monitorFactions.ts +++ b/src/modules/discord/commands/monitorFactions.ts @@ -87,29 +87,7 @@ export class MonitorFactions { }) .then(guild => { if (guild) { - this.db.model.faction.findOne({ faction_name_lower: factionNameLower }) - .then(faction => { - if (faction) { - message.channel.send(Responses.getResponse(Responses.SUCCESS)); - } else { - this.db.model.faction.create({ - faction_name: factionName, - faction_name_lower: factionNameLower, - updated_at: new Date() - }) - .then(system => { - message.channel.send(Responses.getResponse(Responses.SUCCESS)); - }) - .catch(err => { - message.channel.send(Responses.getResponse(Responses.FAIL)); - console.log(err); - }); - } - }) - .catch(err => { - message.channel.send(Responses.getResponse(Responses.FAIL)); - console.log(err); - }) + message.channel.send(Responses.getResponse(Responses.SUCCESS)); } else { message.channel.send(Responses.getResponse(Responses.FAIL)) .then(() => { diff --git a/src/modules/discord/commands/monitorSystems.ts b/src/modules/discord/commands/monitorSystems.ts index 826feb5..24c2a70 100644 --- a/src/modules/discord/commands/monitorSystems.ts +++ b/src/modules/discord/commands/monitorSystems.ts @@ -92,29 +92,7 @@ export class MonitorSystems { }) .then(guild => { if (guild) { - this.db.model.system.findOne({ system_name_lower: systemNameLower }) - .then(system => { - if (system) { - message.channel.send(Responses.getResponse(Responses.SUCCESS)); - } else { - this.db.model.system.create({ - system_name: systemName, - system_name_lower: systemNameLower, - updated_at: new Date() - }) - .then(system => { - message.channel.send(Responses.getResponse(Responses.SUCCESS)); - }) - .catch(err => { - message.channel.send(Responses.getResponse(Responses.FAIL)); - console.log(err); - }); - } - }) - .catch(err => { - message.channel.send(Responses.getResponse(Responses.FAIL)); - console.log(err); - }) + message.channel.send(Responses.getResponse(Responses.SUCCESS)); } else { message.channel.send(Responses.getResponse(Responses.FAIL)) .then(() => { diff --git a/src/modules/discord/commands/systemStatus.ts b/src/modules/discord/commands/systemStatus.ts index 3543f6a..358489c 100644 --- a/src/modules/discord/commands/systemStatus.ts +++ b/src/modules/discord/commands/systemStatus.ts @@ -15,6 +15,7 @@ */ import * as discord from 'discord.js'; +import * as request from 'request'; import App from '../../../server'; import { Responses } from '../responseDict'; import { DB } from '../../../db/index'; @@ -48,72 +49,130 @@ export class SystemStatus { if (argsArray.length >= 2) { let systemName: string = argsArray.slice(1).join(" ").toLowerCase(); - this.db.model.system.findOne( - { system_name_lower: systemName }) - .then(system => { - if (system) { + let requestOptions = { + url: "http://elitebgs.kodeblox.com/api/ebgs/v1/systems", + method: "GET", + auth: { + 'user': 'guest', + 'pass': 'secret', + 'sendImmediately': true + }, + qs: { name: systemName } + } + + request(requestOptions, (error, response, body) => { + if (!error && response.statusCode == 200) { + let responseData: string = body; + if (responseData.length === 2) { + message.channel.send(Responses.getResponse(Responses.FAIL)) + .then(() => { + message.channel.send("System not found"); + }) + .catch(err => { + console.log(err); + }); + } else { + let responseObject: object = JSON.parse(responseData); + let systemName = responseObject[0].name; + let systemNameLower = responseObject[0].name_lower; + let systemState = responseObject[0].state; + let controlling = responseObject[0].controlling_minor_faction; + let minorFactions = responseObject[0].minor_faction_presences; let embed = new discord.RichEmbed(); embed.setTitle("SYSTEM STATUS"); embed.setColor([255, 0, 255]); - if (system.faction_state === null) { - system.faction_state = "None"; + if (systemState === null) { + systemState = "None"; } - embed.addField(system.system_name, system.faction_state, false); - system.factions.forEach((faction) => { - let factionDetail = ""; - factionDetail += `State : ${faction.faction_state}\n`; - factionDetail += `Influence : ${(faction.faction_influence * 100).toFixed(1)}%\n`; - let pendingStates: string = ""; - if (faction.faction_pending_states.length === 0) { - pendingStates = "None"; - } else { - faction.faction_pending_states.forEach((pendingState, index, factionPendingStates) => { - let trend = this.getTrendIcon(pendingState.trend); - pendingStates = `${pendingStates}${pendingState.state}${trend}`; - if (index !== factionPendingStates.length - 1) { - pendingStates = `${pendingStates}, ` - } - }); + embed.addField(systemName, systemState, false); + let factionPromises = []; + minorFactions.forEach((faction) => { + let requestOptions = { + url: "http://elitebgs.kodeblox.com/api/ebgs/v1/factions", + method: "GET", + auth: { + 'user': 'guest', + 'pass': 'secret', + 'sendImmediately': true + }, + qs: { + name: faction.name_lower, + system: systemNameLower + } } - factionDetail += `Pending States : ${pendingStates}\n`; - let recoveringStates: string = ""; - if (faction.faction_recovering_states.length === 0) { - recoveringStates = "None"; - } else { - faction.faction_recovering_states.forEach((recoveringState, index, factionRecoveringState) => { - let trend = this.getTrendIcon(recoveringState.trend); - recoveringStates = `${recoveringStates}${recoveringState.state}${trend}`; - if (index !== factionRecoveringState.length - 1) { - recoveringStates = `${recoveringStates}, ` + factionPromises.push(new Promise((resolve, reject) => { + request(requestOptions, (error, response, body) => { + if (!error && response.statusCode == 200) { + let responseData: string = body; + if (responseData.length === 2) { + resolve([faction.name, "Faction status not found"]); + } else { + let responseObject: object = JSON.parse(responseData); + let factionName = responseObject[0].name; + let factionNameLower = responseObject[0].name_lower; + let state = responseObject[0].history[0].state; + let influence = responseObject[0].history[0].influence; + let pendingStatesArray = responseObject[0].history[0].pending_states; + let recoveringStatesArray = responseObject[0].history[0].recovering_states; + + let factionDetail = ""; + factionDetail += `State : ${state}\n`; + factionDetail += `Influence : ${(influence * 100).toFixed(1)}%\n`; + + let pendingStates: string = ""; + if (pendingStatesArray.length === 0) { + pendingStates = "None"; + } else { + pendingStatesArray.forEach((pendingState, index, factionPendingStates) => { + let trend = this.getTrendIcon(pendingState.trend); + pendingStates = `${pendingStates}${pendingState.state}${trend}`; + if (index !== factionPendingStates.length - 1) { + pendingStates = `${pendingStates}, ` + } + }); + } + factionDetail += `Pending States : ${pendingStates}\n`; + let recoveringStates: string = ""; + if (recoveringStatesArray.length === 0) { + recoveringStates = "None"; + } else { + recoveringStatesArray.forEach((recoveringState, index, factionRecoveringState) => { + let trend = this.getTrendIcon(recoveringState.trend); + recoveringStates = `${recoveringStates}${recoveringState.state}${trend}`; + if (index !== factionRecoveringState.length - 1) { + recoveringStates = `${recoveringStates}, ` + } + }) + } + factionDetail += `Recovering States : ${recoveringStates}`; + if (controlling === factionNameLower) { + factionName += '* CONTROLLING FACTION'; + } + resolve([factionName, factionDetail]); + } } }) - } - factionDetail += `Recovering States : ${recoveringStates}`; - let factionName = faction.faction_name; - if (system.system_faction === factionName) { - factionName += "* CONTROLLING FACTION"; - } - embed.addField(factionName, factionDetail, false) - }); - embed.setTimestamp(new Date()); - message.channel.send({ embed }) - .catch(err => { - console.log(err); - }); - } else { - message.channel.send(Responses.getResponse(Responses.FAIL)) - .then(() => { - message.channel.send("System is not monitored"); + })); + }) + + Promise.all(factionPromises) + .then(fields => { + fields.forEach(field => { + embed.addField(field[0], field[1]); + }) + embed.setTimestamp(new Date()); + message.channel.send({ embed }) + .catch(err => { + console.log(err); + }); }) .catch(err => { + message.channel.send(Responses.getResponse(Responses.FAIL)); console.log(err); - }); + }) } - }) - .catch(err => { - message.channel.send(Responses.getResponse(Responses.FAIL)); - console.log(err); - }) + } + }) } else { message.channel.send(Responses.getResponse(Responses.NOPARAMS)); } @@ -122,7 +181,6 @@ export class SystemStatus { message.channel.send(Responses.getResponse(Responses.INSUFFICIENTPERMS)); }) } - private getTrendIcon(trend: number): string { if (trend > 0) { return "⬆️"; diff --git a/src/modules/eddn/eddn.ts b/src/modules/eddn/eddn.ts deleted file mode 100644 index 909afac..0000000 --- a/src/modules/eddn/eddn.ts +++ /dev/null @@ -1,69 +0,0 @@ -/* - * KodeBlox Copyright 2017 Sayak Mukhopadhyay - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http: //www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import * as zlib from 'zlib'; -import * as zmq from 'zmq'; -import * as ajv from 'ajv'; - -import { Blackmarket, Commodity, Journal, Outfitting, Shipyard } from './schemas'; - -export class Eddn { - public static readonly relay: string = 'tcp://eddn.edcd.io:9500'; - private socket: zmq.Socket; - - constructor() { - this.socket = zmq.socket('sub'); - this.connectToRelay(); - this.listenToRelay(); - } - - private connectToRelay(): void { - this.socket.connect(Eddn.relay); - console.log('Connected to EDDN relay at port 9500'); - this.socket.subscribe(''); - console.log('Subscribed to EDDN'); - } - - private listenToRelay(): void { - this.socket.on('message', topic => { - let message = JSON.parse(zlib.inflateSync(topic).toString()); - switch (message['$schemaRef']) { - case Blackmarket.schemaId: - let blackmarket = new Blackmarket(message.message); - // blackmarket.display(); - break; - case Commodity.schemaId: - let commodity = new Commodity(message.message); - // commodity.display(); - break; - case Journal.schemaId: - let journal = new Journal(message.message); - journal.trackSystem(); - // journal.display(); - break; - case Outfitting.schemaId: - let outfitting = new Outfitting(message.message); - // outfitting.display(); - break; - case Shipyard.schemaId: - let shipyard = new Shipyard(message.message); - // shipyard.display(); - break; - default: //console.log("Schema not Found"); - } - }); - } -} diff --git a/src/modules/eddn/schemas/blackmarket.ts b/src/modules/eddn/schemas/blackmarket.ts deleted file mode 100644 index 58d095c..0000000 --- a/src/modules/eddn/schemas/blackmarket.ts +++ /dev/null @@ -1,40 +0,0 @@ -/* - * KodeBlox Copyright 2017 Sayak Mukhopadhyay - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http: //www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -export class Blackmarket { - public static readonly schemaId: string = "http://schemas.elite-markets.net/eddn/blackmarket/1"; - private message: any; - private systemName: string; - private stationName: string; - private timestamp: string; - private name: string; - private sellPrice: number; - private prohibited: boolean; - - constructor(message: any) { - this.message = message; - this.systemName = message.systemName; - this.stationName = message.stationName; - this.timestamp = message.timestamp; - this.name = message.name; - this.sellPrice = message.sellPrice; - this.prohibited = message.prohibited; - } - - display(): void { - console.log(this.message); - } -} diff --git a/src/modules/eddn/schemas/commodity.ts b/src/modules/eddn/schemas/commodity.ts deleted file mode 100644 index e52f4f5..0000000 --- a/src/modules/eddn/schemas/commodity.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* - * KodeBlox Copyright 2017 Sayak Mukhopadhyay - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http: //www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -export class Commodity { - public static readonly schemaId: string = "http://schemas.elite-markets.net/eddn/commodity/3"; - private message: any; - private systemName: string; - private stationName: string; - private timestamp: string; - private commodities: SingleCommodity; - - constructor(message: any) { - this.message = message; - this.systemName = message.systemName; - this.stationName = message.stationName; - this.timestamp = message.timestamp; - this.commodities = new SingleCommodity(message.commodities); - } - - display(): void { - console.log(this.message); - } -} - -export class SingleCommodity { - private name: string; - private meanPrice: number; - private buyPrice: number; - private stock: number; - private stockBracket: any; - private sellPrice: number; - private demand: number; - private demandBracket: any; - private statusFlags: string[]; - - constructor(commodity: any) { - this.name = commodity.name; - this.meanPrice = commodity.meanPrice; - this.buyPrice = commodity.buyPrice; - this.stock = commodity.stock; - this.stockBracket = commodity.stockBracket; - this.sellPrice = commodity.sellPrice; - this.demand = commodity.demand; - this.demandBracket = commodity.demandBracket; - this.statusFlags = commodity.statusFlags; - } -} diff --git a/src/modules/eddn/schemas/index.ts b/src/modules/eddn/schemas/index.ts deleted file mode 100644 index c17025b..0000000 --- a/src/modules/eddn/schemas/index.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * KodeBlox Copyright 2017 Sayak Mukhopadhyay - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http: //www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -export * from './blackmarket'; -export * from './commodity'; -export * from './journal'; -export * from './outfitting'; -export * from './shipyard'; diff --git a/src/modules/eddn/schemas/journal.ts b/src/modules/eddn/schemas/journal.ts deleted file mode 100644 index 5c4f376..0000000 --- a/src/modules/eddn/schemas/journal.ts +++ /dev/null @@ -1,161 +0,0 @@ -/* - * KodeBlox Copyright 2017 Sayak Mukhopadhyay - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http: //www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { DB } from '../../../db/index'; -import App from '../../../server'; - -export class Journal { - public static readonly schemaId: string = "http://schemas.elite-markets.net/eddn/journal/1"; - private message: any; - private timestamp: string; - private event: string; - private starSystem: string; - private starPos: number[]; - private misc: any; - private db: DB - - constructor(message: any) { - this.message = JSON.parse(JSON.stringify(message)); - this.timestamp = message.timestamp; - this.event = message.event; - this.starSystem = message.StarSystem; - this.starPos = message.StarPos; - this.initialiseMisc(message); - this.db = App.db; - } - - initialiseMisc(message): void { - delete message.timestamp; - delete message.event; - delete message.StarSystem; - delete message.StarPos; - this.misc = message; - } - - display(): void { - console.log(this.message); - } - - trackSystem(): void { - if (this.event === "FSDJump") { - if (this.misc.Factions) { - let factionArray = []; - let factionNameArray = []; - this.misc.Factions.forEach(faction => { - let factionObject: any = {}; - factionObject.faction_name = faction.Name; - factionObject.faction_name_lower = faction.Name.toLowerCase(); - factionObject.faction_state = faction.FactionState; - factionObject.faction_government = faction.Government; - factionObject.faction_influence = faction.Influence; - factionObject.faction_pending_states = []; - if (faction.PendingStates) { - faction.PendingStates.forEach(pendingState => { - let pendingStateObject: any = {}; - pendingStateObject.state = pendingState.State; - pendingStateObject.trend = pendingState.Trend; - factionObject.faction_pending_states.push(pendingStateObject); - }); - } - factionObject.faction_recovering_states = []; - if (faction.RecoveringStates) { - faction.RecoveringStates.forEach(recoveringState => { - let recoveringStateObject: any = {}; - recoveringStateObject.state = recoveringState.State; - recoveringStateObject.trend = recoveringState.Trend; - factionObject.faction_pending_states.push(recoveringStateObject); - }); - } - factionObject.updated_at = new Date(); - factionArray.push(factionObject); - factionNameArray.push(factionObject.faction_name_lower); - }); - let updateObject: any = { - system_name: this.starSystem, - system_faction: this.misc.SystemFaction, - system_faction_lower: this.misc.SystemFaction.toLowerCase(), - faction_state: this.misc.FactionState, - system_allegiance: this.misc.SystemAllegiance, - system_economy: this.misc.SystemEconomy, - system_government: this.misc.SystemGovernment, - system_security: this.misc.SystemSecurity, - factions: factionArray - }; - if (this.misc.Powers) { - updateObject.powers = this.misc.Powers; - updateObject.powerplay_state = this.misc.PowerplayState; - } - this.db.model.system.findOneAndUpdate( - { system_name_lower: this.starSystem.toLowerCase() }, - updateObject - ) - .then(system => { - // console.log(system); - }) - .catch(err => { - console.log(err); - }); - this.db.model.faction.find({ - $or: [ - { faction_name_lower: { $in: factionNameArray } }, - { "faction_presence.system_name": this.starSystem } - ] - }) - .then(factions => { - if (factions) { - factions.forEach(faction => { - let readFaction: any; - let indexOfFaction = factionArray.findIndex(x => x.faction_name === faction.faction_name); - let indexOfSystem = faction.faction_presence.findIndex(x => x.system_name_lower === this.starSystem.toLowerCase()); - if (indexOfSystem !== -1) { - faction.faction_presence.splice(indexOfSystem, 1); - } - if (indexOfFaction !== -1) { - readFaction = factionArray[indexOfFaction]; - faction.faction_government = readFaction.faction_government; - let presenceObject: any = {}; - - presenceObject.system_name = this.starSystem; - presenceObject.system_name_lower = this.starSystem.toLowerCase(); - presenceObject.influence = readFaction.faction_influence; - presenceObject.state = readFaction.faction_state; - if (this.misc.SystemFaction === faction.faction_name) { - presenceObject.isControlling = true; - } else { - presenceObject.isControlling = false; - } - presenceObject.pending_states = readFaction.faction_pending_states; - presenceObject.recovering_states = readFaction.faction_recovering_states; - presenceObject.updated_at = new Date(); - faction.faction_presence.push(presenceObject); - } - this.db.model.faction.findOneAndUpdate( - { faction_name_lower: faction.faction_name_lower }, - faction - ) - .then(faction => { - // console.log(faction); - }) - .catch(err => { - console.log(err); - }) - }); - } - }) - } - } - } -} diff --git a/src/modules/eddn/schemas/outfitting.ts b/src/modules/eddn/schemas/outfitting.ts deleted file mode 100644 index e08b394..0000000 --- a/src/modules/eddn/schemas/outfitting.ts +++ /dev/null @@ -1,36 +0,0 @@ -/* - * KodeBlox Copyright 2017 Sayak Mukhopadhyay - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http: //www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -export class Outfitting { - public static readonly schemaId:string = "http://schemas.elite-markets.net/eddn/outfitting/2"; - private message: any; - private systemName: string; - private stationName: string; - private timestamp: string; - private modules: string[]; - - constructor(message: any) { - this.message = message; - this.systemName = message.systemName; - this.stationName = message.stationName; - this.timestamp = message.timestamp; - this.modules = message.modules; - } - - display(): void { - console.log(this.message); - } -} diff --git a/src/modules/eddn/schemas/shipyard.ts b/src/modules/eddn/schemas/shipyard.ts deleted file mode 100644 index 6d1321b..0000000 --- a/src/modules/eddn/schemas/shipyard.ts +++ /dev/null @@ -1,36 +0,0 @@ -/* - * KodeBlox Copyright 2017 Sayak Mukhopadhyay - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http: //www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -export class Shipyard { - public static readonly schemaId:string = "http://schemas.elite-markets.net/eddn/shipyard/2"; - private message: any; - private systemName: string; - private stationName: string; - private timestamp: string; - private ships: string[]; - - constructor(message: any) { - this.message = message; - this.systemName = message.systemName; - this.stationName = message.stationName; - this.timestamp = message.timestamp; - this.ships = message.ships; - } - - display(): void { - console.log(this.message); - } -} diff --git a/src/server.ts b/src/server.ts index 0ee6326..23169fc 100644 --- a/src/server.ts +++ b/src/server.ts @@ -22,7 +22,6 @@ import * as bodyParser from 'body-parser'; import * as cookieParser from 'cookie-parser'; import IndexRouter from './routes/index'; -import { Eddn } from './modules/eddn/eddn'; import { DiscordClient } from './modules/discord/client'; import { DB } from './db'; @@ -30,13 +29,11 @@ class App { public express: express.Application; public db: DB; public discordClient: DiscordClient; - public eddn: Eddn; constructor() { this.express = express(); this.middleware(); this.routes(); - this.eddn = new Eddn(); this.discordClient = new DiscordClient(); this.db = new DB(); }