-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathupdater.js
86 lines (71 loc) · 2.99 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
/* 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 check$', fromMe: true, dontAddCommandList: 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.replace('Update','Fixed').replace('.js','') + '*\n';
}
);
await message.client.sendMessage(
message.jid,
degisiklikler, MessageType.text
);
}
}));
Asena.addCommand({pattern: 'update start$', fromMe: true,dontAddCommandList: true, desc: Lang.UPDATE_NOW_DESC}, (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 {
await message.client.sendMessage(
message.jid,Lang.UPDATING, MessageType.text);
try {
var app = await heroku.get('/apps/' + Config.HEROKU.APP_NAME)
} catch {
await message.client.sendMessage(
message.jid,Lang.INVALID_HEROKU, MessageType.text);
await new Promise(r => setTimeout(r, 1000));
return await message.client.sendMessage(
message.jid,Lang.IN_AF, 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);
await message.sendMessage(Lang.AFTER_UPDATE);
}
}));