Skip to content

Commit

Permalink
Fix bugs: attempt to kick the admin through addbanlist and antispam bug
Browse files Browse the repository at this point in the history
  • Loading branch information
N1ghtF1re committed Aug 2, 2018
1 parent b559703 commit 9c1ef44
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
15 changes: 8 additions & 7 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

# INITIANALISATION


needkick = [] # Пользователи в ЧС беседы. Формат: [{'id':id, 'chat_id':chat_id}, {...}]


Expand Down Expand Up @@ -110,7 +111,6 @@ def voiceProcessing(event, kick_list,vk,element, ind):
# Формируем и отправляем сообщения о голосе
user_message = bot_msg.vote_accepted.format(str(element['count_yes']),str(element['count_no']))
writeMessage(vk, event.chat_id, user_message)
print(kick_list)
else:
writeMessage(vk, event.chat_id, bot_msg.err_vote_for_yourself)

Expand Down Expand Up @@ -381,14 +381,15 @@ def main():


if (event.type == VkEventType.MESSAGE_NEW) and event.from_chat: # Событие: новое сообщение в чате
event.text = event.text.lower()
if antispam(event,spam_list):

answer = event.text.split() # Отправленное юзверем сообщение

chat_id = event.chat_id


if (len(answer) == 2) and (answer[0].lower() == '!voteban'): # если сообщение из двух строк и первое - служебное !voteban
if (len(answer) == 2) and (answer[0] == '!voteban'): # если сообщение из двух строк и первое - служебное !voteban
if not(chats.isAdmin(vk_session, my_id, chat_id)): # Если бот не является админом
writeMessage(vk_session, chat_id, bot_msg.no_admin_rights)
else:
Expand All @@ -412,7 +413,7 @@ def main():
user_message = bot_msg.voting_is_active
writeMessage(vk_session, chat_id, user_message)

if (len(answer) == 1) and ((answer[0].lower() == '!votehelp') or (answer[0].lower() == '!voteban')):
if (len(answer) == 1) and ((answer[0] == '!votehelp') or (answer[0] == '!voteban')):
message = bot_msg.help.format(const.vote_time, const.vote_count)
writeMessage(vk_session, chat_id , message)
if (len(answer) == 1) and (answer[0] in const.kick_commands) and searchKickList(kick_list, chat_id):
Expand All @@ -421,14 +422,14 @@ def main():
if (len(answer) == 1) and (answer[0] in const.anti_kick_commands) and searchKickList(kick_list, chat_id):
voiceProcessing(event,kick_list,vk_session, searchKickList(kick_list, event.chat_id),'count_no')

if (len(answer) == 2) and (answer[0].lower() == '!unban'):
if (len(answer) == 2) and (answer[0] == '!unban'):
if not (chats.isAdmin(vk_session, event.user_id, chat_id)):
writeMessage(vk_session, event.chat_id, bot_msg.you_are_not_admin)
else:
user_id = answer[1]
unbanUser(vk_session,user_id,needkick,event.chat_id)

if (len(answer) == 1) and (answer[0].lower() == '!banlist'):
if (len(answer) == 1) and (answer[0] == '!banlist'):
user_message = ''
if len(needkick) != 0:
# user_message =
Expand All @@ -443,7 +444,7 @@ def main():
else:
writeMessage(vk_session, event.chat_id, bot_msg.banlist_empty)

if (len(answer) == 2) and (answer[0].lower() == '!addinbanlist'):
if (len(answer) == 2) and (answer[0] == '!addinbanlist'):
if not (chats.isAdmin(vk_session, event.user_id, chat_id)):
writeMessage(vk_session, event.chat_id, bot_msg.you_are_not_admin)
else:
Expand All @@ -453,7 +454,7 @@ def main():
if chats.isUserInConversation(vk_session,user_id,event.chat_id):
checkForBan(vk_session, needkick, event)

if (len(answer) == 1) and (answer[0].lower() == '!uptime'):
if (len(answer) == 1) and (answer[0] == '!uptime'):
now = int(time.time()) # Текущее время
delta = now - start_date # Разница во времени
writeMessage(vk_session, event.chat_id, bot_msg.my_uptime + formatDeltaTime(delta))
Expand Down
2 changes: 1 addition & 1 deletion units/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def isCanKick(vk, user_id, chat_id, NoCheckIN = False):
'''
if not NoCheckIN or getUser(vk,user_id):
if NoCheckIN or chats.isUserInConversation(vk, user_id, chat_id): # Поиск в беседе пользователя. Если найден - продолжаем
if NoCheckIN or not(chats.isAdmin(vk, getUser(vk,user_id)['id'], chat_id)): # Если пользователь - не админ, продолжаем
if not(chats.isUserInConversation(vk, user_id, chat_id)) or not(chats.isAdmin(vk, getUser(vk,user_id)['id'], chat_id)): # Если пользователя нет в беседе или если пользователь - не админ, продолжаем
if not(user_id in const.nokick):
return True
else:
Expand Down

0 comments on commit 9c1ef44

Please sign in to comment.