-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
135 lines (123 loc) · 3.8 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
const Discord = require('discord.js');
const sqlite = require('sqlite3').verbose();
const { prefix, token } = require('./config.json'); //Prefix is the symbol you type before the command for example !play in rythm I can't show you the file as it's contain my token :D
const client = new Discord.Client();
const http = require('http');
const welcome = require('./welcome');
const auth = require('./auth');
let counter = 0;
http.createServer((req, res) => {
res.writeHead(200, {
'Content-type': 'text/plain',
});
res.writeHead(200, {
'Content-type': 'text/plain',
});
res.write('Hey');
res.end();
}).listen(4000);
client.once('ready', () => {
console.log('Ready!');
let db = new sqlite.Database(
'./users.db',
sqlite.OPEN_READWRITE | sqlite.OPEN_CREATE
);
db.run(
'CREATE TABLE IF NOT EXISTS user(id TEXT NOT NULL, code INTEGER NOT NULL)'
);
client.user.setActivity('sci!help');
});
const welcomeChannel = 'CHANNEL ID';
welcome(client, welcomeChannel, ['CHANNEL ID', 'CHANNEL ID']);
client.on('message', (message) => {
if (message.author.bot != client.user.id) {
// Dealing with !d bump
try {
message.embeds.forEach((embed) => {
let desc = embed.description;
// message.channel.send(embed.description);
if (desc.search(/bump done/i) != -1) {
message.channel.send(
`Thanks for helping the server ${desc.substring(
0,
desc.indexOf(',')
)} \n https://tenor.com/810B.gif`
);
} else if (desc.search(/Please wait another/i) != -1) {
message.channel.send(
`Thank you for trying to help the server ${desc.substring(
0,
desc.indexOf(',')
)}, try again later https://tenor.com/G8M4.gif`
);
}
});
} catch (err) {
return;
}
}
if (!message.author.bot) {
if (message.content.startsWith(`${prefix}ping`)) {
message.channel.send('Pong');
}
if (message.content.startsWith(`${prefix}help`)) {
message.channel.send('Sorry, this bot is under construction');
}
//Get user code
if (message.content.startsWith(`${prefix}code`)) {
let db = new sqlite.Database('./users.db', sqlite.OPEN_READONLY);
let query = `SELECT * FROM user where id = ?`;
db.get(query, message.author.id, (err, row) => {
if (err) console.log(err);
if (row == undefined) {
message.channel.send(
`I can't find a code, ping staff to investigate the issue`
);
} else {
message.channel.send(`Your code is: ${row.code}`);
}
});
}
// Check if the message starts with my acees(so it doesn't read all messages)
if (message.content.toLowerCase().startsWith('my acsess')) {
// Opens the data-base
let db = new sqlite.Database('./users.db', sqlite.OPEN_READWRITE);
// SQL query to search for the column with the id of the user
let query = `SELECT * FROM user WHERE id = ?`;
// Do the search
db.get(query, [message.author.id], (err, row) => {
// Logs any errors
if (err) console.log(err);
// If the id is not found in the data-base
if (row == undefined) {
message.channel.send('Something went wrong');
return;
} else {
// If the id is found, and the code is found, and the user agrees to the rules run the function auth
// else, the code is not found send a message with Check the code again.
let code = message.content.match(/(\d+)/)[0];
console.log(code, row.code);
if (
code == row.code &&
message.content.search(/I agree/i) != -1
) {
auth(message);
db.run(remove, message.author.id, (err) => {
if (err) console.log(err);
console.log('Deletion done');
counter = 0;
});
return;
} else {
counter++;
console.log(counter);
message.channel.send('Check the code again');
}
}
});
}
}
});
// https://tenor.com/810B.gif
// https://tenor.com/G8M4.gif
client.login(token);