forked from yusufusta/WhatsAsena
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdater.js
91 lines (80 loc) · 3.29 KB
/
updater.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
/* Copyright (C) 2020 Yusuf Usta.
Licensed under the GPL-3.0 License;
you may not use this file except in compliance with the License.
WhatsAsena - Yusuf Usta
*/
const simpleGit = require('simple-git');
const git = simpleGit();
const Asena = require('../events');
const {MessageType} = require('@adiwajshing/baileys');
const Config = require('../config');
const exec = require('child_process').exec;
const Heroku = require('heroku-client');
const { PassThrough } = require('stream');
const heroku = new Heroku({ token: Config.HEROKU.API_KEY })
const Language = require('../language');
const Lang = Language.getString('updater');
Asena.addCommand({pattern: 'update$', fromMe: true, desc: Lang.UPDATER_DESC}, (async (message, match) => {
await git.fetch();
var commits = await git.log([Config.BRANCH + '..origin/' + Config.BRANCH]);
if (commits.total === 0) {
await message.client.sendMessage(
message.jid,
Lang.UPDATE, MessageType.text
);
} else {
var degisiklikler = Lang.NEW_UPDATE;
commits['all'].map(
(commit) => {
degisiklikler += '🔹 [' + commit.date.substring(0, 10) + ']: ' + commit.message + ' <' + commit.author_name + '>\n';
}
);
await message.client.sendMessage(
message.jid,
degisiklikler + '```', MessageType.text
);
}
}));
Asena.addCommand({pattern: 'update now$', fromMe: true, desc: Lang.UPDATE_NOW_DESC, dontAddCommandList: true}, (async (message, match) => {
await git.fetch();
var commits = await git.log([Config.BRANCH + '..origin/' + Config.BRANCH]);
if (commits.total === 0) {
return await message.client.sendMessage(
message.jid,
Lang.UPDATE, MessageType.text
);
} else {
var guncelleme = await message.reply(Lang.UPDATING);
if (Config.HEROKU.HEROKU) {
try {
var app = await heroku.get('/apps/' + Config.HEROKU.APP_NAME)
} catch {
return await message.client.sendMessage(
message.jid,Lang.INVALID_HEROKU, MessageType.text);
}
git.fetch('upstream', Config.BRANCH);
git.reset('hard', ['FETCH_HEAD']);
var git_url = app.git_url.replace(
"https://", "https://api:" + Config.HEROKU.API_KEY + "@"
)
try {
await git.addRemote('heroku', git_url);
} catch { console.log('heroku remote ekli'); }
await git.push('heroku', Config.BRANCH);
await message.client.sendMessage(
message.jid,Lang.UPDATED, MessageType.text);
} else {
git.pull((async (err, update) => {
if(update && update.summary.changes) {
await message.client.sendMessage(
message.jid,Lang.UPDATED_LOCAL, MessageType.text);
exec('npm install').stderr.pipe(process.stderr);
} else if (err) {
await message.client.sendMessage(
message.jid,'*❌ Güncelleme başarısız oldu!*\n*Hata:* ```' + err + '```', MessageType.text);
}
}));
await guncelleme.delete();
}
}
}));