-
Notifications
You must be signed in to change notification settings - Fork 0
/
funcs.py
80 lines (57 loc) · 2.64 KB
/
funcs.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
from aiogram import Bot, types
from Database.DataUsers import *
from buttons import *
from dotenv import load_dotenv
import re
from functools import lru_cache
import string
import random
load_dotenv()
bot = Bot(token=os.getenv("TOKEN"))
async def show_rating(chat_id: int):
# Запрос топ 4 пользователей из БД
top_users = supabase.table('UsersData').select('full_name', 'balance', 'tgusr').order('balance', desc = True).limit(4).execute()
# Формируем текст рейтинга
rating_text = "🏆 Рейтинг пользователей 🏆\n\n"
for i, user in enumerate(top_users.data):
position = i + 1
full_name = user['full_name']
balance = user['balance']
tgusr = user['tgusr']
rating_text += f"{position}. {full_name} ({tgusr}) - {balance} баллов\n"
# Отправляем сообщение
await bot.send_message(chat_id, rating_text, reply_markup=ikbmadminrating)
async def show_user_rating(chat_id: int):
# Запрос топ 4 пользователей из БД
top_users = supabase.table('UsersData').select('full_name', 'balance', ).order('balance', desc = True).limit(4).execute()
# Формируем текст рейтинга
rating_text = "🏆 Рейтинг пользователей 🏆\n\n"
for i, user in enumerate(top_users.data):
position = i + 1
full_name = user['full_name']
balance = user['balance']
rating_text += f"{position}. {full_name} - {balance} баллов\n"
# Отправляем сообщение
await bot.send_message(chat_id, rating_text, reply_markup=ikbmrating)
# generate id for survey
async def generate_id_for_survey(length):
characters = string.ascii_letters + string.digits
random_string = ''.join(random.choice(characters) for _ in range(length))
return random_string
# Validation BAD words
standart_dirt = [1093, 1091, 1081, 124, 1073, 1083, 1103, 124, 1077, 1073, 124,
1087, 1080, 1079, 1076, 124, 1105, 1073, 124, 1079, 1072, 1083, 1091, 1087] # censored
standart_dirt = ''.join(chr(n) for n in standart_dirt)
def _get_search(pattern: str):
@lru_cache()
def hide_search(word: str) -> bool:
return bool(re.search(pattern, word))
return hide_search
def is_dirt(pattern: str=standart_dirt):
funk = _get_search(pattern)
def hide_search(text: str) -> bool:
for word in re.findall(r'\w+', text):
if funk(word.lower()):
return True
return False
return hide_search