Skip to content

Commit

Permalink
WhatsAsena: Heroku Plugin
Browse files Browse the repository at this point in the history
* added translations

* heroku plugin
  • Loading branch information
arunpt authored Dec 7, 2020
1 parent 9333d0b commit 6ed0b19
Show file tree
Hide file tree
Showing 9 changed files with 255 additions and 1 deletion.
19 changes: 19 additions & 0 deletions language/AZ.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,25 @@
"NEED_REPLY": "```Xaiş edirəm bir mesaja cavap verin!```",
"MUST_TEXT": "```Cavab mətn olmalıdır```"
},
"heroku": {
"RESTART_DESC": "WhatsAsena-nı yenidən başladın",
"RESTART_MSG": "```yenidən başladır ...```",
"SHUTDOWN_DESC": "WhatsAsena-nı söndürün",
"SHUTDOWN_MSG": "```söndürmək ⛔```",
"DYNO_DESC": "Heroku dyno istifadəsini yoxlayın",
"DYNO_TOTAL": "```Ümumi kvota```",
"DYNO_USED": "```Kota istifadə edildi```",
"PERCENTAGE": "```faiz```",
"DYNO_LEFT": "```qalıq balans```",
"SETVAR_DESC": "dəsti heroku config var",
"SET_SUCCESS": "Uğurla quruldu ```{} ➜ {}```",
"KEY_VAL_MISSING": "```Ya key və ya value yoxdur```",
"INVALID": "```Yanlış key:value formatı```",
"GETVAR_DESC": "almaq heroku config var",
"DELVAR_DESC": "Sil heroku config var",
"DEL_SUCCESS": "```{} uğurla silindi```",
"NOT_FOUND": "```bu açar üçün heç bir nəticə tapılmadı```"
},
"filters": {
"FILTER_DESC": "Filter əlavə edər. Yazdığın filter'i biri yazsa, yazdığınız cavabı göndərər. Əgər sadəcə filter yazsanız, yazılan filter'ləri göstərər.",
"NO_FILTER": "*❌ Bu grupda filter yoxdur!*",
Expand Down
21 changes: 20 additions & 1 deletion language/EN.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"IM_NOT_AFK": "```I am not AFK anymore!```",
"AFK_TEXT": "```Bip bop! This is a bot. My owner is not here at the moment.```",
"AFK_TEXT_NOMD": "Bip bop! This is a bot. My owner is not here at the moment.",
"HOUR": "time",
"HOUR": "hour",
"MINUTE": "minute",
"SECOND": "second"
},
Expand All @@ -66,6 +66,25 @@
"NEED_REPLY": "```Please reply to a message!```",
"MUST_TEXT": "```Please reply to any message```"
},
"heroku": {
"RESTART_DESC": "Restart WhatsAsena",
"RESTART_MSG": "```restarting...```",
"SHUTDOWN_DESC": "Shutdown WhatsAsena",
"SHUTDOWN_MSG": "```shutting down ⛔```",
"DYNO_DESC": "Check heroku dyno usage",
"DYNO_TOTAL": "```Total Quota```",
"DYNO_USED": "```Quota used```",
"PERCENTAGE": "```Percentage```",
"DYNO_LEFT": "```Remaining```",
"SETVAR_DESC": "Set heroku config var",
"SET_SUCCESS": "Successfully set ```{} ➜ {}```",
"KEY_VAL_MISSING": "```Either Key or Value is missing```",
"INVALID": "```Invalid key:value format```",
"GETVAR_DESC": "Get heroku config var",
"DELVAR_DESC": "Delete heroku config var",
"DEL_SUCCESS": "```{} successfully deleted```",
"NOT_FOUND": "```no results found for this key```"
},
"filters": {
"FILTER_DESC": "It adds a filter. If someone writes your filter, it send the answer. If you just write .filter, it show's your filter list.",
"NO_FILTER": "*❌ There are no filters in this chat!*",
Expand Down
19 changes: 19 additions & 0 deletions language/ES.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,25 @@
"NEED_REPLY": "```¡Responde a un mensaje!```",
"MUST_TEXT": "```Responde cualquier mensaje```"
},
"heroku": {
"RESTART_DESC": "Reiniciar WhatsAsena",
"RESTART_MSG": "```reiniciando...```",
"SHUTDOWN_DESC": "Apagar WhatsAsena",
"SHUTDOWN_MSG": "```Apagando ⛔```",
"DYNO_DESC": "Verificar el uso de heroku dyno",
"DYNO_TOTAL": "```Cuota total```",
"DYNO_USED": "```Cuota utilizada```",
"PERCENTAGE": "```Porcentaje```",
"DYNO_LEFT": "```Restante```",
"SETVAR_DESC": "conjunto heroku config var",
"SET_SUCCESS": "Establecido con éxito ```{} ➜ {}```",
"KEY_VAL_MISSING": "```Falta la key o el value```",
"INVALID": "```Clave no válida: formato de valor```",
"GETVAR_DESC": "obtener heroku config var",
"DELVAR_DESC": "Eliminar heroku config var",
"DEL_SUCCESS": "```{} eliminado con éxito```",
"NOT_FOUND": "```no se encontraron resultados para esta key```"
},
"filters": {
"FILTER_DESC": "Agrega un filtro. Si alguien escribe el filtro que escribiste, envía la respuesta que escribiste. Si solo escribe filtro, devuelve los filtros que agregó.",
"NO_FILTER": "*❌ ¡No hay filtros en este chat!*",
Expand Down
19 changes: 19 additions & 0 deletions language/HI.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,25 @@
"NEED_REPLY": "```कृपया एक संदेश का जवाब दें!```",
"MUST_TEXT": "```कृपया किसी भी संदेश का जवाब दें```"
},
"heroku": {
"RESTART_DESC": "WhatsAsena को फिर से शुरू करें",
"RESTART_MSG": "```पुनरारंभ करते हुए प्रतीक्षा करें...```",
"SHUTDOWN_DESC": "WhatsAsena को बंद करो",
"SHUTDOWN_MSG": "```बंद कर रहा है ⛔```",
"DYNO_DESC": "heroku dyno उपयोग की जाँच करें",
"DYNO_TOTAL": "```कुल कोटा```",
"DYNO_USED": "```उपयोग किया कोटा```",
"PERCENTAGE": "```प्रतिशत```",
"DYNO_LEFT": "```शेष```",
"SETVAR_DESC": "सेट heroku config var",
"SET_SUCCESS": "सफलतापूर्वक सेट किया गया ```{} ➜ {}```",
"KEY_VAL_MISSING": "```या तो key या value गायब है```",
"INVALID": "```अमान्य key:value स्वरूप```",
"GETVAR_DESC": "heroku config var को प्राप्त करना",
"DELVAR_DESC": "heroku config var को हटाना",
"DEL_SUCCESS": "```{} सफलतापूर्वक हटा दिया गया```",
"NOT_FOUND": "```इस key के लिए कोई परिणाम नहीं मिले```"
},
"filters": {
"FILTER_DESC": "यह एक फिल्टर जोड़ता है. अगर कोई आपका फ़िल्टर लिखता है, यह जवाब भेजता है. अगर तुम सिर्फ लिखो. filter, यह आपकी फ़िल्टर सूची दिखाता है।",
"NO_FILTER": "*❌ इस चैट में कोई फ़िल्टर नहीं हैं!*",
Expand Down
19 changes: 19 additions & 0 deletions language/ID.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,25 @@
"TERM_DESC": "Memungkinkan untuk menjalankan perintah di shell server.",
"GIVE_ME_CODE": "*Beri aku kode!*"
},
"heroku": {
"RESTART_DESC": "Mulai ulang WhatsAsena",
"RESTART_MSG": "```memulai ulang harap tunggu...```",
"SHUTDOWN_DESC": "Matikan WhatsAsena",
"SHUTDOWN_MSG": "```mematikan ⛔```",
"DYNO_DESC": "Periksa penggunaan heroku dyno",
"DYNO_TOTAL": "```Total Kuota```",
"DYNO_USED": "```Kuota terpakai```",
"PERCENTAGE": "```Persentase```",
"DYNO_LEFT": "```Sisa```",
"SETVAR_DESC": "Set heroku config var",
"SET_SUCCESS": "Berhasil disetel ```{} ➜ {}```",
"KEY_VAL_MISSING": "```Baik Kunci atau Nilai tidak ada```",
"INVALID": "```Kunci tidak valid: format nilai```",
"GETVAR_DESC": "Dapatkan heroku config var",
"DELVAR_DESC": "menghapus heroku config var",
"DEL_SUCCESS": "```{} berhasil dihapus```",
"NOT_FOUND": "```tidak ada hasil yang ditemukan untuk kunci ini```"
},
"nekobin": {
"NEKO_DESC": "Pesan yang dibalas akan ditambahkan ke nekobin.com.",
"NEED_REPLY": "```Harap balas pesan!```",
Expand Down
19 changes: 19 additions & 0 deletions language/ML.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,25 @@
"NEED_REPLY": "മറ്റേതെങ്കിലും മെസ്സേജിന് മറുപടിയായി അയക്കുക!",
"MUST_TEXT": "മറുപടി അയക്കുന്നത് ഒരു വാക്കിനയിരിക്കണം, മറ്റൊന്നും സ്വീകരിക്കുന്നതല്ല"
},
"heroku": {
"RESTART_DESC": "WhatsAsena യെ റീസ്റ്റാർട്ട് ചെയ്യുക",
"RESTART_MSG": "```റീസ്റ്റാർട്ട് ചെയ്യുന്നു..```",
"SHUTDOWN_DESC": "WhatsAsena യെ ഓഫ് ചെയ്യുക",
"SHUTDOWN_MSG": "```ഓഫ് ചെയ്യുന്നു ⛔```",
"DYNO_DESC": "heroku dyno ഉപയോഗം അറിയാൻ",
"DYNO_TOTAL": "```മൊത്തം ക്വാട്ട```",
"DYNO_USED": "```ഉപയോഗിച്ച ക്വാട്ട```",
"PERCENTAGE": "```ശതമാനം```",
"DYNO_LEFT": "```ശേഷിക്കുന്ന```",
"SETVAR_DESC": "heroku config var സെറ്റ് ചെയ്യാൻ",
"SET_SUCCESS": "വിജയകരമായി സെറ്റ് ചെയ്തു ```{} ➜ {}```",
"KEY_VAL_MISSING": "```കീ അല്ലെങ്കിൽ വാല്യു നൽകിയിട്ടില്ല```",
"INVALID": "```കീ:വാല്യു ഫോർമാറ്റ് തെറ്റാണ്```",
"GETVAR_DESC": "heroku config var ലഭിക്കാൻ",
"DELVAR_DESC": "heroku config var നീക്കം ചെയ്യാൻ",
"DEL_SUCCESS": "```{} വിജയകരമായി നീക്കം ചെയ്തിരിക്കുന്നു```",
"NOT_FOUND": "```നിങൾ കൊടുത്ത ഈ കീ എനിക്ക് കണ്ടെത്താനായില്ല```"
},
"filters": {
"FILTER_DESC": "ഇത് ഒരു ഫിൽട്ടർ ചേർക്കുന്നു. ആരെങ്കിലും നിങ്ങളുടെ ഫിൽ‌റ്റർ‌ എഴുതുകയാണെങ്കിൽ‌, അത് ഉത്തരം അയയ്‌ക്കുന്നു. നിങ്ങൾ .filter എന്ന് എഴുതുകയാണെങ്കിൽ, അത് നിങ്ങളുടെ ഫിൽട്ടർ ലിസ്റ്റാണെന്ന് കാണിക്കുന്നു.",
"NO_FILTER": "*❌ യാതൊരു ഫിൽറ്റർ ആഡ് ചെയ്തിട്ടില്ല!*",
Expand Down
19 changes: 19 additions & 0 deletions language/TR.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,25 @@
"NEED_REPLY": "```Lütfen bir mesaja yanıt verin!```",
"MUST_TEXT": "```Lütfen herhangi bir mesajı yanıtlayın```"
},
"heroku": {
"RESTART_DESC": "WhatsAsena'yı yeniden başlatın",
"RESTART_MSG": "```yeniden başlatma...```",
"SHUTDOWN_DESC": "WhatsAsena'yı kapatın",
"SHUTDOWN_MSG": "```kapatmak ⛔```",
"DYNO_DESC": "Heroku dyno kullanımını kontrol edin",
"DYNO_TOTAL": "```Toplam Kota```",
"DYNO_USED": "```Kullanılan kota```",
"PERCENTAGE": "```Yüzde```",
"DYNO_LEFT": "```Kalan```",
"SETVAR_DESC": "Ayarlamak heroku config var",
"SET_SUCCESS": "Başarıyla ayarlandı ```{} ➜ {}```",
"KEY_VAL_MISSING": "```key veya value eksik```",
"INVALID": "```Geçersiz key: value biçimi```",
"GETVAR_DESC": "almak heroku config var",
"DELVAR_DESC": "Sil heroku config var",
"DEL_SUCCESS": "```{} başarıyla silindi```",
"NOT_FOUND": "```bu anahtar için sonuç bulunamadı```"
},
"filters": {
"FILTER_DESC": "Filtre ekler. Yazdığınız filtreyi birisi yazarsa yazdığınıı cevabı gönderir. Eğer sadece filter yazarsanız eklediğiniz filtreleri getirir.",
"NO_FILTER": "*❌ Bu sohbette hiç filter yok!*",
Expand Down
1 change: 1 addition & 0 deletions plugins/afk.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,4 @@ Asena.addCommand({pattern: 'afk ?(.*)', fromMe: true, deleteCommand: false, desc
}
}));

