|
|
|
@ -0,0 +1,161 @@
|
|
|
|
|
import telebot
|
|
|
|
|
import os
|
|
|
|
|
import json
|
|
|
|
|
|
|
|
|
|
from telebot import types,util
|
|
|
|
|
|
|
|
|
|
if not os.path.exists('db.json'):
|
|
|
|
|
with open('db.json', 'w') as f:
|
|
|
|
|
json.dump({}, f)
|
|
|
|
|
|
|
|
|
|
global db
|
|
|
|
|
with open('db.json', 'r') as f:
|
|
|
|
|
db = json.load(f)
|
|
|
|
|
|
|
|
|
|
bot = telebot.TeleBot(db['token'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_admins(message):
|
|
|
|
|
admins = bot.get_chat_administrators(chat_id=message.chat.id)
|
|
|
|
|
true_admins = []
|
|
|
|
|
for i in admins:
|
|
|
|
|
if i.status == "creator" or i.can_restrict_members == True:
|
|
|
|
|
true_admins.append(i.user.id)
|
|
|
|
|
#print(i.can_restrict_members, " ", i.user.id, " ", " ", i.status, " ", i.user.username )
|
|
|
|
|
return true_admins
|
|
|
|
|
|
|
|
|
|
def write_db(db):
|
|
|
|
|
with open('db.json', 'w') as f:
|
|
|
|
|
json.dump(db, f)
|
|
|
|
|
|
|
|
|
|
def get_target(message):
|
|
|
|
|
try:
|
|
|
|
|
target = message.reply_to_message.from_user.id
|
|
|
|
|
except:
|
|
|
|
|
print(message.text[message.text.find(" ") + 1 :])
|
|
|
|
|
#target = bot.get_chat(chat_id=message.text[message.text.find(" ") + 1 :]).id
|
|
|
|
|
target = bot.get_chat_member(user_id=message.text[message.text.find(" ") + 1 :])
|
|
|
|
|
|
|
|
|
|
return target
|
|
|
|
|
|
|
|
|
|
@bot.message_handler(commands=['help', 'start'])
|
|
|
|
|
def send_welcome(message):
|
|
|
|
|
bot.reply_to(message, """Колотушка работает 🔨
|
|
|
|
|
|
|
|
|
|
Что это такое?
|
|
|
|
|
Это минимальный бот-модератор без слежки с открым кодом.
|
|
|
|
|
Код: https://gitea.gulyaipole.fun/justuser/just_moderator
|
|
|
|
|
|
|
|
|
|
Список команд:
|
|
|
|
|
""")
|
|
|
|
|
|
|
|
|
|
@bot.message_handler(commands=['mute'])
|
|
|
|
|
def mute(message):
|
|
|
|
|
if message.from_user.id in get_admins(message):
|
|
|
|
|
try:
|
|
|
|
|
target = get_target(message)
|
|
|
|
|
|
|
|
|
|
if len(message.text.split()) == 1:
|
|
|
|
|
bot.restrict_chat_member(message.chat.id, target, until_date = message.date)
|
|
|
|
|
bot.reply_to(message, f"""Пользователь { telebot.util.user_link(message.reply_to_message.from_user) } был заглушен.""", parse_mode='HTML')
|
|
|
|
|
else:
|
|
|
|
|
time = int(message.text.split()[1]) * 60
|
|
|
|
|
print(time)
|
|
|
|
|
bot.restrict_chat_member(message.chat.id, target, until_date = message.date+time)
|
|
|
|
|
bot.reply_to(message, f"""Пользователь { telebot.util.user_link(message.reply_to_message.from_user) } был заглушён на {time/60} минут(ы).""", parse_mode='HTML')
|
|
|
|
|
|
|
|
|
|
except:
|
|
|
|
|
bot.reply_to(message, "Что-то пошло не так ♿️")
|
|
|
|
|
else:
|
|
|
|
|
bot.reply_to(message, "Увы, но у вас нету прав.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@bot.message_handler(commands=['unmute'])
|
|
|
|
|
def unmute(message):
|
|
|
|
|
if message.from_user.id in get_admins(message):
|
|
|
|
|
try:
|
|
|
|
|
target = get_target(message)
|
|
|
|
|
|
|
|
|
|
bot.restrict_chat_member(message.chat.id, target, can_send_messages=True, can_send_other_messages = True, until_date = message.date)
|
|
|
|
|
|
|
|
|
|
bot.reply_to(message, f"""Пользователь { telebot.util.user_link(message.reply_to_message.from_user) } снова имеет дар речи.
|
|
|
|
|
""", parse_mode='HTML')
|
|
|
|
|
except:
|
|
|
|
|
bot.reply_to(message, "Что-то пошло не так ♿️")
|
|
|
|
|
else:
|
|
|
|
|
bot.reply_to(message, "Увы, но у вас нету прав.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@bot.message_handler(commands=['kick'])
|
|
|
|
|
def kick(message):
|
|
|
|
|
if message.from_user.id in get_admins(message):
|
|
|
|
|
try:
|
|
|
|
|
target = get_target(message)
|
|
|
|
|
|
|
|
|
|
bot.ban_chat_member(message.chat.id, target)
|
|
|
|
|
bot.unban_chat_member(message.chat.id, target)
|
|
|
|
|
|
|
|
|
|
bot.reply_to(message, f"""Пользователь { telebot.util.user_link(message.reply_to_message.from_user) } был исключён.
|
|
|
|
|
""", parse_mode='HTML')
|
|
|
|
|
except:
|
|
|
|
|
bot.reply_to(message, "Что-то пошло не так ♿️")
|
|
|
|
|
else:
|
|
|
|
|
bot.reply_to(message, "Увы, но у вас нету прав.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@bot.message_handler(commands=['ban'])
|
|
|
|
|
def ban(message):
|
|
|
|
|
if message.from_user.id in get_admins(message):
|
|
|
|
|
try:
|
|
|
|
|
target = get_target(message)
|
|
|
|
|
|
|
|
|
|
bot.ban_chat_member(message.chat.id, target)
|
|
|
|
|
|
|
|
|
|
bot.reply_to(message, f"""Пользователь { telebot.util.user_link(message.reply_to_message.from_user) } исключён и заблокирован.
|
|
|
|
|
""", parse_mode='HTML')
|
|
|
|
|
except:
|
|
|
|
|
bot.reply_to(message, "Что-то пошло не так ♿️")
|
|
|
|
|
else:
|
|
|
|
|
bot.reply_to(message, "Увы, но у вас нету прав.")
|
|
|
|
|
|
|
|
|
|
@bot.message_handler(commands=['unban'])
|
|
|
|
|
def unban(message):
|
|
|
|
|
if message.from_user.id in get_admins(message):
|
|
|
|
|
try:
|
|
|
|
|
target = get_target(message)
|
|
|
|
|
|
|
|
|
|
bot.unban_chat_member(message.chat.id, target)
|
|
|
|
|
|
|
|
|
|
bot.reply_to(message, f"""Пользователь { telebot.util.user_link(message.reply_to_message.from_user) } разблокирован.
|
|
|
|
|
""", parse_mode='HTML')
|
|
|
|
|
except:
|
|
|
|
|
bot.reply_to(message, "Что-то пошло не так ♿️")
|
|
|
|
|
else:
|
|
|
|
|
bot.reply_to(message, "Увы, но у вас нету прав.")
|
|
|
|
|
|
|
|
|
|
@bot.message_handler(commands=['setwelcome'])
|
|
|
|
|
def setwelcome(message):
|
|
|
|
|
if message.from_user.id in get_admins(message):
|
|
|
|
|
db["welcome"] = message.html_text[ message.text.find(" ") + 1 :]
|
|
|
|
|
|
|
|
|
|
bot.reply_to(message, f"""Установлено новое приветственное сообщение:
|
|
|
|
|
\n{db["welcome"]}""", parse_mode='HTML')
|
|
|
|
|
write_db(db)
|
|
|
|
|
else:
|
|
|
|
|
bot.reply_to(message, "Увы, но у вас нету прав.")
|
|
|
|
|
|
|
|
|
|
@bot.message_handler(commands=['welcome'])
|
|
|
|
|
def welcome(message):
|
|
|
|
|
global db
|
|
|
|
|
bot.reply_to(message, f"""Приветственное сообщение:
|
|
|
|
|
\n{db["welcome"]}""", parse_mode='HTML')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@bot.message_handler(content_types=["new_chat_members"])
|
|
|
|
|
def handler_new_member(message):
|
|
|
|
|
global db
|
|
|
|
|
bot.reply_to(message, db["welcome"], parse_mode='HTML')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bot.polling()
|