Commit f5931e2d authored by Daniel Pérez Fernández's avatar Daniel Pérez Fernández 🕶
Browse files

New command /save, translation updates

- New command /save to forward msg to private chat with bot
- Disable poll command in index.js (I wait for api official update)
- Fixed missing translation in endpoll command
- Minor improvements
parent 29b3ea1c
......@@ -30,4 +30,5 @@ const error = require('./src/settings/log_error');
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 poll = require('./src/commands/plugins/poll');
const savemsg = require('./src/commands/plugins/savemsg');
......@@ -2,65 +2,65 @@
const app = require('../../settings/app');
app.bot.onText(/^\!poll|^\/poll/, function(msg) {
app.bot.onText(/^\!poll|^\/poll/, function (msg) {
var texto = msg.text.substring(5);
var texto = msg.text.substring(5);
var array = texto.split(";"); // Conver text to Array
if (array.length >= 3) { // Check if array have 3 elements
var array = texto.split(";"); // Conver text to Array
if (array.length >= 3) { // Check if array have 3 elements
//Loop to remove spaces from the array at the end and beginning
for (var i = 0; i <= (array.length - 1); i++) {
var mod_array = array[i].trim(); // Temporarily save the text without spaces
array.splice(i, 1,mod_array); // Save the text without spaces in "array"
}
// Loop to trim the text within the values ​​allowed by the API
for (var i = 0; i <= (array.length - 1); i++){
if (i == 0) {
var aux = array[i].substr(0,254); // "Cut" the string of the question due max 255 characters allow
array.splice(i, 1,aux);
}
else{
var aux = array[i].substr(0,99); // "Cut" the string options due max 100 characters allow
array.splice(i, 1,aux);
}
}
//Loop to remove spaces from the array at the end and beginning
for (var i = 0; i <= (array.length - 1); i++) {
var mod_array = array[i].trim(); // Temporarily save the text without spaces
array.splice(i, 1, mod_array); // Save the text without spaces in "array"
}
// Loop to trim the text within the values ​​allowed by the API
for (var i = 0; i <= (array.length - 1); i++) {
if (i == 0) {
var aux = array[i].substr(0, 254); // "Cut" the string of the question due max 255 characters allow
array.splice(i, 1, aux);
}
else {
var aux = array[i].substr(0, 99); // "Cut" the string options due max 100 characters allow
array.splice(i, 1, aux);
}
}
var options_poll = []; // Create an empty array to save the answers
var options_poll = []; // Create an empty array to save the answers
// Loop to save answers in new array called "options poll"
for (var i = 1; i <= (array.length - 1); i++){ // "var i" strart with element 1 of the array, because element 0 is the question
if (i <= 10) { // Only save array positions 1 to 10
var aux = array[i];
options_poll.splice(i - 1, 1,aux);
}
}
// Loop to save answers in new array called "options poll"
for (var i = 1; i <= (array.length - 1); i++) { // "var i" strart with element 1 of the array, because element 0 is the question
if (i <= 10) { // Only save array positions 1 to 10
var aux = array[i];
options_poll.splice(i - 1, 1, aux);
}
}
// Checking Chat Type -- Comprobación del tipo de Chat
if(msg.chat.type == 'private'){
app.bot.sendMessage(msg.chat.id, app.i18n.__('Command only available for supergroups'));
}
else{
app.bot.deleteMessage(msg.chat.id, msg.message_id);
app.bot.sendPoll(msg.chat.id, array[0], options_poll,{parse_mode : "Markdown"});
}
// Error when the array has less than 3 elements
}else{
app.bot.sendMessage(msg.chat.id, app.i18n.__('⛔️ Error, the poll has to have a minimum of two options\n Example: /poll Question; Answer 1; Answer 2'),{parse_mode : "Markdown"});
}
// Checking Chat Type -- Comprobación del tipo de Chat
if (msg.chat.type == 'private') {
app.bot.sendMessage(msg.chat.id, app.i18n.__('Command only available for supergroups'));
}
else {
app.bot.deleteMessage(msg.chat.id, msg.message_id);
app.bot.sendPoll(msg.chat.id, array[0], options_poll, { parse_mode: "Markdown" });
}
// Error when the array has less than 3 elements
} else {
app.bot.sendMessage(msg.chat.id, app.i18n.__('⛔️ Error, the poll has to have a minimum of two options\n Example: /poll Question; Answer 1; Answer 2'), { parse_mode: "Markdown" });
}
});
app.bot.onText(/^\!endpoll|^\/endpoll/, function(msg) {
app.bot.onText(/^\!endpoll|^\/endpoll/, function (msg) {
var chat_id = msg.chat.id;
try {
var replyId_messageId = msg.reply_to_message.message_id;
if (msg.reply_to_message.poll.is_closed == true){
if (msg.reply_to_message.poll.is_closed == true) {
app.bot.sendMessage(msg.chat.id, "Encuesta previamente cerrada");
}
if (msg.reply_to_message.poll.is_closed == false){ // Check if poll is not close
app.bot.stopPoll(msg.chat.id,replyId_messageId); // Close Poll
if (msg.reply_to_message.poll.is_closed == false) { // Check if poll is not close
app.bot.stopPoll(msg.chat.id, replyId_messageId); // Close Poll
}
} catch (error) {
app.bot.sendMessage(chat_id, "Tienes que responder directamente al mensaje de la encuesta con el comando /endpoll");
app.bot.sendMessage(chat_id, app.i18n.__('You need to reply to poll message with the command /endpoll'));
}
});
\ No newline at end of file
'use strict';
const app = require('../../settings/app');
app.bot.onText(/^\!save|^\/save/, function(msg) {
try {
var userid = msg.from.id; // id of user
var chat_id = msg.chat.id; // id of the original "msg" chat to forward
var msg_id = msg.reply_to_message.message_id; // id of the msg to forward
app.bot.forwardMessage(userid,chat_id,msg_id).then(function(resp) {
// console.log("OK");
}).catch(function(error) {
if (error.response && error.response.statusCode === 403) { // Error 403: Bot was blocked by the user
app.bot.sendMessage(chat_id, app.i18n.__('⛔️ I can not send you messeges, you should start me first in private'));
}
});
} catch (error) {
app.bot.sendMessage(chat_id, app.i18n.__('⛔️ Error, you need to reply a messege for save it'));
}
});
\ No newline at end of file
......@@ -59,5 +59,7 @@
"\nI can add users: " : "\nI can add users: ",
"\nI can restrict users: " : "\nI can restrict users: ",
"\nI can pin messages: " : "\nI can pin messages: ",
"\nI can add administrators: " : "\nI can add administrators: "
}
"\nI can add administrators: " : "\nI can add administrators: ",
"⛔️ Error, you need to reply a messege for save it" : "⛔️ Error, you need to reply a messege for save it",
"⛔️ I can not send you messeges, you should start me first in private" : "⛔️ I can not send you messeges, you should start me first in private"
}
\ No newline at end of file
......@@ -59,5 +59,7 @@
"\nI can add users: " : "\nPuedo añadir usuarios: ",
"\nI can restrict users: " : "\nPuedo restringir usuarios: ",
"\nI can pin messages: " : "\nPuedo anclar mensajes: ",
"\nI can add administrators: " : "\nPuedo añadir administradores: "
"\nI can add administrators: " : "\nPuedo añadir administradores: ",
"⛔️ Error, you need to reply a messege for save it" : "⛔️ Error, necesitas responder al mensaje para poder guardarlo",
"⛔️ I can not send you messeges, you should start me first in private" : "⛔️ Yo no puedo enviarte mensajes, debes hablarme tu primero por privado"
}
\ 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