· 6 years ago · Jan 17, 2020, 07:52 PM
1# CONFIG
2login = 0
3passwd = "#"
4
5
6import os
7import time
8import datetime
9import random
10import vk
11import vk_api
12from vk_api.longpoll import VkLongPoll, VkEventType
13from urllib.parse import quote
14
15def main():
16 print("BOT from \"Lesya BOT\" pwd Shuhov.")
17 print()
18 print("1. ПАССИВНЫЙ РЕЖИМ")
19 print(" учавствует в боях")
20 print()
21 who = int(input("Что будем делать: "))
22
23 the_fight = -1
24
25 if (who == 1):
26 print ("")
27 the_fight = 0
28 elif (who == 2):
29 print("")
30
31 #функции
32 def cmd(message):
33 rand = random.randint(1000000, 999999999999)
34 api.messages.send(peer_id=-158861435,message=message,random_id=rand)
35
36 def captcha_handler(captcha):
37 key = input("Введите код капчи {0}: ".format(captcha.get_url())).strip()
38 return captcha.try_again(key)
39 def clear_cookie():
40 cookie_file = 'vk_config.v2.json'
41 if os.path.exists(cookie_file):
42 os.remove(cookie_file)
43 def to_console(text):
44 time = datetime.datetime.now()
45 time = time.strftime("%d.%m.%Y %H:%M")
46 print(f" [СОБЫТИЕ][{time}] {text}")
47 def fight():
48 cmd("бой")
49 to_console("Бой начат.")
50
51 #функции end
52 clear_cookie()
53
54 session = vk_api.VkApi(
55 app_id=2685278, client_secret='lxhD8OD7dMsqtXIm5IUY',
56 login=login, password=passwd,
57 captcha_handler=captcha_handler # функция для обработки капчи
58 )
59
60 try:
61 session.auth()
62 except vk_api.AuthError as error_msg:
63 print(error_msg)
64 return
65 api = session.get_api()
66
67 launch = 0
68 longpoll = VkLongPoll(session)
69 for event in longpoll.listen():
70
71 if (who == 1):
72 if the_fight == 0:
73 fight()
74 the_fight = 1
75 if event.to_me:
76 if event.from_group:
77 if event.group_id == 158861435:
78 #print(event.text)
79 if the_fight >= 1:
80 victory = event.text.find("Ваши питомцы победили!")
81 no_victory = event.text.find("Ваши питомцы проиграли")
82 if victory > -1: #ПОБЕДА АОАОАОАОАО
83 to_console("Ваши питомцы победили.")
84 fight()
85 if no_victory > -1: #ПОРАЖЕНИЕ АОАОАОАОАО
86 to_console("Ваши питомцы проиграли.")
87 fight()
88 elif event.from_me:
89 if event.from_group:
90 if event.group_id == 158861435:
91 if the_fight >= 1:
92 battle_condition = event.text.find("Вы напали на игрока")
93 if battle_condition > -1:
94 to_console("Бой начат.")
95
96 input("Нажмите Enter для выхода...")
97if __name__ == '__main__':
98 main()