Add /del
This commit is contained in:
parent
45bf3eace2
commit
7fe6869dfc
169
mod.py
169
mod.py
@ -4,7 +4,7 @@ import json
|
||||
|
||||
from telebot import types,util
|
||||
|
||||
global db, users, blocks
|
||||
global db, users, la
|
||||
|
||||
####### CREATE DB IF NOT EXIST
|
||||
|
||||
@ -23,13 +23,11 @@ if not os.path.exists('users.json'):
|
||||
with open("users.json", "w") as outfile:
|
||||
outfile.write(js)
|
||||
|
||||
|
||||
if not os.path.exists('blocks.json'):
|
||||
blocks = []
|
||||
js = json.dumps(blocks, indent=2)
|
||||
with open("blocks.json", "w") as outfile:
|
||||
if not os.path.exists('la.json'):
|
||||
la = {}
|
||||
js = json.dumps(la, indent=2)
|
||||
with open("la.json", "w") as outfile:
|
||||
outfile.write(js)
|
||||
|
||||
############WORK WITH DBs##########
|
||||
|
||||
def read_db():
|
||||
@ -53,16 +51,16 @@ def write_users():
|
||||
with open("users.json", "w") as outfile:
|
||||
outfile.write(js)
|
||||
|
||||
|
||||
|
||||
def read_blocks():
|
||||
global blocks
|
||||
with open('blocks.json', 'r') as openfile:
|
||||
blocks = json.load(openfile)
|
||||
def write_blocks():
|
||||
global blocks
|
||||
js = json.dumps(blocks, indent=2)
|
||||
with open("blocks.json", "w") as outfile:
|
||||
# LA - Low Admin.
|
||||
# Admin permissions in bot without admin rights.
|
||||
def read_la():
|
||||
global la
|
||||
with open('la.json', 'r') as openfile:
|
||||
la = json.load(openfile)
|
||||
def write_la():
|
||||
global la
|
||||
js = json.dumps(la, indent=2)
|
||||
with open("la.json", "w") as outfile:
|
||||
outfile.write(js)
|
||||
|
||||
####################FAST HASH#################
|
||||
@ -92,8 +90,9 @@ def get_admins(message):
|
||||
|
||||
# Fix for anon admins, all anon (not premium) users == admins
|
||||
def is_anon(message):
|
||||
if message.from_user.username == "Channel_Bot" and message.from_user.is_premium == None:
|
||||
return True
|
||||
if message.from_user.username == "Channel_Bot" or message.from_user.username == "GroupAnonymousBot":
|
||||
if message.from_user.is_premium == None:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
@ -102,6 +101,7 @@ def get_target(message):
|
||||
if len(message.text.split()) > 1 and message.text.split()[1][0] == "@":
|
||||
username = message.text.split()[1][1:]
|
||||
global users
|
||||
read_users()
|
||||
if sha(username) in users:
|
||||
return users[sha(username)]
|
||||
else:
|
||||
@ -128,6 +128,18 @@ def get_name(message):
|
||||
except:
|
||||
catch_error(message)
|
||||
|
||||
def have_rights(message, set_la = False):
|
||||
global la ; read_la()
|
||||
if message.from_user.id in get_admins(message):
|
||||
return True
|
||||
elif is_anon(message):
|
||||
return True
|
||||
elif str(message.chat.id) in la and not set_la:
|
||||
if str(message.from_user.username) in la[str(message.chat.id)]:
|
||||
return True
|
||||
else:
|
||||
bot.reply_to(message, "Увы, но у вас нету прав.")
|
||||
|
||||
def key_by_value(dictionary, key):
|
||||
for i in dictionary:
|
||||
if dictionary[i] == key:
|
||||
@ -182,6 +194,7 @@ def help(message):
|
||||
/lock ⇁ Блокировка чата (для обычных пользователей)
|
||||
/unlock ⇁ Снятие блокировки чата
|
||||
/chatid ⇁ Айди чата
|
||||
/del ⇁ Удаление сообщения
|
||||
|
||||
/secret ⇁ Функция для получения ссылки html на пользователя в лс.
|
||||
/html <code> ⇁ Отправка текста сообщения в режиме формата html.
|
||||
@ -192,7 +205,7 @@ def help(message):
|
||||
@bot.message_handler(commands=['mute'])
|
||||
def mute(message):
|
||||
try:
|
||||
if message.from_user.id in get_admins(message) or is_anon(message):
|
||||
if have_rights(message):
|
||||
target = get_target(message)
|
||||
if target:
|
||||
if len(message.text.split()) == 1:
|
||||
@ -207,8 +220,6 @@ def mute(message):
|
||||
bot.reply_to(message, f"""Пользователь { get_name(message) } был заглушён на {time/60} минут(ы).""", parse_mode='HTML')
|
||||
else:
|
||||
catch_error(message, "no_user")
|
||||
else:
|
||||
bot.reply_to(message, "Увы, но у вас нету прав.")
|
||||
except:
|
||||
catch_error(message)
|
||||
|
||||
@ -216,7 +227,7 @@ def mute(message):
|
||||
@bot.message_handler(commands=['unmute'])
|
||||
def unmute(message):
|
||||
try:
|
||||
if message.from_user.id in get_admins(message) or is_anon(message):
|
||||
if have_rights(message):
|
||||
target = get_target(message)
|
||||
if target:
|
||||
bot.restrict_chat_member(message.chat.id, target, can_send_messages=True, can_send_other_messages = True, until_date = message.date)
|
||||
@ -233,7 +244,7 @@ def unmute(message):
|
||||
@bot.message_handler(commands=['kick'])
|
||||
def kick(message):
|
||||
try:
|
||||
if message.from_user.id in get_admins(message) or is_anon(message):
|
||||
if have_rights(message):
|
||||
target = get_target(message)
|
||||
if target:
|
||||
bot.ban_chat_member(message.chat.id, target)
|
||||
@ -252,7 +263,7 @@ def kick(message):
|
||||
@bot.message_handler(commands=['ban'])
|
||||
def ban(message):
|
||||
try:
|
||||
if message.from_user.id in get_admins(message) or is_anon(message):
|
||||
if have_rights(message):
|
||||
target = get_target(message)
|
||||
if target:
|
||||
bot.ban_chat_member(message.chat.id, target)
|
||||
@ -268,7 +279,7 @@ def ban(message):
|
||||
@bot.message_handler(commands=['unban'])
|
||||
def unban(message):
|
||||
try:
|
||||
if message.from_user.id in get_admins(message) or is_anon(message):
|
||||
if have_rights(message):
|
||||
target = get_target(message)
|
||||
if target:
|
||||
bot.unban_chat_member(message.chat.id, target)
|
||||
@ -284,7 +295,7 @@ def unban(message):
|
||||
@bot.message_handler(commands=['setwelcome'])
|
||||
def setwelcome(message):
|
||||
try:
|
||||
if message.from_user.id in get_admins(message) or is_anon(message):
|
||||
if have_rights(message):
|
||||
global db
|
||||
db[str(message.chat.id)] = message.html_text[ message.text.find(" ") + 1 :]
|
||||
|
||||
@ -309,7 +320,7 @@ def welcome(message):
|
||||
@bot.message_handler(commands=['lock'])
|
||||
def lock(message):
|
||||
try:
|
||||
if message.from_user.id in get_admins(message) or is_anon(message):
|
||||
if have_rights(message):
|
||||
bot.set_chat_permissions(message.chat.id, telebot.types.ChatPermissions(can_send_messages=False, can_send_other_messages = False, can_send_polls = False))
|
||||
bot.reply_to(message, "Чат был заблокирован 🔒")
|
||||
else:
|
||||
@ -320,7 +331,7 @@ def lock(message):
|
||||
@bot.message_handler(commands=['unlock'])
|
||||
def unlock(message):
|
||||
try:
|
||||
if message.from_user.id in get_admins(message) or is_anon(message):
|
||||
if have_rights(message):
|
||||
bot.set_chat_permissions(message.chat.id, telebot.types.ChatPermissions(can_send_messages=True, can_send_other_messages = True, can_send_polls = True))
|
||||
bot.reply_to(message, "Чат был разблокирован 🔓")
|
||||
else:
|
||||
@ -331,7 +342,7 @@ def unlock(message):
|
||||
@bot.message_handler(commands=['id'])
|
||||
def getid(message):
|
||||
try:
|
||||
if message.from_user.id in get_admins(message) or is_anon(message):
|
||||
if have_rights(message):
|
||||
bot.reply_to(message, "ID: " + telebot.formatting.hcode(str(get_target(message))), parse_mode="HTML" )
|
||||
else:
|
||||
bot.reply_to(message, "Увы, но у вас нету прав.")
|
||||
@ -339,11 +350,22 @@ def getid(message):
|
||||
catch_error(message)
|
||||
|
||||
|
||||
@bot.message_handler(commands=['del'])
|
||||
def secret(message):
|
||||
try:
|
||||
if have_rights(message):
|
||||
bot.delete_message(message.chat.id, message.reply_to_message.id)
|
||||
bot.delete_message(message.chat.id, message.id)
|
||||
else:
|
||||
bot.reply_to(message, "Увы, но у вас нету прав.")
|
||||
except:
|
||||
catch_error(message)
|
||||
|
||||
|
||||
@bot.message_handler(commands=['secret'])
|
||||
def secret(message):
|
||||
try:
|
||||
if message.from_user.id in get_admins(message) or is_anon(message):
|
||||
if have_rights(message):
|
||||
bot.send_message(message.from_user.id, telebot.util.user_link(message.reply_to_message.from_user))
|
||||
bot.delete_message(message.chat.id, message.id)
|
||||
else:
|
||||
@ -363,13 +385,90 @@ def html(message):
|
||||
@bot.message_handler(commands=['chatid'])
|
||||
def chatid(message):
|
||||
try:
|
||||
if message.from_user.id in get_admins(message) or is_anon(message):
|
||||
if have_rights(message):
|
||||
bot.reply_to(message, "Айди чата: " + telebot.formatting.hcode( str(message.chat.id) ), parse_mode='HTML')
|
||||
else:
|
||||
bot.reply_to(message, "Увы, но у вас нету прав.")
|
||||
except:
|
||||
catch_error(message)
|
||||
|
||||
############ LOW-ADMIN ##############
|
||||
|
||||
def have_la(id):
|
||||
try:
|
||||
global la ; read_la()
|
||||
if id in la:
|
||||
return True
|
||||
else:
|
||||
la[id] = []
|
||||
write_la()
|
||||
return True
|
||||
except:
|
||||
catch_error(message)
|
||||
|
||||
@bot.message_handler(commands=['la-list'])
|
||||
def la_list(message):
|
||||
try:
|
||||
if have_rights(message, set_la=True):
|
||||
global la ; read_la()
|
||||
if have_la(str(message.chat.id)):
|
||||
s = "Список администраторов в режиме low-admin:\n"
|
||||
for i in la[str(message.chat.id)]:
|
||||
s = s + '\n@' + i
|
||||
bot.reply_to(message, s, parse_mode='HTML')
|
||||
except:
|
||||
catch_error(message)
|
||||
|
||||
@bot.message_handler(commands=['la-add'])
|
||||
def la_add(message):
|
||||
try:
|
||||
if have_rights(message, set_la=True):
|
||||
global la ; read_la()
|
||||
if have_la(message.chat.id):
|
||||
nick = message.text.split()[1][1:]
|
||||
la[message.chat.id].append(nick)
|
||||
write_la()
|
||||
bot.reply_to(message, f"Пользователь @{nick} успешно добавлен в список администраторов.")
|
||||
except:
|
||||
catch_error(message)
|
||||
|
||||
@bot.message_handler(commands=['la-del'])
|
||||
def la_del(message, set_la=True):
|
||||
try:
|
||||
if have_rights(message, set_la=True):
|
||||
global la ; read_la()
|
||||
if have_la(message.chat.id):
|
||||
nick = message.text.split()[1][1:]
|
||||
|
||||
if nick in la[message.chat.id]:
|
||||
del la[message.chat.id]
|
||||
write_la()
|
||||
bot.reply_to(message, f"Пользователь @{nick} был исключён из списка администраторов.")
|
||||
except:
|
||||
catch_error(message)
|
||||
|
||||
|
||||
#######################JOIN REQUEST #############
|
||||
|
||||
|
||||
@bot.chat_join_request_handler()
|
||||
def join_request(message: telebot.types.ChatJoinRequest):
|
||||
try:
|
||||
bot.send_message(message.chat.id, f"""Поступила заявка на вступление от { telebot.util.user_link(message.from_user) }
|
||||
Принять: { telebot.formatting.hcode(f"/accept {message.from_user.id}") }""", parse_mode="HTML")
|
||||
except:
|
||||
catch_error(message)
|
||||
|
||||
@bot.message_handler(commands=['accept'])
|
||||
def accept_request(message):
|
||||
try:
|
||||
if have_rights(message):
|
||||
if len(message.text.split()) == 2:
|
||||
bot.approve_chat_join_request(message.chat.id, message.text.split()[1] )
|
||||
bot.reply_to(message, "Заявка принята.")
|
||||
except:
|
||||
catch_error(message)
|
||||
|
||||
######################SUPPORT########
|
||||
|
||||
@bot.message_handler(commands=['support'])
|
||||
@ -422,12 +521,12 @@ def catch_error(message, err_type = None):
|
||||
logging.error(traceback.format_exc()) # Log error
|
||||
err = log_stream.getvalue() # Error to variable
|
||||
|
||||
bot.reply_to(message, "Critical error (свяжитись через /support ) :\n\n" + telebot.formatting.hcode(err), parse_mode='HTML')
|
||||
bot.send_message(message.chat.id, "Critical error (свяжитись через /support ) :\n\n" + telebot.formatting.hcode(err), parse_mode='HTML')
|
||||
|
||||
log_stream.truncate(0) # Clear
|
||||
log_stream.seek(0) # Clear
|
||||
elif err_type == "no_user":
|
||||
bot.reply_to(message, "Не указан пользователь.")
|
||||
bot.send_message(message.chat.id, "Не указан пользователь.")
|
||||
|
||||
|
||||
##################MAIN THREAD#####
|
||||
@ -440,5 +539,5 @@ while True:
|
||||
except:
|
||||
pass
|
||||
'''
|
||||
bot.polling()
|
||||
bot.polling(allowed_updates=telebot.util.update_types)
|
||||
'''
|
||||
|
Loading…
Reference in New Issue
Block a user