From 30524dd01be823575e81be6490f2f5faf20fcbe7 Mon Sep 17 00:00:00 2001 From: BluLightShow <20815595+BluLightShow@users.noreply.github.com> Date: Fri, 29 Jan 2021 19:56:53 -0600 Subject: [PATCH 1/5] refactor(staff cmds): move to new handlers Signed-off-by: BluLightShow <20815595+BluLightShow@users.noreply.github.com> --- bot.js | 24 ++++++++++++++++++- config.json | 9 ++++++- listeners/messageReactionAdd.js | 2 +- {commands => staff_commands}/gist.js | 2 +- {commands => staff_commands}/say.js | 0 {commands => staff_commands}/setavatar.js | 0 staff_inhibitors/staffRequired.js | 29 +++++++++++++++++++++++ 7 files changed, 62 insertions(+), 4 deletions(-) rename {commands => staff_commands}/gist.js (96%) rename {commands => staff_commands}/say.js (100%) rename {commands => staff_commands}/setavatar.js (100%) create mode 100644 staff_inhibitors/staffRequired.js diff --git a/bot.js b/bot.js index 7eb6ae9..504b1b3 100644 --- a/bot.js +++ b/bot.js @@ -14,7 +14,7 @@ module.exports = { class MainClient extends AkairoClient { constructor () { super({ - ownerID: ['200616508328509442', '223217915673968641'] + ownerID: config.owners }, { fetchAllMembers: true, presence: { @@ -30,13 +30,35 @@ class MainClient extends AkairoClient { prefix: config.prefix, defaultCooldown: 5000 }) + this.staffComandHandler = new CommandHandler(this, { + directory: './staff_commands/', + prefix: config.staffPrefix, + defaultCooldown: 1000 + }) + + this.staffInhibitorHandler = new InhibitorHandler(this, { + directory: './staff_inhibitors/' + }) + this.listenerHandler = new ListenerHandler(this, { directory: './listeners/' }) + + // Main Handlers this.commandHandler.useListenerHandler(this.listenerHandler) this.listenerHandler.loadAll() this.commandHandler.loadAll() + + // Staff Handlers + this.staffComandHandler.useInhibitorHandler(this.staffInhibitorHandler) + this.staffComandHandler.loadAll() + this.staffInhibitorHandler.loadAll() } } const client = new MainClient() + +if (config.token) { + client.login(config.token) +} else { client.login(process.env.BOT_TOKEN) +} diff --git a/config.json b/config.json index 3b07f18..2b5a0da 100644 --- a/config.json +++ b/config.json @@ -1,9 +1,16 @@ { + "token": "", + "debug": false, "prefix": "!", + "staffPrefix": "=", "embeds": { "footer":"Arduino Bot • Submit bugs on GitHub!", "color": "17989e" }, "pasteEmoji": "752975737400721549", - "helperRoleID": "452631962373455893" + "roles": { + "helper": "452631962373455893", + "staff": "451380797782360069" + }, + "owners": ["200616508328509442", "223217915673968641"] } \ No newline at end of file diff --git a/listeners/messageReactionAdd.js b/listeners/messageReactionAdd.js index e830001..d84d008 100644 --- a/listeners/messageReactionAdd.js +++ b/listeners/messageReactionAdd.js @@ -21,7 +21,7 @@ class MessageReactionAddListener extends Listener { if (reaction.emoji.id === config.pasteEmoji && reaction.me) { - if (user.id === reaction.message.author.id || reaction.message.guild.members.resolve(user.id).roles.cache.find(role => role.id === config.helperRoleID)) { + if (user.id === reaction.message.author.id || reaction.message.guild.members.resolve(user.id).roles.cache.find(role => role.id === config.roles.helper)) { let message = reaction.message let content = message.content diff --git a/commands/gist.js b/staff_commands/gist.js similarity index 96% rename from commands/gist.js rename to staff_commands/gist.js index ddad9ed..d482c2a 100644 --- a/commands/gist.js +++ b/staff_commands/gist.js @@ -24,7 +24,7 @@ class GistCommand extends Command { } exec(message, args) { - if (args.message && message.member.roles.cache.find(role => role.id === config.helperRoleID)) { + if (args.message) { var code = args.message gists.create({ "description": `Code by ${code.author.tag} - ${new Date()}`, diff --git a/commands/say.js b/staff_commands/say.js similarity index 100% rename from commands/say.js rename to staff_commands/say.js diff --git a/commands/setavatar.js b/staff_commands/setavatar.js similarity index 100% rename from commands/setavatar.js rename to staff_commands/setavatar.js diff --git a/staff_inhibitors/staffRequired.js b/staff_inhibitors/staffRequired.js new file mode 100644 index 0000000..ddc6e9d --- /dev/null +++ b/staff_inhibitors/staffRequired.js @@ -0,0 +1,29 @@ +const { Inhibitor } = require('discord-akairo') +const config = require('../config.json') + +class StaffRequiredInhibitor extends Inhibitor { + constructor() { + super('staffRequired', { + reason: 'staffRoleRequired', + type: 'post' + }) + } + + exec(message, command) { + let member = message.guild.members.cache.find(member => member.id === message.author.id) + + var roleAbsent = roleId => { + if (member.roles.cache.find(role => role.id === roleId)) { + return false + } else { + return true + } + } + if (command.id === "gist") { + return roleAbsent(config.roles.helper) + } else { + return roleAbsent(config.roles.staff) + } + } +} +module.exports = StaffRequiredInhibitor \ No newline at end of file From 66c48af8fec28a60ab574e96e7cbbe24209f1ebf Mon Sep 17 00:00:00 2001 From: BluLightShow <20815595+BluLightShow@users.noreply.github.com> Date: Tue, 23 Feb 2021 07:45:33 -0600 Subject: [PATCH 2/5] chore: update codeblock screenshot and tweak text Signed-off-by: BluLightShow <20815595+BluLightShow@users.noreply.github.com> --- commands/codeblock.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/commands/codeblock.js b/commands/codeblock.js index b4804ce..03b7fb1 100644 --- a/commands/codeblock.js +++ b/commands/codeblock.js @@ -16,8 +16,8 @@ class CodeBlockCommand extends Command { new MessageEmbed(embed) .setTimestamp(new Date()) .setTitle('How to Send Code Blocks') - .setImage('https://cdn.discordapp.com/attachments/747642578668748800/754151197425795202/unknown.png') - .setDescription('Surround the code in three backticks. If using new lines, a file extension can be placed directly after the first 3 backticks to highlight in that language. An example is shown below, highlighting code in C++.') + .setImage('https://cdn.discordapp.com/attachments/758046379133239407/813767505000398929/rllpwo.png') + .setDescription('Surround the code in three backticks. If using new lines, a file extension can be placed directly after the first 3 backticks to highlight in that language. An example is shown below, highlighting code in C++. The backtick key is typically found to the left of the 1 key.') ) } } From 1793dd373bb732a246a049c917a0dce7afa5c07d Mon Sep 17 00:00:00 2001 From: BluLightShow <20815595+BluLightShow@users.noreply.github.com> Date: Fri, 9 Apr 2021 07:27:10 -0500 Subject: [PATCH 3/5] fix: catch msg react failures Signed-off-by: BluLightShow <20815595+BluLightShow@users.noreply.github.com> --- listeners/message.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/listeners/message.js b/listeners/message.js index dd75b9b..e25e0ad 100644 --- a/listeners/message.js +++ b/listeners/message.js @@ -31,7 +31,7 @@ class MessageListener extends Listener { // Initial reaction for code block pastes if (message.content.includes('```') && message.content.match(/```/g).length >= 2) { - message.react(config.pasteEmoji) + message.react(config.pasteEmoji).catch(err => console.error(err)) } // Message link flattening From 44efccf4f328db6039bab787073a35c4e9e5d2aa Mon Sep 17 00:00:00 2001 From: BluLightShow <20815595+BluLightShow@users.noreply.github.com> Date: Tue, 20 Apr 2021 09:30:43 -0500 Subject: [PATCH 4/5] feat: canned responses, environment file Signed-off-by: BluLightShow <20815595+BluLightShow@users.noreply.github.com> --- bot.js | 11 +++++---- commands/codeblock.js | 2 +- commands/tag.js | 42 +++++++++++++++++++++++++++++++++ listeners/ready.js | 1 + package-lock.json | 7 +++++- package.json | 1 + staff_commands/setavatar.js | 29 ----------------------- tags/avrdude.json | 47 +++++++++++++++++++++++++++++++++++++ tags/template.json | 11 +++++++++ 9 files changed, 116 insertions(+), 35 deletions(-) create mode 100644 commands/tag.js delete mode 100644 staff_commands/setavatar.js create mode 100644 tags/avrdude.json create mode 100644 tags/template.json diff --git a/bot.js b/bot.js index 504b1b3..b15055a 100644 --- a/bot.js +++ b/bot.js @@ -1,18 +1,19 @@ +require('dotenv').config() const { AkairoClient, CommandHandler, InhibitorHandler, ListenerHandler } = require('discord-akairo') const Discord = require('discord.js') const version = require('./package.json').version const config = require('./config.json') const embed = new Discord.MessageEmbed() -.setFooter(config.embeds.footer) -.setColor(config.embeds.color) + .setFooter(config.embeds.footer) + .setColor(config.embeds.color) module.exports = { embed } class MainClient extends AkairoClient { - constructor () { + constructor() { super({ ownerID: config.owners }, { @@ -58,7 +59,9 @@ class MainClient extends AkairoClient { const client = new MainClient() if (config.token) { + console.log("Logging in via config token...") client.login(config.token) } else { -client.login(process.env.BOT_TOKEN) + console.log("Logging in via environment token...") + client.login(process.env.BOT_TOKEN) } diff --git a/commands/codeblock.js b/commands/codeblock.js index 03b7fb1..8afbd6e 100644 --- a/commands/codeblock.js +++ b/commands/codeblock.js @@ -17,7 +17,7 @@ class CodeBlockCommand extends Command { .setTimestamp(new Date()) .setTitle('How to Send Code Blocks') .setImage('https://cdn.discordapp.com/attachments/758046379133239407/813767505000398929/rllpwo.png') - .setDescription('Surround the code in three backticks. If using new lines, a file extension can be placed directly after the first 3 backticks to highlight in that language. An example is shown below, highlighting code in C++. The backtick key is typically found to the left of the 1 key.') + .setDescription('Surround the code in three backticks. If using new lines, a file extension can be placed directly after the first 3 backticks to highlight in that language. An example is shown below, highlighting code in arduino. The backtick key is typically found to the left of the 1 key.') ) } } diff --git a/commands/tag.js b/commands/tag.js new file mode 100644 index 0000000..11cc5df --- /dev/null +++ b/commands/tag.js @@ -0,0 +1,42 @@ +const { Command } = require('discord-akairo') +const config = require('../config.json') +const fs = require('fs') +const { MessageEmbed } = require('discord.js') +const { embed } = require('../bot') + +class TagCommand extends Command { + constructor() { + super('tag', { + aliases: ['tag', 'qr', 'res'], + channel: 'guild', + description: 'Send a canned response in the channel.', + args: [ + { + id: 'tagAlias', + type: 'string' + } + ] + }) + } + + exec(message, args) { + var files = fs.readdirSync('./tags') + files.forEach(file => { + if (file.endsWith('.json') && (file !== 'template.json')) { + var tagFile = JSON.parse(fs.readFileSync(`./tags/${file}`)) + if (tagFile.aliases.includes(args.tagAlias)) { + var tagEmbed = new MessageEmbed(embed) + .setTitle(tagFile.title) + + if (tagFile.image) tagEmbed.setImage(tagFile.image) + tagFile.fields.forEach(field => { + tagEmbed.addField(field.name, field.value, false) + }) + + message.channel.send(tagEmbed) + } + } + }) + } +} +module.exports = TagCommand diff --git a/listeners/ready.js b/listeners/ready.js index 790a8dc..4ae3dde 100644 --- a/listeners/ready.js +++ b/listeners/ready.js @@ -11,6 +11,7 @@ class ReadyListener extends Listener { exec() { console.log(`Arduino Bot ${version} ready for battle!`) + console.log(`Logged into account: ${this.client.user.tag}`) } } module.exports = ReadyListener \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 9c270d0..854887b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "arduino-bot", - "version": "v0.1.1", + "version": "v0.1.2", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -535,6 +535,11 @@ "esutils": "^2.0.2" } }, + "dotenv": { + "version": "8.2.0", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-8.2.0.tgz", + "integrity": "sha512-8sJ78ElpbDJBHNeBzUbUVLsqKdccaa/BXF1uPTw3GrvQTBgrQrtObr2mUrE38vzYd8cEv+m/JBfDLioYcfXoaw==" + }, "emoji-regex": { "version": "8.0.0", "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", diff --git a/package.json b/package.json index 79e7b15..0b91113 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "dependencies": { "discord-akairo": "^8.1.0", "discord.js": "^12.5.1", + "dotenv": "^8.2.0", "gists": "^2.0.0" }, "scripts": { diff --git a/staff_commands/setavatar.js b/staff_commands/setavatar.js deleted file mode 100644 index cbe853d..0000000 --- a/staff_commands/setavatar.js +++ /dev/null @@ -1,29 +0,0 @@ -const { Command } = require('discord-akairo') -const { MessageEmbed } = require('discord.js') -const { embed } = require('../bot') - -class SetAvatarCommand extends Command { - constructor() { - super('setavatar', { - aliases: ['setavatar', 'setpicture'], - description: "(For admins) Sets the bot's profile picture.", - userPermissions: 'ADMINISTRATOR', - args: [ - { - id: 'url', - type: 'url' - } - ] - }) - } - - exec(message, args) { - this.client.user.setAvatar(args.url).then(() => { - message.channel.send(new MessageEmbed(embed) - .setTitle('Success') - .setTimestamp(new Date()) - ) - }) - } -} -module.exports = SetAvatarCommand \ No newline at end of file diff --git a/tags/avrdude.json b/tags/avrdude.json new file mode 100644 index 0000000..8f8323e --- /dev/null +++ b/tags/avrdude.json @@ -0,0 +1,47 @@ +{ + "title": "Solving Avrdude Communication Error (try in order)", + "aliases": ["avrdude"], + "fields": [ + { + "name": "1.", + "value": "If serial monitor is open, close it." + }, + { + "name": "2.", + "value": "Try changing the port you are connecting and selecting it from software, you can find it in tools -> port." + }, + { + "name": "3.", + "value": "Check if the power led on your board lights up. If it's on unplug and re-plug your board. Now check for blinking leds. If only power or no led lights up ask for further assistance. (not for all boards)" + }, + { + "name": "4.", + "value": "Try using the old bootloader. Go to tools -> processor and select 328p(old bootloader). If you are not on Nano, you can skip this step and try it after doing option 5. In that case select your board as nano before you try(make sure you have a 328p chip board like uno)." + }, + { + "name": "5.", + "value": "Try pressing reset button on arduino, if when you reset the onboard led doesn't blink, you probably have a broken bootloader, you can check [this tutorial](https://www.arduino.cc/en/Hacking/Bootloader?from=Tutorial.Bootloader) for how to burn bootloader." + }, + { + "name": "6.", + "value": "If there's anything connected to Tx and Rx pins, try removing everything attached to them them." + }, + { + "name": "7.", + "value": "This might just be a communication problem or your computer getting confused so try restarting your computer." + }, + { + "name": "8.", + "value": "Check your drivers, sometimes just reinstalling them works. If you are using a clone board you might have CH340 communication chip, which isn't supported for Uno. You can check that by looking at your board and checking a chip's name (not the big one). [Click here](https://learn.sparkfun.com/tutorials/how-to-install-ch340-drivers/all) for installing CH340 chip. If you don't have CH340 chip you can try installing drivers from Windows device manager." + }, + { + "name": "9.", + "value": "You can try checking [this website](https://learn.sparkfun.com/tutorials/how-to-install-ftdi-drivers/windows---in-depth) for your drivers." + }, + { + "name": "10.", + "value": "Last thing might be Arduino IDE's problem. If you think that's the case try reinstalling Arduino IDE." + } + ], + "image": "" +} \ No newline at end of file diff --git a/tags/template.json b/tags/template.json new file mode 100644 index 0000000..92a6b44 --- /dev/null +++ b/tags/template.json @@ -0,0 +1,11 @@ +{ + "title": "", + "aliases": [], + "fields": [ + { + "name": "", + "value": "" + } + ], + "image": "" +} \ No newline at end of file From c888c1f19a92d0562d1ba4b74a8963d2278e397d Mon Sep 17 00:00:00 2001 From: BluLightShow <20815595+BluLightShow@users.noreply.github.com> Date: Tue, 20 Apr 2021 09:34:01 -0500 Subject: [PATCH 5/5] chore: bump version Signed-off-by: BluLightShow <20815595+BluLightShow@users.noreply.github.com> --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0b91113..4ffd3dd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "arduino-bot", - "version": "v0.1.2", + "version": "v0.1.3", "description": "A bot to help the arduino community!", "main": "bot.js", "dependencies": {