Skip to content

Commit

Permalink
more bug fixes for new version
Browse files Browse the repository at this point in the history
  • Loading branch information
Geczy committed Sep 2, 2023
1 parent 51d37f2 commit bd35821
Show file tree
Hide file tree
Showing 19 changed files with 973 additions and 152 deletions.
31 changes: 12 additions & 19 deletions packages/dota/src/dev/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,26 +64,19 @@ async function handleNewUser(providerAccountId: string) {
Object.entries(data).filter(([key, value]) => Boolean(value)),
)

prisma.account
.update({
data: {
user: {
update: filteredData,
},
await prisma.account.update({
data: {
user: {
update: filteredData,
},
where: {
provider_providerAccountId: {
provider: 'twitch',
providerAccountId: providerAccountId,
},
},
where: {
provider_providerAccountId: {
provider: 'twitch',
providerAccountId: providerAccountId,
},
})
.then(() => {
console.log('updated user info for', { providerAccountId, data: filteredData })
})
.catch((e) => {
console.log(e, 'error saving new user info for', e.broadcasterId)
})
},
})
} catch (e) {
console.log(e, 'error on getStreamByUserId')
}
Expand Down Expand Up @@ -271,7 +264,7 @@ async function onlineEvent({ userId, startDate }: { userId: string; startDate: D
return await prisma.user.update({
data: {
stream_online: true,
stream_start_date: startDate,
stream_start_date: startDate.toISOString(),
},
where: {
id: userId,
Expand Down
106 changes: 55 additions & 51 deletions packages/dota/src/dota/GSIHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,11 @@ export class GSIHandler {
const mmr = this.client.SteamAccount.length ? 0 : this.getMmr()

this.creatingSteamAccount = true
const { data } = await supabase
const { data: res } = await supabase
.from('steam_accounts')
.select('id, userId, mmr, connectedUserIds')
.eq('steam32Id', steam32Id)
const res = data?.[0]
.single()

if (res?.id) {
await this.handleExistingAccount(res, steam32Id)
Expand Down Expand Up @@ -358,8 +358,9 @@ export class GSIHandler {
kda: scores.kda,
radiant_score: scores.radiant_score,
dire_score: scores.dire_score,
updated_at: new Date().toISOString(),
})
.match({ match_id: matchId, userId: this.client.token })
.match({ matchId: matchId, userId: this.client.token })

logger.info('[DATABASE] Updated bet with winnings', extraInfo)
this.emitWLUpdate()
Expand Down Expand Up @@ -455,7 +456,9 @@ export class GSIHandler {
const { data: bet } = await supabase
.from('bets')
.select('matchId, myTeam, id')
.match({ matchId: client.gsi.map.matchid, userId: client.token, won: null })
.eq('matchId', client.gsi.map.matchid)
.eq('userId', client.token)
.is('won', null)

// Saving to redis so we don't have to query the db again
await redisClient.client.set(`${client.token}:matchId`, client?.gsi?.map?.matchid || '')
Expand Down Expand Up @@ -667,12 +670,12 @@ export class GSIHandler {
})

const response = await getRankDetail(this.getMmr(), this.getSteam32())
if (!this.client.steam32Id || !response || !('standing' in response)) return

await supabase
.from('steam_accounts')
.update({ leaderboard_rank: response.standing })
.eq('steam32Id', this.client.steam32Id)
if (this.client.steam32Id && response && 'standing' in response) {
await supabase
.from('steam_accounts')
.update({ leaderboard_rank: response.standing })
.eq('steam32Id', this.client.steam32Id)
}

const TreadToggleData = this.treadsData
const toggleHandler = async () => {
Expand All @@ -699,52 +702,53 @@ export class GSIHandler {
logger.error('err toggleHandler', { e })
}

if (!betsEnabled || !this.client.stream_online) {
logger.info('Bets are not enabled, stopping here', { name: this.client.name })
await this.resetClientState()
return
}

setTimeout(() => {
this.client.token &&
closeTwitchBet(won, this.getChannelId())
.then(() => {
logger.info('[BETS] end bets', {
event: 'end_bets',
matchId,
name: this.client.name,
winning_team: localWinner,
player_team: myTeam,
didWin: won,
})
})
.catch((e: any) => {
logger.error('[BETS] Error closing twitch bet', {
channel,
e: e?.message || e,
matchId,
})
})
.finally(() => {
this.resetClientState().catch((e) => {
logger.error('Error resetting client state', { e })
})
const message = won
? t('bets.won', { lng: this.client.locale, emote: 'Happi' })
: t('bets.lost', { lng: this.client.locale, emote: 'Happi' })

const chattersEnabled = getValueOrDefault(DBSettings.chatter, this.client.settings)
const {
matchOutcome: { enabled: chatterEnabled },
} = getValueOrDefault(DBSettings.chatters, this.client.settings)

if (!chattersEnabled || !chatterEnabled) {
return
}
say(this.client, message, { delay: false })

const message = won
? t('bets.won', { lng: this.client.locale, emote: 'Happi' })
: t('bets.lost', { lng: this.client.locale, emote: 'Happi' })
if (!betsEnabled) {
logger.info('Bets are not enabled, stopping here', { name: this.client.name })
this.resetClientState().catch(() => {
//
})
return
}

say(this.client, message, { delay: false })
closeTwitchBet(won, this.getChannelId())
.then(() => {
logger.info('[BETS] end bets', {
event: 'end_bets',
matchId,
name: this.client.name,
winning_team: localWinner,
player_team: myTeam,
didWin: won,
})
})
.catch((e: any) => {
logger.error('[BETS] Error closing twitch bet', {
channel,
e: e?.message || e,
matchId,
})
})
.finally(() => {
this.resetClientState().catch((e) => {
logger.error('Error resetting client state', { e })
})

const chattersEnabled = getValueOrDefault(DBSettings.chatter, this.client.settings)
const {
matchOutcome: { enabled: chatterEnabled },
} = getValueOrDefault(DBSettings.chatters, this.client.settings)

if (!chattersEnabled || !chatterEnabled) {
return
}
})
}, getStreamDelay(this.client.settings))
}

Expand Down
22 changes: 10 additions & 12 deletions packages/dota/src/dota/lib/updateMmr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,19 +100,17 @@ export async function updateMmr({
mmr, // New MMR value
})
.eq('id', token)
.then(() => {
const client = findUser(token)

if (client && tellChat) {
tellChatNewMMR({
streamDelay: getValueOrDefault(DBSettings.streamDelay, client.settings),
locale: client.locale,
token: client.token,
mmr,
oldMmr: currentMmr,
})
}

const client = findUser(token)
if (client && tellChat) {
tellChatNewMMR({
streamDelay: getValueOrDefault(DBSettings.streamDelay, client.settings),
locale: client.locale,
token: client.token,
mmr,
oldMmr: currentMmr,
})
}

return
}
Expand Down
4 changes: 2 additions & 2 deletions packages/dota/src/twitch/commands/fixdbl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ commandHandler.registerCommand('fixdbl', {
.from('bets')
.select('matchId, won, is_party, id, is_doubledown')
.eq('userId', message.channel.client.token)
.neq('won', null)
.order('createdAt', { ascending: false })
.not('won', 'is', null)
.order('created_at', { ascending: false })
.limit(1)
const bet = data ? data[0] : null

Expand Down
4 changes: 2 additions & 2 deletions packages/dota/src/twitch/commands/fixparty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ commandHandler.registerCommand('fixparty', {
.from('bets')
.select('matchId, won, is_party, id, is_doubledown')
.eq('userId', message.channel.client.token)
.neq('won', null)
.order('createdAt', { ascending: false })
.not('won', 'is', null)
.order('created_at', { ascending: false })
.limit(1)
const bet = data ? data[0] : null

Expand Down
27 changes: 13 additions & 14 deletions packages/dota/src/twitch/commands/lgs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,26 @@ commandHandler.registerCommand('lgs', {
}

const { steam32Id } = message.channel.client
const { data } = await supabase
const { data: lg } = await supabase
.from('bets')
.select(
`
won,
is_party,
is_doubledown,
matchId,
kda,
lobby_type,
hero_name,
created_at,
updated_at
`,
won,
is_party,
is_doubledown,
matchId,
kda,
lobby_type,
hero_name,
created_at,
updated_at
`,
)
.eq('steam32Id', steam32Id)
.neq('won', null)
.not('won', 'is', null)
.order('created_at', { ascending: false })
.limit(1)

const lg = data ? data[0] : null
.single()

if (!lg) {
chatClient.say(
Expand Down
Loading

0 comments on commit bd35821

Please sign in to comment.