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 #60 from Sparkbots/Development
Browse files Browse the repository at this point in the history
Release 0.1.0
  • Loading branch information
TobiasFeld22 authored Jul 1, 2018
2 parents d481407 + 6cf22f5 commit 04b2b8b
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 39 deletions.
34 changes: 32 additions & 2 deletions functions/engines/checkUpdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ Engine.code = async (client) => {
version = versions.beta
command = "npm install sparkbots@beta"
}
var data = {
version,
command
}
if (version.version !== Spark.version) {
if (client.config.ignoreUpdate) {
if (client.config.ignoreUpdate instanceof Array && client.config.ignoreUpdate.includes(version.version) == true) {
Expand All @@ -30,13 +34,14 @@ Engine.code = async (client) => {
return
}
}
checkOwner(client, data)

if (discordStatus) {
console.log(`${chalk.yellow("Spark")} update ${chalk.yellow(version.version)} has been released!\n\nTo update, type the following command: ${chalk.blue(command)}\nIn your bot's directory.\n\nTo read about what has been changed go to https://discordspark.com/releases \n\nWant to ignore this message?\nAdd ${chalk.red(`ignoreUpdate: ["${version.version}"]`)} to your start file.`)
var owner = await client.fetchUser(client.config.ownerID);
owner.send(`Spark update **${version.version}** has been released!\n\nTo update, type the following command: **${command}**\nIn your bot's directory.\n\nTo read about what has been changed go to https://discordspark.com/releases \n\nWant to ignore this message?\nAdd this to your start file: \`\`\`json\nignoreUpdate: ["${version.version}"]\n\`\`\``)
checkOwner(client, data)
} else {
console.log("You're running this bot on an unreleased version. (" + chalk.red(Spark.version) + ") compatibility and support may not be up to date with what you expect.\nIf you don't know what this means please stop the bot, and type: " + chalk.blue("npm install sparkbots") + " To get back to a stable release.")

}
}
} catch (e) {
Expand All @@ -47,4 +52,29 @@ Engine.code = async (client) => {
}
}
}

