Skip to content

Commit

Permalink
Merge pull request #30 from Fifa12fcb/main
Browse files Browse the repository at this point in the history
haste now support files
  • Loading branch information
davidcralph authored Sep 10, 2021
2 parents 7bfd602 + 383a6fb commit ff1133b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"url": "https://github.com/davidjcralph/hastebin-bot"
},
"dependencies": {
"discord.js": "12.5.1"
"discord.js": "12.5.1",
"fs": "0.0.1-security"
}
}
10 changes: 4 additions & 6 deletions src/commands/haste.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
const fetch = require('node-fetch');
const fs = require('fs');

exports.run = async (client, msg, args) => {
if (!args[0] && msg.attachments.size < 0) {
if (!args[0] || msg.attachments.size < 0) {
return msg.channel.send(':x: | I can\'t post nothing to Hastebin!');
}

let body = args.slice(0).join(' ');

if (msg.attachments.size > 0) {
body = await (await fetch(msg.attachments.first().url)).text();
}
let body = []; //Define body
client.config.dir_uploader ? body = fs.readFileSync(args[0], 'utf8') : body = args.slice(0).join(' '); //using ternary operator to check if dir_uploader is true or false.

const options = {
method: 'POST',
Expand Down
3 changes: 2 additions & 1 deletion src/config.example.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"token": "Discord Bot Token",
"prefix": "hb!",
"hasteurl": "https://hastebin.com"
"hasteurl": "https://hastebin.com",
"dir_uploader": true
}

0 comments on commit ff1133b

Please sign in to comment.