Skip to content

Commit

Permalink
Update to latest Eris, add /commands and /ocr --hastebin.
Browse files Browse the repository at this point in the history
- Use default allowedMentions client option.
  • Loading branch information
retrixe committed Jun 21, 2020
1 parent 2f6cacd commit d30b280
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"@material-ui/core": "^3.0.1",
"@material-ui/icons": "^3.0.1",
"apollo-boost": "^0.1.4",
"eris": "^0.12.0",
"eris": "^0.13.3",
"graphql": "^14.0.2",
"graphql-yoga": "^1.16.7",
"isomorphic-unfetch": "^2.0.0",
Expand Down
4 changes: 2 additions & 2 deletions server/bot/commands/admin/emoji.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ export const handleAddemoji: Command = {
return true
}
// Fetch the emoji.
let image
let image: false | Buffer
try {
// image = Buffer.from(await (await fetch(url)).arrayBuffer())
image = await fetchLimited(url, 0.25)
} catch (e) { return `Invalid image URL, you ${getInsult()}` }
// If emoji larger than 384 KB (in case)
if (image === false || image === true || (image.byteLength / 1024) >= 384) {
if (image === false || (image.byteLength / 1024) >= 384) {
return `Your emoji is larger than 256 KB, resize your image!
I recommend using <https://picresize.com/> if the emoji is JPG.
Set step 2 to No Change, set Max Filesize to 255 in step 4 and set to Best quality.
Expand Down
9 changes: 6 additions & 3 deletions server/bot/commands/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ export const handleOcr: Command = {
description: 'Get text from an image.',
fullDescription: 'Get text from an image. Powered by Google Cloud Vision.',
example: '/ocr <with uploaded image>',
usage: '/ocr <link to image/uploaded image>',
usage: '/ocr (--hastebin) <link to image/uploaded image>',
argsRequired: false
},
generator: async (message, args) => {
// 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
Expand All @@ -46,7 +49,7 @@ export const handleOcr: Command = {
const text = result.responses[0].fullTextAnnotation.text
let hastebin = ''
try {
if (text.length > 2000) {
if (text.length > 2000 || useHastebin) {
const { key } = await fetch('https://hasteb.in/documents', {
method: 'POST', body: text
}).then(e => e.json())
Expand All @@ -58,7 +61,7 @@ export const handleOcr: Command = {
// Return our answer.
return {
content: hastebin
? `🤔 **Text recognition result uploaded to hasteb.in due to length:**
? `🤔 **Text recognition result uploaded to hasteb.in${!useHastebin ? ' due to length' : ''}:**
https://hasteb.in/${hastebin} (will be deleted after 30 days)`
: '🤔 **Text recognition result:**\n' + text,
embed: {
Expand Down
4 changes: 2 additions & 2 deletions server/bot/commands/help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { zeroWidthSpace, getInsult } from '../imports/tools'
import { rootURL } from '../../../config.json5'
import { Command } from '../client'

const generalHelp = {
export const generalHelp = {
description: `**Jony Ive can do many commands 📡**
\`/halp\` and \`/help\` - The most innovative help.`,
fields: [
Expand Down Expand Up @@ -84,7 +84,7 @@ Arguments in () are optional :P

export const handleHelp: IveBotCommand = {
name: 'help',
aliases: ['halp'],
aliases: ['halp', 'commands'],
opts: {
description: 'The most innovative help.',
fullDescription: 'The most innovative halp.',
Expand Down
1 change: 1 addition & 0 deletions server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const port = parseInt(process.env.PORT, 10) || 3000 // If port variable has been

// Create a client to connect to Discord API Gateway.
const client = new Client(token === 'dotenv' ? process.env.IVEBOT_TOKEN : token, {
allowedMentions: { everyone: false, roles: true, users: true },
autoreconnect: true,
restMode: true
})
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2726,10 +2726,10 @@ enhanced-resolve@^4.1.0:
memory-fs "^0.4.0"
tapable "^1.0.0"

eris@^0.12.0:
version "0.12.0"
resolved "https://registry.yarnpkg.com/eris/-/eris-0.12.0.tgz#4bcb0d4705fe188a59baec0baf6b31fcf5c9f809"
integrity sha512-LIw+uEOfHFCdE9BXL3wqxwml+74TJ7eMiMcyeW/jsmiWndDzybA/WlakiXAAnyg9a5OULOkHlKLOFsl+EgoZag==
eris@^0.13.3:
version "0.13.3"
resolved "https://registry.yarnpkg.com/eris/-/eris-0.13.3.tgz#22abb71f9ce0d453200b537cad457dc39c7b302b"
integrity sha512-WBtLyknOWZpYZL9yPhez0oKUWvYpunSg43hGxawwjwSf3gFXmbEPYrT8KlmZXtpJnX16eQ7mzIq+MgSh3LarEg==
dependencies:
ws "^7.2.1"
optionalDependencies:
Expand Down

0 comments on commit d30b280

Please sign in to comment.