-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
170 lines (133 loc) · 4.74 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
160
161
162
163
164
165
166
167
168
169
170
import requests
from telegram import ParseMode
import json
from typing import Tuple, Dict, Any, Optional
from telegram import ReplyKeyboardMarkup, ReplyKeyboardRemove, Bot
from telegram import InlineKeyboardMarkup, InlineKeyboardButton, Update
import logging
from telegram.ext import (
Updater,
CommandHandler,
MessageHandler,
Filters,
ConversationHandler,
CallbackQueryHandler,
CallbackContext,
ChatMemberHandler,
)
from telegram import Update, Chat, ChatMember, ParseMode, ChatMemberUpdated, KeyboardButtonPollType, Poll, KeyboardButton
from telegram.ext import (
Updater,
CommandHandler,
PollAnswerHandler,
PollHandler,
MessageHandler,
Filters,
CallbackContext,
)
from telegram.utils import helpers
logging.basicConfig(
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO
)
logger = logging.getLogger(__name__)
CHAT_ID = -1001386280522
def get_db() -> list():
url = 'https://leetcode-rating.herokuapp.com/rating'
r = requests.get(url)
db = r.json()
return db
def get_token () -> str:
with open ("token.txt", "r") as myfile:
# FUCK YOU HACKERS
token=myfile.read().replace('\n', '')
return token
def get_text(n_min = 0, n_max = None) -> str:
db = get_db()
response = ""
if n_max == None:
n_max = len(db)
for i in db[n_min:n_max]:
response += f"{i['username']}: {i['score']}\n"
return response
def select_tail(update: Update, context: CallbackContext) -> None:
user = update.message.from_user
chat = update.effective_chat
text = update.message.text
if chat.id != CHAT_ID:
return
response = get_text(n_min = -11)
response += '\nЕсли ты в списке, то иди чаль прогу'
update.message.reply_text(response)
return
def select_top(update: Update, context: CallbackContext) -> None:
user = update.message.from_user
chat = update.effective_chat
text = update.message.text
if chat.id != CHAT_ID:
return
response = get_text(n_min = 0, n_max = 11)
response += '\nЕсли ты не в списке, то иди чаль прогу'
update.message.reply_text(response)
return
def select_update(update: Update, context: CallbackContext) -> None:
user = update.message.from_user
chat = update.effective_chat
text = update.message.text
logger.info(user.id)
if chat.id != CHAT_ID:
return
try:
output = requests.options('https://leetcode-rating.herokuapp.com/update-scores').headers
except:
update.message.reply_text("Ошибка, хз мой создатель тупее меня самого")
return
response = f'Обновлено в {output["Date"]}'
update.message.reply_text(response)
return
def select_me(update: Update, context: CallbackContext) -> None:
user = update.message.from_user
chat = update.effective_chat
text = update.message.text
if chat.id != CHAT_ID:
return
if len(text.split(' ')) != 2:
update.message.reply_text("""Брух, есімің кім?\n\n/me <LEETCODE username>""")
return
db = get_db()
leetcode_username = text.split(' ')[1]
for i in db:
if leetcode_username.lower() == i['username'].lower():
update.message.reply_text(f"{i['username']}: {i['score']}\n\nЯ не холодильник, каждый раз открывая ничего не появится. Иди чаль прогу")
return
update.message.reply_text("Не нашел.\nЕсли не нашел значит не чалишь. Иди чаль прогу")
return
def select_stats(update: Update, context: CallbackContext) -> None:
user = update.message.from_user
chat = update.effective_chat
text = update.message.text
if chat.id != CHAT_ID:
return
if '-y' not in text.split(' ')[:3]:
update.message.reply_text("""Братиш, где -y? ты что хочешь всех заспамить огромным текстом?
Лучше напиши /top или /me <username>""")
return
update.message.reply_text(get_text())
return
def main() -> None:
updater = Updater(get_token()) # liberobot
dispatcher = updater.dispatcher
logs_handlers = [
# CommandHandler("stats", select_stats, Filters.chat_type.groups),
CommandHandler("top", select_top),
CommandHandler("update", select_update),
CommandHandler("tail", select_tail),
CommandHandler("me", select_me),
]
for i in logs_handlers:
dispatcher.add_handler(i)
updater.start_polling(allowed_updates=Update.ALL_TYPES)
updater.idle()
return
if __name__ == '__main__':
# print(get_db())
main()