Добавление pin/unpin, исправление багов

main
Your Name 2 months ago
parent 62e437b3b8
commit a285f55363

@ -4,7 +4,7 @@ import json
from telebot import types,util
global db, users, la
global users, la
####### CREATE DB IF NOT EXIST
@ -31,11 +31,10 @@ if not os.path.exists('la.json'):
############WORK WITH DBs##########
def read_db():
global db
with open('db.json', 'r') as openfile:
db = json.load(openfile)
def write_db():
global db
return db
def write_db(db):
js = json.dumps(db, indent=2)
with open('db.json', 'w') as outfile:
outfile.write(js)
@ -189,7 +188,7 @@ def analytic(message):
#############TOKEN INIT#####
read_db()
db = read_db()
read_users()
bot = telebot.TeleBot(db['token'])
@ -320,20 +319,19 @@ def unban(message):
def setwelcome(message):
try:
if have_rights(message):
global db
db = read_db()
db[str(message.chat.id)] = message.html_text[ message.text.find(' ') + 1 :]
bot.reply_to(message, f'''Установлено новое приветственное сообщение:
\n{db[str(message.chat.id)]}''', parse_mode='HTML')
write_db()
write_db(db)
except Exception as e:
catch_error(message, e)
@bot.message_handler(commands=['welcome'])
def welcome(message):
try:
global db
read_db()
db = read_db()
bot.reply_to(message, f'''Приветственное сообщение:
\n{db[str(message.chat.id)]}''', parse_mode='HTML')
except Exception as e:
@ -377,6 +375,22 @@ def delete(message):
except Exception as e:
catch_error(message, e)
@bot.message_handler(commands=['pin'])
def pin(message):
try:
if have_rights(message):
bot.pin_chat_message(message.chat.id, message.reply_to_message.id)
except:
catch_error(message, e)
@bot.message_handler(commands=['unpin'])
def unpin(message):
try:
if have_rights(message):
bot.unpin_chat_message(message.chat.id, message.reply_to_message.id)
except:
catch_error(message, e)
### EXPEREMENTAL
@bot.message_handler(commands=['secret'])
@ -438,7 +452,7 @@ def la_list(message):
try:
if have_rights(message, set_la=True):
la = read_la()
if have_la(str(message.chat.id)):
if have_la(message):
s = 'Список администраторов в режиме low-admin:\n'
for i in la[str(message.chat.id)]:
s = s + '\n@' + i
@ -451,7 +465,7 @@ def la_add(message):
try:
if have_rights(message, set_la=True):
la = read_la()
if have_la(message.chat.id):
if have_la(message):
nick = message.text.split()[1][1:]
print(la)
la[str(message.chat.id)].append(nick)
@ -466,7 +480,7 @@ def la_del(message, set_la=True):
try:
if have_rights(message, set_la=True):
la = read_la()
if have_la(message.chat.id):
if have_la(message):
nick = message.text.split()[1][1:]
if nick in la[str(message.chat.id)]:
@ -514,8 +528,12 @@ def support(message):
@bot.message_handler(content_types=['new_chat_members'])
def handler_new_member(message):
try:
global db
read_db()
db = read_db()
if str(message.chat.id) not in db:
db[str(message.chat.id)] = 'Приветственное сообщение не задано.\n Задайте его с помощью /setwelcome ...'
la = read_la()
la[str(message.chat.id)] = []
write_la(la)
bot.reply_to(message, db[str(message.chat.id)], parse_mode='HTML')
analytic(message)
except Exception as e:

Loading…
Cancel
Save