Skip to content

Commit

Permalink
new: dev command to get logs for newrelic
Browse files Browse the repository at this point in the history
  • Loading branch information
Geczy committed Apr 20, 2024
1 parent 951e3ca commit a39db83
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 165 deletions.
38 changes: 1 addition & 37 deletions packages/dota/src/dev/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,43 +288,7 @@ async function handleNewUser(providerAccountId: string, botApi: ApiClient) {
// )
// }

// const getLogQuery = async (name: string) => {
// const user = await prisma.user.findFirst({
// select: {
// name: true,
// id: true,
// Account: {
// select: {
// providerAccountId: true,
// },
// },
// SteamAccount: {
// select: {
// steam32Id: true,
// },
// },
// },
// where: {
// name,
// },
// })

// if (!user) return ''

// return `
// channel:${user.name} or
// name:${user.name} or
// ${user.SteamAccount.map((a) => `steam32Id:${a.steam32Id} or`).join(' ')}
// token:${user.id} or
// userId:${user.id} or
// user:${user.id} or
// token:${user.Account?.providerAccountId ?? ''} or
// message:Starting! or
// twitchId:${user.Account?.providerAccountId ?? ''}
// `
// }

// // console.log(await getLogQuery('grubby'))
// console.log(await getLogQuery('gorgc'))

// /*
// server.dota.dota2.on('ready', async () => {
Expand Down
194 changes: 71 additions & 123 deletions packages/dota/src/twitch/commands/test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,50 @@
import { sendExtensionPubSubBroadcastMessage } from '@twurple/ebs-helper'
import DOTA_ITEM_IDS from 'dotaconstants/build/item_ids.json' assert { type: 'json' }
import DOTA_ITEMS from 'dotaconstants/build/items.json' assert { type: 'json' }
import { t } from 'i18next'

import supabase from '../../db/supabase.js'
import { gsiHandlers } from '../../dota/lib/consts.js'
import { getAccountsFromMatch } from '../../dota/lib/getAccountsFromMatch.js'
import { steamSocket } from '../../steam/ws.js'
import { DelayedGames } from '../../types.js'
import { logger } from '../../utils/logger.js'
import { chatClient } from '../chatClient.js'
import commandHandler from '../lib/CommandHandler.js'

const getLogQuery = async (name: string) => {
const { data: user, error } = await supabase
.from('users')
.select(
`
name,
id,
Account:accounts (
providerAccountId
),
SteamAccount:steam_accounts (
steam32Id
)
`,
)
.eq('name', name)
.single()

if (error) {
console.error(error)
return
}

if (!user) return ''

return `
channel:${user.name} or
name:${user.name} or
${user.SteamAccount.map((a) => `steam32Id:${a.steam32Id} or`).join(' ')}
token:${user.id} or
userId:${user.id} or
user:${user.id} or
token:${user.Account?.providerAccountId ?? ''} or
message:Starting! or
twitchId:${user.Account?.providerAccountId ?? ''}
`
}

commandHandler.registerCommand('test', {
permission: 4, // Only admin is 4, not even streamer

Expand All @@ -20,110 +54,20 @@ commandHandler.registerCommand('test', {
channel: { name: channel, client },
} = message

if (args[0] === 'pub') {
const config = {
clientId: process.env.TWITCH_EXT_CLIENT_ID!,
secret: process.env.TWITCH_EXT_SECRET!,
ownerId: process.env.TWITCH_BOT_PROVIDERID!,
}

const accountId = client.Account?.providerAccountId ?? ''

await sendExtensionPubSubBroadcastMessage(
config,
accountId,
JSON.stringify({
items: ['blink', 'bottle', 'boots'],
neutral: 'enchanted_mango',
hero: 70,
abilities: [
'antimage_mana_break',
'antimage_blink',
'antimage_spell_shield',
'antimage_mana_void',
],
heroes: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
}),
)
}

if (args[0] === 'user') {
const accountId = client.Account?.providerAccountId ?? ''
chatClient.whisper(userId, `${channel} ${accountId} ${client.steam32Id} ${client.token}`)
return
}

if (args[0] === 'reset') {
const handler = gsiHandlers.get(client.token)
await handler?.resetClientState()

chatClient.say(channel, 'Reset')
chatClient.whisper(userId, 'Reset')
return
}

if (args[0] === 'items') {
const [, matchId, steam32Id] = args
let itemList: string[] | false | undefined = false

steamSocket.emit('getUserSteamServer', steam32Id, async (err: any, steamServerId: string) => {
chatClient.whisper(
userId,
`${channel} ${steamServerId} ${client.steam32Id} ${client.token}`,
)

if (!steamServerId) {
chatClient.say(channel, t('gameNotFound', { lng: message.channel.client.locale }))
return
}

logger.info('test command', {
command: 'TEST',
steam32Id: steam32Id || client.steam32Id,
steamServerId,
})

const getDelayedDataPromise = new Promise<DelayedGames>((resolve, reject) => {
steamSocket.emit(
'getRealTimeStats',
{
match_id: matchId,
forceRefetchAll: true,
steam_server_id: steamServerId,
token: client.token,
},
(err: any, cards: any) => {
if (err) {
reject(err)
} else {
resolve(cards)
}
},
)
})

const playerIdx = 1
const delayedData = await getDelayedDataPromise
const teamIndex = (playerIdx ?? 0) > 4 ? 1 : 0
const teamPlayerIdx = (playerIdx ?? 0) % 5
const itemIds = delayedData.teams[teamIndex]?.players[teamPlayerIdx]?.items

itemList =
Array.isArray(itemIds) &&
itemIds.length > 0 &&
itemIds
.map((itemId) => {
const id = itemId as unknown as keyof typeof DOTA_ITEM_IDS
const itemShortname = DOTA_ITEM_IDS[id] as keyof typeof DOTA_ITEMS
const item = DOTA_ITEMS[itemShortname]
const itemName: string | boolean = item && 'dname' in item && item.dname

return itemName || itemShortname
})
.filter(Boolean)

console.log(itemList)
})
}

if (args[0] === 'cards') {
const { accountIds } = await getAccountsFromMatch({
gsi: client.gsi,
Expand All @@ -147,31 +91,35 @@ commandHandler.registerCommand('test', {
return
}

const [steam32Id] = args

steamSocket.emit(
'getUserSteamServer',
steam32Id || client.steam32Id,
(err: any, steamServerId: string) => {
console.log({ steamServerId })
if (!steamServerId) {
chatClient.say(channel, t('gameNotFound', { lng: message.channel.client.locale }))
return
}

logger.info('test command', {
command: 'TEST',
steam32Id: steam32Id || client.steam32Id,
steamServerId,
})

chatClient.whisper(
userId,
`${channel} https://api.steampowered.com/IDOTA2MatchStats_570/GetRealtimeStats/v1/?key=${process
.env
.STEAM_WEB_API!}&server_steam_id=${steamServerId} ${client.steam32Id} ${client.token}`,
)
},
)
if (args[0] === 'logs') {
const query = await getLogQuery(channel)
chatClient.whisper(userId, query || "Couldn't find user")
return
}

if (args[0] === 'server') {
const [steam32Id] = args

steamSocket.emit(
'getUserSteamServer',
steam32Id || client.steam32Id,
(err: any, steamServerId: string) => {
chatClient.whisper(userId, steamServerId)
if (!steamServerId) {
chatClient.say(channel, t('gameNotFound', { lng: message.channel.client.locale }))
return
}

chatClient.whisper(
userId,
`${channel} https://api.steampowered.com/IDOTA2MatchStats_570/GetRealtimeStats/v1/?key=${process
.env
.STEAM_WEB_API!}&server_steam_id=${steamServerId} ${client.steam32Id} ${client.token}`,
)
},
)

return
}
},
})
5 changes: 0 additions & 5 deletions packages/dota/src/twitch/commands/wl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ commandHandler.registerCommand('wl', {
return
}

logger.info('[WL] Checking WL for steam32Id', {
steam32Id: client.steam32Id,
name: client.name,
})

const mmrEnabled = getValueOrDefault(DBSettings['mmr-tracker'], client.settings)

getWL({
Expand Down

0 comments on commit a39db83

Please sign in to comment.