module.exports = { secondsToHms };
120 changes: 120 additions & 0 deletions plugins/heroku.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/*
Heroku plugin for WhatsAsena - W4RR10R
Licensed under the GPL-3.0 License;
you may not use this file except in compliance with the License.
WhatsAsena - Yusuf Usta
*/

const Asena = require('../events');
const Config = require('../config');
const Heroku = require('heroku-client');
const {secondsToHms} = require('./afk');
const got = require('got');
const Language = require('../language');
const Lang = Language.getString('heroku');

const heroku = new Heroku({
token: Config.HEROKU.API_KEY
});


let baseURI = '/apps/' + Config.HEROKU.APP_NAME;

Asena.addCommand({pattern: 'restart', fromMe: true, desc: Lang.RESTART_DESC}, (async (message, match) => {
await message.sendMessage(Lang.RESTART_MSG);
console.log(baseURI);
await heroku.delete(baseURI + '/dynos').catch(async (error) => {
await message.sendMessage(error.message);
});
}));

Asena.addCommand({pattern: 'shutdown', fromMe: true, desc: Lang.SHUTDOWN_DESC}, (async(message, match) => {
await heroku.get(baseURI + '/formation').then(async (formation) => {
forID = formation[0].id;
await message.sendMessage(Lang.SHUTDOWN_MSG);
await heroku.patch(baseURI + '/formation/' + forID, {
body: {
quantity: 0
}
});
}).catch(async (err) => {
await message.sendMessage(error.message);
});
}));

