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

Youtube #465

Draft
wants to merge 26 commits into
base: master
Choose a base branch
from
Draft
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
874 changes: 0 additions & 874 deletions .yarn/releases/yarn-3.6.3.cjs

This file was deleted.

893 changes: 893 additions & 0 deletions .yarn/releases/yarn-4.0.2.cjs

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
nodeLinker: node-modules
yarnPath: .yarn/releases/yarn-3.6.3.cjs

yarnPath: .yarn/releases/yarn-4.0.2.cjs
9 changes: 9 additions & 0 deletions docker-compose-dev.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
services:
twitch-chat:
platform: linux/arm64
image: "ghcr.io/dotabod/twitch-chat:v2.0-dev"
volumes:
- $PWD/packages/twitch/chat/src/:/app/packages/twitch/chat/src/

steam:
platform: linux/arm64

image: "ghcr.io/dotabod/steam:v2.0-dev"
volumes:
- $PWD/packages/steam/src:/app/packages/steam/src

twitch-events:
platform: linux/arm64

image: "ghcr.io/dotabod/twitch-events:v2.0-dev"
volumes:
- $PWD/packages/twitch/events/src:/app/packages/twitch/events/src

dota:
platform: linux/arm64

image: "ghcr.io/dotabod/dota:v2.0-dev"
volumes:
- $PWD/packages/dota/src:/app/packages/dota/src
Expand All @@ -27,6 +34,8 @@ services:
- donotstart

mongodb:
platform: linux/arm64

container_name: mongodb
image: "mongo:latest"
volumes:
Expand Down
12 changes: 10 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ services:
restart: on-failure

twitch-chat:
image: "ghcr.io/dotabod/twitch-chat:v2.1"
image: "ghcr.io/dotabod/twitch-chat:v2.15"
platform: linux/amd64
container_name: twitch-chat
restart: on-failure
Expand Down Expand Up @@ -34,6 +34,14 @@ services:
- TWITCH_BOT_PROVIDERID
- TWITCH_CLIENT_ID
- TWITCH_CLIENT_SECRET
- KICK_EMAIL
- KICK_PASSWORD
- KICK_2FA_SECRET
- YOUTUBE_CLIENT_ID
- YOUTUBE_CLIENT_SECRET
- YOUTUBE_REDIRECT_URI
- YOUTUBE_ACCESS_TOKEN
- YOUTUBE_REFRESH_TOKEN
volumes:
- $PWD/packages/twitch/chat/locales:/app/packages/twitch/chat/locales

Expand Down Expand Up @@ -97,7 +105,7 @@ services:
- TWITCH_EVENTSUB_SECRET

dota:
image: "ghcr.io/dotabod/dota:v2.1"
image: "ghcr.io/dotabod/dota:v2.15"
platform: linux/amd64
container_name: dota
restart: on-failure
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,5 @@
"yarn eslint"
]
},
"packageManager": "yarn@3.6.3"
"packageManager": "yarn@4.0.2"
}
7 changes: 3 additions & 4 deletions packages/Dockerfile.chat
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
FROM node:20-alpine3.17 as base

# Add Git, Python3, make, g++ in a single RUN command
RUN apk add --no-cache git python3 make g++ \
&& yarn cache clean
RUN apk add --no-cache git python3 make g++ && yarn cache clean

# Set build context and work directories
ARG BUILD_CONTEXT
Expand Down Expand Up @@ -40,8 +39,8 @@ ARG NODE_ENV

# Meta-data and labels
LABEL org.opencontainers.image.source="https://github.com/dotabod/backend" \
org.opencontainers.image.description="Dotabod container: ${BUILD_CONTEXT}" \
org.opencontainers.image.licenses="AGPL-3.0"
org.opencontainers.image.description="Dotabod container: ${BUILD_CONTEXT}" \
org.opencontainers.image.licenses="AGPL-3.0"

# Create unprivileged user and switch to it
RUN adduser -D dotadockeruser
Expand Down
7 changes: 3 additions & 4 deletions packages/Dockerfile.dota
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
FROM node:20-alpine3.17 as base

# Add Git, Python3, make, g++ in a single RUN command
RUN apk add --no-cache git python3 make g++ \
&& yarn cache clean
RUN apk add --no-cache git python3 make g++ && yarn cache clean

# Set build context and work directories
ARG BUILD_CONTEXT
Expand Down Expand Up @@ -44,8 +43,8 @@ ARG NODE_ENV

# Meta-data and labels
LABEL org.opencontainers.image.source="https://github.com/dotabod/backend" \
org.opencontainers.image.description="Dotabod container: ${BUILD_CONTEXT}" \
org.opencontainers.image.licenses="AGPL-3.0"
org.opencontainers.image.description="Dotabod container: ${BUILD_CONTEXT}" \
org.opencontainers.image.licenses="AGPL-3.0"

# Create unprivileged user and switch to it
RUN adduser -D dotadockeruser
Expand Down
2 changes: 1 addition & 1 deletion packages/dota/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"express": "^4.18.2",
"lodash.isequal": "^4.5.0",
"lru-cache": "^10.0.1",
"mongodb": "^6.1.0",
"mongodb": "^6.3.0",
"newrelic": "^11.1.0",
"node-gyp": "^9.4.0",
"redis": "^4.6.9",
Expand Down
47 changes: 30 additions & 17 deletions packages/dota/src/db/getDBUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,22 @@ export default async function getDBUser({

let userId = token || null
if (providerAccountId) {
const { data } = await supabase
.from('accounts')
.select('userId')
.eq('providerAccountId', providerAccountId)
.single()
userId = data?.userId ?? null
if (providerAccountId.includes('kick:')) {
providerAccountId = providerAccountId.split(':')[1] || providerAccountId
const { data } = await supabase
.from('users')
.select('id')
.eq('kick', providerAccountId)
.single()
userId = data?.id ?? null
} else {
const { data } = await supabase
.from('accounts')
.select('userId')
.eq('providerAccountId', providerAccountId)
.single()
userId = data?.userId ?? null
}
}

if (!userId) {
Expand All @@ -63,12 +73,15 @@ export default async function getDBUser({
id,
name,
mmr,
kick,
youtube,
steam32Id,
stream_online,
stream_start_date,
beta_tester,
locale,
Account:accounts (
accounts (
provider,
refresh_token,
scope,
expires_at,
Expand Down Expand Up @@ -114,9 +127,8 @@ export default async function getDBUser({
return client
}

const Account = Array.isArray(user?.Account) ? user.Account[0] : user.Account
if (!Account) {
logger.info('Invalid token missing Account??', { token: lookupToken })
if (!user.accounts.length) {
logger.info('Invalid token missing any accounts', { token: lookupToken })
invalidTokens.add(lookupToken)
deleteLookupToken(lookupToken)
return
Expand All @@ -128,12 +140,10 @@ export default async function getDBUser({
steam32Id: user.steam32Id || user.SteamAccount[0]?.steam32Id || 0,
token: user.id,
stream_start_date: user.stream_start_date ? new Date(user.stream_start_date) : null,
Account: {
...Account,
obtainment_timestamp: Account.obtainment_timestamp
? new Date(Account.obtainment_timestamp)
: null,
},
accounts: user.accounts.map((a) => ({
...a,
obtainment_timestamp: a.obtainment_timestamp ? new Date(a.obtainment_timestamp) : null,
})),
}

const gsiHandler = gsiHandlers.get(userInfo.id) || new GSIHandler(userInfo)
Expand All @@ -144,7 +154,10 @@ export default async function getDBUser({
}

gsiHandlers.set(userInfo.id, gsiHandler)
twitchIdToToken.set(Account.providerAccountId, userInfo.id)
const twitchAccount = user.accounts?.find((a) => a.provider === 'twitch')
if (twitchAccount) {
twitchIdToToken.set(twitchAccount.providerAccountId, userInfo.id)
}
}

deleteLookupToken(lookupToken)
Expand Down
6 changes: 4 additions & 2 deletions packages/dota/src/db/getWL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Database } from './supabase-types.js'

interface WL {
lng: string
token: string
channelId: string
mmrEnabled: false
startDate?: Date | null
Expand Down Expand Up @@ -35,13 +36,14 @@ const updateStats = (
}
}

export async function getWL({ lng, channelId, mmrEnabled, startDate }: WL) {
export async function getWL({ lng, token, channelId, mmrEnabled, startDate }: WL) {
if (!channelId) {
return Promise.resolve({ record: [{ win: 0, lose: 0, type: 'U' }], msg: null })
}

const { data: matches, error } = await supabase.rpc('get_grouped_bets', {
channel_id: channelId,
// sending token for channel_id because couldn't change the function param
channel_id: token,
start_date:
startDate?.toISOString() ??
new Date(new Date().getTime() - 12 * 60 * 60 * 1000).toISOString(),
Expand Down
Loading