-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
159 lines (148 loc) · 7.39 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import os
from dotenv import load_dotenv
import helpers
from telegram.ext import (
PicklePersistence,
Application,
CommandHandler,
ConversationHandler,
MessageHandler,
filters,
CallbackQueryHandler
)
from constants import *
from main_menu import start, main_menu, error_handler
from main_menu.admin import send_admin_message, admin
from main_menu.fav_players import get_new_player, get_players_order, add_new_player, type_delete_number, \
favourite_players, type_choose_number, get_chosen_players_order
from main_menu.live import live
from main_menu.live_league import live_league, select_league_match, league_back, league_refresh
from main_menu.matches import matches, get_match_id
from main_menu.players_menu import check_account_id, save_account_id, player_menu, \
type_account_id, wl, recent_matches, player_heroes_stats, peers, totals, \
leaver_status, refresh, wordcloud
from main_menu.players_menu.players_matches import next_hero_list, choose_hero_to_sort, player_matches, sort_by_hero, \
sort_by_kda, sort_by_wl
from main_menu.pro_player import type_pro_player, get_pro_player_name
from warnings import filterwarnings
from telegram.warnings import PTBUserWarning
filterwarnings(action="ignore", message=r".*CallbackQueryHandler", category=PTBUserWarning)
load_dotenv()
def main() -> None:
persistence = PicklePersistence(filepath='persistence.pkl')
app = Application.builder().token(os.getenv('TOKEN')).persistence(persistence).build()
conv_handler = ConversationHandler(
entry_points=[CommandHandler("start", start)],
states={
MAIN_MENU: [
MessageHandler(filters.Regex("^🔍 SEARCH MATCHES$"), matches),
MessageHandler(filters.Regex("^📈 PLAYER'S STATS$"), check_account_id),
MessageHandler(filters.Regex("^🔍 SEARCH PRO PLAYERS$"), type_pro_player),
MessageHandler(filters.Regex("^⭐ FAVOURITE PLAYERS$"), favourite_players),
MessageHandler(filters.Regex("^🔴 LIVE MATCHES$"), live),
MessageHandler(filters.Regex("^🔵 LIVE LEAGUE MATCHES$"), live_league)
],
LIVE: [
MessageHandler(filters.Regex("^MAIN MENU$"), main_menu)
],
LIVE_LEAGUE: [CallbackQueryHandler(select_league_match)],
SELECTED_LEAGUE_MATCH: [
CallbackQueryHandler(league_back, pattern="^back$"),
CallbackQueryHandler(league_refresh, pattern="^refresh$")
],
TYPING_MATCH_ID: [MessageHandler(filters.TEXT & ~filters.COMMAND, get_match_id)],
TYPE_PRO_PLAYER: [MessageHandler(filters.TEXT & ~filters.COMMAND, get_pro_player_name)],
ADD_NEW_PLAYER: [MessageHandler(filters.TEXT & ~filters.COMMAND, get_new_player)],
DELETE_PLAYER: [MessageHandler(filters.TEXT & ~filters.COMMAND, get_players_order)],
CHOOSE_PLAYER: [MessageHandler(filters.TEXT & ~filters.COMMAND, get_chosen_players_order)],
MATCHES: [
MessageHandler(filters.Regex("^WRITE OTHER ID$"), matches),
],
PRO_PLAYER: [
MessageHandler(filters.Regex("^WRITE OTHER PLAYER$"), type_pro_player),
],
TYPE_ACCOUNT_ID: [MessageHandler(filters.TEXT & ~filters.COMMAND, save_account_id)],
WL: [MessageHandler(filters.Regex("^BACK$"), check_account_id)],
RECENT_MATCHES: [MessageHandler(filters.Regex("^BACK$"), check_account_id)],
SORT_BY_HERO: [
MessageHandler(filters.Regex("^NEXT LIST$"), next_hero_list),
MessageHandler(filters.Regex("^BACK$"), choose_hero_to_sort),
MessageHandler(filters.Regex("^BACK TO SORT MENU$"), player_matches),
MessageHandler(filters.TEXT & ~filters.COMMAND, sort_by_hero),
],
PLAYER_MATCHES: [
MessageHandler(filters.Regex("^KILLS$"), sort_by_kda),
MessageHandler(filters.Regex("^DEATHS$"), sort_by_kda),
MessageHandler(filters.Regex("^ASSISTS$"), sort_by_kda),
MessageHandler(filters.Regex("^WIN$"), sort_by_wl),
MessageHandler(filters.Regex("^LOSE$"), sort_by_wl),
MessageHandler(filters.Regex("^HERO$"), choose_hero_to_sort),
MessageHandler(filters.Regex("^BACK$"), player_matches),
MessageHandler(filters.Regex("^BACK TO PLAYER'S MENU$"), player_menu),
],
PLAYER_HEROES: [
MessageHandler(filters.Regex("^BACK$"), player_menu),
],
PEERS: [
MessageHandler(filters.Regex("^BACK$"), player_menu),
],
TOTALS: [
MessageHandler(filters.Regex("^BACK$"), player_menu),
],
LEAVER_STATUS: [
MessageHandler(filters.Regex("^BACK$"), player_menu),
],
WORDCLOUD: [
MessageHandler(filters.Regex("^BACK$"), player_menu),
],
REFRESH: [
MessageHandler(filters.Regex("^BACK$"), player_menu),
],
FAVOURITE_PLAYERS: [
MessageHandler(filters.Regex("^ADD NEW PLAYER$"), add_new_player),
MessageHandler(filters.Regex("^DELETE PLAYER$"), type_delete_number),
MessageHandler(filters.Regex("^CHOOSE PLAYER$"), type_choose_number),
MessageHandler(filters.Regex("^BACK$"), main_menu),
],
PLAYERS: [
MessageHandler(filters.Regex("^CHOOSE ANOTHER PLAYER$"), favourite_players),
MessageHandler(filters.Regex("^WRITE OTHER ID$"), type_account_id),
MessageHandler(filters.Regex("^PLAYER'S MENU$"), player_menu),
MessageHandler(filters.Regex("^MAIN MENU$"), main_menu),
MessageHandler(filters.Regex("^WIN/LOSE$"), wl),
MessageHandler(filters.Regex("^RECENT MATCHES$"), recent_matches),
MessageHandler(filters.Regex("^SORTED MATCHES$"), player_matches),
MessageHandler(filters.Regex("^MOST PICKED HEROES$"), player_heroes_stats),
MessageHandler(filters.Regex("^PEERS$"), peers),
MessageHandler(filters.Regex("^TOTALS$"), totals),
MessageHandler(filters.Regex("^LEAVER STATUS$"), leaver_status),
MessageHandler(filters.Regex("^REFRESH$"), refresh),
MessageHandler(filters.Regex("^WORDCLOUD$"), wordcloud)
],
UNKNOWN: [
CommandHandler("menu", start)
],
TYPE_ADMIN_MESSAGE: [
MessageHandler(filters.TEXT & ~filters.COMMAND, send_admin_message)
],
ADMIN: [
MessageHandler(filters.Regex("^GOT IT$"), main_menu),
]
},
fallbacks=[
CommandHandler("admin", admin),
CommandHandler("menu", start),
MessageHandler(filters.Regex("^🔴 LIVE MATCHES$"), live),
MessageHandler(filters.Regex("^🔵 LIVE LEAGUE MATCHES$"), live_league),
MessageHandler(filters.Regex("^MAIN MENU$"), main_menu)
],
persistent=True,
name='main_conv'
)
app.add_handler(conv_handler)
app.add_error_handler(error_handler)
helpers.mongodb_heroes_init()
helpers.mongodb_pro_players_init()
app.run_polling()
if __name__ == "__main__":
main()