A sourcebin command to create and retrieve bins. Opun installing, click the green "run" button in the bottom right hand side of the screen and the command will be created.
// authenticates you with the API standard library
// type `await lib.` to display API autocomplete
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
const sourcebin = require('sourcebin');
const event = context.params.event;
if (event.token === 'A_UNIQUE_TOKEN') {
console.log(`Got here: A`);
await lib.discord.commands['@0.1.1'].create({
guild_id: process.env.guildId,
name: 'sourcebin',
description: `Sourcebin commands.`,
options: [
{
name: 'create',
description: `Create a sourcebin`,
type: 1,
options: [
{
name: 'name',
description: 'File name',
type: 3,
required: true,
},
{
name: 'language',
description: 'Language or language id.',
type: 3,
required: true,
},
{
name: 'title',
description: 'Bin name',
type: 3,
required: true,
},
{
name: 'description',
description: 'Bin description',
type: 3,
required: true,
},
{
name: 'content',
description: 'File content',
type: 3,
required: true,
},
],
},
{
name: 'get',
description: 'Retrieve a bin',
type: 1,
options: [
{
name: 'query',
description: 'Bin key or url',
type: 3,
},
],
},
],
});
return;
}
await lib.discord.interactions['@1.0.1'].responses.create({
token: event.token,
response_type: 'DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE',
});
async function updateResponse(bin) {
await lib.discord.interactions['@1.0.1'].responses.update({
token: event.token,
content: '',
embeds: [
{
type: 'rich',
title:
event.data.options[0].options.length > 2
? 'Sourcebin Created!'
: 'Here is your sourcebin!',
color: 0xff5555,
thumbnail: {
url: 'https://media.discordapp.net/attachments/923888368025239562/969739888448647238/Sourcebin_Logo.png',
},
description: [
`**Title**: ${bin.title}`,
`**Language**: ${bin.files[0].language.name}`,
`**Key**: ${bin.key}`,
`**URL**: ${bin.url}`,
].join('\n'),
},
],
components: [
{
type: 1,
components: [
{
type: 2,
style: 5,
label: 'Open',
url: bin.url,
},
],
},
],
});
}
switch (event.data.options[0].name) {
case 'create':
const options = event.data.options[0].options.map((x) => x.value);
const bin = await sourcebin.create(
[
{
name: options[0],
content: options[4],
language: options[1],
},
],
{
title: options[2],
description: options[3],
}
);
await updateResponse(bin);
break;
case 'get':
const query = event.data.options[0].options[0].value;
await sourcebin
.get(query)
.then(async (Bin) => {
await updateResponse(Bin);
})
.catch(async (err) => {
await lib.discord.interactions['@1.0.1'].responses.update({
token: event.token,
content: err.message,
});
});
break;
}