Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion packages/dota/src/db/get-db-user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ export default async function getDBUser({
let subscription: SocketClient['subscription'] | undefined
if (Array.isArray(user.subscriptions) && user.subscriptions.length > 0) {
const activeSubscription =
user.subscriptions.find((sub: SubscriptionRow) => isSubscriptionActive(sub)) ||
user.subscriptions.find((sub: SubscriptionRow) => isSubscriptionActive(sub)) ??
user.subscriptions[0]
subscription = {
...activeSubscription,
Expand Down
4 changes: 1 addition & 3 deletions packages/dota/src/db/redis-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ class RedisClient {
}

public static getInstance(): RedisClient {
if (RedisClient.instance === undefined) {
RedisClient.instance = new RedisClient()
}
RedisClient.instance ??= new RedisClient()
return RedisClient.instance
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/dota/src/db/watcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ class SetupSupabase {
giftQuantity: giftQuantityNum,
})
}
} else if (giftQuantityRaw != null) {
} else if (giftQuantityRaw !== null && giftQuantityRaw !== undefined) {
// Log only if it was provided but invalid
logger.warn('Gift quantity is invalid or not positive', {
giftId: newObj.id,
Expand Down
30 changes: 14 additions & 16 deletions packages/dota/src/dota/events/gsi-events/event.chat_message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ const isLikelyEnglish = function isLikelyEnglish(message: string): boolean {
/\b(the|and|or|but|in|on|at|to|for|of|with|by|an|a|is|are|was|were|be|been|being|have|has|had|do|does|did|will|would|could|should|may|might|must|can|shall|this|that|these|those|here|there|where|when|why|how|what|who|which|all|some|any|every|most|many|much|few|little|no|not|yes|ok|okay|hi|hello|hey|bye|good|bad|big|small|long|short|hot|cold|new|old|high|low|right|wrong|true|false|first|last|next|now|then|soon|later|before|after|up|down|in|out|on|off|over|under|above|below|left|right|front|back|inside|outside|open|close|full|empty|fast|slow|easy|hard|quick|quickly|slowly|carefully|well|badly|better|best|worse|worst|more|most|less|least|many|much|few|little|some|any|every|all|no|none|nothing|something|anything|everything|everyone|someone|anyone|noone)\b/giu

const wordCount = message.split(/\s+/u).length
const englishWordMatches = (message.match(englishWords) || []).length
const englishWordMatches = (message.match(englishWords) ?? []).length
const englishRatio = wordCount > 0 ? englishWordMatches / wordCount : 0
const hasNonLatinChars = detectNonLatinCharacters(message)

Expand Down Expand Up @@ -404,20 +404,18 @@ eventHandler.registerEvent(`event:${DotaEventTypes.ChatMessage}`, {
})

// Set timeout if not already set
if (!buffer.timeout) {
buffer.timeout = setTimeout(async () => {
const currentBuffer = translationBuffers.get(clientKey)
if (currentBuffer) {
await processTranslationBuffer(
currentBuffer.messages,
dotaClient,
translateInChat,
translateOnOverlay,
typedLanguage
)
translationBuffers.delete(clientKey)
}
}, TRANSLATION_DEBOUNCE_TIME)
}
buffer.timeout ??= setTimeout(async () => {
const currentBuffer = translationBuffers.get(clientKey)
if (currentBuffer) {
await processTranslationBuffer(
currentBuffer.messages,
dotaClient,
translateInChat,
translateOnOverlay,
typedLanguage
)
translationBuffers.delete(clientKey)
}
}, TRANSLATION_DEBOUNCE_TIME)
},
})
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ eventHandler.registerEvent(`event:${DotaEventTypes.RoshanKilled}`, {

// TODO: move this to a redis handler
const redisJson = await redisClient.getJson<RoshRes>(`${dotaClient.getToken()}:roshan`)
const count = redisJson ? Number(redisJson.count) : 0
const count = redisJson ? redisJson.count : 0
const res = {
count: count + 1,
maxDate,
Expand Down
4 changes: 2 additions & 2 deletions packages/dota/src/dota/events/gsi-events/newdata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ const saveMatchData = async function saveMatchData(client: SocketClient) {
{
match_id: matchId,
refetchCards: true,
steam_server_id: currentSteamServerId.toString(),
steam_server_id: currentSteamServerId,
token: client.token,
},
(err: unknown, data: DelayedGames) => {
Expand Down Expand Up @@ -383,7 +383,7 @@ const saveMatchData = async function saveMatchData(client: SocketClient) {
// Update cache with complete data
matchDataCache.set(cacheKey, {
lobbyType: String(delayedData.match.lobby_type),
steamServerId: currentSteamServerId.toString(),
steamServerId: currentSteamServerId,
timestamp: Date.now(),
})
}
Expand Down
2 changes: 1 addition & 1 deletion packages/dota/src/dota/events/minimap/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class MinimapParser {
// Simplify Coordinates
if (entity.xpos !== undefined) {
if (entity.xpos >= 0) {
entity.xpos = Number(entity.xpos) + Number(this.xLength)
entity.xpos += this.xLength
} else {
entity.xpos = this.xLength - Math.abs(entity.xpos)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/dota/src/dota/get-stream-delay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ export const getStreamDelay = function getStreamDelay(
settings: SocketClient['settings'],
subscription?: SubscriptionRow
) {
return Number(getValueOrDefault(DBSettings.streamDelay, settings, subscription)) + GLOBAL_DELAY
return getValueOrDefault(DBSettings.streamDelay, settings, subscription) + GLOBAL_DELAY
}
80 changes: 52 additions & 28 deletions packages/dota/src/dota/gsi-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ class GSIHandler implements GSIHandlerType {

private captureInGameSnapshot() {
const matchId = this.client.gsi?.map?.matchid
if (matchId == null || matchId.length === 0 || matchId === '0') {
if (matchId === null || matchId === undefined || matchId.length === 0 || matchId === '0') {
return
}

Expand Down Expand Up @@ -398,7 +398,7 @@ class GSIHandler implements GSIHandlerType {
if (!this.client.stream_online) {
return
}
if (matchId == null || matchId.length === 0 || matchId === '0') {
if (matchId === null || matchId === undefined || matchId.length === 0 || matchId === '0') {
return
}

Expand Down Expand Up @@ -450,7 +450,12 @@ class GSIHandler implements GSIHandlerType {
// so add to their list of steam accounts
async updateSteam32Id() {
const steamId = this.client.gsi?.player?.steamid
if (this.creatingSteamAccount || steamId == null || steamId.length === 0) {
if (
this.creatingSteamAccount ||
steamId === null ||
steamId === undefined ||
steamId.length === 0
) {
return
}

Expand All @@ -460,7 +465,7 @@ class GSIHandler implements GSIHandlerType {

try {
steam32Id = steamID64toSteamID32(steamId)
if (steam32Id == null || steam32Id === 0) {
if (steam32Id === null || steam32Id === undefined || steam32Id === 0) {
this.creatingSteamAccount = false
return
}
Expand Down Expand Up @@ -508,7 +513,7 @@ class GSIHandler implements GSIHandlerType {
return
}

if (res?.id != null && res.id.length > 0) {
if (res?.id !== null && res?.id !== undefined && res.id.length > 0) {
await this.handleExistingAccount(res, steam32Id)
} else {
const created = await this.createNewSteamAccount(mmr, steam32Id)
Expand All @@ -520,7 +525,7 @@ class GSIHandler implements GSIHandlerType {

this.creatingSteamAccount = false
} catch (error) {
if (steam32Id != null && steam32Id !== 0) {
if (steam32Id !== null && steam32Id !== undefined && steam32Id !== 0) {
this.client.multiAccount = steam32Id
this.multiAccountRevalidatedAt = Date.now()
}
Expand Down Expand Up @@ -556,7 +561,9 @@ class GSIHandler implements GSIHandlerType {
leaderboard_rank: null,
mmr: res.mmr,
name:
this.client.gsi?.player?.name != null && this.client.gsi.player.name.length > 0
this.client.gsi?.player?.name !== null &&
this.client.gsi?.player?.name !== undefined &&
this.client.gsi.player.name.length > 0
? this.client.gsi.player.name
: null,
steam32Id,
Expand All @@ -580,7 +587,8 @@ class GSIHandler implements GSIHandlerType {
logger.info('[STEAM32ID] Adding steam32Id', { name: this.client.name })

const playerName = this.client.gsi?.player?.name
const name = playerName != null && playerName.length > 0 ? playerName : null
const name =
playerName !== null && playerName !== undefined && playerName.length > 0 ? playerName : null
const { error } = await supabase.from('steam_accounts').insert({
mmr,
name,
Expand Down Expand Up @@ -709,7 +717,7 @@ class GSIHandler implements GSIHandlerType {

// We at least want the hero name so it can go in the twitch bet title
const heroName = client.gsi.hero?.name
if (heroName == null || heroName.length === 0) {
if (heroName === null || heroName === undefined || heroName.length === 0) {
// console.log(`if (!client.gsi.hero?.name || !client.gsi.hero.name.length) {`)
return
}
Expand Down Expand Up @@ -765,7 +773,8 @@ class GSIHandler implements GSIHandlerType {
.is('won', null)
.single()
if (
predictionResponse.data?.predictionId != null &&
predictionResponse.data?.predictionId !== null &&
predictionResponse.data?.predictionId !== undefined &&
predictionResponse.data.predictionId.length > 0
) {
await refundTwitchBet(this.getChannelId(), predictionResponse.data.predictionId)
Expand Down Expand Up @@ -843,7 +852,7 @@ class GSIHandler implements GSIHandlerType {
}

// Check if this bet for this match id already exists, dont continue if it does
if (bet?.[0]?.id != null && bet[0].id.length > 0) {
if (bet?.[0]?.id !== null && bet?.[0]?.id !== undefined && bet[0].id.length > 0) {
logger.info('[BETS] Found a bet in the database', { id: bet?.[0]?.id })
this.openingBets = false
return
Expand Down Expand Up @@ -1042,15 +1051,15 @@ class GSIHandler implements GSIHandlerType {
? this.client.gsi?.player?.team_name
: null))

if (this.openingBets || matchId == null || matchId.length === 0) {
if (this.openingBets || matchId === null || matchId === undefined || matchId.length === 0) {
logger.debug('[BETS] Not closing bets', {
endingBets: this.endingBets,
name: this.client.name,
openingBets: this.openingBets,
playingMatchId: matchId,
})

if (matchId == null || matchId.length === 0) {
if (matchId === null || matchId === undefined || matchId.length === 0) {
await this.resetClientState()
}
return
Expand Down Expand Up @@ -1109,9 +1118,14 @@ class GSIHandler implements GSIHandlerType {
// Pretty rare case, 26 times in 7 days. Usually when they test Dotabod in a custom lobby
// Custom lobbies create a match ID but don't report any stats
if (
(this.client.gsi?.map?.dire_score == null || this.client.gsi.map.dire_score === 0) &&
(this.client.gsi?.map?.radiant_score == null || this.client.gsi.map.radiant_score === 0) &&
this.client.gsi?.map?.matchid != null &&
(this.client.gsi?.map?.dire_score === null ||
this.client.gsi?.map?.dire_score === undefined ||
this.client.gsi.map.dire_score === 0) &&
(this.client.gsi?.map?.radiant_score === null ||
this.client.gsi?.map?.radiant_score === undefined ||
this.client.gsi.map.radiant_score === 0) &&
this.client.gsi?.map?.matchid !== null &&
this.client.gsi?.map?.matchid !== undefined &&
this.client.gsi.map.matchid.length > 0
) {
logger.info('This is likely a no stats recorded match', {
Expand All @@ -1137,14 +1151,15 @@ class GSIHandler implements GSIHandlerType {
.is('won', null)
.single()
if (
predictionResponse.data?.predictionId != null &&
predictionResponse.data?.predictionId !== null &&
predictionResponse.data?.predictionId !== undefined &&
predictionResponse.data.predictionId.length > 0
) {
const oldBetId = await refundTwitchBet(
this.getChannelId(),
predictionResponse.data.predictionId
)
if (oldBetId != null && oldBetId.length > 0) {
if (oldBetId !== null && oldBetId !== undefined && oldBetId.length > 0) {
await supabase
.from('matches')
.update({ predictionId: null, updated_at: new Date().toISOString() })
Expand All @@ -1168,13 +1183,13 @@ class GSIHandler implements GSIHandlerType {

// Use the lobby type from Redis if it exists (including 0)
// Otherwise default to ranked
const localLobbyType = playingLobbyType === null ? LOBBY_TYPE_RANKED : playingLobbyType
const localLobbyType = playingLobbyType ?? LOBBY_TYPE_RANKED

const isParty = getValueOrDefault(DBSettings.onlyParty, this.client.settings)

await this.updateMMR({
// 22 is game mode for normal game non turbo
gameMode: playingGameMode === null ? 22 : playingGameMode,
gameMode: playingGameMode ?? 22,
heroName,
heroSlot,
increase: won,
Expand Down Expand Up @@ -1205,7 +1220,8 @@ class GSIHandler implements GSIHandlerType {
)

if (
treadToggleData?.treadToggles != null &&
treadToggleData?.treadToggles !== null &&
treadToggleData?.treadToggles !== undefined &&
treadToggleData.treadToggles > 0 &&
this.client.stream_online
) {
Expand Down Expand Up @@ -1266,7 +1282,12 @@ class GSIHandler implements GSIHandlerType {

say(this.client, message, { chattersKey: 'matchOutcome', delay: false })

if (!betsEnabled || predictionId == null || predictionId.length === 0) {
if (
!betsEnabled ||
predictionId === null ||
predictionId === undefined ||
predictionId.length === 0
) {
logger.debug('Bets are not enabled or no prediction was opened, stopping here', {
name: this.client.name,
})
Expand Down Expand Up @@ -1334,7 +1355,7 @@ class GSIHandler implements GSIHandlerType {
.eq('userId', this.client.token)
.single()

if (error !== null || matchData == null) {
if (error !== null || matchData === null || matchData === undefined) {
logger.info('[BETS] Match already closed or not found, skipping early DC winner check', {
error: error?.message,
matchId,
Expand Down Expand Up @@ -1376,7 +1397,9 @@ class GSIHandler implements GSIHandlerType {
await supabase
.from('matches')
.update({
...(snapshotMatch.hero_name != null && snapshotMatch.hero_name.length > 0
...(snapshotMatch.hero_name !== null &&
snapshotMatch.hero_name !== undefined &&
snapshotMatch.hero_name.length > 0
? { hero_name: snapshotMatch.hero_name }
: {}),
dire_score: snapshotMatch.dire_score,
Expand Down Expand Up @@ -1454,7 +1477,7 @@ class GSIHandler implements GSIHandlerType {
.eq('userId', this.client.token)
.single()

if (matchNotEnded == null || error !== null) {
if (matchNotEnded === null || matchNotEnded === undefined || error !== null) {
logger.info('[BETS] Match already ended, skipping early DC winner check', {
matchId,
name: this.client.name,
Expand Down Expand Up @@ -1511,7 +1534,7 @@ class GSIHandler implements GSIHandlerType {
'getMatchMinimalDetails',
{ match_id: Number(matchId) },
(err: unknown, response: MatchMinimalDetailsResponse) => {
if (err != null) {
if (err !== null && err !== undefined) {
reject(err)
} else {
resolve(response)
Expand Down Expand Up @@ -1586,14 +1609,15 @@ class GSIHandler implements GSIHandlerType {
.is('won', null)
.single()
if (
predictionResponse.data?.predictionId != null &&
predictionResponse.data?.predictionId !== null &&
predictionResponse.data?.predictionId !== undefined &&
predictionResponse.data.predictionId.length > 0
) {
const oldBetId = await refundTwitchBet(
this.getChannelId(),
predictionResponse.data.predictionId
)
if (oldBetId != null && oldBetId.length > 0) {
if (oldBetId !== null && oldBetId !== undefined && oldBetId.length > 0) {
await supabase
.from('matches')
.update({ predictionId: null, updated_at: new Date().toISOString() })
Expand Down
2 changes: 1 addition & 1 deletion packages/dota/src/dota/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const setupTranslations = async () => {
preload: readdirSync(join('./locales')).filter((fileName: string) => {
const joinedPath = join(join('./locales'), fileName)
const isDirectory = lstatSync(joinedPath).isDirectory()
return !!isDirectory
return isDirectory
}),
returnEmptyString: false,
returnNull: false,
Expand Down
4 changes: 2 additions & 2 deletions packages/dota/src/dota/lib/announce-features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export const dispatchFeatureAnnouncements = async function dispatchFeatureAnnoun
}

const guardKey = `${client.token}:featureAnnouncedMatch`
if ((await redisClient.client.get(guardKey)) === String(matchId)) {
if ((await redisClient.client.get(guardKey)) === matchId) {
return
}

Expand All @@ -142,7 +142,7 @@ export const dispatchFeatureAnnouncements = async function dispatchFeatureAnnoun
continue
}
if (await announceFeatureOnce(client, feature)) {
await redisClient.client.set(guardKey, String(matchId))
await redisClient.client.set(guardKey, matchId)
return
}
}
Expand Down
Loading