mirror of
https://github.com/thedevs-network/the-guard-bot
synced 2025-09-01 06:35:23 +00:00
Merge pull request #35 from TheDevs-Network/develop
Disable channel warning, adding master username
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
{
|
{
|
||||||
"masterID": 123456789, // enter the master admin ID here. It must be number.
|
"master": 123456789, // master admin ID as a number or username as astring.
|
||||||
"token": "", // enter the bot token here.
|
"token": "", // bot token.
|
||||||
"numberOfWarnsToBan": 3, // Number of warns that will get someone banned.
|
"numberOfWarnsToBan": 3, // Number of warns that will get someone banned.
|
||||||
"groupsInlineKeyboard": [], // [[inlineButton]] -> inline keyboard to be added to reply to /groups
|
"groupsInlineKeyboard": [], // [[inlineButton]] -> inline keyboard to be added to reply to /groups
|
||||||
"excludedChannels": [], // [String] -> list of channels usernames to be excluded from warnings
|
"excludedChannels": [], // [String] -> list of channels usernames to be excluded from warnings, use "*" to disable this feature.
|
||||||
"excludedGroups": [] // [String] -> list of groups links to be excluded from warnings
|
"excludedGroups": [] // [String] -> list of groups links to be excluded from warnings, use "*" to disable this feature.
|
||||||
}
|
}
|
||||||
|
@@ -31,6 +31,10 @@ const banHandler = async ({ chat, message, reply, telegram, me, state }) => {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (await isAdmin(userToBan)) {
|
||||||
|
return reply('ℹ️ <b>Can\'t ban other admins.</b>', replyOptions);
|
||||||
|
}
|
||||||
|
|
||||||
if (reason.length === 0) {
|
if (reason.length === 0) {
|
||||||
return reply('ℹ️ <b>Need a reason to ban.</b>', replyOptions);
|
return reply('ℹ️ <b>Need a reason to ban.</b>', replyOptions);
|
||||||
}
|
}
|
||||||
@@ -41,10 +45,6 @@ const banHandler = async ({ chat, message, reply, telegram, me, state }) => {
|
|||||||
message.reply_to_message.message_id);
|
message.reply_to_message.message_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (await isAdmin(userToBan)) {
|
|
||||||
return reply('ℹ️ <b>Can\'t ban other admins.</b>', replyOptions);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (await isBanned(userToBan)) {
|
if (await isBanned(userToBan)) {
|
||||||
return reply(`🚫 ${link(userToBan)} <b>is already banned.</b>`,
|
return reply(`🚫 ${link(userToBan)} <b>is already banned.</b>`,
|
||||||
replyOptions);
|
replyOptions);
|
||||||
|
@@ -13,7 +13,6 @@ const leaveCommandHandler = async ctx => {
|
|||||||
const group = /^-?\d+/.test(groupName)
|
const group = /^-?\d+/.test(groupName)
|
||||||
? { id: Number(groupName) }
|
? { id: Number(groupName) }
|
||||||
: { title: groupName };
|
: { title: groupName };
|
||||||
console.log(group);
|
|
||||||
const isGroup = await managesGroup(group);
|
const isGroup = await managesGroup(group);
|
||||||
if (!isGroup) {
|
if (!isGroup) {
|
||||||
return replyWithHTML(
|
return replyWithHTML(
|
||||||
|
@@ -29,14 +29,15 @@ const removeCommandHandler = async ({ chat, message, reply, state }) => {
|
|||||||
replyOptions);
|
replyOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (command.role === 'Master' && !isMaster) {
|
const role = command.role.toLowerCase();
|
||||||
|
if (role === 'master' && !isMaster) {
|
||||||
return reply('ℹ️ <b>Sorry, only master can remove this command.</b>',
|
return reply('ℹ️ <b>Sorry, only master can remove this command.</b>',
|
||||||
replyOptions);
|
replyOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
await removeCommand({ name: commandName });
|
await removeCommand({ name: commandName });
|
||||||
return reply(
|
return reply(
|
||||||
`✅ <code>/${commandName}</code> ` +
|
`✅ <code>!${commandName}</code> ` +
|
||||||
'<b>has been removed successfully.</b>',
|
'<b>has been removed successfully.</b>',
|
||||||
replyOptions);
|
replyOptions);
|
||||||
};
|
};
|
||||||
|
@@ -35,14 +35,14 @@ const warnHandler = async ({ message, chat, reply, me, state }) => {
|
|||||||
|
|
||||||
const reason = message.text.split(' ').slice(1).join(' ').trim();
|
const reason = message.text.split(' ').slice(1).join(' ').trim();
|
||||||
|
|
||||||
if (reason.length === 0) {
|
|
||||||
return reply('ℹ️ <b>Need a reason to warn.</b>', replyOptions);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (await isAdmin(userToWarn)) {
|
if (await isAdmin(userToWarn)) {
|
||||||
return reply('ℹ️ <b>Can\'t warn other admins.</b>', replyOptions);
|
return reply('ℹ️ <b>Can\'t warn other admins.</b>', replyOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (reason.length === 0) {
|
||||||
|
return reply('ℹ️ <b>Need a reason to warn.</b>', replyOptions);
|
||||||
|
}
|
||||||
|
|
||||||
await warn(userToWarn, reason);
|
await warn(userToWarn, reason);
|
||||||
const warnCount = await getWarns(userToWarn);
|
const warnCount = await getWarns(userToWarn);
|
||||||
const promises = [
|
const promises = [
|
||||||
|
@@ -66,7 +66,8 @@ const addCustomCmdHandler = async ({ chat, message, reply, state }, next) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (command.state === 'role') {
|
if (command.state === 'role') {
|
||||||
if (text !== 'Master' && text !== 'Admins' && text !== 'Everyone') {
|
const role = text.toLowerCase();
|
||||||
|
if (role !== 'master' && role !== 'admins' && role !== 'everyone') {
|
||||||
reply('Please send a valid role.', Markup.keyboard([
|
reply('Please send a valid role.', Markup.keyboard([
|
||||||
[ 'Master', 'Admins', 'Everyone' ]
|
[ 'Master', 'Admins', 'Everyone' ]
|
||||||
])
|
])
|
||||||
@@ -75,7 +76,7 @@ const addCustomCmdHandler = async ({ chat, message, reply, state }, next) => {
|
|||||||
.extra());
|
.extra());
|
||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
await updateCommand({ id, role: text, state: 'content' });
|
await updateCommand({ id, role, state: 'content' });
|
||||||
reply(
|
reply(
|
||||||
'Send the content you wish to be shown when the command is used.' +
|
'Send the content you wish to be shown when the command is used.' +
|
||||||
'.\n\nSupported contents:\n- <b>Text (HTML)</b>\n- <b>Photo</b>' +
|
'.\n\nSupported contents:\n- <b>Text (HTML)</b>\n- <b>Photo</b>' +
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
// Config
|
// Config
|
||||||
const { masterID } = require('../../config.json');
|
const { master } = require('../../config.json');
|
||||||
|
|
||||||
// DB
|
// DB
|
||||||
const { addUser, isUser } = require('../../stores/user');
|
const { addUser, isUser } = require('../../stores/user');
|
||||||
@@ -27,7 +27,11 @@ const addUserHandler = async (ctx, next) => {
|
|||||||
|
|
||||||
ctx.state = {
|
ctx.state = {
|
||||||
isAdmin: user && user.status === 'admin',
|
isAdmin: user && user.status === 'admin',
|
||||||
isMaster: user && user.id === masterID,
|
isMaster: user &&
|
||||||
|
(user.id === Number(master) ||
|
||||||
|
user.username &&
|
||||||
|
user.username.toLowerCase() ===
|
||||||
|
String(master).replace('@', '').toLowerCase()),
|
||||||
user: newUser,
|
user: newUser,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -16,13 +16,14 @@ const bot = require('../../bot');
|
|||||||
const { replyOptions } = require('../../bot/options');
|
const { replyOptions } = require('../../bot/options');
|
||||||
|
|
||||||
// DB
|
// DB
|
||||||
const { ban, warn } = require('../../stores/user');
|
const { ban, warn, getWarns } = require('../../stores/user');
|
||||||
const { listGroups } = require('../../stores/group');
|
const { listGroups } = require('../../stores/group');
|
||||||
|
|
||||||
const removeLinks = async ({ message, chat, reply, state }, next) => {
|
const removeLinks = async ({ message, chat, reply, state }, next) => {
|
||||||
const { isAdmin, user } = state;
|
const { isAdmin, user } = state;
|
||||||
const groups = await listGroups();
|
const groups = await listGroups();
|
||||||
const groupLinks = [
|
const groupLinks = excludedGroups !== '*' &&
|
||||||
|
[
|
||||||
...groups.map(group => group.link
|
...groups.map(group => group.link
|
||||||
? group.link.split('/joinchat/')[1]
|
? group.link.split('/joinchat/')[1]
|
||||||
: ''),
|
: ''),
|
||||||
@@ -34,10 +35,12 @@ const removeLinks = async ({ message, chat, reply, state }, next) => {
|
|||||||
if (
|
if (
|
||||||
message.forward_from_chat &&
|
message.forward_from_chat &&
|
||||||
message.forward_from_chat.type !== 'private' &&
|
message.forward_from_chat.type !== 'private' &&
|
||||||
|
excludedChannels !== '*' &&
|
||||||
!excludedChannels.includes(message.forward_from_chat.username) ||
|
!excludedChannels.includes(message.forward_from_chat.username) ||
|
||||||
message.text &&
|
message.text &&
|
||||||
(message.text.includes('t.me') ||
|
(message.text.includes('t.me') ||
|
||||||
message.text.includes('telegram.me')) &&
|
message.text.includes('telegram.me')) &&
|
||||||
|
excludedGroups !== '*' &&
|
||||||
!(excludedChannels.includes(message.text) ||
|
!(excludedChannels.includes(message.text) ||
|
||||||
groupLinks.includes(message.text.split('/joinchat/')[1]))
|
groupLinks.includes(message.text.split('/joinchat/')[1]))
|
||||||
) {
|
) {
|
||||||
@@ -45,13 +48,14 @@ const removeLinks = async ({ message, chat, reply, state }, next) => {
|
|||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
const reason = 'Channel forward/link';
|
const reason = 'Channel forward/link';
|
||||||
const warnCount = await warn(user, reason);
|
await warn(user, reason);
|
||||||
|
const warnCount = await getWarns(user);
|
||||||
const promises = [
|
const promises = [
|
||||||
bot.telegram.deleteMessage(chat.id, message.message_id)
|
bot.telegram.deleteMessage(chat.id, message.message_id)
|
||||||
];
|
];
|
||||||
if (warnCount < numberOfWarnsToBan) {
|
if (warnCount.length < numberOfWarnsToBan) {
|
||||||
promises.push(reply(
|
promises.push(reply(
|
||||||
`⚠️ ${link(user)} <b>got warned!</b> (${warnCount}/3)` +
|
`⚠️ ${link(user)} <b>got warned!</b> (${warnCount.length}/3)` +
|
||||||
`\n\nReason: ${reason}`,
|
`\n\nReason: ${reason}`,
|
||||||
replyOptions));
|
replyOptions));
|
||||||
} else {
|
} else {
|
||||||
@@ -59,7 +63,7 @@ const removeLinks = async ({ message, chat, reply, state }, next) => {
|
|||||||
promises.push(ban(user,
|
promises.push(ban(user,
|
||||||
'Reached max number of warnings'));
|
'Reached max number of warnings'));
|
||||||
promises.push(reply(
|
promises.push(reply(
|
||||||
`🚫 ${link(user)} <b>got banned</b>! (${warnCount}/3)` +
|
`🚫 ${link(user)} <b>got banned</b>! (${warnCount.length}/3)` +
|
||||||
'\n\nReason: Reached max number of warnings',
|
'\n\nReason: Reached max number of warnings',
|
||||||
replyOptions));
|
replyOptions));
|
||||||
}
|
}
|
||||||
|
@@ -18,15 +18,16 @@ const runCustomCmdHandler = async (ctx, next) => {
|
|||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
|
|
||||||
const { caption, content, role, type } = command;
|
const { caption, content, type } = command;
|
||||||
|
const role = command.role.toLowerCase();
|
||||||
const replyTo = message.reply_to_message
|
const replyTo = message.reply_to_message
|
||||||
? { reply_to_message_id: message.reply_to_message.message_id }
|
? { reply_to_message_id: message.reply_to_message.message_id }
|
||||||
: {};
|
: {};
|
||||||
const options = Object.assign(replyTo, caption ? { caption } : {});
|
const options = Object.assign(replyTo, caption ? { caption } : {});
|
||||||
if (
|
if (
|
||||||
role === 'Master' &&
|
role === 'master' &&
|
||||||
!isMaster ||
|
!isMaster ||
|
||||||
role === 'Admins' &&
|
role === 'admins' &&
|
||||||
!isAdmin
|
!isAdmin
|
||||||
) {
|
) {
|
||||||
return next();
|
return next();
|
||||||
|
@@ -5,15 +5,19 @@ const { replyOptions } = require('../../bot/options');
|
|||||||
|
|
||||||
const { admin } = require('../../stores/user');
|
const { admin } = require('../../stores/user');
|
||||||
const { addGroup, managesGroup } = require('../../stores/group');
|
const { addGroup, managesGroup } = require('../../stores/group');
|
||||||
const { masterID } = require('../../config.json');
|
const { master } = require('../../config.json');
|
||||||
|
|
||||||
const addedToGroupHandler = async (ctx, next) => {
|
const addedToGroupHandler = async (ctx, next) => {
|
||||||
const msg = ctx.message;
|
const msg = ctx.message;
|
||||||
const { telegram } = ctx;
|
const { telegram } = ctx;
|
||||||
|
const isMaster = ctx.from.id === Number(master) ||
|
||||||
|
ctx.from.username &&
|
||||||
|
ctx.from.username.toLowerCase() ===
|
||||||
|
String(master).replace('@', '').toLowerCase();
|
||||||
|
|
||||||
const wasAdded = msg.new_chat_members.some(user =>
|
const wasAdded = msg.new_chat_members.some(user =>
|
||||||
user.username === ctx.me);
|
user.username === ctx.me);
|
||||||
if (wasAdded && ctx.from.id === masterID) {
|
if (wasAdded && isMaster) {
|
||||||
await admin(ctx.from);
|
await admin(ctx.from);
|
||||||
if (!await managesGroup({ id: ctx.chat.id })) {
|
if (!await managesGroup({ id: ctx.chat.id })) {
|
||||||
try {
|
try {
|
||||||
|
Reference in New Issue
Block a user