-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from Ry0xi/feature/middleware-discord-handle-pi…
…ng-message feat: add discord-handle-ping-message-middleware
- Loading branch information
Showing
8 changed files
with
208 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
*.js | ||
!jest.config.js | ||
!.eslintrc.js | ||
!prettierrc.js | ||
!.prettierrc.js | ||
*.d.ts | ||
node_modules | ||
.env | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module.exports = { | ||
singleQuote: true, | ||
trailingComma: 'all', | ||
overrides: [ | ||
{ | ||
files: '*.md', | ||
options: { | ||
tabWidth: 2, | ||
}, | ||
}, | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import type { APIGatewayProxyEventV2 } from 'aws-lambda'; | ||
import type { InteractionType } from 'discord-interactions'; | ||
|
||
export interface DiscordInteractionEvent | ||
extends Omit<APIGatewayProxyEventV2, 'body'> { | ||
body: InteractionBodyType; | ||
} | ||
|
||
export interface InteractionBodyType { | ||
id: string; | ||
application_id: string; | ||
type: InteractionType; | ||
token: string; | ||
// type: 1の時以外は存在する | ||
// https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-interaction-data | ||
data?: ApplicationCommandInteractionData; | ||
} | ||
|
||
export interface ApplicationCommandInteractionData { | ||
id: string; | ||
type: ApplicationCommandType; | ||
name: string; | ||
// Discordのパラメータ上ではオプショナルだが、コマンドの情報のために必須 | ||
options: Array<ApplicationCommandInteractionDataOption>; | ||
} | ||
|
||
export interface ApplicationCommandInteractionDataOption { | ||
name: string; | ||
value: string | number | boolean; | ||
options?: Array<ApplicationCommandInteractionDataOption>; | ||
} | ||
|
||
// https://discord.com/developers/docs/interactions/application-commands#application-command-object-application-command-types | ||
export enum ApplicationCommandType { | ||
CHAT_INPUT = 1, | ||
USER = 2, | ||
MESSAGE = 3, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import type middy from '@middy/core'; | ||
import type { APIGatewayProxyResultV2 } from 'aws-lambda'; | ||
import { InteractionType } from 'discord-interactions'; | ||
|
||
import type { DiscordInteractionEvent } from '@/handlers/interaction-event-schema'; | ||
|
||
const discordHandlePingMessageMiddleware = (): middy.MiddlewareObj< | ||
DiscordInteractionEvent, | ||
APIGatewayProxyResultV2 | ||
> => { | ||
/** | ||
* PING - PONG | ||
* | ||
* @see https://discord.com/developers/docs/interactions/receiving-and-responding#receiving-an-interaction | ||
*/ | ||
const discordHandlePingMessageMiddlewareBefore: middy.MiddlewareFn< | ||
DiscordInteractionEvent, | ||
APIGatewayProxyResultV2 | ||
> = async (request): Promise<APIGatewayProxyResultV2 | void> => { | ||
const interactionType = request.event.body.type; | ||
|
||
if (interactionType === InteractionType.PING) { | ||
return { | ||
statusCode: 200, | ||
body: JSON.stringify({ | ||
type: InteractionType.PING, | ||
}), | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
}; | ||
} | ||
}; | ||
|
||
return { | ||
before: discordHandlePingMessageMiddlewareBefore, | ||
}; | ||
}; | ||
|
||
export default discordHandlePingMessageMiddleware; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters