@ -48,6 +48,14 @@ def write_users():
outfile . write ( js )
outfile . write ( js )
####################FAST HASH#################
from xxhash import xxh32
# Generate fast hash
def sha ( text ) :
text = str ( text )
return xxh32 ( text ) . hexdigest ( )
##################FUNCTIONS########
##################FUNCTIONS########
def get_admins ( message ) :
def get_admins ( message ) :
@ -68,14 +76,38 @@ def get_admins(message):
def get_target ( message ) :
def get_target ( message ) :
try :
try :
target = message . reply_to_message . from_user . id
# if True:
if target not in get_admins ( message ) :
if len ( message . text . split ( ) ) > 1 and message . text . split ( ) [ 1 ] [ 0 ] == " @ " :
return target
username = message . text . split ( ) [ 1 ] [ 1 : ]
global users
if sha ( username ) in users :
return users [ sha ( username ) ]
else :
return None
else :
else :
return None
target = message . reply_to_message . from_user . id
if target not in get_admins ( message ) :
return target
else :
return None
except :
except :
return None
return None
def get_name ( message ) :
try :
text = message . text . split ( )
# If message with @username
if len ( text ) > 1 and text [ 1 ] [ 0 ] == ' @ ' :
return text [ 1 ]
# Reply to message
else :
return telebot . util . user_link ( message . reply_to_message . from_user )
except :
catch_error ( message )
#return telebot.util.user_link(message.reply_to_message.from_user)
def key_by_value ( dictionary , key ) :
def key_by_value ( dictionary , key ) :
for i in dictionary :
for i in dictionary :
if dictionary [ i ] == key :
if dictionary [ i ] == key :
@ -85,14 +117,12 @@ def key_by_value(dictionary, key):
def analytic ( message ) :
def analytic ( message ) :
global users
global users
# print(message.from_user.username)
if key_by_value ( users , message . from_user . id ) == message . from_user . username :
if key_by_value ( users , message . from_user . id ) == message . from_user . username :
print ( 11111 )
pass
elif message . from_user . username == " None " :
elif message . from_user . username == " None " :
print ( 22222 )
pass
else :
else :
users [ message. from_user . username ] = message . from_user . id
users [ sha( message. from_user . username ) ] = message . from_user . id
write_users ( )
write_users ( )
@ -100,6 +130,7 @@ def analytic(message):
read_db ( )
read_db ( )
read_users ( )
bot = telebot . TeleBot ( db [ ' token ' ] )
bot = telebot . TeleBot ( db [ ' token ' ] )
@ -142,11 +173,14 @@ def mute(message):
if target :
if target :
if len ( message . text . split ( ) ) == 1 :
if len ( message . text . split ( ) ) == 1 :
bot . restrict_chat_member ( message . chat . id , target , until_date = message . date )
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 ' )
bot . reply_to ( message , f """ Пользователь { get_name ( message ) } был заглушен. """ , parse_mode = ' HTML ' )
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
time = int ( message . text . split ( ) [ 1 ] ) * 60
bot . restrict_chat_member ( message . chat . id , target , until_date = message . date + 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 ' )
bot . reply_to ( message , f """ Пользователь { get_name( message ) } был заглушён на { time / 60 } минут(ы). """ , parse_mode = ' HTML ' )
else :
else :
catch_error ( message , " no_user " )
catch_error ( message , " no_user " )
else :
else :
@ -162,7 +196,7 @@ def unmute(message):
target = get_target ( message )
target = get_target ( message )
if target :
if target :
bot . restrict_chat_member ( message . chat . id , target , can_send_messages = True , can_send_other_messages = True , until_date = message . date )
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 ) } снова имеет дар речи.
bot . reply_to ( message , f """ Пользователь { get_name( message ) } снова имеет дар речи.
""" , parse_mode= ' HTML ' )
""" , parse_mode= ' HTML ' )
else :
else :
catch_error ( message , " no_user " )
catch_error ( message , " no_user " )
@ -181,7 +215,7 @@ def kick(message):
bot . ban_chat_member ( message . chat . id , target )
bot . ban_chat_member ( message . chat . id , target )
bot . unban_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 ) } был исключён.
bot . reply_to ( message , f """ Пользователь { get_name( message ) } был исключён.
""" , parse_mode= ' HTML ' )
""" , parse_mode= ' HTML ' )
else :
else :
catch_error ( message , " no_user " )
catch_error ( message , " no_user " )
@ -198,7 +232,7 @@ def ban(message):
target = get_target ( message )
target = get_target ( message )
if target :
if target :
bot . ban_chat_member ( message . chat . id , target )
bot . ban_chat_member ( message . chat . id , target )
bot . reply_to ( message , f """ Пользователь { telebot. util . user_link ( message . reply_to_message . from_user ) } исключён и заблокирован.
bot . reply_to ( message , f """ Пользователь { get_name( message ) } исключён и заблокирован.
""" , parse_mode= ' HTML ' )
""" , parse_mode= ' HTML ' )
else :
else :
catch_error ( message , " no_user " )
catch_error ( message , " no_user " )
@ -214,7 +248,7 @@ def unban(message):
target = get_target ( message )
target = get_target ( message )
if target :
if target :
bot . unban_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 ) } разблокирован.
bot . reply_to ( message , f """ Пользователь { get_name( message ) } разблокирован.
""" , parse_mode= ' HTML ' )
""" , parse_mode= ' HTML ' )
else :
else :
catch_error ( message , " no_user " )
catch_error ( message , " no_user " )
@ -282,6 +316,27 @@ def getid(message):
@bot.message_handler ( commands = [ ' secret ' ] )
def secret ( message ) :
try :
if message . from_user . id in get_admins ( 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 :
bot . reply_to ( message , " Увы, но у вас нету прав. " )
except :
catch_error ( message )
@bot.message_handler ( commands = [ ' html ' ] )
def html ( message ) :
try :
text = ' ' . join ( message . text . split ( ) [ 1 : ] )
bot . send_message ( message . chat . id , text , parse_mode = ' HTML ' )
bot . delete_message ( message . chat . id , message . id )
except :
catch_error ( message )
######################SUPPORT########
######################SUPPORT########
@bot.message_handler ( commands = [ ' support ' ] )
@bot.message_handler ( commands = [ ' support ' ] )
@ -324,11 +379,7 @@ def handler_new_member(message):
@bot.message_handler ( func = lambda message : True )
@bot.message_handler ( func = lambda message : True )
def catch_all_messages ( message ) :
def catch_all_messages ( message ) :
#analytic(message)
analytic ( message )
global users
print ( " I see " )
print ( key_by_value ( users , message . from_user . id ) )
print ( " I don ' t see " )
# For what?
# For what?
# This add users = {}
# This add users = {}
@ -353,7 +404,7 @@ def catch_error(message, err_type = None):
logging . error ( traceback . format_exc ( ) ) # Log error
logging . error ( traceback . format_exc ( ) ) # Log error
err = log_stream . getvalue ( ) # Error to variable
err = log_stream . getvalue ( ) # Error to variable
bot . reply_to ( message , " Critical error (свяж е тись через /support сообщение ) :\n \n " + telebot . formatting . hcode ( err ) , parse_mode = ' HTML ' )
bot . reply_to ( message , " 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