Skip to content

Commit

Permalink
Merge staging into main
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] authored Jun 5, 2023
2 parents 6e86b4b + 34c510b commit 566b200
Show file tree
Hide file tree
Showing 16 changed files with 458 additions and 384 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cleanup-registry.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Delete old versions
uses: snok/container-retention-policy@f617f1ca161a52bce48417eedd76924e71d0b4d9 # v2.1.0
uses: snok/container-retention-policy@2ebfab771446f9cde79044dab61eec867ac1d62b # v2.1.1
with:
image-names: ${{ env.IMAGE_NAMES }}
cut-off: 2 days ago UTC
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/continuous-delivery.yml
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ jobs:
done
- name: Update Continuous Delivery check run
uses: guidojw/actions/update-check-run@abb0ee8d1336edf73383f2e5a09abd3a22f25b13 # v1.3.3
uses: guidojw/actions/update-check-run@870d7c8de5aeb08420bb88d8fbddb0222a9eac61 # v1.4.0
with:
app_id: ${{ vars.GH_APP_ID }}
private_key: ${{ secrets.GH_APP_PRIVATE_KEY }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
echo '::add-matcher::.github/problem-matchers/tsc.json'
- name: Build test image
uses: guidojw/actions/build-docker-image@abb0ee8d1336edf73383f2e5a09abd3a22f25b13 # v1.3.3
uses: guidojw/actions/build-docker-image@870d7c8de5aeb08420bb88d8fbddb0222a9eac61 # v1.4.0
with:
name: app

Expand All @@ -51,7 +51,7 @@ jobs:
bash <(curl https://raw.githubusercontent.com/rhysd/actionlint/main/scripts/download-actionlint.bash) 1.6.24
- name: Load test image
uses: guidojw/actions/load-docker-image@abb0ee8d1336edf73383f2e5a09abd3a22f25b13 # v1.3.3
uses: guidojw/actions/load-docker-image@870d7c8de5aeb08420bb88d8fbddb0222a9eac61 # v1.4.0
with:
name: app

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ jobs:
done
- name: Update Publish Image check run
uses: guidojw/actions/update-check-run@abb0ee8d1336edf73383f2e5a09abd3a22f25b13 # v1.3.3
uses: guidojw/actions/update-check-run@870d7c8de5aeb08420bb88d8fbddb0222a9eac61 # v1.4.0
with:
app_id: ${{ vars.GH_APP_ID }}
private_key: ${{ secrets.GH_APP_PRIVATE_KEY }}
Expand Down
403 changes: 202 additions & 201 deletions .yarn/releases/yarn-3.5.1.cjs → .yarn/releases/yarn-3.6.0.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ plugins:
- path: .yarn/plugins/@yarnpkg/plugin-typescript.cjs
spec: "@yarnpkg/plugin-typescript"

yarnPath: .yarn/releases/yarn-3.5.1.cjs
yarnPath: .yarn/releases/yarn-3.6.0.cjs
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
"@sentry/integrations": "^7.53.1",
"@sentry/node": "^7.53.1",
"@sentry/integrations": "^7.54.0",
"@sentry/node": "^7.54.0",
"axios": "^1.4.0",
"class-validator": "^0.14.0",
"common-tags": "^1.8.2",
"discord.js": "^14.11.0",
"dotenv": "^16.0.3",
"dotenv": "^16.1.4",
"emoji-regex": "^10.2.1",
"inversify": "^6.0.1",
"lodash": "^4.17.21",
Expand All @@ -42,9 +42,9 @@
"@types/node-cron": "^3.0.7",
"@types/pluralize": "^0.0.29",
"@types/ws": "^8.5.4",
"@typescript-eslint/eslint-plugin": "^5.59.7",
"eslint": "^8.41.0",
"eslint-config-standard-with-typescript": "^34.0.1",
"@typescript-eslint/eslint-plugin": "^5.59.9",
"eslint": "^8.42.0",
"eslint-config-standard-with-typescript": "^35.0.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-n": "^16.0.0",
"eslint-plugin-promise": "^6.1.1",
Expand All @@ -55,5 +55,5 @@
"engines": {
"node": ">=16.6.0"
},
"packageManager": "yarn@3.5.1"
"packageManager": "yarn@3.6.0"
}
12 changes: 12 additions & 0 deletions src/client/dispatcher.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
ApplicationCommandOptionType,
type AutocompleteInteraction,
type ChatInputCommandInteraction,
type CommandInteractionOption,
type Interaction,
Expand Down Expand Up @@ -31,6 +32,8 @@ export default class Dispatcher {
public async handleInteraction (interaction: Interaction): Promise<void> {
if (interaction.isChatInputCommand()) {
await this.handleCommandInteraction(interaction)
} else if (interaction.isAutocomplete()) {
await this.handleAutocompleteInteraction(interaction)
} else if (interaction.isMessageComponent()) {
await this.handleMessageComponentInteraction(interaction)
}
Expand Down Expand Up @@ -97,6 +100,15 @@ export default class Dispatcher {
: await command.execute(interaction, subCommandGroupName, subCommandName, args)
}

private async handleAutocompleteInteraction (interaction: AutocompleteInteraction): Promise<void> {
const command = this.commandFactory(interaction.commandName)
if (typeof command === 'undefined') {
throw new Error(`Unknown command "${interaction.commandName}".`)
}

await command.autocomplete(interaction)
}

private async handleMessageComponentInteraction (interaction: MessageComponentInteraction): Promise<void> {
if (interaction.isButton()) {
if (!interaction.inGuild() || interaction.customId.startsWith('prompt:')) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type ChatInputCommandInteraction, EmbedBuilder } from 'discord.js'
import { type AutocompleteInteraction, type ChatInputCommandInteraction, EmbedBuilder } from 'discord.js'
import { argumentUtil, constants, timeUtil } from '../../../../utils'
import { groupService, userService, verificationService } from '../../../../services'
import { inject, injectable, named } from 'inversify'
Expand Down Expand Up @@ -258,4 +258,31 @@ export default class TrainingsCommand extends SubCommandCommand<TrainingsCommand
await interaction.reply('Sent you a DM with the upcoming trainings.')
}
}

public override async autocomplete (interaction: AutocompleteInteraction): Promise<void> {
if (applicationConfig.apiEnabled !== true || !interaction.inGuild()) {
await interaction.respond([])
return
}
const context = this.guildContexts.resolve(interaction.guildId) as GuildContext
if (context.robloxGroupId === null) {
await interaction.respond([])
return
}

const option = interaction.options.getFocused(true)
if (option.name === 'type' || (option.name === 'value' && interaction.options.getString('key') === 'type')) {
const results = (await groupService.getTrainingTypes(context.robloxGroupId)).filter(trainingType => (
trainingType.abbreviation.toLowerCase().startsWith(option.value) ||
trainingType.name.toLowerCase().startsWith(option.value)
))
await interaction.respond(results.map(result => ({
name: result.name,
value: result.abbreviation
})).slice(0, 25))
return
}

await super.autocomplete(interaction)
}
}
8 changes: 6 additions & 2 deletions src/interactions/application-commands/slash-commands/base.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { type AnyFunction, type KeyOfType, type OverloadedParameters, constants } from '../../../utils'
import type { Argument, ArgumentOptions } from '.'
import type { AutocompleteInteraction, ChatInputCommandInteraction } from 'discord.js'
import { inject, injectable, type interfaces } from 'inversify'
import { AroraClient } from '../../../client'
import type { ChatInputCommandInteraction } from 'discord.js'

const { TYPES } = constants

Expand All @@ -27,7 +27,7 @@ type SubCommandNames<T, U = OverloadedParameters<T>> = {

export interface SubCommandCommandOptions<T extends SubCommandCommand<any>> extends BaseCommandOptions {
subCommands: {
[K in Exclude<KeyOfType<T, AnyFunction>, 'setOptions' | 'execute'>]: T[K] extends AnyFunction
[K in Exclude<KeyOfType<T, AnyFunction>, 'setOptions' | 'execute' | 'autocomplete'>]: T[K] extends AnyFunction
? Parameters<T[K]>[1] extends string
? { [U in keyof SubCommandNames<T[K]> as Exclude<SubCommandNames<T[K]>[U], never>]: SubCommandOptions }
: SubCommandOptions
Expand All @@ -47,6 +47,10 @@ export default abstract class BaseCommand<T extends CommandOptions = BaseCommand
public setOptions (options: T): void {
this.options = options
}

public async autocomplete (interaction: AutocompleteInteraction): Promise<void> {
await interaction.respond([])
}
}

@injectable()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,48 @@
import type { ChatInputCommandInteraction } from 'discord.js'
import type { AutocompleteInteraction, ChatInputCommandInteraction } from 'discord.js'
import { ApplyOptions } from '../../../../utils/decorators'
import { Command } from '../base'
import type { CommandOptions } from '..'
import { injectable } from 'inversify'

const AVAILABLE_STATUS_CODES = [
100, 101, 102,
100, 101, 102, 103,
200, 201, 202, 203, 204, 206, 207,
300, 301, 302, 303, 304, 305, 307, 308,
400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, 418, 420, 421, 422, 423,
424, 425, 426, 429, 431, 444, 450, 451, 497, 498, 499,
500, 501, 502, 503, 504, 506, 507, 508, 509, 510, 511, 521, 523, 525, 599
500, 501, 502, 503, 504, 506, 507, 508, 509, 510, 511, 521, 522, 523, 525, 599
]

@ApplyOptions<CommandOptions>({
command: {
args: [
{
key: 'statuscode',
name: 'statusCode',
validate: (val: string) => AVAILABLE_STATUS_CODES.includes(parseInt(val)),
required: false
}
]
}
})
@injectable()
export default class HttpCatCommand extends Command {
public async execute (interaction: ChatInputCommandInteraction): Promise<void> {
await interaction.reply(`https://http.cat/${AVAILABLE_STATUS_CODES[Math.floor(Math.random() * AVAILABLE_STATUS_CODES.length)]}`)
public async execute (
interaction: ChatInputCommandInteraction,
{ statusCode }: { statusCode: number }
): Promise<void> {
statusCode ??= AVAILABLE_STATUS_CODES[Math.floor(Math.random() * AVAILABLE_STATUS_CODES.length)]
await interaction.reply(`https://http.cat/${statusCode}`)
}

public override async autocomplete (interaction: AutocompleteInteraction): Promise<void> {
const option = interaction.options.getFocused(true)
if (option.name === 'statuscode') {
const results = AVAILABLE_STATUS_CODES.map(String).filter(statusCode => statusCode.startsWith(option.value))
await interaction.respond(results.map(result => ({ name: result, value: result })).slice(0, 25))
return
}

await super.autocomplete(interaction)
}
}
29 changes: 28 additions & 1 deletion src/interactions/application-commands/slash-commands/main/tag.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { type ChatInputCommandInteraction, EmbedBuilder, type GuildMember } from 'discord.js'
import {
type AutocompleteInteraction,
type ChatInputCommandInteraction,
EmbedBuilder,
type GuildMember
} from 'discord.js'
import type { GuildContext, Tag } from '../../../../structures'
import { constants, util } from '../../../../utils'
import { inject, injectable, named } from 'inversify'
Expand Down Expand Up @@ -60,4 +65,26 @@ export default class TagsCommand extends Command {
await interaction.reply({ embeds: [embed] })
}
}

public override async autocomplete (interaction: AutocompleteInteraction): Promise<void> {
if (!interaction.inGuild()) {
return
}
const context = this.guildContexts.resolve(interaction.guildId) as GuildContext

const option = interaction.options.getFocused(true)
if (option.name === 'query') {
const results = context.tags.cache.reduce<string[]>((result, tag) => {
result.push(...tag.names.cache.filter(tagName => (
tagName.name.toLowerCase().startsWith(option.value))
).map(tagName => tagName.name))
return result
}, [])
console.log(results)
await interaction.respond(results.map(result => ({ name: result, value: result })).slice(0, 25))
return
}

await super.autocomplete(interaction)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ const trainingsCommand: RESTPutAPIApplicationCommandsJSONBody[number] = {
name: 'type',
description: 'The type of this training',
type: ApplicationCommandOptionType.String,
required: true
required: true,
autocomplete: true
}, {
name: 'date',
description: 'The date to schedule this training at',
Expand Down Expand Up @@ -68,7 +69,8 @@ const trainingsCommand: RESTPutAPIApplicationCommandsJSONBody[number] = {
name: 'value',
description: 'The value to change this key to',
type: ApplicationCommandOptionType.String,
required: true
required: true,
autocomplete: true
}]
}, {
name: 'list',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
import type { RESTPutAPIApplicationCommandsJSONBody } from 'discord.js'
import {
ApplicationCommandOptionType,
type RESTPutAPIApplicationCommandsJSONBody
} from 'discord.js'

const httpCatCommand: RESTPutAPIApplicationCommandsJSONBody[number] = {
name: 'httpcat',
description: 'Posts a picture of a random HTTP cat',
default_member_permissions: null
description: 'Posts a picture of a HTTP cat',
default_member_permissions: null,
options: [{
name: 'statuscode',
description: 'Status code to post a HTTP cat picture of',
type: ApplicationCommandOptionType.Integer,
autocomplete: true
}]
}

export default httpCatCommand
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const tagCommand: RESTPutAPIApplicationCommandsJSONBody[number] = {
options: [{
name: 'query',
description: 'The tag to post',
type: ApplicationCommandOptionType.String
type: ApplicationCommandOptionType.String,
autocomplete: true
}, {
name: 'who',
description: 'The member to post this tag for',
Expand Down
Loading

0 comments on commit 566b200

Please sign in to comment.