Skip to content

Commit

Permalink
Add /ocr <message link> for confunded people.
Browse files Browse the repository at this point in the history
  • Loading branch information
retrixe committed Jul 11, 2020
1 parent fbe72a5 commit 9eaa4d0
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions server/bot/commands/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,19 @@ export const handleOcr: Command = {
usage: '/ocr (--hastebin) <link to image/uploaded image>',
argsRequired: false
},
generator: async (message, args) => {
generator: async (message, args, { client }) => {
// To hasteb.in or not to hasteb.in.
const useHastebin = args[0] === '--hastebin'
if (useHastebin) args.shift()
// Get the image and convert it to Base64.
try {
const url = args.length ? args.join('%20') : message.attachments[0].url
// Check if a message link was passed.
const regex = /https?:\/\/((canary|ptb|www).)?discord(app)?.com\/channels\/\d{17,18}\/\d{17,18}\/\d{17,18}/
let url = args.length ? args.join('%20') : message.attachments[0].url
if (regex.test(url)) {
const split = url.split('/')
url = (await client.getMessage(split[split.length - 2], split.pop())).attachments[0].url
}
// const image = Buffer.from(await (await fetch(url)).arrayBuffer()).toString('base64')
const fetchedImage = await fetchLimited(url, 16)
if (fetchedImage === false) return 'The file provided is larger than 16 MB!'
Expand Down

0 comments on commit 9eaa4d0

Please sign in to comment.