Skip to content

Commit

Permalink
Merge pull request #222 from KenEucker/develop
Browse files Browse the repository at this point in the history
3.2.5
  • Loading branch information
KenEucker authored Jan 4, 2024
2 parents 279260f + 9eebe68 commit 3422ff8
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 25 deletions.
16 changes: 9 additions & 7 deletions examples/node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,17 @@ const getAllGamesAsync = async (pre, client, out = false, opts = {}) => {

const get1PlayerAsync = async (pre, client, out = false, opts = {}) => {
opts.limit = opts.limit ? opts.limit : 10
const testPlayerData = await client.getPlayer('Ken', opts).catch(console.error)
log(`${pre} :: success fully retrieved player data`, testPlayerData, out)
const name = 'Ken'
const testPlayerData = await client.getPlayer(name, opts).catch(console.error)
log(`${pre} :: success fully retrieved player data for [${name}]`, testPlayerData, out)

return testPlayerData
}

const get10PlayersAsync = async (pre, client, out = false, opts = {}) => {
opts.limit = opts.limit ? opts.limit : 10
const testPlayerData = await client.getPlayers(undefined, opts).catch(console.error)
log(`${pre} :: success fully retrieved player data`, testPlayerData, out)
log(`${pre} :: success fully retrieved 10 players data`, testPlayerData, out)

return testPlayerData
}
Expand Down Expand Up @@ -188,8 +189,8 @@ const runTests = async (out = false) => {
await get10PlayersAsync("BikeTag", biketagDefaultInstance, out)
}

if (false) {
// if (bikeTagImgurInstance) {
// if (false) {
if (bikeTagImgurInstance) {
console.log(pretty("Imgur BikeTag Client Instantiated"), imgurInstanceOpts)
await getGameAsync("Imgur", bikeTagImgurInstance, out)
// await getTag1Async("Imgur", bikeTagImgurInstance, out)
Expand All @@ -201,13 +202,14 @@ const runTests = async (out = false) => {
// await get10PlayersAsync("Imgur", bikeTagImgurInstance, out)
}

if (bikeTagSanityInstance) {
if (false) {
// if (bikeTagSanityInstance) {
console.log(pretty("Sanity BikeTag Client Instantiated"), sanityInstanceOpts)
// await getTag1Async("Sanity", bikeTagSanityInstance, out)
// await get10TagsAsync("Sanity", bikeTagSanityInstance, out)
await getGameAsync("Sanity", bikeTagSanityInstance, out)
// await getAllGamesAsync("Sanity", bikeTagSanityInstance, out)
// await get10PlayersAsync("Sanity", bikeTagSanityInstance, out)
await get10PlayersAsync("Sanity", bikeTagSanityInstance, out)
await get1PlayerAsync("Sanity", bikeTagSanityInstance, out)
// await get10AchievementsAsync("Sanity", bikeTagSanityInstance, out)
// await get10AmbassadorsAsync("Sanity", bikeTagSanityInstance, out)
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "biketag",
"version": "3.2.4",
"version": "3.2.5",
"description": "The Javascript client API for BikeTag Games",
"main": "./biketag.node.js",
"browser": "./biketag.js",
Expand Down
3 changes: 2 additions & 1 deletion src/common/expressions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ export const getPlayerFromTextRegex = new RegExp(
/((?:proof\s*(?:found\s*at\s*)?(?:\(.*\))?\s*by\s*)(.*?(?= on \[|$)))|((?:tag\s*(?:(?:\(\s*hint:\s*)?.*\))?\s*by\s*)(.+?(?= on \[|\r|\n|$))?)|((?:tag\s*(?:(?:\(\s*hint:\s*)?.*\))?\s*by\s*)(.+?(?= on \[|\r|\n))?)|((?:credit goes to:\s*)(.*)(?:\sfor finding))|(?:tag\s*)(?:number\s*)?(\d*)?(?:\s*by\s*)(.+?(?= on \[|$|\n))/i
)

/// Removed an OR from here, TEST: #64 proof found at (Earth) by Tim on [1/4/24@11:16:05)
export const getFoundLocationFromTextRegex = new RegExp(
/(?:is\s*(at|the)?\s*\(?)(.*)(?:\)|]|$)|(?:found\s*(at)?\s*\(?)(.*)(?:\)|])|(?:found\s*at\s*\()(.*)(?:\))|(?:\[(?:\s*bike\s*)(?:\s*tag\s*))#?(\d+)(?:(?:\])|(?:\s*.\s*(.*)\]))/im
/(?:is\s*(?:at|the)?\s*?)(.*?)(?=\s*by\s+|\]|$)|(?:found)\s*(?:at)?\s*\(([^()]+(\([^()]+\)[^()]*)*)\)(.*(?:\)|]|$))|(?:found\s*at\s*\()(.*(?:\)))/im
)

export const getConfirmedBoundaryFromTextRegex = new RegExp(
Expand Down
24 changes: 15 additions & 9 deletions src/common/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,11 @@ export const getFoundLocationFromText = (
return fallback
}

const foundLocation = (foundLocationText[1] || '').trim()
const foundLocation = (
foundLocationText[1] ??
foundLocationText[2] ??
''
).trim()
putCacheIfExists(cacheKey, foundLocation, cache)

return foundLocation
Expand Down Expand Up @@ -472,13 +476,14 @@ export const getDateStringForImgurDescription = (isodate: number): string => {

export const getImgurFoundDescriptionFromBikeTagData = (
tag: Tag,
includeCredit = true
includeCredit = true,
includeDate = true
): string =>
`#${tag.tagnumber} proof${
tag.foundLocation ? ` found at (${tag.foundLocation})` : ''
}${
includeCredit ? ` by ${tag.foundPlayer}` : ''
}${getDateStringForImgurDescription(tag.foundTime)}`
}${includeCredit ? ` by ${tag.foundPlayer}` : ''}${
includeDate ? getDateStringForImgurDescription(tag.foundTime) : ''
}`

export const getImgurFoundTitleFromBikeTagData = (tag: Tag): string =>
`${
Expand Down Expand Up @@ -507,13 +512,14 @@ export const getImgurMysteryTitleFromBikeTagData = (tag: Tag): string =>
export const getImgurMysteryDescriptionFromBikeTagData = (
tag: Tag,
includeCredit = true,
includeHint = true
includeHint = true,
includeDate = true
): string =>
`#${tag.tagnumber} tag ${
includeHint && tag.hint ? `(hint: ${tag.hint})` : ''
}${
includeCredit ? ` by ${tag.mysteryPlayer}` : ''
}${getDateStringForImgurDescription(tag.mysteryTime)}`
}${includeCredit ? ` by ${tag.mysteryPlayer}` : ''}${
includeDate ? getDateStringForImgurDescription(tag.mysteryTime) : ''
}`

export const getOnlyMysteryTagFromTagData = (tagData: Tag): Tag => {
const onlyMysteryTagFields = {
Expand Down
6 changes: 5 additions & 1 deletion src/imgur/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,11 @@ export function getFoundLocationFromText(
return fallback as string
}

const foundLocation = (foundLocationText[4] || '').trim()
const foundLocation = (
foundLocationText[1] ??
foundLocationText[2] ??
''
).trim()
putCacheIfExists(cacheKey, foundLocation, cache)

return foundLocation
Expand Down
9 changes: 7 additions & 2 deletions src/sanity/getPlayers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ export async function getPlayers(
payload.names?.length === 1 ? payload.names[0] : undefined,
payload.slugs,
undefined,
fields
fields,
payload.game?.length
? ` && "${payload.game.toLowerCase()}" in games[]->slug.current`
: undefined
)

return client.fetch(query, {}).then((players) => {
Expand All @@ -37,7 +40,9 @@ export async function getPlayers(
if (payload.slugs?.length) {
playersData = playersData.filter((p) => payload.slugs?.includes(p.slug))
} else if (payload.names?.length) {
playersData = playersData.filter((p) => payload.names?.includes(p.name))
playersData = playersData.filter((p) =>
payload.names?.includes(p.name.toLowerCase())
)
}

const response = {
Expand Down
5 changes: 3 additions & 2 deletions src/sanity/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,8 @@ export function constructSanityDocumentQuery(
player?: string,
slugs: string[] = [],
tagnumbers: number[] = [],
fields: string[] = []
fields: string[] = [],
append = ''
): any {
const gameQuery = game
? ` && ((game._ref in *[_type=="game" && lower(name)=="${game.toLowerCase()}"]._id) || (count(*[ _type == "game" && lower(name) =="${game.toLowerCase()}" && ^._id in ${docType}s[]._ref ]) > 0))`
Expand All @@ -448,7 +449,7 @@ export function constructSanityDocumentQuery(
? ` && tagnumber in ${JSON.stringify(tagnumbers)}`
: ''

return `*[_type == "${docType}"${gameQuery}${playerQuery}${slugsQuery}${tagnumbersQuery}]{${fields}}`
return `*[_type == "${docType}"${gameQuery}${playerQuery}${slugsQuery}${tagnumbersQuery}${append}]{${fields}}`
}

export function constructSanityFieldsQuery(
Expand Down

0 comments on commit 3422ff8

Please sign in to comment.