Skip to content
This repository has been archived by the owner on Oct 4, 2019. It is now read-only.

Commit

Permalink
Merge pull request #2 from TobiasFeld22/Tobias-updates
Browse files Browse the repository at this point in the history
Update check
  • Loading branch information
TobiasFeld22 authored Aug 31, 2017
2 parents 86dc6d2 + c3a46cd commit 6c6e951
Show file tree
Hide file tree
Showing 11 changed files with 381 additions and 175 deletions.
88 changes: 88 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# Logs
logs
*.log
npm-debug.log*

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules
jspm_packages

# Optional npm cache directory
.npm

# Optional REPL history
.node_repl_history

# =========================
# Operating System Files
# =========================

# OSX
# =========================

.DS_Store
.AppleDouble
.LSOverride

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

# Windows
# =========================

# Windows image file caches
Thumbs.db
ehthumbs.db

# Folder config file
Desktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msm
*.msp

# Windows shortcuts
*.lnk

# custom.
config.json
18 changes: 18 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
## Contributing to EDB

We want to make it easy for you to help with developing, we just want to make sure of a few things.

1. All code is examined using eslint (npm install eslint && eslint .), using our configuration file included inside of the repository.
2. Malicious code is not allowed, deliberately adding bugs or causing (parts of) the framework to chrash.
3. All code submitted must be "beautified" before posting, if you want to keep it simple, just use [this one](https://jsbeautifier.org)

## Submitting a new issue

Before submitting a new issue:

- Search the issues to see if your issue hasn't been added before, (and if it has a fix already.)
- No issues about external modules used for commands etc. we will only look at the issue if the cause of the issue lies within the frameworks code
Contact the developer that made the module for more information.
- No issues asking us for help on how to set up a bot, You can find info about how to set a bot up on our website. If the website is not clear enough,
create an issue and tell us what should be made easier to understand for other users.
- Don't add "me 2" or something like that in the commands. You can react with :thumbsup: on the initial issue to show us.
50 changes: 38 additions & 12 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
/* eslint no-console: 0 */
const Discord = require("discord.js");

const client = new Discord.Client();
const setup = require("./setup.js");
const fs = require("fs")
var util = require("./src/util.js")
var developer = false;
module.exports = {};
module.exports.version = require("./package.json").version;
module.exports.start = function(config) {
console.log("Loading commands")
setup(fs, config, require("path").dirname(require.main.filename)).then((commands) => {
Expand Down Expand Up @@ -38,24 +41,45 @@ function start(client, config, commanddata) {
}
})
client.on("ready", () => {
if (client.user.bot == false) {
return console.warn("This wrapper doesn't support selfbots.")
}
client.fetchApplication().then((application) => {
if (application.owner === null) {
return console.error("Owner check failed, please invite your bot to your server using this url\n https://discordapp.com/oauth2/authorize?client_id=" + client.user.id + "&scope=bot, then try to start the bot again.")
if (application.owner == null){
if (client.config.owner_id == null) {
return console.error("Can't fetch the owner's id, please follow instructions here <page_link>.")
} else if (client.users.get(client.config.owner_id) == undefined) {
return console.error("The bot can't find the owner_id set up inside your file, \nThis could be because it's not valid, or because you are not in a server with it, please invite it to a server where you are on.")
}
config.owner_id = application.owner.id
}else{
client.config.owner_id = application.owner.id
}

}).catch((err) => {
if (developer) {
console.warn("Can't fetch application, error: \n", err)
} else if (client.config.owner_id == null) {
return console.error("Can't fetch the owner's id, please follow instructions here <page_link>.")
} else if (client.users.get(client.config.owner_id) == undefined) {
return console.error("The bot can't find the owner_id set up inside your file, \nThis could be because it's not valid, or because you are not in a server with it, please invite it to a server where you are on.")
}
})

console.log(commanddata.commands.size + " commands | " + commanddata.aliases.size + " aliases, bot online")
console.log("To add new commands, type \"" + config.prefix + "createcommand <name> <alias1> <alias2> <alias3>\" to generate a new template!")
util.checkUpdate(module.exports).then(update => {
console.log(update)
}).catch(err => {
console.warn(err)
})



next()
})
.catch(() => {
return console.error("Bot check failed, This wrapper doesn't support selfbots.")
})

function next() {
console.log(commanddata.commands.size + " commands | " + commanddata.aliases.size + " aliases, bot online")
console.log("To add new commands, type \"" + config.prefix + "easybot <name>\" to generate a new template!")
}
})



client.on("message", (message) => {


Expand Down Expand Up @@ -92,6 +116,8 @@ function doCommand(command, client, message) {
message.channel.send("[EDB] Command: **" + command.name + "** | Requires the " + mod + " package to be installed.\nTo install this package, close the script and type: `npm install " + mod.slice(1, -1) + "`")
}

} else {
console.warn("Command: " + command.name + " | had an error. Show the developer of the command module that you are getting this error code: \n" + err)
}
}

Expand Down
47 changes: 47 additions & 0 deletions commands/createcommand.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
var command = module.exports = {}
var path = require("path")
var fs = require("fs")
command.name = "createcommand"

command.command = function(client, message) {
var args = message.content.split(" ");
if (!message.author.id == client.config.owner_id) {
return
}
if (args[1] == null) {
return message.channel.send("[EDB] Please specify the name for the command. If you want to use aliases, type them space-seperated behind the name.");

}

var data = {
aliases: [],
name: args[1]
}
if (args[1].match(/[/\\<>:*|]/g)){
return message.channel.send("[EDB] Filenames can't include one of these characters: ` / \\ < > : * | `, please try a different filename.")
}
if (args[2] != null) {
args.forEach((i, index) => {
if (index > 1) {
data.aliases.push(i)
}
})
}
fs.access(path.resolve(path.dirname(require.main.filename), "commands/" + data.name + ".js"), fs.constants.R_OK, (err) => {
if (!err) {
return message.channel.send("[EDB] This file does already exist. Please try a different name. ")
}

fs.writeFile(path.resolve(path.dirname(require.main.filename), "commands/" + data.name + ".js"), "exports.name = \"" + data.name + "\" \nexports.aliases = " + JSON.stringify(data.aliases) + "\nexports.command = function(client, message){\n\n//Write your command functions here.\n\n} ", {options: "utf8"}, (err) => {
if (err) {
return message.channel.send("[EDB] Failed to create this file, try to create it manually using this template: ```javascript\nexports.name = \"" + data.name + "\" \nexports.aliases = \"" + JSON.stringify(data.aliases) + "\"\nexports.command = function(client, message){\n\n//Write your command functions here.\n\n} \n```")
}
return message.channel.send("[EDB] Created `commands/" + data.name + ".js`, with **" + data.aliases.length + "** aliases. \nPut some code into this file to make it do something.")

})




})
}
2 changes: 1 addition & 1 deletion commands/reload.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ command.command = function(client, message) {
if (client.config.owner_id !== message.author.id) {
return
}
client.commanddata = null;
var args = message.content.split(" ")
if (args[1] == null) {
args[1] = ""
Expand All @@ -37,6 +36,7 @@ function reloadcommands(client, config, message) {
return m.edit("[EDB] Reloaded **" + client.commanddata.commands.size + "** commands succesfully.\n**" + commands.issues + "** command failed to load. See the console for more info.")
}
m.edit("[EDB] Reloaded **" + client.commanddata.commands.size + "** commands succesfully.")

}).catch((err) => {
err.stack.toLowerCase()
})
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

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

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"name": "easy-discord-bot",
"version": "0.0.1",
"version": "0.0.2-beta.0",
"description": "An easy to use discord bot, which uses small modules for getting commands and messages. ",
"main": "app.js",
"dependencies": {
"discord.js": "^11.1.0",
"fs": "latest"
"fs": "latest",
"request": "latest"
},
"devDependencies": {},
"scripts": {
Expand Down
25 changes: 25 additions & 0 deletions src/checkUpdate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const request = require("request");
module.exports = function(edb) {
return new Promise(function(resolve, reject) {
request("https://easy-discord-bot.tk/update?currentversion=" + edb.version,
function(error, response, body) {
if (error) {
return reject("Sorry, There was a issue whilst checking for a update, try again later.")
} else if (response.statusCode == 200) {
var data = JSON.parse(body)
if (data.update_required) {
var version = null;
if (edb.version.includes("beta")) {
version = data.latest_beta
} else {
version = data.latest
}

return resolve("\nAn update is required, please type npm install easy-discord-bot \nto install the latest version ( v" + edb.version + " --> v" + version + ")")
}
}


})
});
}
Loading

0 comments on commit 6c6e951

Please sign in to comment.