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