-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: use biome for formatting and linting (#57)
- Loading branch information
1 parent
a5710cb
commit 9b396aa
Showing
19 changed files
with
1,015 additions
and
1,878 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"$schema": "https://biomejs.dev/schemas/1.6.4/schema.json", | ||
"files": { | ||
"include": ["src/**/*.ts", "examples/*.js"] | ||
}, | ||
"organizeImports": { | ||
"enabled": true | ||
}, | ||
"linter": { | ||
"enabled": true, | ||
"rules": { | ||
"recommended": true | ||
} | ||
}, | ||
"javascript": { | ||
"formatter": { | ||
"quoteStyle": "single" | ||
} | ||
} | ||
} |
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,28 @@ | ||
const express = require('express'); | ||
const { InteractionType, InteractionResponseType, verifyKeyMiddleware } = require('../dist'); | ||
const { | ||
InteractionType, | ||
InteractionResponseType, | ||
verifyKeyMiddleware, | ||
} = require('../dist'); | ||
|
||
const app = express(); | ||
|
||
app.post('/interactions', verifyKeyMiddleware(process.env.CLIENT_PUBLIC_KEY), (req, res) => { | ||
const interaction = req.body; | ||
if (interaction.type === InteractionType.APPLICATION_COMMAND) { | ||
res.send({ | ||
type: InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE, | ||
data: { | ||
content: 'Hello world', | ||
}, | ||
}); | ||
} | ||
}); | ||
app.post( | ||
'/interactions', | ||
verifyKeyMiddleware(process.env.CLIENT_PUBLIC_KEY), | ||
(req, res) => { | ||
const interaction = req.body; | ||
if (interaction.type === InteractionType.APPLICATION_COMMAND) { | ||
res.send({ | ||
type: InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE, | ||
data: { | ||
content: 'Hello world', | ||
}, | ||
}); | ||
} | ||
}, | ||
); | ||
|
||
app.listen(8999, () => { | ||
console.log('Example app listening at http://localhost:8999'); | ||
console.log('Example app listening at http://localhost:8999'); | ||
}); |
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,26 +1,34 @@ | ||
const express = require('express'); | ||
const bodyParser = require('body-parser'); | ||
|
||
const { InteractionType, InteractionResponseType, verifyKeyMiddleware } = require('../dist'); | ||
const { | ||
InteractionType, | ||
InteractionResponseType, | ||
verifyKeyMiddleware, | ||
} = require('../dist'); | ||
|
||
const app = express(); | ||
|
||
app.post('/interactions', verifyKeyMiddleware(process.env.CLIENT_PUBLIC_KEY), (req, res) => { | ||
const interaction = req.body; | ||
if (interaction.type === InteractionType.APPLICATION_COMMAND) { | ||
res.send({ | ||
type: InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE, | ||
data: { | ||
content: 'Hello world', | ||
}, | ||
}); | ||
} | ||
}); | ||
app.post( | ||
'/interactions', | ||
verifyKeyMiddleware(process.env.CLIENT_PUBLIC_KEY), | ||
(req, res) => { | ||
const interaction = req.body; | ||
if (interaction.type === InteractionType.APPLICATION_COMMAND) { | ||
res.send({ | ||
type: InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE, | ||
data: { | ||
content: 'Hello world', | ||
}, | ||
}); | ||
} | ||
}, | ||
); | ||
|
||
// It's best to set up body-parser so that it does NOT apply to interaction | ||
// routes. | ||
app.use(bodyParser.json()); | ||
|
||
app.listen(8999, () => { | ||
console.log('Example app listening at http://localhost:8999'); | ||
console.log('Example app listening at http://localhost:8999'); | ||
}); |
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,28 +1,37 @@ | ||
const { InteractionResponseType, InteractionType, verifyKey } = require('discord-interactions'); | ||
const { | ||
InteractionResponseType, | ||
InteractionType, | ||
verifyKey, | ||
} = require('discord-interactions'); | ||
|
||
const CLIENT_PUBLIC_KEY = process.env.CLIENT_PUBLIC_KEY; | ||
|
||
module.exports.myInteraction = async (req, res) => { | ||
// Verify the request | ||
const signature = req.get('X-Signature-Ed25519'); | ||
const timestamp = req.get('X-Signature-Timestamp'); | ||
const isValidRequest = await verifyKey(req.rawBody, signature, timestamp, CLIENT_PUBLIC_KEY); | ||
if (!isValidRequest) { | ||
return res.status(401).end('Bad request signature'); | ||
} | ||
// Verify the request | ||
const signature = req.get('X-Signature-Ed25519'); | ||
const timestamp = req.get('X-Signature-Timestamp'); | ||
const isValidRequest = await verifyKey( | ||
req.rawBody, | ||
signature, | ||
timestamp, | ||
CLIENT_PUBLIC_KEY, | ||
); | ||
if (!isValidRequest) { | ||
return res.status(401).end('Bad request signature'); | ||
} | ||
|
||
// Handle the payload | ||
const interaction = req.body; | ||
if (interaction && interaction.type === InteractionType.APPLICATION_COMMAND) { | ||
res.send({ | ||
type: InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE, | ||
data: { | ||
content: `You used: ${interaction.data.name}`, | ||
}, | ||
}); | ||
} else { | ||
res.send({ | ||
type: InteractionResponseType.PONG, | ||
}); | ||
} | ||
// Handle the payload | ||
const interaction = req.body; | ||
if (interaction && interaction.type === InteractionType.APPLICATION_COMMAND) { | ||
res.send({ | ||
type: InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE, | ||
data: { | ||
content: `You used: ${interaction.data.name}`, | ||
}, | ||
}); | ||
} else { | ||
res.send({ | ||
type: InteractionResponseType.PONG, | ||
}); | ||
} | ||
}; |
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,21 +1,30 @@ | ||
const express = require('express'); | ||
const { InteractionType, InteractionResponseFlags, InteractionResponseType, verifyKeyMiddleware } = require('../dist'); | ||
const { | ||
InteractionType, | ||
InteractionResponseFlags, | ||
InteractionResponseType, | ||
verifyKeyMiddleware, | ||
} = require('../dist'); | ||
|
||
const app = express(); | ||
|
||
app.post('/interactions', verifyKeyMiddleware(process.env.CLIENT_PUBLIC_KEY), (req, res) => { | ||
const interaction = req.body; | ||
if (interaction.type === InteractionType.MESSAGE_COMPONENT) { | ||
res.send({ | ||
type: InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE, | ||
data: { | ||
content: 'Hello, you interacted with a component.', | ||
flags: InteractionResponseFlags.EPHEMERAL, | ||
}, | ||
}); | ||
} | ||
}); | ||
app.post( | ||
'/interactions', | ||
verifyKeyMiddleware(process.env.CLIENT_PUBLIC_KEY), | ||
(req, res) => { | ||
const interaction = req.body; | ||
if (interaction.type === InteractionType.MESSAGE_COMPONENT) { | ||
res.send({ | ||
type: InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE, | ||
data: { | ||
content: 'Hello, you interacted with a component.', | ||
flags: InteractionResponseFlags.EPHEMERAL, | ||
}, | ||
}); | ||
} | ||
}, | ||
); | ||
|
||
app.listen(8999, () => { | ||
console.log('Example app listening at http://localhost:8999'); | ||
console.log('Example app listening at http://localhost:8999'); | ||
}); |
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,48 +1,56 @@ | ||
const express = require('express'); | ||
const { InteractionType, InteractionResponseType, verifyKeyMiddleware } = require('../dist'); | ||
const { | ||
InteractionType, | ||
InteractionResponseType, | ||
verifyKeyMiddleware, | ||
} = require('../dist'); | ||
|
||
const app = express(); | ||
|
||
app.post('/interactions', verifyKeyMiddleware(process.env.CLIENT_PUBLIC_KEY), (req, res) => { | ||
const interaction = req.body; | ||
if (interaction.type === InteractionType.APPLICATION_COMMAND) { | ||
res.send({ | ||
type: InteractionResponseType.APPLICATION_MODAL, | ||
data: { | ||
title: 'Test', | ||
custom_id: 'test-modal', | ||
components: [ | ||
{ | ||
type: 1, | ||
components: [ | ||
{ | ||
type: 4, | ||
style: 1, | ||
label: 'Short Input', | ||
custom_id: 'short-input', | ||
placeholder: 'Short Input', | ||
}, | ||
], | ||
}, | ||
{ | ||
type: 1, | ||
components: [ | ||
{ | ||
type: 4, | ||
style: 1, | ||
label: 'Paragraph Input', | ||
custom_id: 'paragraph-input', | ||
placeholder: 'Paragraph Input', | ||
required: false, | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
}); | ||
} | ||
}); | ||
app.post( | ||
'/interactions', | ||
verifyKeyMiddleware(process.env.CLIENT_PUBLIC_KEY), | ||
(req, res) => { | ||
const interaction = req.body; | ||
if (interaction.type === InteractionType.APPLICATION_COMMAND) { | ||
res.send({ | ||
type: InteractionResponseType.APPLICATION_MODAL, | ||
data: { | ||
title: 'Test', | ||
custom_id: 'test-modal', | ||
components: [ | ||
{ | ||
type: 1, | ||
components: [ | ||
{ | ||
type: 4, | ||
style: 1, | ||
label: 'Short Input', | ||
custom_id: 'short-input', | ||
placeholder: 'Short Input', | ||
}, | ||
], | ||
}, | ||
{ | ||
type: 1, | ||
components: [ | ||
{ | ||
type: 4, | ||
style: 1, | ||
label: 'Paragraph Input', | ||
custom_id: 'paragraph-input', | ||
placeholder: 'Paragraph Input', | ||
required: false, | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
}); | ||
} | ||
}, | ||
); | ||
|
||
app.listen(8999, () => { | ||
console.log('Example app listening at http://localhost:8999'); | ||
console.log('Example app listening at http://localhost:8999'); | ||
}); |
Oops, something went wrong.