Skip to content

Commit

Permalink
Fix paste.gg, update to Eris 0.15.
Browse files Browse the repository at this point in the history
  • Loading branch information
retrixe committed Apr 21, 2021
1 parent 10ae686 commit 6d2d2b6
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 30 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.14.0",
"eris": "^0.15.0",
"graphql": "^14.0.2",
"graphql-yoga": "^1.16.7",
"isomorphic-unfetch": "^2.0.0",
Expand Down
11 changes: 6 additions & 5 deletions server/bot/commands/api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

// All the types!
import { Command } from '../imports/types'
// All the tools!
Expand Down Expand Up @@ -61,6 +60,7 @@ export const handleOcr: Command = {
if (text.length > 2000 || useHastebin) {
const { result } = await fetch('https://api.paste.gg/v1/pastes', {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({
name: 'IveBot /ocr result', files: [{ content: { format: 'text', value: text } }]
})
Expand All @@ -75,7 +75,7 @@ export const handleOcr: Command = {
return {
content: hastebin
? `🤔 **Text recognition result uploaded to paste.gg${!useHastebin ? ' due to length' : ''}:**
https://paste.gg/p/anonymous/${id} (use this key to delete: \`${deletionKey}\`)`
https://paste.gg/p/anonymous/${hastebin} (use this key to delete: \`${deletionKey}\`)`
: '🤔 **Text recognition result:**\n' + text,
embed: {
color: 0x666666,
Expand Down Expand Up @@ -123,10 +123,11 @@ export const handleHastebin: Command = {
// Now send the request.
const req = await fetch('https://api.paste.gg/v1/pastes', {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({
name: 'IveBot /ocr result',
name: 'IveBot paste.gg upload',
files: [{
name: message.attachments.length ? message.attachments[0].name : 'pastefile1',
name: message.attachments.length ? message.attachments[0].filename : 'pastefile1',
content: { format: 'text', value: text.toString('utf8') }
}]
})
Expand All @@ -135,7 +136,7 @@ export const handleHastebin: Command = {
// Parse the response.
const res = await req.json()
const { id, deletion_key: deletionKey } = res.result
return res.key
return id
? `**paste.gg URL:**\nhttps://paste.gg/p/anonymous/${id}\nDeletion key: ${deletionKey}`
: 'Failed to upload text to paste.gg!'
} catch (e) { return `Invalid text file, you ${getInsult()}.` }
Expand Down
6 changes: 4 additions & 2 deletions server/bot/commands/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ export const handleEval: Command = {
const res = inspect(await Promise.resolve(eval(toEval)), false, 0)
// const res = eval(`(async () => { const a = ${toEval}; return a })()`)
message.addReaction('✅')
return res !== 'undefined' ? `${'```'}${res}${'```'}`.replace(client.token, 'censored') : undefined
const token = (client as unknown as { _token: string })._token
return res !== 'undefined' ? `${'```'}${res}${'```'}`.replace(token, 'censored') : undefined
} catch (e) {
const channel = await client.getDMChannel(host)
message.addReaction('❌')
Expand Down Expand Up @@ -214,7 +215,8 @@ getContent/getCleanContent(messageID), createMessage(content), getReactions(mess
})
const res = inspect(await Promise.resolve(result), false, 0)
message.addReaction('✅')
return res !== 'undefined' ? `${'```'}${res}${'```'}` : undefined
const token = (context.client as unknown as { _token: string })._token
return res !== 'undefined' ? `${'```'}${res.replace(token, '')}${'```'}` : undefined
} catch (e) {
message.addReaction('❌')
return `**Error:**
Expand Down
29 changes: 17 additions & 12 deletions server/bot/commands/utilities.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// All the types!
import Eris, { Message, GuildTextableChannel } from 'eris'
import Eris, { Message, GuildTextableChannel, Constants } from 'eris'
import { Command } from '../imports/types'
// All the needs!
import { getIdFromMention, getInsult, getUser } from '../imports/tools'
Expand Down Expand Up @@ -172,7 +172,8 @@ export const handlePermissions: Command = {
const color = member ? (member.roles.map(i => member.guild.roles.get(i)).sort(
(a, b) => a.position > b.position ? -1 : 1
).find(i => i.color !== 0) || { color: 0 }).color : 0
const permissions = member.permission
const permissions = member.permissions
const permissionKeys = Object.keys(permissions.json) as (keyof Constants['Permissions'])[]
const channelPerm = (message.channel as GuildTextableChannel).permissionsOf(user.id)
return {
content: `✅ **Permissions of ${user.username}:**`,
Expand All @@ -190,23 +191,27 @@ export const handlePermissions: Command = {
? 'Owner! (use `/perms --ignore-admin` to show perms regardless)'
: permissions.has('administrator') && !ignoreAdmin
? 'Administrator! (use `/perms --ignore-admin` to show perms regardless)'
: Object.keys(permissions.json).filter(perm => permissions.has(perm))
: permissionKeys
.filter(perm => permissions.has(perm))
.map(perm => (perm.substr(0, 1).toUpperCase() + perm.substr(1))
.replace(/[A-Z]+/g, s => ' ' + s))
.join(', ').replace('TTSMessages', 'TTS Messages')
},
!(message.member.guild.ownerID === user.id || permissions.has('administrator')) || ignoreAdmin
? {
name: 'Channel Permissions',
value: (Object.keys(permissions.json)
.filter(perm => !permissions.has(perm) && channelPerm.has(perm))
.map(perm => (perm.substr(0, 1).toUpperCase() + perm.substr(1))
.replace(/[A-Z]+/g, s => ' ' + s))
.join(', ') + Object.keys(permissions.json)
.filter(perm => permissions.has(perm) && !channelPerm.has(perm))
.map(perm => '**!(' + (perm.substr(0, 1).toUpperCase() + perm.substr(1))
.replace(/[^(][A-Z]+/g, s => s.substr(0, 1) + ' ' + s.substr(1)) + ')**')
.join(', ')).replace('TTSMessages', 'TTS Messages')
value: (
permissionKeys
.filter(perm => !permissions.has(perm) && channelPerm.has(perm))
.map(perm => (perm.substr(0, 1).toUpperCase() + perm.substr(1))
.replace(/[A-Z]+/g, s => ' ' + s))
.join(', ') +
permissionKeys
.filter(perm => permissions.has(perm) && !channelPerm.has(perm))
.map(perm => '**!(' + (perm.substr(0, 1).toUpperCase() + perm.substr(1))
.replace(/[^(][A-Z]+/g, s => s.substr(0, 1) + ' ' + s.substr(1)) + ')**')
.join(', ')
).replace('TTSMessages', 'TTS Messages')
} : { name: '', value: '' }
].filter(e => !!e.value),
footer: { text: 'User ID: ' + user.id }
Expand Down
4 changes: 4 additions & 0 deletions server/bot/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ export default async (message: Message, client: Client, tempDB: DB, db: Db) => {
// Auto responses and easter eggs.
if (command.startsWith('is dot a good boy')) sendResponse('Shame on you. He\'s undefined.')
else if (command.startsWith('iphone x')) sendResponse(`You don't deserve it. 😎`)
else if (command.startsWith('iphone 11')) sendResponse(`You don't deserve it. 😎`)
else if (command.startsWith('iphone 12')) sendResponse(`You don't deserve it. 😎`)
else if (command.startsWith('iphone 13')) sendResponse(`You don't deserve it. 😎`)
else if (command.startsWith('iphone se')) sendResponse(`lol peasant`)
else if (command.startsWith('triggered')) sendResponse('Ah, pathetic people again.')
else if (command.startsWith('ayy')) sendResponse('lmao')
// Handle answers to gunfight.
Expand Down
2 changes: 1 addition & 1 deletion server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const dev = process.env.NODE_ENV !== 'production'
const port = parseInt(process.env.PORT, 10) || 3000 // If port variable has been set.

// Create a client to connect to Discord API Gateway.
const client = new Client(token === 'dotenv' ? process.env.IVEBOT_TOKEN : token, {
const client = new Client('Bot ' + token === 'dotenv' ? process.env.IVEBOT_TOKEN : token, {
allowedMentions: { everyone: false, roles: true, users: true },
autoreconnect: true,
restMode: true
Expand Down
35 changes: 26 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1491,6 +1491,13 @@ are-we-there-yet@~1.1.2:
delegates "^1.0.0"
readable-stream "^2.0.6"

argparse@^1.0.7:
version "1.0.10"
resolved "https://registry.yarnpkg.com/argparse/-/argparse-1.0.10.tgz#bcd6791ea5ae09725e17e5ad988134cd40b3d911"
integrity sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==
dependencies:
sprintf-js "~1.0.2"

arr-diff@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/arr-diff/-/arr-diff-4.0.0.tgz#d6461074febfec71e7e15235761a329a5dc7c520"
Expand Down Expand Up @@ -2813,14 +2820,14 @@ enhanced-resolve@^4.1.0:
memory-fs "^0.4.0"
tapable "^1.0.0"

eris@^0.14.0:
version "0.14.0"
resolved "https://registry.yarnpkg.com/eris/-/eris-0.14.0.tgz#0d13391c0fc1a7b678b2f8d1fc3ec6aef05700d3"
integrity sha512-/W6X0SFR2swtA9oc4ga5Wh1TQcZtPgbUaDDdwYc67fvFUAtwC+V1xzWUZq2yDeJnTfB8Uot9SJWA8Lthe2sDtQ==
eris@^0.15.0:
version "0.15.0"
resolved "https://registry.yarnpkg.com/eris/-/eris-0.15.0.tgz#d0744d993d508b2951bc6d0ab380ae39b63c0666"
integrity sha512-muBdi5XyMXdxFQ8xUG6yofq40/Z02CHlqJP7zIdHhpdDiHvFM/mybGiFAHuoSYcsVTTvEfbUaAJ+SDEmMjARYw==
dependencies:
ws "^7.2.1"
optionalDependencies:
opusscript "^0.0.7"
opusscript "^0.0.8"
tweetnacl "^1.0.1"

errno@^0.1.2, errno@^0.1.3, errno@^0.1.4, errno@~0.1.7:
Expand Down Expand Up @@ -3093,6 +3100,11 @@ espree@^5.0.1:
acorn-jsx "^5.0.0"
eslint-visitor-keys "^1.0.0"

esprima@^4.0.0:
version "4.0.1"
resolved "https://registry.yarnpkg.com/esprima/-/esprima-4.0.1.tgz#13b04cdb3e6c5d19df91ab6987a8695619b0aa71"
integrity sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==

esquery@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/esquery/-/esquery-1.0.1.tgz#406c51658b1f5991a5f9b62b1dc25b00e3e5c708"
Expand Down Expand Up @@ -5434,10 +5446,10 @@ optionator@^0.8.2:
type-check "~0.3.2"
word-wrap "~1.2.3"

opusscript@^0.0.7:
version "0.0.7"
resolved "https://registry.yarnpkg.com/opusscript/-/opusscript-0.0.7.tgz#7dd7ec55b302d26bf588e6fc3feb090b8c7da856"
integrity sha512-DcBadTdYTUuH9zQtepsLjQn4Ll6rs3dmeFvN+SD0ThPnxRBRm/WC1zXWPg+wgAJimB784gdZvUMA57gDP7FdVg==
opusscript@^0.0.8:
version "0.0.8"
resolved "https://registry.yarnpkg.com/opusscript/-/opusscript-0.0.8.tgz#00b49e81281b4d99092d013b1812af8654bd0a87"
integrity sha512-VSTi1aWFuCkRCVq+tx/BQ5q9fMnQ9pVZ3JU4UHKqTkf0ED3fKEPdr+gKAAl3IA2hj9rrP6iyq3hlcJq3HELtNQ==

os-browserify@^0.3.0:
version "0.3.0"
Expand Down Expand Up @@ -6664,6 +6676,11 @@ split-string@^3.0.1, split-string@^3.0.2:
dependencies:
extend-shallow "^3.0.0"

sprintf-js@~1.0.2:
version "1.0.3"
resolved "https://registry.yarnpkg.com/sprintf-js/-/sprintf-js-1.0.3.tgz#04e6926f662895354f3dd015203633b857297e2c"
integrity sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=

ssri@^6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/ssri/-/ssri-6.0.1.tgz#2a3c41b28dd45b62b63676ecb74001265ae9edd8"
Expand Down

0 comments on commit 6d2d2b6

Please sign in to comment.