This repository has been archived by the owner on Jun 13, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
81 lines (71 loc) · 2.77 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
const Eris = require('eris');
const fs = require('fs');
const path = require('path');
const child_process = require('child_process');
const config = require('./config.json');
const client = new Eris.Client(config.token);
// If forkdata doesn't exist, clone
if (!fs.existsSync(path.join(__dirname, 'forkdata'))) {
child_process.exec(`git clone ${config.github} -b gh-pages forkdata`);
child_process.exec('git config user.name "DiscordForkAppdata"', {
cwd: path.join(__dirname, 'forkdata')
});
child_process.exec('git config user.email "[email protected]"', {
cwd: path.join(__dirname, 'forkdata')
});
}
client.on('ready', () => {
console.log('Ready!');
});
const nullThen = () => {};
client.on('messageCreate', (message) => {
if (message.author.id === client.user.id) return;
if (config.owners.includes(message.author.id) && message.content === '£push') {
child_process.exec('git add .', {
cwd: path.join(__dirname, 'forkdata')
});
child_process.exec(`git commit -m "Manual push by ${message.author.username.replace(/"/g, '\\"')} via Discord"`, {
cwd: path.join(__dirname, 'forkdata')
});
child_process.exec('git push', {
cwd: path.join(__dirname, 'forkdata')
}, (error, stdout, stderr) => {
if (error) {
message.channel.createMessage(`Error running command:\n${error.message}`).then(nullThen).catch(nullThen);
} else {
message.channel.createMessage(`\`\`\`\nstdout\n${stdout}\n\nstderr\n${stderr}\`\`\``).then(nullThen).catch(nullThen);
}
});
} else {
try {
const inData = JSON.parse(message.content);
if (typeof inData === 'object' && inData.for === config.for) {
const outData = {};
const botCount = parseInt(inData.botCount, 10) >= 0 ? parseInt(inData.botCount, 10) : 0;
if (botCount) outData.botCount = botCount;
const fileData = JSON.stringify(outData, null, 2) + '\n';
fs.writeFile(path.join(__dirname, 'forkdata', `${message.author.id}.json`), fileData, { encoding: 'utf8' }, (error) => {
if (error) {
message.channel.createMessage(JSON.stringify({
message: `Error writing to file`,
data: error.message,
success: false,
for: message.author.id
}, null, 2)).then(nullThen).catch(nullThen);
} else {
message.channel.createMessage(JSON.stringify({
message: `Success writing to file`,
data: fileData,
success: true,
for: message.author.id
}, null, 2)).then(nullThen).catch(nullThen);
}
});
}
} catch (e) {
// console.log(e);
// message.channel.createMessage(`Error encountered:\n${e.message}`);
}
}
});
client.connect();