@ -84,8 +84,8 @@ def get_admins(message):
if i . status == " creator " or i . can_restrict_members == True :
if i . status == " creator " or i . can_restrict_members == True :
true_admins . append ( i . user . id )
true_admins . append ( i . user . id )
return true_admins
return true_admins
except :
except Exception as e :
catch_error ( message )
catch_error ( message , e )
return None
return None
# Fix for anon admins, all anon (not premium) users == admins
# Fix for anon admins, all anon (not premium) users == admins
@ -96,35 +96,30 @@ def is_anon(message):
else :
else :
return False
return False
# Return id from db/chat of user
def get_target ( message ) :
def get_target ( message ) :
# try:
try :
if True :
global users
global users
if len ( message . text . split ( ) ) > 1 and message . text . split ( ) [ 1 ] [ 0 ] == " @ " :
username = message . text . split ( ) [ 1 ] [ 1 : ]
spl = message . text . split ( )
read_users ( )
if len ( spl ) > 1 and ( spl [ 1 ] [ 0 ] == ' @ ' or spl [ 2 ] [ 0 ] == ' @ ' ) :
if sha ( username ) in users :
for i in spl :
return users [ sha ( username ) ]
if i [ 0 ] == ' @ ' :
else :
username = i [ 1 : ]
print ( 1 )
break
return None
elif len ( message . text . split ( ) ) > 1 and message . text . split ( ) [ 2 ] [ 0 ] == " @ " :
username = message . text . split ( ) [ 2 ] [ 1 : ]
read_users ( )
read_users ( )
if sha ( username ) in users :
if sha ( username ) in users :
return users [ sha ( username ) ]
return users [ sha ( username ) ]
else :
else :
print ( 2 )
return None
return None
else :
else :
target = message . reply_to_message . from_user . id
target = message . reply_to_message . from_user . id
if target not in get_admins ( message ) :
if target not in get_admins ( message ) :
return target
return target
else :
else :
print ( 3 )
return None
return None
# except:
except :
# return None
return None
def get_name ( message ) :
def get_name ( message ) :
try :
try :
@ -138,8 +133,26 @@ def get_name(message):
# Reply to message
# Reply to message
else :
else :
return telebot . util . user_link ( message . reply_to_message . from_user )
return telebot . util . user_link ( message . reply_to_message . from_user )
except :
except Exception as e :
catch_error ( message )
catch_error ( message , e )
# Get time for '/mute'
# [time, time_in_sec, format]
def get_time ( message ) :
formats = { ' s ' : [ 1 , ' секунд(ы) ' ] , ' m ' : [ 60 , ' минут(ы) ' ] , ' h ' : [ 3600 , ' час(а ) ' ] , ' d ' : [ 86400 , ' день/дня ' ] }
text = message . text . split ( ) [ 1 : ] ; time = None
# Find format in text
for i in text :
if time :
break
for f in list ( formats . keys ( ) ) :
print ( i , ' ' , f )
if f in i :
time = [ i [ : - 1 ] , int ( i [ : - 1 ] ) * formats [ i [ - 1 ] ] [ 0 ] , formats [ i [ - 1 ] ] [ 1 ] ]
break
return time
def have_rights ( message , set_la = False ) :
def have_rights ( message , set_la = False ) :
global la ; read_la ( )
global la ; read_la ( )
@ -220,22 +233,22 @@ def mute(message):
try :
try :
if have_rights ( message ) :
if have_rights ( message ) :
target = get_target ( message )
target = get_target ( message )
print ( target )
time = get_time ( message )
if target :
if target :
if len ( message . text . split ( ) ) == 1 :
if time :
bot . restrict_chat_member ( message . chat . id , target , until_date = message . date )
bot . restrict_chat_member ( message . chat . id , target , until_date = message . date + time [ 1 ] )
bot . reply_to ( message , f """ Пользователь { get_name ( message ) } был заглушен. """ , parse_mode = ' HTML ' )
answer = f " Пользователь { get_name ( message ) } был заглушён на { time [ 0 ] } { time [ 2 ] } . "
elif len ( message . text . split ( ) ) == 2 and message . text . split ( ) [ 1 ] [ 0 ] == " @ " :
bot . restrict_chat_member ( message . chat . id , target , until_date = message . date )
bot . reply_to ( message , f """ Пользователь { get_name ( message ) } был заглушен. """ )
else :
else :
time = int ( message . text . split ( ) [ 1 ] ) * 60
bot . restrict_chat_member ( message . chat . id , target , until_date = message . date )
bot . restrict_chat_member ( message . chat . id , target , until_date = message . date + time )
answer = f " Пользователь { get_name ( message ) } был заглушен. "
bot . reply_to ( message , f """ Пользователь { get_name ( message ) } был заглушён на { time / 60 } минут(ы). """ , parse_mode = ' HTML ' )
try :
bot . reply_to ( message , answer , parse_mode = ' HTML ' )
except :
bot . reply_to ( message , answer )
else :
else :
catch_error ( message , " no_user " )
catch_error ( message , ' None ' , ' no_user ' )
except :
except Exception as e :
catch_error ( message )
catch_error ( message , e )
@bot.message_handler ( commands = [ ' unmute ' ] )
@bot.message_handler ( commands = [ ' unmute ' ] )
@ -248,11 +261,9 @@ def unmute(message):
bot . reply_to ( message , f """ Пользователь { get_name ( message ) } снова имеет дар речи.
bot . reply_to ( message , f """ Пользователь { get_name ( message ) } снова имеет дар речи.
""" , parse_mode= ' HTML ' )
""" , parse_mode= ' HTML ' )
else :
else :
catch_error ( message , " no_user " )
catch_error ( message , None , " no_user " )
else :
except Exception as e :
bot . reply_to ( message , " Увы, но у вас нету прав. " )
catch_error ( message , e )
except :
catch_error ( message )
@bot.message_handler ( commands = [ ' kick ' ] )
@bot.message_handler ( commands = [ ' kick ' ] )
@ -267,11 +278,9 @@ def kick(message):
bot . reply_to ( message , f """ Пользователь { get_name ( message ) } был исключён.
bot . reply_to ( message , f """ Пользователь { get_name ( message ) } был исключён.
""" , parse_mode= ' HTML ' )
""" , parse_mode= ' HTML ' )
else :
else :
catch_error ( message , " no_user " )
catch_error ( message , None , " no_user " )
else :
except Exception as e :
bot . reply_to ( message , " Увы, но у вас нету прав. " )
catch_error ( message , e )
except :
catch_error ( message )
@bot.message_handler ( commands = [ ' ban ' ] )
@bot.message_handler ( commands = [ ' ban ' ] )
@ -284,11 +293,9 @@ def ban(message):
bot . reply_to ( message , f """ Пользователь { get_name ( message ) } исключён и заблокирован.
bot . reply_to ( message , f """ Пользователь { get_name ( message ) } исключён и заблокирован.
""" , parse_mode= ' HTML ' )
""" , parse_mode= ' HTML ' )
else :
else :
catch_error ( message , " no_user " )
catch_error ( message , None , " no_user " )
else :
except Exception as e :
bot . reply_to ( message , " Увы, но у вас нету прав. " )
catch_error ( message , e )
except :
catch_error ( message )
@bot.message_handler ( commands = [ ' unban ' ] )
@bot.message_handler ( commands = [ ' unban ' ] )
def unban ( message ) :
def unban ( message ) :
@ -300,11 +307,9 @@ def unban(message):
bot . reply_to ( message , f """ Пользователь { get_name ( message ) } разблокирован.
bot . reply_to ( message , f """ Пользователь { get_name ( message ) } разблокирован.
""" , parse_mode= ' HTML ' )
""" , parse_mode= ' HTML ' )
else :
else :
catch_error ( message , " no_user " )
catch_error ( message , None , " no_user " )
else :
except Exception as e :
bot . reply_to ( message , " Увы, но у вас нету прав. " )
catch_error ( message , e )
except :
catch_error ( message )
@bot.message_handler ( commands = [ ' setwelcome ' ] )
@bot.message_handler ( commands = [ ' setwelcome ' ] )
def setwelcome ( message ) :
def setwelcome ( message ) :
@ -316,10 +321,8 @@ def setwelcome(message):
bot . reply_to ( message , f """ Установлено новое приветственное сообщение:
bot . reply_to ( message , f """ Установлено новое приветственное сообщение:
\n { db [ str ( message . chat . id ) ] } """ , parse_mode= ' HTML ' )
\n { db [ str ( message . chat . id ) ] } """ , parse_mode= ' HTML ' )
write_db ( )
write_db ( )
else :
except Exception as e :
bot . reply_to ( message , " Увы, но у вас нету прав. " )
catch_error ( message , e )
except :
catch_error ( message )
@bot.message_handler ( commands = [ ' welcome ' ] )
@bot.message_handler ( commands = [ ' welcome ' ] )
def welcome ( message ) :
def welcome ( message ) :
@ -328,8 +331,8 @@ def welcome(message):
read_db ( )
read_db ( )
bot . reply_to ( message , f """ Приветственное сообщение:
bot . reply_to ( message , f """ Приветственное сообщение:
\n { db [ str ( message . chat . id ) ] } """ , parse_mode= ' HTML ' )
\n { db [ str ( message . chat . id ) ] } """ , parse_mode= ' HTML ' )
except :
except Exception as e :
catch_error ( message )
catch_error ( message , e )
@bot.message_handler ( commands = [ ' lock ' ] )
@bot.message_handler ( commands = [ ' lock ' ] )
def lock ( message ) :
def lock ( message ) :
@ -339,8 +342,8 @@ def lock(message):
bot . reply_to ( message , " Чат был заблокирован 🔒 " )
bot . reply_to ( message , " Чат был заблокирован 🔒 " )
else :
else :
bot . reply_to ( message , " Увы, но у вас нету прав. " )
bot . reply_to ( message , " Увы, но у вас нету прав. " )
except :
except Exception as e :
catch_error ( message )
catch_error ( message , e )
@bot.message_handler ( commands = [ ' unlock ' ] )
@bot.message_handler ( commands = [ ' unlock ' ] )
def unlock ( message ) :
def unlock ( message ) :
@ -348,20 +351,16 @@ def unlock(message):
if have_rights ( 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 . 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 , " Чат был разблокирован 🔓 " )
bot . reply_to ( message , " Чат был разблокирован 🔓 " )
else :
except Exception as e :
bot . reply_to ( message , " Увы, но у вас нету прав. " )
catch_error ( message , e )
except :
catch_error ( message )
@bot.message_handler ( commands = [ ' id ' ] )
@bot.message_handler ( commands = [ ' id ' ] )
def getid ( message ) :
def getid ( message ) :
try :
try :
if have_rights ( message ) :
if have_rights ( message ) :
bot . reply_to ( message , " ID: " + telebot . formatting . hcode ( str ( get_target ( message ) ) ) , parse_mode = " HTML " )
bot . reply_to ( message , " ID: " + telebot . formatting . hcode ( str ( get_target ( message ) ) ) , parse_mode = " HTML " )
else :
except Exception as e :
bot . reply_to ( message , " Увы, но у вас нету прав. " )
catch_error ( message , e )
except :
catch_error ( message )
@bot.message_handler ( commands = [ ' del ' ] )
@bot.message_handler ( commands = [ ' del ' ] )
@ -370,11 +369,10 @@ def delete(message):
if have_rights ( message ) :
if have_rights ( message ) :
bot . delete_message ( message . chat . id , message . reply_to_message . id )
bot . delete_message ( message . chat . id , message . reply_to_message . id )
bot . delete_message ( message . chat . id , message . id )
bot . delete_message ( message . chat . id , message . id )
else :
except Exception as e :
bot . reply_to ( message , " Увы, но у вас нету прав. " )
catch_error ( message , e )
except :
catch_error ( message )
### EXPEREMENTAL
@bot.message_handler ( commands = [ ' secret ' ] )
@bot.message_handler ( commands = [ ' secret ' ] )
def secret ( message ) :
def secret ( message ) :
@ -382,10 +380,8 @@ def secret(message):
if have_rights ( message ) :
if have_rights ( message ) :
bot . send_message ( message . from_user . id , telebot . util . user_link ( message . reply_to_message . from_user ) )
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 )
bot . delete_message ( message . chat . id , message . id )
else :
except Exception as e :
bot . reply_to ( message , " Увы, но у вас нету прав. " )
catch_error ( message , e )
except :
catch_error ( message )
@bot.message_handler ( commands = [ ' html ' ] )
@bot.message_handler ( commands = [ ' html ' ] )
def html ( message ) :
def html ( message ) :
@ -393,8 +389,10 @@ def html(message):
text = ' ' . join ( message . text . split ( ) [ 1 : ] )
text = ' ' . join ( message . text . split ( ) [ 1 : ] )
bot . send_message ( message . chat . id , text , parse_mode = ' HTML ' )
bot . send_message ( message . chat . id , text , parse_mode = ' HTML ' )
bot . delete_message ( message . chat . id , message . id )
bot . delete_message ( message . chat . id , message . id )
except :
except Exception as e :
catch_error ( message )
catch_error ( message , e )
###
@bot.message_handler ( commands = [ ' chatid ' ] )
@bot.message_handler ( commands = [ ' chatid ' ] )
def chatid ( message ) :
def chatid ( message ) :
@ -403,8 +401,8 @@ def chatid(message):
bot . reply_to ( message , " Айди чата: " + telebot . formatting . hcode ( str ( message . chat . id ) ) , parse_mode = ' HTML ' )
bot . reply_to ( message , " Айди чата: " + telebot . formatting . hcode ( str ( message . chat . id ) ) , parse_mode = ' HTML ' )
else :
else :
bot . reply_to ( message , " Увы, но у вас нету прав. " )
bot . reply_to ( message , " Увы, но у вас нету прав. " )
except :
except Exception as e :
catch_error ( message )
catch_error ( message , e )
############ LOW-ADMIN ##############
############ LOW-ADMIN ##############
@ -417,8 +415,8 @@ def have_la(id):
la [ id ] = [ ]
la [ id ] = [ ]
write_la ( )
write_la ( )
return True
return True
except :
except Exception as e :
catch_error ( message )
catch_error ( message , e )
@bot.message_handler ( commands = [ ' la-list ' ] )
@bot.message_handler ( commands = [ ' la-list ' ] )
def la_list ( message ) :
def la_list ( message ) :
@ -430,8 +428,8 @@ def la_list(message):
for i in la [ str ( message . chat . id ) ] :
for i in la [ str ( message . chat . id ) ] :
s = s + ' \n @ ' + i
s = s + ' \n @ ' + i
bot . reply_to ( message , s , parse_mode = ' HTML ' )
bot . reply_to ( message , s , parse_mode = ' HTML ' )
except :
except Exception as e :
catch_error ( message )
catch_error ( message , e )
@bot.message_handler ( commands = [ ' la-add ' ] )
@bot.message_handler ( commands = [ ' la-add ' ] )
def la_add ( message ) :
def la_add ( message ) :
@ -443,8 +441,8 @@ def la_add(message):
la [ message . chat . id ] . append ( nick )
la [ message . chat . id ] . append ( nick )
write_la ( )
write_la ( )
bot . reply_to ( message , f " Пользователь @ { nick } успешно добавлен в список администраторов. " )
bot . reply_to ( message , f " Пользователь @ { nick } успешно добавлен в список администраторов. " )
except :
except Exception as e :
catch_error ( message )
catch_error ( message , e )
@bot.message_handler ( commands = [ ' la-del ' ] )
@bot.message_handler ( commands = [ ' la-del ' ] )
def la_del ( message , set_la = True ) :
def la_del ( message , set_la = True ) :
@ -458,8 +456,8 @@ def la_del(message, set_la=True):
del la [ message . chat . id ]
del la [ message . chat . id ]
write_la ( )
write_la ( )
bot . reply_to ( message , f " Пользователь @ { nick } был исключён из списка администраторов. " )
bot . reply_to ( message , f " Пользователь @ { nick } был исключён из списка администраторов. " )
except :
except Exception as e :
catch_error ( message )
catch_error ( message , e )
#######################JOIN REQUEST #############
#######################JOIN REQUEST #############
@ -470,8 +468,8 @@ def join_request(message: telebot.types.ChatJoinRequest):
try :
try :
bot . send_message ( message . chat . id , f """ Поступила заявка на вступление от { telebot . util . user_link ( message . from_user ) }
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 " )
Принять : { telebot . formatting . hcode ( f " /accept { message . from_user . id } " ) } """ , parse_mode= " HTML " )
except :
except Exception as e :
catch_error ( message )
catch_error ( message , e )
@bot.message_handler ( commands = [ ' accept ' ] )
@bot.message_handler ( commands = [ ' accept ' ] )
def accept_request ( message ) :
def accept_request ( message ) :
@ -480,18 +478,18 @@ def accept_request(message):
if len ( message . text . split ( ) ) == 2 :
if len ( message . text . split ( ) ) == 2 :
bot . approve_chat_join_request ( message . chat . id , message . text . split ( ) [ 1 ] )
bot . approve_chat_join_request ( message . chat . id , message . text . split ( ) [ 1 ] )
bot . reply_to ( message , " Заявка принята. " )
bot . reply_to ( message , " Заявка принята. " )
except :
except Exception as e :
catch_error ( message )
catch_error ( message , e )
######################SUPPORT########
######################SUPPORT########
@bot.message_handler ( commands = [ ' support ' ] )
@bot.message_handler ( commands = [ ' support ' ] )
def support ( message ) :
def support ( message ) :
try :
try :
bot . reply_to ( message , f """ Связь с аднимистратором в @just_anonchat_bot :
bot . reply_to ( message , f """ Связь с аднимистратором в @just_anonchat_bot
Адрес - { telebot . formatting . hcode ( " c :justuser" ) } """ , parse_mode= " HTML " )
Адрес - { telebot . formatting . hcode ( " :justuser" ) } """ , parse_mode= " HTML " )
except :
except Exception as e :
catch_error ( message )
catch_error ( message , e )
#####################WELCOME#####
#####################WELCOME#####
@ -501,8 +499,8 @@ def handler_new_member(message):
global db
global db
read_db ( )
read_db ( )
bot . reply_to ( message , db [ str ( message . chat . id ) ] , parse_mode = ' HTML ' )
bot . reply_to ( message , db [ str ( message . chat . id ) ] , parse_mode = ' HTML ' )
except :
except Exception as e :
catch_error ( message )
catch_error ( message , e )
##############ANALYTIC########
##############ANALYTIC########
@ -528,17 +526,29 @@ global log_stream
log_stream = StringIO ( )
log_stream = StringIO ( )
logging . basicConfig ( stream = log_stream )
logging . basicConfig ( stream = log_stream )
def catch_error ( message , err_type = None ) :
# Known errors
known_errs = {
" A request to the Telegram API was unsuccessful. Error code: 400. Description: Bad Request: not enough rights to restrict/unrestrict chat member " : " Увы, но у бота не хватает прав для этого. "
}
# message error err_type ('no_user', ...)
def catch_error ( message , e , err_type = None ) :
if not err_type :
if not err_type :
global log_stream
global log_stream , known_errs
e = str ( e )
logging . error ( traceback . format_exc ( ) ) # Log error
# Check error in known_errs
err = log_stream . getvalue ( ) # Error to variable
print ( e )
if e in known_errs :
bot . send_message ( message . chat . id , known_errs [ e ] )
else :
logging . error ( traceback . format_exc ( ) ) # Log error
err = log_stream . getvalue ( ) # Error to variable
bot . send_message ( message . chat . id , " 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 . truncate ( 0 ) # Clear
log_stream . seek ( 0 ) # Clear
log_stream . seek ( 0 ) # Clear
elif err_type == " no_user " :
elif err_type == " no_user " :
bot . send_message ( message . chat . id , " Н е указан пользователь." )
bot . send_message ( message . chat . id , " Н е указан пользователь." )
@ -552,6 +562,6 @@ while True:
exit ( )
exit ( )
except :
except :
pass
pass
'''
# '''
bot . polling ( allowed_updates = telebot . util . update_types )
bot . polling ( )
'''
# '''