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
395 changes: 246 additions & 149 deletions package-lock.json

Large diffs are not rendered by default.

38 changes: 4 additions & 34 deletions packages/bot/src/functions/general/commands/version.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const createInfoEmbedMock = jest.fn((title: string, message: string) => ({
message,
}))

jest.mock('../../../../package.json', () => ({ version: '9.9.9' }))

jest.mock('../../../utils/general/embeds', () => ({
createInfoEmbed: (...args: unknown[]) =>
createInfoEmbedMock(...(args as [string, string])),
Expand All @@ -22,54 +24,22 @@ function createInteraction() {
}

describe('version command', () => {
const originalNpmVersion = process.env.npm_package_version
const originalCommitSha = process.env.COMMIT_SHA

beforeEach(() => {
jest.clearAllMocks()
})

afterEach(() => {
process.env.npm_package_version = originalNpmVersion
process.env.COMMIT_SHA = originalCommitSha
})

it('defers reply as ephemeral', async () => {
const interaction = createInteraction()
await versionCommand.execute({ interaction } as any)
expect(deferReplyMock).toHaveBeenCalledWith({ ephemeral: true })
})

it('replies with semver when npm_package_version is set', async () => {
process.env.npm_package_version = '2.6.60'
delete process.env.COMMIT_SHA
const interaction = createInteraction()
await versionCommand.execute({ interaction } as any)
expect(createInfoEmbedMock).toHaveBeenCalledWith(
'Bot Version',
'v2.6.60',
)
})

it('replies with commit sha when npm_package_version is unset', async () => {
delete process.env.npm_package_version
process.env.COMMIT_SHA = 'abc1234567890'
const interaction = createInteraction()
await versionCommand.execute({ interaction } as any)
expect(createInfoEmbedMock).toHaveBeenCalledWith(
'Bot Version',
'commit abc1234',
)
})

it('replies with unknown when neither env var is set', async () => {
delete process.env.npm_package_version
delete process.env.COMMIT_SHA
it('replies with version from package.json', async () => {
const interaction = createInteraction()
await versionCommand.execute({ interaction } as any)
expect(createInfoEmbedMock).toHaveBeenCalledWith(
'Bot Version',
'unknown',
'v9.9.9',
)
})
})
7 changes: 2 additions & 5 deletions packages/bot/src/functions/general/commands/version.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import { SlashCommandBuilder } from '@discordjs/builders'
import Command from '../../../models/Command'
import { createInfoEmbed } from '../../../utils/general/embeds'
import { version } from '../../../../package.json'

function resolveVersion(): string {
const semver = process.env.npm_package_version
if (semver) return `v${semver}`
const sha = process.env.COMMIT_SHA
if (sha) return `commit ${sha.slice(0, 7)}`
return 'unknown'
return `v${version}`
}

export default new Command({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ jest.mock('@lucky/shared/utils', () => ({
getPrismaClient: getPrismaClientMock,
}))

jest.mock('../../../twitch/twitchApi', () => ({
jest.mock('../../../../twitch/twitchApi', () => ({
getTwitchUserByLogin: getTwitchUserByLoginMock,
}))

jest.mock('../../../twitch', () => ({
jest.mock('../../../../twitch', () => ({
refreshTwitchSubscriptions: refreshTwitchSubscriptionsMock,
}))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
twitchNotificationService,
} from '@lucky/shared/services'
import { getPrismaClient } from '@lucky/shared/utils'
import { getTwitchUserByLogin } from '../../../twitch/twitchApi'
import { refreshTwitchSubscriptions } from '../../../twitch'
import { getTwitchUserByLogin } from '../../../../twitch/twitchApi'
import { refreshTwitchSubscriptions } from '../../../../twitch'

export type SetupMode = 'dry-run' | 'apply'

Expand Down Expand Up @@ -333,7 +333,7 @@
result.applied.push(
'Perfil visual do servidor preservado (sem mudanças de ícone/splash/banner).',
)
result.applied.push(

Check warning on line 336 in packages/bot/src/functions/management/commands/helpers/serversetupCriativaria.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Do not call `Array#push()` multiple times.

See more on https://sonarcloud.io/project/issues?id=LucasSantana-Dev_Lucky&issues=AZ1MBG48MUxrdBOhTRPb&open=AZ1MBG48MUxrdBOhTRPb&pullRequest=464
'Planejado: reutilizar/upload da imagem estática da Criativaria para templates no canal da equipe.',
)
return null
Expand Down Expand Up @@ -553,7 +553,7 @@
)

result.applied.push(`Auto-mensagem welcome ${welcomeResult}.`)
result.applied.push(`Auto-mensagem leave ${leaveResult}.`)

Check warning on line 556 in packages/bot/src/functions/management/commands/helpers/serversetupCriativaria.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Do not call `Array#push()` multiple times.

See more on https://sonarcloud.io/project/issues?id=LucasSantana-Dev_Lucky&issues=AZ1MBG48MUxrdBOhTRPc&open=AZ1MBG48MUxrdBOhTRPc&pullRequest=464
}

export async function upsertEmbedTemplate(
Expand Down Expand Up @@ -711,7 +711,7 @@
if (items.length === 0) {
return `${title}\n- nenhum item`
}
return `${title}\n${items.map((item) => `- ${item}`).join('\n')}`

Check warning on line 714 in packages/bot/src/functions/management/commands/helpers/serversetupCriativaria.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this code to not use nested template literals.

See more on https://sonarcloud.io/project/issues?id=LucasSantana-Dev_Lucky&issues=AZ1MBG48MUxrdBOhTRPd&open=AZ1MBG48MUxrdBOhTRPd&pullRequest=464
}

export function resolveSetupMode(modeValue: string | null): SetupMode {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
formatCriativariaSummary,
resolveSetupMode,
runCriativariaSetup,
} from './serversetupCriativaria'
} from './helpers/serversetupCriativaria'

jest.mock('../../../utils/general/interactionReply', () => ({
interactionReply: jest.fn(),
Expand All @@ -16,7 +16,7 @@ jest.mock('@lucky/shared/utils', () => ({
errorLog: jest.fn(),
}))

jest.mock('./serversetupCriativaria', () => ({
jest.mock('./helpers/serversetupCriativaria', () => ({
resolveSetupMode: jest.fn(),
runCriativariaSetup: jest.fn(),
formatCriativariaSummary: jest.fn(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
formatCriativariaSummary,
resolveSetupMode,
runCriativariaSetup,
} from './serversetupCriativaria.js'
} from './helpers/serversetupCriativaria.js'

interface ChannelDef {
name: string
Expand Down
27 changes: 19 additions & 8 deletions packages/bot/src/functions/music/commands/play/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import {
blendAutoplayTracks,
} from '../../../../utils/music/queueManipulation'

const DISCORD_UNKNOWN_INTERACTION_CODE = 10062

function isTrackAlreadyQueued(
queue: { tracks: { toArray?: () => Array<{ id?: string; url?: string }> } },
track: { id?: string; url?: string },
Expand Down Expand Up @@ -140,14 +142,23 @@ export default new Command({
data: { query, guildId: interaction.guildId },
})

await interaction.editReply({
embeds: [
createErrorEmbed(
'Play Error',
'Could not find or play the requested track',
),
],
})
// DiscordAPIError[10062] = Unknown Interaction — token expired or bot
// restarted between deferReply and editReply. No reply is possible.
const code = (error as { code?: number })?.code
if (code === DISCORD_UNKNOWN_INTERACTION_CODE) return

try {
await interaction.editReply({
embeds: [
createErrorEmbed(
'Play Error',
'Could not find or play the requested track',
),
],
})
} catch {
// interaction already dead — nothing to do
}
}
},
})