discord-toolkit-bot
discord-toolkit-bot copied to clipboard
Automatically upload files in help channels to a bin service
As mentioned in the /tag query: bin
command, users should upload large code snippets to a bin service instead of uploading them as files. Some reasons include:
- They cannot be viewed within the client on mobile (must open in browser or download)
- Trying to expand it will lead to the same issue, it will just be a big codeblock again but hideable
- Trying to view full-screen and referring back to other messages in chat is a hassle
- You cannot Ctrl + F to quickly find a keyword
- You can upload the code to a bin service yourself but that can become a hassle, especially on mobile
- You can always tell the user to upload it to a bin service themselves, but they're d.js members so you never know
Possible Solution
Upon detecting a message in a help channel with a .txt
/.js
/.ts
file, upload the contents of the file to a bin service. Then, silently reply to the message with the link to the bin.
As for which bin service to use, I think sourcebin is the most popular but I can't find if they have a public API or not. Pastebin is a close contender.
Concept
I'd like it, but as a context menu command to not clutter the chat
You must be human. Accounts registered or maintained by "bots" or other automated methods are not permitted. ~https://sourceb.in/terms
What about https://srcshare.io/? They also have an API: https://api.wornoffkeys.com/v1/srcshare
What about https://srcshare.io/? They also have an API: https://api.wornoffkeys.com/v1/srcshare
That link's broken for me.
// 20231009211137
// https://api.wornoffkeys.com/v1/srcshare
{
"errorType": "Runtime.UnhandledPromiseRejection",
"errorMessage": "CastError: Cast to ObjectId failed for value \"\" (type string) at path \"_id\" for model \"srcshare-code\"",
"trace": [
"Runtime.UnhandledPromiseRejection: CastError: Cast to ObjectId failed for value \"\" (type string) at path \"_id\" for model \"srcshare-code\"",
" at process.<anonymous> (file:///var/runtime/index.mjs:1250:17)",
" at process.emit (node:events:513:28)",
" at emit (node:internal/process/promises:140:20)",
" at processPromiseRejections (node:internal/process/promises:274:27)",
" at processTicksAndRejections (node:internal/process/task_queues:97:32)"
]
}
That link's broken for me.
Yeah, not sure what that's about but I've used it, I just made a fetch request, something like this:
fetch("https://api.wornoffkeys.com/v1/srcshare", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
tabs: [
{
name: "Code",
content: `${code}`,
},
{
name: "Error",
content: `${error}`,
},
],
language: `${language}`,
title: `${title}`,
description: `${description}`,
}),
});