├── .gitignore ├── LICENSE ├── README.md ├── package.json └── src ├── commands ├── haste.js ├── help.js ├── ping.js └── stats.js ├── config.example.json ├── events ├── messageCreate.js └── ready.js └── index.js /.gitignore: -------------------------------------------------------------------------------- 1 | # Directories 2 | .vscode/ 3 | node_modules/ 4 | 5 | # Files 6 | yarn.lock 7 | config.json 8 | package-lock.json 9 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017-2022 David Ralph 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # hastebin-bot 2 | An opensource Discord bot that posts data to Hastebin. 3 | 4 | ## Installation 5 | ### Requirements 6 | * [Node.js](https://nodejs.org) 7 | * [Git](https://git-scm.com) (Optional) 8 | ### Setup 9 | 1. ``git clone https://github.com/davidcralph/hastebin-bot`` (If you don't have Git just go to **Clone or download** and click **Download ZIP**) 10 | 2. ``npm i`` (in the bot ``src`` directory) 11 | 3. Rename ``config.example.json`` to ``config.json`` and fill in the config file with your Discord bot token (optionally with a different prefix and Hastebin instance) 12 | 4. ``node index.js`` (or simply ``npm start``) 13 | 5. Have fun! 14 | 15 | ## Support 16 | Please open an issue or ask in my [Discord Server](https://discord.gg/HJmmmTB) 17 | 18 | ## License 19 | [MIT](LICENSE) 20 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "private": true, 3 | "name": "hastebin-bot", 4 | "version": "0.4.0", 5 | "author": "David Ralph", 6 | "license": "MIT", 7 | "description": "An opensource Discord bot that posts data to Hastebin", 8 | "main": "index.js", 9 | "scripts": { 10 | "start": "cd src && node index.js" 11 | }, 12 | "bugs": { 13 | "url": "https://github.com/davidcralph/hastebin-bot/issues" 14 | }, 15 | "homepage": "https://github.com/davidcralph/hastebin-bot", 16 | "repository": { 17 | "type": "git", 18 | "url": "https://github.com/davidcralph/hastebin-bot" 19 | }, 20 | "dependencies": { 21 | "discord.js": "13.6.0" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/commands/haste.js: -------------------------------------------------------------------------------- 1 | const fetch = require('node-fetch'); 2 | const fs = require('fs'); 3 | 4 | exports.run = async (client, msg, args) => { 5 | if (!args[0] && !msg.attachments.first().url) { 6 | return msg.channel.send(':x: | I can\'t post nothing to Hastebin!'); 7 | } 8 | 9 | // Define body 10 | let body = []; 11 | // using ternary operator to check if dir_uploader is true or false. 12 | client.config.dir_uploader ? body = (fs.existsSync(args[0]) ? fs.readFileSync(args[0], 'utf8') : null) : body = (args.slice(0).join(' ') || await (await fetch(msg.attachments.first().url)).text()); 13 | if (body === null) { 14 | return msg.channel.send(':x: | File doesn\'t exist!'); 15 | } 16 | 17 | const options = { 18 | method: 'POST', 19 | body: body, 20 | headers: { 21 | 'Content-Type': 'application/json' 22 | } 23 | } 24 | 25 | const res = await (await fetch(`${client.config.hasteurl}/documents`, options)).json(); 26 | 27 | msg.channel.send(`:white_check_mark: | Posted ${args[0] ? 'text' : 'file'} to Hastebin at this URL: ${client.config.hasteurl}/${res.key}`); 28 | }; 29 | -------------------------------------------------------------------------------- /src/commands/help.js: -------------------------------------------------------------------------------- 1 | const { MessageEmbed } = require('discord.js'); 2 | 3 | exports.run = (_client, msg) => { 4 | const embed = new MessageEmbed() 5 | .setTitle('Commands:') 6 | .addField('help', 'Returns this message.') 7 | .addField('ping', 'Pong! Returns the bot\'s ping.') 8 | .addField('stats', 'Get the bot stats.') 9 | .addField('haste ', 'Upload text to Hastebin.') 10 | .setFooter({ text: 'Made by davidcralph | https://github.com/davidcralph/hastebin-bot' }); 11 | 12 | msg.channel.send({ embeds: [embed] }); 13 | }; 14 | -------------------------------------------------------------------------------- /src/commands/ping.js: -------------------------------------------------------------------------------- 1 | exports.run = (client, msg) => { 2 | msg.channel.send(`:ping_pong: | Pong! The ping is **${(client.ws.ping)}**ms.`); 3 | }; 4 | -------------------------------------------------------------------------------- /src/commands/stats.js: -------------------------------------------------------------------------------- 1 | exports.run = (client, msg) => { 2 | msg.channel.send(`:robot: | I am on **${client.guilds.cache.size}** guilds with **${client.users.cache.size}** users!`); 3 | }; 4 | -------------------------------------------------------------------------------- /src/config.example.json: -------------------------------------------------------------------------------- 1 | { 2 | "token": "Discord Bot Token", 3 | "prefix": "hb!", 4 | "hasteurl": "https://hastebin.com", 5 | "dir_uploader": true 6 | } 7 | -------------------------------------------------------------------------------- /src/events/messageCreate.js: -------------------------------------------------------------------------------- 1 | module.exports = (client, msg) => { 2 | if (msg.author.bot || msg.content.indexOf(client.config.prefix) !== 0) { 3 | return; 4 | } 5 | 6 | const args = msg.content.slice(client.config.prefix.length).trim().split(/ +/g); 7 | const cmd = client.commands.get(args.shift().toLowerCase()); 8 | 9 | if (!cmd) { 10 | return; 11 | } 12 | 13 | try { 14 | cmd.run(client, msg, args); 15 | } catch (e) { 16 | console.log(e); 17 | msg.channel.send(':x: | Something went wrong ```' + e + '```'); 18 | } 19 | }; 20 | -------------------------------------------------------------------------------- /src/events/ready.js: -------------------------------------------------------------------------------- 1 | module.exports = () => { 2 | console.log('Connected to Discord!'); 3 | }; 4 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | const { readdir } = require('fs'); 2 | const { Client, Collection } = require('discord.js'); 3 | 4 | const client = new Client({ 5 | intents: [ 6 | 'GUILDS', 7 | 'GUILD_INTEGRATIONS', 8 | 'GUILD_MESSAGES', 9 | 'GUILD_MESSAGE_TYPING', 10 | 'DIRECT_MESSAGES', 11 | 'DIRECT_MESSAGE_TYPING' 12 | ], 13 | disableEveryone: true, 14 | autoReconnect: true 15 | }); 16 | 17 | readdir('./events/', (err, files) => { 18 | if (err) { 19 | return console.log(err); 20 | } 21 | 22 | files.forEach(file => { 23 | let eventName = file.split('.')[0]; 24 | const event = require(`./events/${file}`); 25 | console.log(`Loading ${eventName}.js!`); 26 | client.on(eventName, event.bind(null, client)); 27 | }); 28 | }); 29 | 30 | client.config = require('./config.json'); 31 | client.commands = new Collection(); 32 | 33 | readdir('./commands/', (err, files) => { 34 | if (err) { 35 | return console.log(err); 36 | } 37 | 38 | files.forEach(file => { 39 | let commandName = file.split('.')[0]; 40 | console.log(`Loading ${commandName}.js!`); 41 | client.commands.set(commandName, require(`./commands/${file}`)); 42 | }); 43 | }); 44 | 45 | client.login(client.config.token); 46 | --------------------------------------------------------------------------------