async function checkOwner(client, data) {
if ((new Date(data.version.release_date).getTime() + 999943200000) > new Date().getTime()) {
client.config.updateErrors = true
try {
var owner = await client.fetchUser(client.config.ownerID);
var channel = await owner.createDM()
var messages = await channel.fetchMessages({limit: 10})
messages = messages.filter(i => {
return i.content.includes(`["${data.version.version}"]`)
})
if (messages.size == 0) {
owner.send(`Spark update **${data.version.version}** has been released!\n\nTo update, type the following command: **${data.command}**\nIn your bot's directory.\n\nTo read about what has been changed go to https://discordspark.com/releases \n\nWant to ignore this message?\nAdd this to your start file: \`\`\`json\nignoreUpdate: ["${data.version.version}"]\n\`\`\``)
} else if (client.config.updateErrors) {
console.warn("No update dm sent, as there was (1+) sent in the channel (last 10)")
}

} catch (e) {
if (client.config.updateErrors) {
console.error("Error while dming owner for update:")
console.error(e)
}
}
}
}
Engine.export(module)
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sparkbots",
"version": "0.1.0-beta.2",
"version": "0.1.0",
"description": "Spark is a powerful modular framework that makes creating Discord bots easy.",
"main": "app.js",
"dependencies": {
Expand Down
8 changes: 6 additions & 2 deletions src/module_classes/Observer.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ module.exports = function(client) {
if (!options) {
options = {}
}
this.type = options.type
if (options.type) {
this.type = options.type
}
this.disabled = options.disabled
if (this.disabled) {
this.client.config.disabled.add("observers", this.name)
Expand All @@ -17,6 +19,7 @@ module.exports = function(client) {
}

disable() {
this.disabled = true
this.client.config.disabled.add("observers", this.name)
}

Expand All @@ -26,7 +29,8 @@ module.exports = function(client) {
"command",
"all"
].includes(type)) {
console.error(this.name + " | Error on function setType: | Please use one of these 3 types: \"messages\" \"commands\" \"all\"")
console.error(this.name + " | Error on function setType: | Please use one of these 3 types: \"message\" \"command\" \"all\"")
this.type = "all"
} else {
this.type = type
}
Expand Down
22 changes: 13 additions & 9 deletions src/search_files/loadEvent.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
const DataStore = require("./../dataStore.js")
module.exports = async function(data, location) {
if (!data.dataStore) {data.dataStore = {}}
if (!data.dataStore) {
data.dataStore = {}
}

data.dataStore.events = new DataStore();
var temp = await data.searchInDirectories(location);
var events = [];
temp.forEach(i => {
try {
var temp = require(i)
events.push({event: temp, location: i})
events.push({
event: temp,
location: i
})
} catch (e) {
console.error(`${i} | Error while loading event: \n ${e}`)
}
Expand All @@ -20,19 +25,18 @@ module.exports = async function(data, location) {
if (event.constructor.name !== "Event") {
console.warn(`${i.location} | Error while loading event: \n File is not a event class | See https://discordspark.com/docs/events for more info.`)
i = null;
return;
}
if (typeof event.name != "string" || event.name.length < 1) {
console.warn(`${i.location} | Error while loading event: \n No event name specified | See https://discordspark.com/documentation/events for more info.`)
i = null;
console.warn(`${i.location} | Error while loading event: \n No event name specified | See https://discordspark.com/documentation/events for more info.`)
i = null;
}
if (typeof event.event != "string") {
console.warn(`${i.location} | Error while loading event: \n No event specified | See https://discordspark.com/documentation/events for more info.`)
i = null;
console.warn(`${i.location} | Error while loading event: \n No event specified | See https://discordspark.com/documentation/events for more info.`)
i = null;
}
if (typeof event.code != "function") {
console.warn(`${i.location} | Error while loading event: \n No code specified | See https://discordspark.com/documentation/events for more info.`)
i = null;
console.warn(`${i.location} | Error while loading event: \n No code specified | See https://discordspark.com/documentation/events for more info.`)
i = null;
}

})
Expand Down
13 changes: 9 additions & 4 deletions src/search_files/loadObserver.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const DataStore = require("./../dataStore.js")
module.exports = async function(data, location) {
if (!data.dataStore) {data.dataStore = {}}
if (!data.dataStore) {
data.dataStore = {}
}
if (!data.dataStore.functions) {
data.dataStore.functions = {};
}
Expand All @@ -10,7 +12,10 @@ module.exports = async function(data, location) {
temp.forEach(i => {
try {
var temp = require(i)
observer.push({observer: temp, location: i})
observer.push({
observer: temp,
location: i
})
} catch (e) {
console.error(`${i} | Error while loading observer: \n ${e}`)
}
Expand All @@ -25,8 +30,8 @@ module.exports = async function(data, location) {
return;
}
if (typeof observer.type != "string" || ![
"messages",
"commands",
"message",
"command",
"all"
].includes(observer.type)) {
observer.type = "all"
Expand Down
47 changes: 26 additions & 21 deletions src/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ module.exports = (client) => {
if (message.channel.type == "text" && client.customConfig.has(message.guild.id) && client.customConfig.get(message.guild.id).prefix) {
p = client.customConfig.get(message.guild.id).prefix
}
if (typeof p == "string") {
p = [p]
}
var prefixMatched = false;
p.forEach(async (i, n) => {
if (message.content.startsWith(i)) {
Expand All @@ -57,12 +60,11 @@ module.exports = (client) => {
executeCommand(client, message, command.name)
}
}
if ((n + 1) == p.length && prefixMatched == false) {
await observer(client, message)
}

} else if ((n + 1) == p.length && prefixMatched == false) {
await observer(client, message)
}
})

})
}

Expand All @@ -75,12 +77,12 @@ async function observer(client, message, command) {
}
}
if (command) {
if (ignoreBots >= 3) {
if (ignoreBots >= 3 && message.author.bot == true) {
return
}
try {
results = await client.dataStore.functions.observer.filter(i => {
return (i.observer.type == "all" || i.observer.type == "commands")
return (i.observer.type == "all" || i.observer.type == "command")
})
.filter(i => (client.config.disabled.has("observers", i.observer.name) == false))
if (message.channel.type == "text") {
Expand All @@ -99,23 +101,26 @@ async function observer(client, message, command) {
console.log(e)
return false
}
}
if (ignoreBots == 2 || ignoreBots == 4) {
return
}
try {
results = await client.dataStore.functions.observer.filter(i => {
return (i.observer.type == "all" || i.observer.type == "commands")
})
.filter(i => (client.config.disabled.has("observers", i.observer.name) == false))
if (message.channel.type == "text") {
results = results.filter(i => client.customConfig.get(message.guild.id).disabled.has("observers", i.observer.name) == false)
} else {
if (ignoreBots == 2 || ignoreBots == 4) {
if (message.author.bot == true) {
return
}
}
results = results.map(i => (i.observer.code(client, message)))
} catch (e) {
console.log(e)
}
try {
results = await client.dataStore.functions.observer.filter(i => {
return (i.observer.type == "all" || i.observer.type == "message")
})
.filter(i => (client.config.disabled.has("observers", i.observer.name) == false))
if (message.channel.type == "text") {
results = results.filter(i => client.customConfig.get(message.guild.id).disabled.has("observers", i.observer.name) == false)
}

results = results.map(i => (i.observer.code(client, message)))
} catch (e) {
console.log(e)
}
}
}

async function isValidCommand(client, message, commandName) {
Expand Down

0 comments on commit 04b2b8b

Please sign in to comment.