Skip to content

Commit

Permalink
Merge pull request #75 from BluLightShow/develop
Browse files Browse the repository at this point in the history
Merge v0.1.3
  • Loading branch information
max-bromberg authored Apr 20, 2021
2 parents a29827a + c888c1f commit 4af32cf
Show file tree
Hide file tree
Showing 15 changed files with 181 additions and 42 deletions.
35 changes: 30 additions & 5 deletions bot.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
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: ['200616508328509442', '223217915673968641']
ownerID: config.owners
}, {
fetchAllMembers: true,
presence: {
Expand All @@ -30,13 +31,37 @@ 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()
client.login(process.env.BOT_TOKEN)

if (config.token) {
console.log("Logging in via config token...")
client.login(config.token)
} else {
console.log("Logging in via environment token...")
client.login(process.env.BOT_TOKEN)
}
4 changes: 2 additions & 2 deletions commands/codeblock.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 arduino. The backtick key is typically found to the left of the 1 key.')
)
}
}
Expand Down
29 changes: 0 additions & 29 deletions commands/setavatar.js

This file was deleted.

42 changes: 42 additions & 0 deletions commands/tag.js
Original file line number Diff line number Diff line change
@@ -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
9 changes: 8 additions & 1 deletion config.json
Original file line number Diff line number Diff line change
@@ -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"]
}
2 changes: 1 addition & 1 deletion listeners/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion listeners/messageReactionAdd.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions listeners/ready.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 6 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"name": "arduino-bot",
"version": "v0.1.2",
"version": "v0.1.3",
"description": "A bot to help the arduino community!",
"main": "bot.js",
"dependencies": {
"discord-akairo": "^8.1.0",
"discord.js": "^12.5.1",
"dotenv": "^8.2.0",
"gists": "^2.0.0"
},
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion commands/gist.js → staff_commands/gist.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()}`,
Expand Down
File renamed without changes.
29 changes: 29 additions & 0 deletions staff_inhibitors/staffRequired.js
Original file line number Diff line number Diff line change
@@ -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
47 changes: 47 additions & 0 deletions tags/avrdude.json
Original file line number Diff line number Diff line change
@@ -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": ""
}
11 changes: 11 additions & 0 deletions tags/template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"title": "",
"aliases": [],
"fields": [
{
"name": "",
"value": ""
}
],
"image": ""
}

0 comments on commit 4af32cf

Please sign in to comment.