This repository was archived by the owner on Dec 20, 2021. It is now read-only.
forked from Spark-Core/Spark
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
137 lines (122 loc) · 5.77 KB
/
app.js
File metadata and controls
137 lines (122 loc) · 5.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/* eslint init-declarations: 0 */
const discord = require("discord.js")
const chalk = require("chalk")
const startBot = require("./src/start.js")
const confirmConfig = require("./src/confirmConfig.js")
let Client;
/*
All modular classes
*/
exports.version = require("./package.json").version;
exports.DataStore = require("./src/dataStore.js")
exports.methods = {RichEmbed: discord.RichEmbed}
exports.CustomConfig = require("./src/CustomConfig.js")
exports.command = function(name, options) {
const Command = require("./src/module_classes/Command.js")()
return new Command(name, options, Client)
}
exports.observer = function(name, options) {
const Observer = require("./src/module_classes/Observer.js")(Client)
return new Observer(name, options)
}
exports.engine = function(name, options) {
const Engine = require("./src/module_classes/Engine.js")(Client)
return new Engine(name, options)
}
exports.snippet = function(name, options) {
const Snippet = require("./src/module_classes/Snippet.js")(Client)
return new Snippet(name, options)
}
exports.permission = function(name, options) {
const Permission = require("./src/module_classes/Permission.js")(Client)
return new Permission(name, options)
}
exports.event = function(name, options) {
const Event = require("./src/module_classes/Event.js")(Client)
return new Event(name, options)
}
exports.start = function(options) {
if (!confirmConfig(options)) {
return
}
if (typeof options.ignoreBots != "boolean" && typeof options.ignoreBots != "string" && options.ignoreBots != null) {
return console.log(`You're trying to start with ${chalk.red("an invalid option:")} ${chalk.red("ignoreBots")}, Please read this article on the docs on how to use this option: ${chalk.blue("https://discordspark.com/documentation/config")}`)
}
if (options.ignoreBots == true) {
options.ignoreBots = 4;
} else if (options.ignoreBots == false) {
options.ignoreBots = null
} else if (options.ignoreBots == "message") {
options.ignoreBots = 1
} else if (options.ignoreBots == "command") {
options.ignoreBots = 2
}
Client = class Client extends discord.Client {
constructor(config) {
super(config)
this.version = require("./package.json").version
this.config = {}
this.customConfig = new exports.DataStore()
this.CustomConfig = exports.CustomConfig
}
async search() {
var data = await require("./src/search.js").func(this)
return data;
}
async start() {
this.dataStore = await this.dataStore;
if (this.config.first) {
console.log(`Welcome to ${chalk.yellow(`Spark V${this.version}`)}!\nTo see the changelog for this update go to this page:\n${chalk.blue("https://github.com/TobiasFeld22/Spark/releases")}\nTo learn more about using Spark, please visit our docs:\n${chalk.blue("https://discordspark.com/")}\n-------------------`)
}
function colours(text, size) {
if (size == 0) {
return chalk.red(text)
}
return chalk.green(text)
}
var commandtext = colours(`${this.dataStore.commands.size} commands\n`, this.dataStore.commands.size)
var observertext = colours(`${this.dataStore.functions.observer.size} observers\n`, this.dataStore.functions.observer.size)
var enginetext = colours(`${this.dataStore.functions.engines.size} engines\n`, this.dataStore.functions.engines.size)
var snippettext = colours(`${this.dataStore.functions.snippet.size} snippets\n`, this.dataStore.functions.snippet.size)
var permissiontext = colours(`${this.dataStore.permissions.size} permissions\n`, this.dataStore.permissions.size)
var eventtext = colours(`${this.dataStore.events.size} events\n`, this.dataStore.events.size)
startBot(this)
console.log(`Your bot (${chalk.yellow(this.user.tag)}) is now ${chalk.green("online!")} | Running on ${this.guilds.size} servers | ${chalk.yellow(`Spark v${this.version}`)}\nWe detected the following data:\n \n ${commandtext} ${observertext} ${enginetext} ${snippettext} ${permissiontext} ${eventtext}`)
}
}
Client = new Client(options.clientOptions);
Client.on("cc_update", function(data) {
Client.customConfig.set(data.id, data)
});
Client.config = options
Client.login(options.token).then(async () => {
try {
var application = await Client.fetchApplication()
Client.config.ownerID = application.owner.id
} catch (e) {
console.log(e)
throw Error("Couldn't fetch application, token may be a invalid / user token. ")
}
Client.guilds.forEach(i => {
i.customConfig = new exports.CustomConfig(Client, i.id);
Client.customConfig.set(i.id, i.customConfig)
})
Client.dataStore = await Client.search()
Client.snippets = {
list: (name) => {
if (!name) {
return Client.dataStore.functions.snippet.map((i, n) => n)
} else if (Client.dataStore.functions.snippet.has(name)) {
return Client.dataStore.functions.snippet.get(name)
}
return null;
}
}
Client.dataStore.functions.snippet.forEach((i, n) => {
Client.snippets[n] = i.snippet.code
})
Client.start(Client)
}).catch(err => {
return console.error("An error occured while trying to login, check your token.", err)
})
}