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

Support multiple game modes #307

Merged
merged 11 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
28 changes: 18 additions & 10 deletions custom-endpoints/nightbot.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,7 @@ export default async function (request, data) {
//console.log(`Skipping cache in ${ENVIRONMENT} environment`);
}

const context = {
data,
util: graphqlUtil,
requestId,
lang: {},
warnings: [],
errors: [],
};
const context = graphqlUtil.getDefaultContext(data, requestId);
const info = {
path: {
key: 'query',
Expand All @@ -68,7 +61,22 @@ export default async function (request, data) {
value: 'lang',
},
value: {
value: url.searchParams.get('l') || 'en'
value: url.searchParams.get('l') || 'en',
}
}
]
},
{
name: {
value: 'query'
},
arguments: [
{
name: {
value: 'gameMode',
},
value: {
value: url.searchParams.get('m') || 'regular',
}
}
]
Expand All @@ -77,7 +85,7 @@ export default async function (request, data) {
}
}
};
const items = await data.item.getItemsByName(context, url.searchParams.get('q'), info);
const items = await data.item.getItemsByName(context, info, url.searchParams.get('q'));

let responseBody = 'Found no item matching that name';

Expand Down
10 changes: 5 additions & 5 deletions datasources/archived-prices.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ import WorkerKVSplit from '../utils/worker-kv-split.mjs';
class ArchivedPricesAPI extends WorkerKVSplit {
constructor(dataSource) {
super('archived_price_data', dataSource);
this.gameModes.push('pve');
}

async getByItemId(context, itemId) {
await this.init(context, itemId);
const data = await this.getKVData(context, itemId);
if (!data) {
async getByItemId(context, info, itemId) {
const { cache } = await this.getCache(context, info, itemId);
if (!cache) {
return Promise.reject(new Error('Archived prices data is empty'));
}

let prices = data.ArchivedPrices[itemId];
let prices = cache.ArchivedPrices[itemId];
if (!prices) {
return [];
}
Expand Down
31 changes: 16 additions & 15 deletions datasources/barters.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,17 @@ const isBothDogtags = id => {
class BartersAPI extends WorkerKV {
constructor(dataSource) {
super('barter_data', dataSource);
this.gameModes.push('pve');
}

async getList(context) {
await this.init(context);
return this.cache.Barter;
async getList(context, info) {
const { cache } = await this.getCache(context, info);
return cache.Barter;
}

async getBartersForItem(context, id) {
await this.init(context);
return this.cache.Barter.filter(barter => {
async getBartersForItem(context, info, id) {
const { cache } = await this.getCache(context, info);
return cache.Barter.filter(barter => {
for (const item of barter.rewardItems) {
if (item.item === id) return true;
if (item.baseId === id) return true;
Expand All @@ -29,9 +30,9 @@ class BartersAPI extends WorkerKV {
});
}

async getBartersUsingItem(context, id) {
await this.init(context);
return this.cache.Barter.filter(barter => {
async getBartersUsingItem(context, info, id) {
const { cache } = await this.getCache(context, info);
return cache.Barter.filter(barter => {
for (const item of barter.requiredItems) {
if (item.item === id) return true;
if (isBothDogtags(id) && isAnyDogtag(item.item)) {
Expand All @@ -45,17 +46,17 @@ class BartersAPI extends WorkerKV {
});
}

async getBartersForTrader(context, id) {
await this.init(context);
return this.cache.Barter.filter(barter => {
async getBartersForTrader(context, info, id) {
const { cache } = await this.getCache(context, info);
return cache.Barter.filter(barter => {
if (barter.trader_id === id) return true;
return false;
});
}

async getBartersForTraderLevel(context, id, level) {
await this.init(context);
return this.cache.Barter.filter(barter => {
async getBartersForTraderLevel(context, info, id, level) {
const { cache } = await this.getCache(context, info);
return cache.Barter.filter(barter => {
if (barter.trader_id === id && barter.level === level) return true;
return false;
});
Expand Down
36 changes: 18 additions & 18 deletions datasources/crafts.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,40 @@ class CraftsAPI extends WorkerKV {
super('craft_data', dataSource);
}

async getList(context) {
await this.init(context);
return this.cache.Craft;
async getList(context, info) {
const { cache } = await this.getCache(context, info);
return cache.Craft;
}

async get(context, id) {
await this.init(context);
return this.cache.Craft.filter(c => c.id === id);
async get(context, info, id) {
const { cache } = await this.getCache(context, info);
return cache.Craft.filter(c => c.id === id);
}

async getCraftsForItem(context, id) {
await this.init(context);
return this.cache.Craft.filter(craft => {
async getCraftsForItem(context, info, id) {
const { cache } = await this.getCache(context, info);
return cache.Craft.filter(craft => {
return craft.rewardItems.some(rew => rew.item === id);
});
}

async getCraftsUsingItem(context, id) {
await this.init(context);
return this.cache.Craft.filter(craft => {
async getCraftsUsingItem(context, info, id) {
const { cache } = await this.getCache(context, info);
return cache.Craft.filter(craft => {
return craft.requiredItems.some(req => req.item === id);
});
}

async getCraftsForStation(context, id) {
await this.init(context);
return this.cache.Craft.filter(craft => {
async getCraftsForStation(context, info, id) {
const { cache } = await this.getCache(context, info);
return cache.Craft.filter(craft => {
return craft.station_id === id;
});
}

async getCraftsForStationLevel(context, id, level) {
await this.init(context);
return this.cache.Craft.filter(craft => {
async getCraftsForStationLevel(context, info, id, level) {
const { cache } = await this.getCache(context, info);
return cache.Craft.filter(craft => {
return craft.station_id === id && craft.level === level;
});
}
Expand Down
36 changes: 18 additions & 18 deletions datasources/hideout.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ class HideoutAPI extends WorkerKV {
super('hideout_data', dataSource);
}

async getList(context) {
await this.init(context);
return this.cache.HideoutStation;
async getList(context, info) {
const { cache } = await this.getCache(context, info);
return cache.HideoutStation;
}

async getModuleById(context, id) {
await this.init(context);
for (const hideoutStation of this.cache.HideoutStation) {
async getModuleById(context, info, id) {
const { cache } = await this.getCache(context, info);
for (const hideoutStation of cache.HideoutStation) {
for (const stage of hideoutStation.levels) {
if (stage.id === id) {
return stage;
Expand All @@ -22,9 +22,9 @@ class HideoutAPI extends WorkerKV {
return Promise.reject(new Error(`No hideout station level found with id ${id}`));
}

async getModuleByLevel(context, stationId, level) {
await this.init(context);
for (const hideoutStation of this.cache.HideoutStation) {
async getModuleByLevel(context, info, stationId, level) {
const { cache } = await this.getCache(context, info);
for (const hideoutStation of cache.HideoutStation) {
if (hideoutStation.id !== stationId) continue;
for (const stage of hideoutStation.levels) {
if (stage.level === level) {
Expand All @@ -35,22 +35,22 @@ class HideoutAPI extends WorkerKV {
return Promise.reject(new Error(`No hideout station level found with id ${stationId} and level ${level}`));
}

async getStation(context, id) {
await this.init(context);
for (const station of this.cache.HideoutStation) {
async getStation(context, info, id) {
const { cache } = await this.getCache(context, info);
for (const station of cache.HideoutStation) {
if (station.id === id) return station;
}
return Promise.reject(new Error(`No hideout station found with id ${id}`));
}

async getLegacyList(context) {
await this.init(context);
return this.cache.HideoutModule;
async getLegacyList(context, info) {
const { cache } = await this.getCache(context, info);
return cache.HideoutModule;
}

async getLegacyModule(context, name, level) {
await this.init(context);
for (const module of this.cache.HideoutModule) {
async getLegacyModule(context, info, name, level) {
const { cache } = await this.getCache(context, info);
for (const module of cache.HideoutModule) {
if (module.name === name && module.quantity === level) {
return module;
}
Expand Down
10 changes: 5 additions & 5 deletions datasources/historical-prices.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import WorkerKVSplit from '../utils/worker-kv-split.mjs';
class historicalPricesAPI extends WorkerKVSplit {
constructor(dataSource) {
super('historical_price_data', dataSource);
this.gameModes.push('pve');
this.defaultDays = 7;
this.maxDays = 7;
this.itemLimitDays = 2;
}

async getByItemId(context, itemId, days = this.defaultDays, halfResults = false) {
await this.init(context, itemId);
const data = await this.getKVData(context, itemId);
if (!data) {
async getByItemId(context, info, itemId, days = this.defaultDays, halfResults = false) {
const { cache } = await this.getCache(context, info, itemId);
if (!cache) {
return Promise.reject(new Error('Historical prices cache is empty'));
}

Expand All @@ -23,7 +23,7 @@ class historicalPricesAPI extends WorkerKVSplit {
}
}

let prices = data.historicalPricePoint[itemId];
let prices = cache.historicalPricePoint[itemId];
if (!prices) {
return [];
}
Expand Down
Loading
Loading