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

Merge branch 'master' into 'master'

Update minor

See merge request !3
parents 28b25039 45ce0f69
Pipeline #141018251 failed with stage
in 35 seconds
......@@ -2,70 +2,80 @@
const app = require('../../settings/app');
// Como esta creado este comando solo funciona si el usuario que manda el mensaje
// No es ni creador ni administrador del grupo
// Debido a la siguiente condición "if (infouser.status == 'member')"
/**
* Como está creado este comando solo funciona si el usuario que invoca el comando NO es ni creador ni administrador dle grupo debido a la siguiente condición <<if (infoUser.status == 'member')>>
*
* Ahora, el bot crea los botones diferenciando de si el chat tiene un alias o no y en función de si es para el cliente oficial de Telegram o bien Telegram X. Esto sirve para poder acceder rápidamente al mensaje reportado.
*/
app.bot.onText(/^\@admin|^\@admins/, function(msg){
app.bot.onText(/^\@admin|^\@admins/, (msg) => {
if (msg.reply_to_message !== undefined) {
var chat = {};
chat.id = msg.chat.id;
chat.type = msg.chat.type;
chat.username = msg.chat.username;
chat.title = msg.chat.title;
if (msg.reply_to_message == undefined){
return;
}
var user = {};
user.id = msg.from.id;
user.name = msg.from.first_name;
user.reply = {};
user.reply.id = msg.reply_to_message.from.id;
user.reply.name = msg.reply_to_message.from.first_name;
const prop = {};
prop.chat_id = msg.chat.id;
prop.from_id = msg.from.id;
prop.type_chat = msg.chat.type;
prop.fromName = msg.from.first_name;
prop.message_id = msg.message_id;
prop.reply_message_id = msg.reply_to_message.message_id;
prop.username_chat = msg.chat.username;
prop.replyIdUser = msg.reply_to_message.from.id;
prop.replyNameUser = msg.reply_to_message.from.first_name;
prop.replyTextUser = msg.reply_to_message.text;
prop.titleChat = msg.chat.title;
var message = {};
message.id = msg.message_id;
message.reply = {};
message.reply.text = msg.reply_to_message.text;
message.reply.message_id = msg.reply_to_message.message_id;
var reply_buttons = {};
reply_buttons.reply_markup = {};
if (prop.type_chat == 'supergroup' && prop.username_chat != null) {
var deep_link = "https://t.me/" + prop.username_chat + "/" + prop.reply_message_id;
}
else {
if (prop.type_chat == 'supergroup' && prop.username_chat == undefined) {
var info_chat_id = String(prop.chat_id); // Conversion to String
var mod_chat_id = info_chat_id.substring(4).trim(); // Removes -100 of the "chat_id" for create the Deep Link
var deep_link = String("tg://openmessage?chat_id=" + mod_chat_id + "&message_id=" + prop.reply_message_id);
var deep_link_tgx = String("t.me" + mod_chat_id + "/" + prop.reply_message_id);
}
}
app.bot.getChatMember(prop.chat_id, prop.from_id).then(function(infouser){
if (infouser.status == 'member'){
app.bot.deleteMessage(prop.chat_id, prop.message_id);
app.bot.sendMessage(prop.chat_id, app.i18n.__('Notifying administrators')).then(function(deletemessage){
setTimeout(function(){
app.bot.deleteMessage(prop.chat_id, deletemessage.message_id);
},10000)
});
if (chat.type == 'supergroup' && chat.username == undefined) {
var mod_id = String(chat.id).substring(4).trim();
var deep_link = String(`tg://openmessage?chat_id=${mod_id}&message_id=${message.reply.message_id}`);
app.bot.getChatAdministrators(prop.chat_id).then(function(adminsgroup){
reply_buttons.reply_markup.inline_keyboard = [
[{ text: `${app.i18n.__('Go to the message')}`, url: `${deep_link}` }]
]
const properties = {};
} else if (chat.type == 'supergroup' && chat.username != null) {
var deep_link = `https://t.me/${chat.username}/${message.reply.message_id}`;
var deep_link_tgx = `t.me/${chat.username}/${message.reply.message_id}`
for (var i = 0; i < adminsgroup.length; i++){
properties.adminsinfo = adminsgroup[i].user
properties.id = adminsgroup[i].user.id
properties.bot = adminsgroup[i].user.is_bot
properties.name = adminsgroup[i].user.first_name
properties.alias = adminsgroup[i].user.username
properties.opts = {parse_mode: 'HTML'}
console.log(deep_link_tgx)
reply_buttons.reply_markup.inline_keyboard = [
[{ text: `${app.i18n.__('Go to the message')}`, url: `${deep_link}` }],
[{ text: `${app.i18n.__('Tg X: Go to the message')}`, url: `${deep_link_tgx}` }]
]
if (properties.bot == false){
app.bot.sendMessage(properties.adminsinfo.id, app.i18n.__('🛎 Alert: \n👨🏻‍💼 <b>Name:</b> ') + prop.fromName + "\n🆔 <b>Id:</b> <code>" + prop.from_id + app.i18n.__('</code>\n\n❌ <b>Offender:</b>\n🙅🏻‍♂️ <b>Name:</b> ') + prop.replyNameUser + "\n🆔 <b>Id:</b> <code>" + prop.replyIdUser + app.i18n.__('</code>\n📃 <b>Text with spam:</b> \n') + prop.replyTextUser + app.i18n.__('\n\n🏛 <b>In the group:</b> ') + prop.titleChat + "\n", {parse_mode: 'HTML', reply_markup:{ inline_keyboard: [[{text: app.i18n.__('Go to the message'), url: deep_link}],[{text: app.i18n.__('Tg X: Go to the message'), url: deep_link}]]}});
}
}
}
app.bot.getChatMember(chat.id, user.id).then((infoUser) => {
if (infoUser.status == 'member') {
app.bot.deleteMessage(chat.id, message.id);
app.bot.sendMessage(chat.id, app.i18n.__(`Notifying administrators`)).then((contentMessage) => {
setTimeout(() => {
app.bot.deleteMessage(contentMessage.chat.id, contentMessage.message_id)
}, 10000)
}).then(() => {
app.bot.getChatAdministrators(chat.id).then((administrators) => {
for (var i = 0; i < administrators.length; i++) {
if (administrators[i].user.is_bot == false) {
app.bot.sendMessage(administrators[i].user.id, `${app.i18n.__('🛎 Alert: \n👨🏻‍💼 <b>Name:</b> ')} ${user.name}\n🆔 <b>Id:</b> <code>${user.id} ${app.i18n.__('</code>\n\n❌ <b>Offender:</b>\n🙅🏻‍♂️ <b>Name:</b> ')}${user.reply.name}\n🆔 <b>Id:</b> <code>${user.reply.id} ${app.i18n.__('</code>\n📃 <b>Text with spam:</b> \n')} ${message.reply.text} ${app.i18n.__('\n\n🏛 <b>In the group:</b> ')}${chat.title} \n`, {
parse_mode: 'HTML',
reply_markup: reply_buttons.reply_markup
})
}else{
app.bot.sendMessage(prop.chat_id, app.i18n.__('This command is exclusive for users. Its function is to send alerts to the admins.'));
}
}
})
})
});
} else {
app.bot.sendMessage(chat.id, `${app.i18n.__('This command is exclusive for users. Its function is to send alerts to the admins.')}`)
}
})
}
})
\ No newline at end of file
......@@ -2,25 +2,26 @@
const app = require('../../settings/app');
app.bot.onText(/^\!link|^\/link/, function(msg){
app.bot.onText(/^\!link|^\/link/, (msg) => {
var chat = {};
chat.id = msg.chat.id;
chat.type = msg.chat.type;
chat.message_id = msg.message_id;
const prop = {
'chat_id': msg.chat.id,
'from_id': msg.from.id,
'chatType': msg.chat.type
}
var user = {};
user.id = msg.from.id;
if ((prop.chatType == 'supergroup')|| (prop.chatType == 'group')){
app.bot.getChatMember(prop.chat_id, prop.from_id).then(function(infouser){
if ((infouser.status == 'creator') || (infouser.status == 'administrator')){
app.bot.exportChatInviteLink(prop.chat_id).then(function(link){
var url = link;
app.bot.sendMessage(prop.chat_id, app.i18n.__('Group link: \n') + url);
});
if ((chat.type == 'supergroup') || (chat.type == 'group')) {
app.bot.getChatMember(chat.id, user.id).then((infoUser) => {
if ((infoUser.status == 'creator') || (infoUser.status == 'administrator')) {
app.bot.exportChatInviteLink(chat.id).then((url_export) => {
app.bot.sendMessage(chat.id, `${app.i18n.__('Group link: \n')} ${url_export.link}`);
})
} else {
app.bot.deleteMessage(prop.chat_id, msg.message_id);
app.bot.sendMessage(prop.chat_id, app.i18n.__('Command only available for admins and creator'));
app.bot.deleteMessage(chat.id, chat.message_id);
app.bot.sendMessage(chat.id, `${app.i18n.__('Command only available for admins and creator')}`)
}
})
}
})
......@@ -2,82 +2,78 @@
const app = require('../../settings/app');
app.bot.onText(/^\!mod|^\/mod/, function(msg) {
if (msg.reply_to_message == undefined){
app.bot.onText(/^\!mod|^\/mod/, (msg) => {
if (msg.reply_to_message !== undefined) {
var permisos = require('../../settings/perms');
var chat = {};
chat.id = msg.chat.id;
chat.type = msg.chat.type;
chat.message_id = msg.message_id;
var user = {};
user.id = msg.from.id;
user.reply = {};
user.reply.id = msg.reply_to_message.from.id;
user.reply.name = msg.reply_to_message.from.first_name;
app.bot.getChatMember(chat.id, user.id).then((infoUser) => {
if ((infoUser.status == 'creator')) {
if (chat.type == 'supergroup') {
app.bot.promoteChatMember(chat.id, user.reply.id, permisos.true).then((newAdmin) => {
if (newAdmin == true) {
app.bot.deleteMessage(chat.id, chat.message_id);
app.bot.sendMessage(chat.id, `✅ ${user.reply.name}${app.i18n.__(' , you are now an administrator.')}`)
}
}).catch((err) => {
if (err) {
app.bot.sendMessage(chat.id, `${app.i18n.__('🤖 The bot does not have permissions to add new administrators')}`, {
parse_mode: 'HTML'
})
}
})
} else {
app.bot.sendMessage(chat.id, `${app.i18n.__('Command only available for supergroups')}`)
}
} else {
app.bot.sendMessage(chat.id, `${app.i18n.__('⛔️ Only the creator of the group can use this command')}`)
}
})
} else {
return;
};
const opts = {
'chat_id': msg.chat.id,
'userReplyName': msg.reply_to_message.from.first_name,
'fromId': msg.from.id,
'messageId': msg.message_id,
'userReplyId': msg.reply_to_message.from.id,
'chatType': msg.chat.type
};
const permisos = {};
permisos.can_change_info = false;
permisos.can_delete_messages = true;
permisos.can_invite_users = true;
permisos.can_restrict_members = true;
permisos.can_pin_messages = true;
permisos.can_promote_members = false;
app.bot.getChatMember(opts.chat_id, opts.fromId).then(function(data){
if ((data.status == 'creator')){
if (opts.chatType == 'supergroup'){
app.bot.promoteChatMember(opts.chat_id, opts.userReplyId, permisos).then(function(result){
app.bot.deleteMessage(opts.chat_id, opts.messageId);
app.bot.sendMessage(opts.chat_id, "" + opts.userReplyName + app.i18n.__(' , you are now an administrator.'));
});
} else{app.bot.sendMessage(opts.chat_id, app.i18n.__('Command only available for supergroups'));}
}
else {
app.bot.sendMessage(opts.chat_id, app.i18n.__('⛔️ Only the creator of the group can use this command'));
}
})
}
});
app.bot.onText(/^\!unmod|^\/unmod/, function(msg) {
if (msg.reply_to_message == undefined){
app.bot.onText(/^\!unmod|^\/unmod/, (msg) => {
if (msg.reply_to_message !== undefined) {
var permisos = require('../../settings/perms');
var chat = {};
chat.id = msg.chat.id;
chat.type = msg.chat.type;
chat.message_id = msg.message_id;
var user = {};
user.id = msg.from.id;
user.reply = {};
user.reply.id = msg.reply_to_message.from.id;
user.reply.name = msg.reply_to_message.from.first_name;
app.bot.getChatMember(chat.id, user.id).then((infoUser) => {
if ((infoUser.status == 'creator')){
if (chat.type == 'supergroup'){
app.bot.promoteChatMember(chat.id, user.reply.id, permisos.false).then((degradateUser) => {
if (degradateUser == true){
app.bot.deleteMessage(chat.id, chat.message_id);
app.bot.sendMessage(chat.id, `❌ ${user.reply.name}${app.i18n.__(' , you are not an administrator')}`)
}
})
} else {
app.bot.sendMessage(chat.id, `${app.i18n.__('Command only available for supergroups')}`)
}
} else {
app.bot.sendMessage(chat.id, `${app.i18n.__('⛔️ Only the creator of the group can use this command')}`)
}
})
} else {
return;
};
const opts = {
'chat_id': msg.chat.id,
'userReplyName': msg.reply_to_message.from.first_name,
'fromId': msg.from.id,
'messageId': msg.message_id,
'userReplyId': msg.reply_to_message.from.id
};
const permisos = {};
permisos.can_change_info = false;
permisos.can_delete_messages = false;
permisos.can_invite_users = false;
permisos.can_restrict_members = false;
permisos.can_pin_messages = false;
permisos.can_promote_members = false;
app.bot.getChatMember(opts.chat_id, opts.fromId).then(function(data){
if ((data.status == 'creator')){
if (opts.chatType == 'supergroup'){
app.bot.promoteChatMember(opts.chat_id, opts.userReplyId, permisos).then(function(result){
app.bot.deleteMessage(opts.chat_id, opts.messageId);
app.bot.sendMessage(opts.chat_id, "" + opts.userReplyName + app.i18n.__(' , you are not an administrator'));
});
} else{app.bot.sendMessage(opts.chat_id, app.i18n.__('Command only available for supergroups'));}
}
else {
app.bot.sendMessage(opts.chat_id, app.i18n.__('⛔️ Only the creator of the group can use this command'));
}
})
});
}
})
\ No newline at end of file
'use strict';
const app = require('../../settings/app')
app.bot.onText(/^\!pin|^\/pin/, function(msg){
if (msg.reply_to_message == undefined){
app.bot.sendMessage(msg.chat.id, app.i18n.__('To use the !pin command you need to reply to the message you want to anchor'));
return;
};
app.bot.onText(/^\!pin|^\/pin/, (msg) => {
if (msg.reply_to_message !== undefined){
var chat = {};
chat.id = msg.chat.id;
chat.type = msg.chat.type;
chat.messageId = msg.message_id;
chat.reply = {};
chat.reply.messageId = msg.reply_to_message.message_id;
var user = {};
user.id = msg.from.id;
const prop = {
'chat_id': msg.chat.id,
'from_id': msg.from.id,
'messageId': msg.message_id,
'chatType': msg.chat.type,
'replyMsg': msg.reply_to_message.message_id
};
const opts = {};
opts.disable_notification = false;
var options = {};
options.disable_notification = false;
app.bot.getChatMember(prop.chat_id, prop.from_id).then(function(data){
if ((data.status == 'creator')|| (data.status == 'administrator')){
if ((prop.chatType == 'supergroup')||(prop.chatType == 'group')){
app.bot.pinChatMessage(prop.chat_id, prop.replyMsg, opts);
app.bot.deleteMessage(prop.chat_id, prop.messageId);
} else if (prop.chatType == 'private'){
app.bot.sendMessage(prop.chat_id, app.i18n.__('Command only available for supergroups'));
app.bot.getChatMember(chat.id, user.id).then((infoUser) => {
if ((infoUser.status == 'creator') || (infoUser.status == 'administrator')){
if ((chat.type == 'supergroup') || (chat.type == 'group')){
app.bot.pinChatMessage(chat.id, chat.reply.messageId, options);
app.bot.deleteMessage(chat.id, chat.messageId)
} else if (chat.type == 'private'){
app.bot.sendMessage(chat.id, `${app.i18n.__('Command only available for supergroups')}`)
}
} else {
app.bot.sendMessage(chat.id, `${app.i18n.__('Command only available for admins and creator')}`)
}
} else {
app.bot.sendMessage(prop.chat_id, app.i18n.__('Command only available for admins and creator'));
}
})
});
})
}
})
app.bot.onText(/^\!unpin|^\/unpin/, function(msg){
app.bot.onText(/^\!unpin|^\/unpin/, (msg) => {
var chat = {};
var user = {};
const prop = {
'chat_id': msg.chat.id,
'from_id': msg.from.id,
'messageId': msg.message_id,
'chatType': msg.chat.type
}
chat.id = msg.chat.id;
chat.messageId = msg.message_id;
chat.type = msg.chat.type;
user.id = msg.from.id;
app.bot.getChatMember(prop.chat_id, prop.from_id).then(function(data){
if ((data.status == 'creator') || (data.status == 'administator')){
if ((prop.chatType == 'supergroup')||(prop.chatType == 'group')){
app.bot.deleteMessage(prop.chat_id, prop.messageId);
app.bot.unpinChatMessage(prop.chat_id)
} else {
app.bot.sendMessage(prop.chat_id, app.i18n.__('Command only available for supergroups'));
}
app.bot.getChatMember(chat.id, user.id).then((infoUser) => {
if ((infoUser.status == 'creator') || (infoUser.status == 'administrator')){
if ((chat.type == 'supergroup') || (chat.type == 'group')){
app.bot.unpinChatMessage(chat.id);
app.bot.deleteMessage(chat.id, chat.messageId);
} else {
app.bot.sendMessage(chat.id, `${app.i18n.__('Command only available for supergroups')}`)
}
} else {
bot.sendMessage(prop.chat_id, app.i18n.__('Sorry, you are not an admin'));
app.bot.sendMessage(chat.id, `${app.i18n.__('Sorry, you are not an admin')}`)
}
})
});
})
'use strict';
const app = require('../../settings/app')
app.bot.onText(/\/start (.+)|\/start/i, function(msg, match){
app.bot.onText(/\/start (.+)|^\/start/i, (msg, match) => {
let invite_code;
var chat = {};
chat.id = msg.chat.id;
var user = {};
user.id = msg.from.id;
user.name = msg.from.first_name;
var invite_code;
const prop = {
'chat_id': msg.chat.id,
'user_id': msg.from.id,
'userName': msg.from.first_name
}
if (match[1] != undefined){
invite_code = match[1];
app.bot.sendMessage(prop.chat_id, app.i18n.__('Hello ') + prop.userName + app.i18n.__(' with invitation code ') + invite_code)
}
else{
app.bot.sendMessage(prop.chat_id, app.i18n.__('Hello ') + prop.userName)
if (match[1] != undefined){
invite_code = match[1];
app.bot.sendMessage(chat.id, `${app.i18n.__('Hello ')} ${user.name} ${app.i18n.__(' with invitation code ')} ${invite_code}`)
} else {
app.bot.sendMessage(chat.id, `${app.i18n.__('Hello ')} ${user.name}`)
}
});
})
\ No newline at end of file
......@@ -2,37 +2,37 @@
const app = require('../../settings/app')
// "Welcome" to new users and "goodbyte"
// "Welcome" to new users and "goodbye"
app.bot.on('message', function(msg){
const prop = {
'chat_id': msg.chat.id,
'chatTitle': msg.chat.title,
'messageId': msg.message_id
}
var chat = {};
chat.id = msg.chat.id;
chat.title = msg.chat.title;
chat.messageId = msg.message_id;
if (msg.new_chat_members != undefined){
const newMember = {
'userId': msg.new_chat_member.id,
'username': msg.new_chat_member.first_name,
'userAlias': msg.new_chat_member.username
var newMember = {};
newMember.id = msg.new_chat_member.id;
newMember.name = msg.new_chat_member.first_name;
if (msg.new_chat_member.username !== undefined){
newMember.alias = msg.new_chat_member.username;
}
app.bot.deleteMessage(prop.chat_id, prop.messageId)
app.bot.sendMessage(prop.chat_id, app.i18n.__('Hello ') + newMember.username + app.i18n.__(', welcome to the group ') + prop.chatTitle)
app.bot.deleteMessage(chat.id, chat.messageId)
app.bot.sendMessage(chat.id, `${app.i18n.__('Hello ')}${newMember.name}${app.i18n.__(', welcome to the group ')}${chat.title}`)
}
else if (msg.left_chat_member != undefined){
const leftMember = {
'leftUserId': msg.left_chat_member.id,
'leftUsername': msg.left_chat_member.first_name,
'leftuserAlias': msg.left_chat_member.username
var leftMember = {};
leftMember.id = msg.left_chat_member.id;
leftMember.name = msg.left_chat_member.first_name;
if (msg.left_chat_member.username !== undefined){
leftMember.alias = msg.left_chat_member.username;
}
app.bot.deleteMessage(prop.chat_id, prop.messageId)
app.bot.sendMessage(prop.chat_id, leftMember.leftUsername + app.i18n.__(' left the group'))
app.bot.deleteMessage(chat.id, chat.messageId)
app.bot.sendMessage(chat.id, `${leftMember.name}${app.i18n.__(' left the group')}`)
}
});
'use strict';
var app = require('../../settings/app');
const app = require('../../settings/app');
/**
* Information for the correct functioning of this plugin:
* Remember to apply in the 'app.js' file
......@@ -11,101 +11,98 @@ const app = require('../../settings/app');
* From there, the code should work correctly.
*/
app.bot.onText(/^\!archive (.+)/, function(msg, match){
app.bot.onText(/^\!archive (.+)/, (msg, match) => {
var URL = require('../../settings/urls');
var chat = {};
chat.id = msg.chat.id;
chat.type = msg.chat.type;
chat.message_id = msg.message_id;
var user = {};