Asena.addCommand({pattern: 'dyno', fromMe: true, desc: Lang.DYNO_DESC}, (async (message, match) => {
heroku.get('/account').then(async (account) => {
// have encountered some issues while calling this API via heroku-client
// so let's do it manually
url = "https://api.heroku.com/accounts/" + account.id + "/actions/get-quota"
headers = {
"User-Agent": "Chrome/80.0.3987.149 Mobile Safari/537.36",
"Authorization": "Bearer " + Config.HEROKU.API_KEY,
"Accept": "application/vnd.heroku+json; version=3.account-quotas",
}
await got(url, {headers: headers}).then(async (res) => {
const resp = JSON.parse(res.body);
total_quota = Math.floor(resp.account_quota);
quota_used = Math.floor(resp.quota_used);
percentage = Math.round((quota_used / total_quota) * 100);
remaining = total_quota - quota_used;
await message.sendMessage(
Lang.DYNO_TOTAL + ": ```{}```\n\n".format(secondsToHms(total_quota)) +
Lang.DYNO_USED + ": ```{}```\n".format(secondsToHms(quota_used)) +
Lang.PERCENTAGE + ": ```{}```\n\n".format(percentage) +
Lang.DYNO_LEFT + ": ```{}```\n".format(secondsToHms(remaining))
);
}).catch(async (err) => {
await message.sendMessage(err.message);
});
});
}));

