Skip to content

Commit

Permalink
chore: use biome for formatting and linting (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeckwith authored May 17, 2024
1 parent a5710cb commit 9b396aa
Show file tree
Hide file tree
Showing 19 changed files with 1,015 additions and 1,878 deletions.
2 changes: 0 additions & 2 deletions .eslintignore

This file was deleted.

16 changes: 0 additions & 16 deletions .eslintrc.json

This file was deleted.

2 changes: 0 additions & 2 deletions .prettierignore

This file was deleted.

5 changes: 0 additions & 5 deletions .prettierrc

This file was deleted.

20 changes: 20 additions & 0 deletions biome.json
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"
}
}
}
5 changes: 0 additions & 5 deletions examples/.eslintrc.json

This file was deleted.

34 changes: 21 additions & 13 deletions examples/express_app.js
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');
});
34 changes: 21 additions & 13 deletions examples/express_app_with_bodyparser.js
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');
});
53 changes: 31 additions & 22 deletions examples/gcloud_function.js
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,
});
}
};
37 changes: 23 additions & 14 deletions examples/message_components.js
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');
});
90 changes: 49 additions & 41 deletions examples/modal_example.js
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');
});
Loading

0 comments on commit 9b396aa

Please sign in to comment.