-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
394 lines (355 loc) · 18.3 KB
/
index.js
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
const discord = require('discord.js');
const { ClientPresenceStatus } = require('discord.js')
var consoleInteraface = require('discord.js-console');
const manager = require('./src/manager')
module.exports.ticketsystem = class {
/**
* Das Ticketsystem
*
* @param {discord.Client} client Client für den bot
* @param {object} options
*
* @param {boolean} options.customconsole
* @param {boolean} options.logging_in_discord
* @param {discord.GuildChannel.ID} options.discord_logging_channel
* @param {object} options.status
* @param {Boolean} options.inviteable Standart ist false
* @param {String} options.adminrolename
* @param {String} options.supporterrolename
* @param {object} options.credits
*
* @param {boolean} options.ticket
* @param {boolean} options.modmail
* @param {boolean} options.voice
* @param {boolean} options.report Report User oder Message
*
* @param {object} options.ticketsettings
* @param {object} options.modmailsettings
* @param {object} options.voicesettings
*
* @param {string} options.ticketsettings.ticketname Um Strings Abzufangen: ?uname? -> Username im ticketname | ?id? -> Ticketid im ticketname | ?thema? -> Ticketthema im ticketname | -> Ticketname spiegelt den namen des Ticketchannels wieder
*
* @param {String} options.status.name
* @param {ClientPresenceStatus} options.status.type
* @param {Boolean} options.status.afk
* @param {object} options.status.activities
*
* @param {boolean} options.credits.enable
* @param {object} options.credits.custom
*
* @param {String} optionen.credits.custom.author
* @param {String} optionen.credits.custom.version
* @param {String} optionen.credits.custom.supportserver
*
* @param {Number} options.status.activities.type Playing {game} = 0 | Streaming {details} = 1 | Listening to {name} = 2 | Watching {details} = 3 | Competing in {name} = 5
* @param {URL} options.status.activities.url
*
*/
constructor(client, options) {
if (!client) { throw new TypeError("Fehlender discord.js client!") } else { this.client = client }
if (!options) { throw new TypeError("Keine Optionen angegeben! Fehlende Optionen: status, credits, adminrolename, supporterrolename") } { this.options = options }
if (!options.status) { throw new TypeError("Keine Status Optionen angegeben") }
if (!options.status.name) { throw new TypeError("Keinen Status Namen angegeben") }
if (!options.status.type) { throw new TypeError("Keinen Status Type ('online', 'idle', 'dnd') angegeben") }
if (!options.status.activities) { throw new TypeError("Keinen Activitie Daten angegeben") }
if (!options.adminrolename) { throw new TypeError("Keinen adminrolename angegeben") }
if (!options.supporterrolename) { throw new TypeError("Keinen supporterrolename angegeben") }
if (!options.credits) { throw new TypeError("keine credits optionen angegeben") }
if (!options.ticket && !options.modmail && !options.voice) { throw new TypeError("Es muss mind. ein Argument (ticket, modmail, voice) definiert werden in den Optionen") }
if (options.ticket == false && options.modmail == false && options.voice == false && options.report == false) { throw new TypeError("Es muss mind. ein Argument (ticket, modmail, voice) aktiviert werden") }
if (!options.status.activities.type && options.status.activities.type != 0 && options.status.activities.type != 1 && options.status.activities.type != 2 && options.status.activities.type != 3 && options.status.activities.type != 5) { throw new Error("Keinen Activity Type angegeben") }
if (!options.inviteable) { options.inviteable = true }
if (!options.credits.custom) { options.credits.custom = manager.credits }
if (!options.credits.custom.author) { options.credits.custom.author = manager.credits.author }
if (!options.credits.custom.version) { options.credits.custom.author = manager.credits.version }
if (!options.credits.custom.supportserver) { options.credits.custom.author = manager.credits.supportserver }
if (!options.ticket) { options.ticket = false }
if (!options.modmail) { options.modmail = false }
if (!options.voice) { options.voice = false }
if (!options.report) { options.report = false }
if( options.ticket == true && (!options.ticketsettings || !options.ticketsettings.ticketname)) { throw new TypeError("Keine Ticketsettings angegeben") }
if( options.modmail == true && !options.modmailsettings) { throw new TypeError("Keine Modmailsettings angegeben") }
if( options.voice == true && !options.voicesettings) { throw new TypeError("Keine Voicesettings angegeben") }
logClear()
logInfo("Ticketsystem Startet")
if (!options.status.afk) { options.status.afk = false }
client.on('error', e => { logError(e + "\n" + e.stack + "\n\n", "Fehler lässt den Bot nicht abstürzen!") })
client.on('warn', w => { logWarning(w) })
client.setMaxListeners(0)
manager.invitemanager(client, options.inviteable, logInfo)
manager.startengin({ ticket: options.ticket, modmail: options.modmail, voice: options.voice, report: options.report }, client, { log: log, Error: logError, Warning: logWarning, Operation: logOperation, Status: logStatus, Clear: logClear, Table: logTable, Info: logInfo }, { admin: options.adminrolename, support: options.supporterrolename }, { fs: options.ticketsettings.ticketname })
this.updatestatus(options.status)
client.on('ready', async () => {
const guilds = await client.guilds.cache.map(g => g)
for (let i = 0; i < guilds.length; i++) {
const g = guilds[i]
const roles = g.roles.cache.map(r => r.name)
if (roles.includes(options.adminrolename)) { } else {
g.roles.create({ name: options.adminrolename, reason: "Für das Ticketsystem! NICHT LÖSCHEN" })
}
if (roles.includes(options.supporterrolename)) { } else {
g.roles.create({ name: options.supporterrolename, reason: "Für das Ticketsystem! NICHT LÖSCHEN" })
}
manager.createGuild(g)
}
logStatus("ONLINE", "Status System")
})
//functions
/**
* Logge eine einfache Nachricht
* @param {string} message Nachricht
*
* @example log("Moin")
*/
function log(message) {
if (!options.customconsole) {
return new consoleInteraface.console(false, 0, false, false, 0).log(message)
}
return new consoleInteraface.console(options.logging_in_discord, options.discord_logging_channel, true, true, client).log(message)
}
/**
* Logge einen Fehler
* @param {string} code Fehlercode
* @param {string} message Nachricht dazu
*
* @exaple logError(error, "Alles Ok")
*/
function logError(code, message) {
if (!options.customconsole) {
return new consoleInteraface.console(false, 0, false, false, 0).logError(code, message)
}
return new consoleInteraface.console(options.logging_in_discord, options.discord_logging_channel, true, true, client).logError(code, message)
}
/**
* Logge eine Warnung
* @param {string} message Warnung
*
* @example logWarning("Moin")
*/
function logWarning(message) {
if (!options.customconsole) {
return new consoleInteraface.console(false, 0, false, false, 0).logWarning(message)
}
return new consoleInteraface.console(options.logging_in_discord, options.discord_logging_channel, true, true, client).logWarning(message)
}
/**
* Logge eine Operation
* @param {string} type Operationstyp
* @param {string} status Status der Operation, z.B. STILL, COMPLEATE, ERROR
* @param {string} message Operationsnachricht
*
* @example logOperation("Login","COMLPLEATE","erfolgreich")
*/
function logOperation(type, status, message) {
if (!options.customconsole) {
return new consoleInteraface.console(false, 0, false, false, 0).logOperation(type, status, message)
}
return new consoleInteraface.console(options.logging_in_discord, options.discord_logging_channel, true, true, client).logOperation(type, status, message)
}
/**
* Logge einen Status
* @param {string} status der Status
* @param {string} message Nachricht zum Status
*
* @example logStatus("Online", "System erfolgreich gestartet")
*/
function logStatus(status, message) {
if (!options.customconsole) {
return new consoleInteraface.console(false, 0, false, false, 0).logStatus(status, message)
}
return new consoleInteraface.console(options.logging_in_discord, options.discord_logging_channel, true, true, client).logStatus(status, message)
}
/**
* Leere die Console
*
* @example logclear()
*/
function logClear() {
if (!options.customconsole) {
return new consoleInteraface.console(false, 0, false, false, 0).logClear()
}
return new consoleInteraface.console(options.logging_in_discord, options.discord_logging_channel, true, true, client).logClear()
}
/**
* Stelle daten in der Console in einer Tabelle dar
* @param {Array} input Array der Daten die in der Tabelle angezeigt werden sollen
* @param {Array} properties Welche Argumente sollen angezeigt werden - Weck lassen oder leres Array lässt alles anzeigen - Index ausgeschlossen!
* @param {boolean} index Wenn true wird die Spalte (index) nicht angezeigt
*
* @example logTable([{ a: 1, b: 'Y' }, { a: 'Z', b: 2 }], [], false)
* @example logTable([{ a: 1, b: 'Y' }, { a: 'Z', b: 2 }], ["a"], false)
* @example logTable([{ a: 1, b: 'Y' }, { a: 'Z', b: 2 }], ["a"], true)
*/
function logTable(input, properties, index) {
if (!options.customconsole) {
return new consoleInteraface.console(false, 0, false, false, 0).logTable(input, properties, index)
}
return new consoleInteraface.console(options.logging_in_discord, options.discord_logging_channel, true, true, client).logTable(input, properties, index)
}
/**
* Logge eine Info
* @param {String} message Nachricht
*
* @example logInfo("Test")
*/
function logInfo(message) {
if (!options.customconsole) {
return new consoleInteraface.console(false, 0, false, false, 0).logInfo(message)
}
return new consoleInteraface.console(options.logging_in_discord, options.discord_logging_channel, true, true, client).logInfo(message)
}
}
/**
* Update den Bot Status
* @param {object} status
*
* @param {String} status.name
* Um Strings Abzufangen:
* "?botname?" - Gibt den namen des Bots aus
*
* @param {ClientPresenceStatus} status.type
* @param {Boolean} status.afk
* @param {object} status.activities
*
* @param {Number} status.activities.type Playing {game} = 0 | Streaming {details} = 1 | Listening to {name} = 2 | Watching {details} = 3 | Competing in {name} = 5
* @param {URL} status.activities.url
*/
updatestatus(status) {
if (!status) { throw new TypeError("Keine Status angaben gefunden!") }
if (!status.name) { throw new TypeError("Keinen Status Namen angegeben") }
if (!status.type) { throw new TypeError("Keinen Status Type ('online', 'idle', 'dnd') angegeben") }
if (!status.activities) { throw new TypeError("Keinen Activitie Daten angegeben") }
if (!status.activities.type && status.activities.type != 0 && status.activities.type != 1 && status.activities.type != 2 && status.activities.type != 3 && status.activities.type != 5) { throw new Error("Keinen Activity Type angegeben") }
this.logOperation("Bot Status", "UPDATE", "start")
this.client.on('ready', () => {
if (status.name.includes("?botname?")) {
status.name = status.name.replace("?botname?", this.client.user.username)
}
if (!status.activities.url) {
this.client.user.setPresence({
status:status.type,
afk:status.afk,
activities:[{
name:status.name,
type: status.activities.type
}]
})
} else {
this.client.user.setPresence({
status:status.type,
afk:status.afk,
activities:[{
name:status.name,
type: status.activities.type,
url:status.activities.url
}]
})
}
this.logOperation("Bot Status", "UPDATE", "finished")
})
setTimeout(() => {this.updatestatus(status)},60000)
}
/**
* Logge eine einfache Nachricht
* @param {string} message Nachricht
*
* @example log("Moin")
*/
log(message) {
if (!this.options.customconsole) {
return new consoleInteraface.console(false, 0, false, false, 0).log(message)
}
return new consoleInteraface.console(this.options.logging_in_discord, this.options.discord_logging_channel, true, true, this.client).log(message)
}
/**
* Logge einen Fehler
* @param {string} code Fehlercode
* @param {string} message Nachricht dazu
*
* @exaple logError(error, "Alles Ok")
*/
logError(code, message) {
if (!this.options.customconsole) {
return new consoleInteraface.console(false, 0, false, false, 0).logError(code, message)
}
return new consoleInteraface.console(this.options.logging_in_discord, this.options.discord_logging_channel, true, true, this.client).logError(code, message)
}
/**
* Logge eine Warnung
* @param {string} message Warnung
*
* @example logWarning("Moin")
*/
logWarning(message) {
if (!this.options.customconsole) {
return new consoleInteraface.console(false, 0, false, false, 0).logWarning(message)
}
return new consoleInteraface.console(this.options.logging_in_discord, this.options.discord_logging_channel, true, true, this.client).logWarning(message)
}
/**
* Logge eine Operation
* @param {string} type Operationstyp
* @param {string} status Status der Operation, z.B. STILL, COMPLEATE, ERROR
* @param {string} message Operationsnachricht
*
* @example logOperation("Login","COMLPLEATE","erfolgreich")
*/
logOperation(type, status, message) {
if (!this.options.customconsole) {
return new consoleInteraface.console(false, 0, false, false, 0).logOperation(type, status, message)
}
return new consoleInteraface.console(this.options.logging_in_discord, this.options.discord_logging_channel, true, true, this.client).logOperation(type, status, message)
}
/**
* Logge einen Status
* @param {string} status der Status
* @param {string} message Nachricht zum Status
*
* @example logStatus("Online", "System erfolgreich gestartet")
*/
logStatus(status, message) {
if (!this.options.customconsole) {
return new consoleInteraface.console(false, 0, false, false, 0).logStatus(status, message)
}
return new consoleInteraface.console(this.options.logging_in_discord, this.options.discord_logging_channel, true, true, this.client).logStatus(status, message)
}
/**
* Leere die Console
*
* @example logclear()
*/
logClear() {
if (!this.options.customconsole) {
return new consoleInteraface.console(false, 0, false, false, 0).logClear()
}
return new consoleInteraface.console(this.options.logging_in_discord, this.options.discord_logging_channel, true, true, this.client).logClear()
}
/**
* Stelle daten in der Console in einer Tabelle dar
* @param {Array} input Array der Daten die in der Tabelle angezeigt werden sollen
* @param {Array} properties Welche Argumente sollen angezeigt werden - Weck lassen oder leres Array lässt alles anzeigen - Index ausgeschlossen!
* @param {boolean} index Wenn true wird die Spalte (index) nicht angezeigt
*
* @example logTable([{ a: 1, b: 'Y' }, { a: 'Z', b: 2 }], [], false)
* @example logTable([{ a: 1, b: 'Y' }, { a: 'Z', b: 2 }], ["a"], false)
* @example logTable([{ a: 1, b: 'Y' }, { a: 'Z', b: 2 }], ["a"], true)
*/
logTable(input, properties, index) {
if (!this.options.customconsole) {
return new consoleInteraface.console(false, 0, false, false, 0).logTable(input, properties, index)
}
return new consoleInteraface.console(this.options.logging_in_discord, this.options.discord_logging_channel, true, true, this.client).logTable(input, properties, index)
}
/**
* Logge eine Info
* @param {String} message Nachricht
*
* @example logInfo("Test")
*/
logInfo(message) {
if (!this.options.customconsole) {
return new consoleInteraface.console(false, 0, false, false, 0).logInfo(message)
}
return new consoleInteraface.console(this.options.logging_in_discord, this.options.discord_logging_channel, true, true, this.client).logInfo(message)
}
}