-
Notifications
You must be signed in to change notification settings - Fork 0
/
selfbot.js
101 lines (88 loc) · 2.94 KB
/
selfbot.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
'use strict';
require('dotenv').config();
// Always Load
const Helper = require('disbot-utils');
const Discord = require('discord.js');
// const Discord = Helper['pseudodiscord.js'];
const config = require('./config');
const DEVELOPMENT = process.env.DEVELOPMENT === 'true';
// Dynamic Loads
const imports = Helper.conditionalLoader(DEVELOPMENT, {
commands: require.resolve('./src/commands.js'),
parse: require.resolve('./src/flags.js'),
});
imports.staticOnFalse();
// Login
const selfbot = new Discord.Client({ bot: false }); // Is self-bot
selfbot.login(process.env.TOKEN);
// Ready
selfbot.on('ready', () => {
console.log('Selfbot is ready.');
});
selfbot.on('message', function (msg) {
if (msg.author.id !== selfbot.user.id) { return; } // Only respond to myself
const commandMatch = Helper
.validateParseCommand(config.prefix, Helper.REGEX_SPACE, msg.content);
if (commandMatch === null) { return; } // Not a valid command format
imports.dynamicOnTrue();
// Now break the parameter into flag and main
const parameterMatch = typeof commandMatch[2] === 'undefined'
? null
: imports.parse.matchArgs.exec(commandMatch[2]);
// Options and defaults (may be overwritten by flags)
const options = {
// Stuff that should not change
origin: msg.channel,
author: msg.author, // Discord.user
member: msg.member, // Discord.guildMember
self: selfbot,
// Stuff that is okay to be overwritten by flags
channel: msg.channel,
serverId: msg.channel.guild.id,
};
// Process the flags to set options
const setFlag = imports.parse.flagSetters;
if (parameterMatch !== null) {
imports.parse.flagList.reduce((protoOptions, flag) => {
const flagMatch = imports.parse[flag].exec(parameterMatch[1]);
if (flagMatch !== null) {
setFlag[flag](protoOptions, flagMatch[1]); // Mutates {protoOptions}
}
//console.log('flagMatch', flag, flagMatch);
return protoOptions;
}, options);
}
const command = commandMatch[1];
const arg = parameterMatch == null
? ''
: (parameterMatch[2] == null ? '' : parameterMatch[2]);
// if (IS_DEVELOPMENT === true && Discord.psuedo === true) {
// console.log('commandMatch', commandMatch);
// console.log('parameterMatch', parameterMatch);
// console.log('commnad', command);
// console.log('arg ', arg);
// console.log('options', options);
// }
// Execute the command
try {
if (imports.commands.run(command, arg, options) == true) {
// msg.delete(); // Delete if valid command
} else {
console.error('an error! nooooo');
}
} catch (err) {
console.error(err);
}
});
//*/
const http = require('http');
const express = require('express');
const app = express();
app.get('/', (request, response) => {
console.log(Date.now() + ' Ping Received');
response.sendStatus(200);
});
app.listen(process.env.PORT);
setInterval(() => {
http.get(`http://${process.env.PROJECT_DOMAIN}.glitch.me/`);
}, 290000);