Commit 4801ed8b authored by Negan's avatar Negan
Browse files

Added /cpanel command

parent 45ce0f69
......@@ -3,32 +3,33 @@ const config = require('./src/settings/config');
const app = require('./src/settings/app');
const error = require('./src/settings/log_error');
// Welcome event and "First time" with the bot -- Evento bienvenida y "Primera vez" con el bot
const start = require('./src/commands/initial_commands/start');
const welcome = require('./src/commands/initial_commands/welcome');
// Welcome event and "First time" with the bot -- Evento bienvenida y "Primera vez" con el bot
const start = require('./src/commands/initial_commands/start');
const welcome = require('./src/commands/initial_commands/welcome');
// Group commands -- Comandos grupales
const pin_unpin = require('./src/commands/groups/pin_unpin');
const exportInviteLink = require('./src/commands/groups/exportInviteLink');
const admin = require('./src/commands/groups/admin');
const mod_unmod = require('./src/commands/groups/mod_unmod');
// Group commands -- Comandos grupales
const pin_unpin = require('./src/commands/groups/pin_unpin');
const exportInviteLink = require('./src/commands/groups/exportInviteLink');
const admin = require('./src/commands/groups/admin');
const mod_unmod = require('./src/commands/groups/mod_unmod');
// Restrictive commands -- Comandos restrictivos
const ban_unban = require('./src/commands/restrict/ban_unban');
const mute_unmute = require('./src/commands/restrict/mute_unmute');
const kick = require('./src/commands/restrict/kick');
// Essentials -- Imprescindibles
const getids = require('./src/commands/plugins/getids');
// Testing
const check = require('./src/commands/test/check');
// Plugins
if(config.token_imgur != ""){
// Restrictive commands -- Comandos restrictivos
const ban_unban = require('./src/commands/restrict/ban_unban');
const mute_unmute = require('./src/commands/restrict/mute_unmute');
const kick = require('./src/commands/restrict/kick');
// Essentials -- Imprescindibles
const getids = require('./src/commands/plugins/getids');
// Testing
const check = require('./src/commands/test/check');
// Plugins
if (config.token_imgur != "") {
const imgur = require('./src/commands/plugins/imgur');
}
const weather = require('./src/commands/plugins/weather');
const webshot = require('./src/commands/plugins/webshot');
const qr = require('./src/commands/plugins/qr');
const archiveorg = require('./src/commands/plugins/archiveorg');
const progeso_ano = require('./src/commands/plugins/progreso_ano');
const poll = require('./src/commands/plugins/poll');
const savemsg = require('./src/commands/plugins/savemsg');
}
const weather = require('./src/commands/plugins/weather');
const webshot = require('./src/commands/plugins/webshot');
const qr = require('./src/commands/plugins/qr');
const archiveorg = require('./src/commands/plugins/archiveorg');
const progeso_ano = require('./src/commands/plugins/progreso_ano');
const poll = require('./src/commands/plugins/poll');
const savemsg = require('./src/commands/plugins/savemsg');
const cpanel = require('./src/commands/plugins/cpanel');
var app = require('../../settings/app');
var database = require('../../database/database');
app.bot.onText(/^\/cpanel/, (msg) => {
if (msg.chat.type == 'private') {
app.bot.removeListener('callback_query');
database.viewUser(msg.from).then((user) => {
if (user.code == true) {
var content = user.content;
if (content.lang != undefined) {
app.i18n.setLocale(content.lang);
app.bot.sendMessage(msg.chat.id, app.i18n.__('change_lang_text'), {
parse_mode: 'HTML',
reply_markup: {
inline_keyboard: [
[{ text: app.i18n.__('change_lang_button'), callback_data: `changeLang_${content.user_id}` }]
]
}
}).then(() => {
cbLang();
})
} else {
app.bot.sendMessage(content.user_id, `🇪🇸 Selecciona el idioma\n🇺🇸 Select the language`, {
parse_mode: 'HTML',
reply_markup: {
inline_keyboard: [
[{ text: `🇪🇸`, callback_data: `setLang_es` }],
[{ text: `🇺🇸`, callback_data: `setLang_en` }]
]
}
}).then(() => {
cbLang();
})
}
}
})
}
})
var cbLang = (() => {
app.bot.addListener('callback_query', (lang_action) => {
var menu = {};
menu.chat = lang_action.message.chat;
menu.message = lang_action.message;
menu.user = lang_action.from;
menu.data = lang_action.data.split("_");
switch (menu.data[0]) {
case 'setLang':
database.setLanguage(menu.user, menu.data[1]).then((user) => {
if (user.code == true) {
var user_content = user.content;
console.log(user_content)
app.i18n.setLocale(user_content.lang)
app.bot.editMessageText(app.i18n.__('predet_lang'), {
parse_mode: 'HTML',
chat_id: menu.chat.id,
message_id: menu.message.message_id,
reply_markup: {
inline_keyboard: [
[{ text: app.i18n.__('change_lang_button'), callback_data: `changeLang_${user_content.user_id}` }]
]
}
});
}
})
break;
case 'changeLang':
//console.log(menu);
app.bot.editMessageText(`🇪🇸 Selecciona el idioma\n🇺🇸 Select the language`, {
chat_id: menu.chat.id,
message_id: menu.message.message_id,
parse_mode: 'HTML',
reply_markup: {
inline_keyboard: [
[{ text: `🇪🇸`, callback_data: `setNewLang_es_${menu.user.id}` }],
[{ text: `🇺🇸`, callback_data: `setNewLang_en_${menu.user.id}` }]
]
}
})
break;
case 'setNewLang':
//console.log(menu)
database.changeLanguage(menu.user, menu.data[1]).then((userUpdateLang) => {
if (userUpdateLang.code == true) {
//console.log(userUpdateLang)
var user = userUpdateLang.content;
app.i18n.setLocale(user.lang);
app.bot.editMessageText(app.i18n.__('predet_lang'), {
chat_id: menu.chat.id,
message_id: menu.message.message_id,
parse_mode: 'HTML',
reply_markup: {
inline_keyboard: [
[{ text: app.i18n.__('change_lang_button'), callback_data: `changeLang_${user.user_id}` }]
]
}
})
}
})
break;
}
})
})
var app = require('../settings/app');
var databaseFn = {};
databaseFn.viewUser = ((userInfo) => {
return new Promise((resolve, reject) => {
app.Database.users.findOne({ "user_id": String(userInfo.id) }, (err, docs) => {
if (err) throw reject(err);
if (docs == null) {
// Hemos condicionado que si el usuario tiene @alias lo guarde, en caso contrario que lo ignore
if (userInfo.username != undefined) {
app.Database.users.insert({ "name": userInfo.first_name, "user_id": String(userInfo.id), "username": userInfo.username }, (err, docsNew) => {
if (err) throw reject(err);
resolve({
code: true,
content: docsNew
})
})
} else {
app.Database.users.insert({"name": userInfo.first_name, "user_id": String(userInfo.id),}, (err, docsNewNotUsername) => {
if (err) throw reject(err);
resolve({
code: true,
content: docsNewNotUsername
})
})
}
} else {
resolve({
code: true,
content: docs
})
}
})
})
});
databaseFn.setLanguage = ((user, lang) => {
return new Promise((resolve, reject) => {
app.Database.users.findOne({ "user_id": String(user.id) }, (err, docs) => {
if (err) throw reject(err);
if (docs != null) {
if (docs.lang == undefined) {
app.Database.users.update({ "user_id": String(user.id) }, { $set: { "lang": lang } }, (err, updateLang) => {
if (err) throw reject(err);
if (updateLang === 1) {
databaseFn.viewUser(user).then((userInfo) => {
if (userInfo.code == true) {
resolve({
code: true,
content: userInfo.content
})
}
})
}
})
} else {
resolve({
code: true,
content: docs
})
}
}
})
})
});
databaseFn.changeLanguage = ((user, new_lang) => {
return new Promise((resolve, reject) => {
app.Database.users.update({
"user_id": String(user.id)
}, { $set: { "lang": new_lang } }, (err, updateLang) => {
if (err) throw reject(err);
if (updateLang === 1) {
//console.log(updateLang)
databaseFn.viewUser(user).then((userInfo) => {
if (userInfo.code == true) {
//console.log(userInfo)
resolve({
code: true,
content: userInfo.content
})
}
}).catch((err) => {
console.log(err)
})
}
})
})
})
module.exports = databaseFn;
\ No newline at end of file
{"name":"♊ Géminis | DXTER Prod.","user_id":"376181667","username":"IscoXXIV","_id":"WqHl73Uskc26FDRr"}
{"name":"♊ Géminis | DXTER Prod.","user_id":"376181667","username":"IscoXXIV","_id":"WqHl73Uskc26FDRr","lang":"es"}
......@@ -11,13 +11,14 @@ const bot = new TelegramBot(config.token_bot, { polling: true });
const rp = require('request-promise')
//Base de datos
const Datastore = require('nedb'), db = new Datastore();
const Datastore = require('nedb');
db.users = new Datastore('./src/database/users.db');
db.chats = new Datastore('./src/database/chats.db');
var Database = {};
Database.users = new Datastore('./src/database/users.db');
Database.chats = new Datastore('./src/database/chats.db');
db.users.loadDatabase();
db.chats.loadDatabase();
Database.users.loadDatabase();
Database.chats.loadDatabase();
// Client Imgur
const imgur = require('imgur');
......@@ -32,7 +33,6 @@ const moment = require('moment');
moment.locale('es');
// Multilang Bot
const i18n = require('i18n');
i18n.configure({
......@@ -44,4 +44,4 @@ i18n.configure({
});
// Modulos exportados
module.exports = { bot, rp, db, imgur, weather, moment, i18n }
module.exports = { bot, rp, Database, imgur, weather, moment, i18n }
'use strict';
module.exports = {
/**
* @type {!string}
* //Token BotTelegram
*/
token_bot: '',
/**
* @type {!string}
* Token Imgur
*/
token_imgur: '' // Optional
}
\ No newline at end of file
......@@ -71,5 +71,9 @@
"hour": "hour",
"It's demutualized": "It's demutualized",
" has been kicked": " has been kicked",
"can rejoin the group": " (can rejoin the group)"
"can rejoin the group": " (can rejoin the group)",
"selectLang": "Select the language of the bot",
"change_lang_button": "🌐 Change Language",
"change_lang_text": "👉 Here you can change language",
"predet_lang": "<i>Okay, I'll set the <b>English</b> language as the default</i>"
}
\ No newline at end of file
......@@ -71,5 +71,9 @@
"hour": "hora",
"It's demutualized": "está desmuteado",
" has been kicked": " ha sido kickeado",
"can rejoin the group" : " (puede volver unirse al grupo)"
"can rejoin the group" : " (puede volver unirse al grupo)",
"selectLang": "Selecciona el lenguaje del bot",
"change_lang_button":"🌐 Cambiar idioma",
"change_lang_text": "👉 Aquí puedes cambiar el idioma",
"predet_lang": "<i>Está bien, estableceré el idioma <b>Español</b> como predeterminado</i>"
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment