Skip to content

Commit

Permalink
Merge pull request #116 from josefaidt/chore/type-interaction-responses
Browse files Browse the repository at this point in the history
  • Loading branch information
josefaidt authored Jul 7, 2022
2 parents 5614882 + 746f238 commit a2417b6
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 11 deletions.
10 changes: 7 additions & 3 deletions src/lib/discord/Command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import type {
APIApplicationCommand,
RESTPostAPIApplicationCommandsJSONBody,
} from 'discord-api-types/v9'
import type { CommandInteraction } from 'discord.js'
import { DiscordCommandOption } from './CommandOption'
import type { CommandInteraction, InteractionReplyOptions } from 'discord.js'
import type { DiscordCommandOption } from './CommandOption'

export interface IDiscordCommandConfig {
name: string
Expand All @@ -16,7 +16,11 @@ export interface IDiscordCommandConfig {

export type DiscordCommandHandler = (
interaction: CommandInteraction
) => string | undefined | Promise<string | undefined>
) =>
| string
| undefined
| InteractionReplyOptions
| Promise<string | undefined | InteractionReplyOptions>

export type CreateDiscordCommandInput = IDiscordCommandConfig & {
handler: DiscordCommandHandler
Expand Down
6 changes: 4 additions & 2 deletions src/lib/discord/commands/contribute.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createCommand, createOption } from '$discord'
import type { CommandInteraction } from 'discord.js'
import type { CommandInteraction, InteractionReplyOptions } from 'discord.js'

const repository = createOption({
name: 'repository',
Expand Down Expand Up @@ -33,7 +33,9 @@ const command = createCommand({
name: 'contribute',
description: 'Learn how to contribute to an Amplify project',
options: [repository],
handler: (interaction: CommandInteraction) => {
handler: (
interaction: CommandInteraction
): InteractionReplyOptions | string => {
const [{ value: repository }] = interaction.options.data
const lines = [
'Thanks for your interest in contributing! To learn how to get started visit the contributing guide:',
Expand Down
6 changes: 4 additions & 2 deletions src/lib/discord/commands/github.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createCommand, createOption } from '$discord'
import type { CommandInteraction } from 'discord.js'
import type { CommandInteraction, InteractionReplyOptions } from 'discord.js'

const repository = createOption({
name: 'repository',
Expand Down Expand Up @@ -30,7 +30,9 @@ const command = createCommand({
name: 'github',
description: 'Gives link to GitHub repository',
options: [repository],
handler: (interaction: CommandInteraction) => {
handler: (
interaction: CommandInteraction
): InteractionReplyOptions | string => {
const [{ value: repository }] = interaction.options.data
return getRepositoryUrl(repository as string)
},
Expand Down
4 changes: 2 additions & 2 deletions src/lib/discord/commands/giverole.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createCommand } from '$discord'
import type { Role, User } from 'discord.js'
import type { Role, User, InteractionReplyOptions } from 'discord.js'

async function handler(interaction) {
async function handler(interaction): Promise<InteractionReplyOptions | string> {
const { member: caller, guild } = interaction
const { role, user } = interaction.options.data.reduce(
(acc, current, index, source) => {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/discord/commands/thread.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { MessageEmbed } from 'discord.js'
import { createCommand, createOption } from '$discord'
import type { ThreadChannel } from 'discord.js'
import type { InteractionReplyOptions, ThreadChannel } from 'discord.js'
import { prisma } from '$lib/db'

export const PREFIXES = {
solved: '✅ - ',
open: '﹖ - ',
}

async function handler(interaction) {
async function handler(interaction): Promise<InteractionReplyOptions | string> {
const channel = interaction.channel as ThreadChannel
const messages = await channel.messages.fetch()
const record = await prisma.question.findUnique({
Expand Down

0 comments on commit a2417b6

Please sign in to comment.