Asena.addCommand({pattern: 'setvar ?(.*)', fromMe: true, desc: Lang.SETVAR_DESC}, (async(message, match) => {
if (match[1] === '') return await message.sendMessage(Lang.KEY_VAL_MISSING);
if ((varKey = match[1].split(':')[0]) && (varValue = match[1].split(':')[1])) {
await heroku.patch(baseURI + '/config-vars', {
body: {
[varKey]: varValue
}
}).then(async (app) => {
await message.sendMessage(Lang.SET_SUCCESS.format(varKey, varValue));
});
} else {
await message.sendMessage(Lang.INVALID);
}
}));


Asena.addCommand({pattern: 'delvar ?(.*)', fromMe: true, desc: Lang.DELVAR_DESC}, (async (message, match) => {
if (match[1] === '') return await message.reply(Lang.KEY_VAL_MISSING);
await heroku.get(baseURI + '/config-vars').then(async (vars) => {
key = match[1].trim();
for (vr in vars) {
if (key == vr) {
await heroku.patch(baseURI + '/config-vars', {
body: {
[key]: null
}
});
return await message.sendMessage(Lang.DEL_SUCCESS.format(key));
}
}
await message.sendMessage(Lang.NOT_FOUND);
}).catch(async (error) => {
await message.sendMessage(error.message);
});

}));

Asena.addCommand({pattern: 'getvar ?(.*)', fromMe: true, desc: Lang.GETVAR_DESC}, (async (message, match) => {
if (match[1] === '') return await message.reply(Lang.KEY_VAL_MISSING);
await heroku.get(baseURI + '/config-vars').then(async (vars) => {
for (vr in vars) {
if (match[1].trim() == vr) return await message.sendMessage("```{} - {}```".format(vr, vars[vr]));
}
await message.sendMessage(Lang.NOT_FOUND);
}).catch(async (error) => {
await message.sendMessage(error.message);
});
}));

0 comments on commit 6ed0b19

Please sign in to comment.