Compare commits

..

10 Commits

Author SHA1 Message Date
hogweed1
72f96576ba море спася геноцид
All checks were successful
continuous-integration/drone/push Build is passing
2025-05-12 21:58:05 +10:00
hogweed1
81db0b2bdb море спася геноцид
All checks were successful
continuous-integration/drone/push Build is passing
2025-05-12 21:57:58 +10:00
hogweed1
2830335b12 space genocide
All checks were successful
continuous-integration/drone/push Build is passing
2025-05-12 21:52:47 +10:00
hogweed1
7e52c86067 be be bechka lo
All checks were successful
continuous-integration/drone/push Build is passing
2025-05-12 21:38:25 +10:00
hogweed1
5f0d211a9b be be be
All checks were successful
continuous-integration/drone/push Build is passing
2025-05-12 21:30:41 +10:00
hogweed1
f4a1cee509 be be be
All checks were successful
continuous-integration/drone/push Build is passing
2025-05-12 21:28:36 +10:00
3b4454fd44 Update handlers/metrics.py
All checks were successful
continuous-integration/drone/push Build is passing
2025-05-12 21:26:04 +10:00
f7a13962f0 init gauges once
All checks were successful
continuous-integration/drone/push Build is passing
init gauges onceinit gauges onceinit gauges onceinit gauges onceinit gauges onceinit gauges onceinit gauges onceinit gauges onceinit gauges onceinit gauges onceinit gauges onceinit gauges onceinit gauges onceinit gauges onceinit gauges onceinit gauges onceinit gauges onceinit gauges once
2025-05-12 21:25:08 +10:00
8a1013d280 Update db_logic/user_stuff.py
All checks were successful
continuous-integration/drone/push Build is passing
2025-05-12 21:12:12 +10:00
afc9b61e92 Update db_logic/user_stuff.py
All checks were successful
continuous-integration/drone/push Build is passing
2025-05-12 21:06:33 +10:00
17 changed files with 112 additions and 176 deletions

7
bot.py
View File

@@ -7,7 +7,6 @@ from global_conf import CONFIG
from prometheus_client import start_http_server
def remake_field_generator(d, field='text'):
if isinstance(d, list):
for k2 in d:
@@ -37,7 +36,6 @@ def filter_grammar_messages(record):
logging.basicConfig(level=logging.DEBUG)
logging.getLogger("aiogram").addFilter(filter_grammar_messages)
# pipisa.register_handlers_pipisa(dp)
# time_new_year.register_handlers_time(dp)
# sendalarm.register_handlers_test(dp)
@@ -49,8 +47,3 @@ if __name__ == '__main__':
logging.info('Бот в строю.')
executor.start_polling(dp, skip_updates=True)
logging.info('Всем пока.')

View File

@@ -2,7 +2,5 @@ from aiogram import Bot, Dispatcher
from global_conf import CONFIG
bot = Bot(token=CONFIG['telegram_token'], parse_mode="HTML")
dp = Dispatcher(bot)

View File

@@ -1,9 +1,6 @@
from global_conf import CONFIG
#### https://docs.python-arango.com/en/main/
from arango import ArangoClient
import logging
import os
@@ -25,10 +22,9 @@ def get_dicks_collection():
logging.error('ошибка DB при взятии коллекции пипис')
logging.error(e)
def get_posts_removal_collection():
try:
arango_client = ArangoClient(hosts=CONFIG['databaso']['host'] )
arango_client = ArangoClient(hosts=CONFIG['databaso']['host'])
pipisa_db = arango_client.db(
CONFIG['databaso']['base'],
username=os.environ['ARANGO_USR'],

View File

@@ -2,14 +2,13 @@ from db_logic import collections
import datetime, logging
def append_post_to_cleaning_sequence(message, type=None):
try:
novenkiy = {
'msg_id': message.message_id,
'chat_id': message.chat.id,
'type': type,
'datetimes': datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
'msg_id': message.message_id,
'chat_id': message.chat.id,
'type': type,
'datetimes': datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
}
metadata = collections.get_posts_removal_collection().insert(novenkiy, overwrite_mode='update')
@@ -18,7 +17,6 @@ def append_post_to_cleaning_sequence(message, type=None):
logging.error('ошибка DB :: добавление нового поста на удаление')
logging.error(e2)
def get_posts_to_be_removed(chat_id, type=None, max_id=None):
# собираем
try:
@@ -42,7 +40,6 @@ def get_posts_to_be_removed(chat_id, type=None, max_id=None):
else:
posts_ret = [ p for p in posts_ret if p['msg_id'] != max([pp['msg_id'] for pp in posts_ret])]
#### TODO удалять все предыдущие без учёта времени
return posts_ret
@@ -50,11 +47,9 @@ def get_posts_to_be_removed(chat_id, type=None, max_id=None):
logging.error('ошибка DB :: получение постов на удаление')
logging.error(e)
def del_post(msg_id, chat_id):
# удаляем из базы
try:
candidate_cursor = collections.get_posts_removal_collection().find(
{
'msg_id': msg_id,

View File

@@ -4,7 +4,6 @@ import logging
def get_tops(top_ = False, glob_ = False, chat_id = None):
if top_:
try:
dicks = [d for d in collections.get_dicks_collection().find({'chat_id': chat_id}, skip=0, limit=1100)]
@@ -20,8 +19,8 @@ def get_tops(top_ = False, glob_ = False, chat_id = None):
else:
logging.error('вызывают хз что!')
top_dicks = sorted(dicks, key=lambda dick: dick['dick_size'], reverse=True)
top_dicks = top_dicks[:( min(len(top_dicks), 10) )]
top_dicks = sorted(dicks, key=lambda dick: dick['dick_size'], reverse=True)
top_dicks = top_dicks[:(min(len(top_dicks), 10))]
dickos = ''
emo = ['🏆','🚀','🍆','🍌','🐍','🐎','🌭','🌶','👌','💩']
@@ -33,7 +32,6 @@ def get_tops(top_ = False, glob_ = False, chat_id = None):
return dickos
def get_antitops(top_ = False, glob_ = False, chat_id = None):
dicks = []
if top_:

View File

@@ -4,7 +4,6 @@ import datetime, logging
def store_new_user(message, result ):
try:
novenkiy = {
'user_id': message.from_user.id,
@@ -16,12 +15,12 @@ def store_new_user(message, result ):
}
metadata = collections.get_dicks_collection().insert(novenkiy, overwrite_mode='update')
metric_wrap(message.chat.id, message.from_user.full_name, abs(result), 1)
logging.debug(f'Успешно добавлен нового пользователь @{message.from_user.username}')
except Exception as e2:
logging.error(f'ошибка DB в /dick :: добавление нового пользователя @{message.from_user.username}')
logging.error(e2)
def update_attempts(message, user ):
try:
metadata = collections.get_dicks_collection().insert(
@@ -37,14 +36,13 @@ def update_attempts(message, user ):
overwrite_mode='update'
)
metric_wrap(message.chat.id, message.from_user.full_name, user['dick_size'], user['attempts'] + 1)
logging.debug(f'Успешно апдейтнули попытку крутить пипису @{message.from_user.username}')
except Exception as e2:
logging.error(f'ошибка DB в /dick :: обновление попытки крутить пипису @{message.from_user.username}')
logging.error(e2)
def update_dick_size(message, user, updatedDick ):
try:
metadata = collections.get_dicks_collection().insert(
{
@@ -65,7 +63,6 @@ def update_dick_size(message, user, updatedDick ):
logging.error(f'ошибка DB в /dick :: обновление пиписы @{message.from_user.username}')
logging.error(e2)
def get_user(message):
try:
#### Чекнуть есть ли юзер в базе

View File

@@ -1,12 +1,11 @@
import random
def RandomDick():
# Забирает рандомный синоним к слову хуй из dick_sinonims.txt
# у линуха и винды не забывай про разные \/
# когда указываешь путь
# кёгда указываешь путь
with open('dicktxt/dick_sinonims.txt', 'r', encoding='utf-8') as file:
words = file.readlines()
return random.choice(words).strip()

View File

@@ -2,8 +2,7 @@ import yaml
import random
def ChangeWord(result): #выбирает рандомное слово для изменения размера пиписы
def ChangeWord(result): #збiрає будь-якое слiво для змєнєння розмiра пiпiси
with open("dicktxt/dick_changes.yaml", 'r', encoding='utf-8') as f:
words = yaml.load(f, Loader=yaml.Loader)

View File

@@ -1 +1,2 @@
from . import ForReadDict

View File

@@ -1,6 +1,11 @@
import yaml
with open("config.yaml", 'r') as f:
CONFIG = yaml.load(f, Loader=yaml.Loader)
METRICS_INITIALIZED = False
pipisa_length_metric = None
user_attempt_metric = None
user_last_attempt_metric = None

View File

@@ -1,6 +1,4 @@
from handlers import pipisa
from handlers import start_help
from handlers import time_new_year

View File

@@ -4,11 +4,9 @@ from create_bot import dp, bot
import logging
from global_conf import CONFIG
admins = CONFIG['telegram_admins_ids']
ban_comands = ['/dick','/topdick']
ban_comands = ['/dick','/topdick']
# Image_promt =['тупица сгенерируй','тупица сгенерируй картинку',\
# 'тупица отправь картинку', 'тупица отправь картинку']
@@ -40,7 +38,6 @@ client = AsyncOpenAI(api_key="sk-BmDsaPA1jByz8QcVxMYDT3BlbkFJwjqBXBAcRQ1aWDzhTQy
# except Exception as e:
# await message.reply('у меня не получилось')
async def gpt_text(req):
completion = await client.chat.completions.create(
messages=[
@@ -58,13 +55,3 @@ async def send(message: types.Message):
if message.from_user.id in admins and message.chat.type == 'private':
response = await gpt_text(message.text)
await message.answer(response.choices[0].message.content)

View File

@@ -1,25 +1,29 @@
import json
import time
from prometheus_client import Gauge, Info
from global_conf import pipisa_length_metric, user_attempt_metric, user_last_attempt_metric
class user_info_struct:
user_id: str
user_fullname: str
dick_size: int
datetimes: str
attemptsCount: int
chat_id: int
user_id: str
user_fullname: str
dick_size: int
datetimes: str
attemptsCount: int
chat_id: int
def metric_wrap(chatID:int, userName: str, length: int, attemptsCount: int):
"""Pass here chat ID, username, pipisa length and attempts count to wrap them into metric."""
pipisa_length_metric = Gauge('user_length_total', 'Pipisa length', labelnames=['ChatID', 'Username'])
user_attempt_metric = Gauge('user_attempts_total', 'Attempts count', labelnames=['ChatID', 'Username'])
user_last_attempt_metric = Gauge('user_last_attempt_time', 'Last attempt time', labelnames=['ChatID', 'Username'])
global pipisa_length_metric
if not pipisa_length_metric:
pipisa_length_metric = Gauge('user_length_total', 'Pipisa length', labelnames=['ChatID', 'Username'])
global user_attempt_metric
if not user_attempt_metric:
user_attempt_metric = Gauge('user_attempts_total', 'Attempts count', labelnames=['ChatID', 'Username'])
global user_last_attempt_metric
if not user_last_attempt_metric:
user_last_attempt_metric = Gauge('user_last_attempt_time', 'Last attempt time', labelnames=['ChatID', 'Username'])
pipisa_length_metric.labels(chatID, userName).set(length)
user_attempt_metric.labels(chatID, userName).set(attemptsCount)

View File

@@ -5,22 +5,16 @@ from random import randint
import datetime, logging
from dicktxt import ForReadDict, WordsChange
from pipisa_functions import pipisa_time
from global_conf import CONFIG
from db_logic import tops, user_stuff, postcleaner
admins = CONFIG['telegram_admins_ids']
@dp.message_handler(commands=["dick"])
async def up_dick(message: types.Message):
if message.from_user.id in admins or message.chat.type != 'private':
postcleaner.append_post_to_cleaning_sequence(message=message, type=f'COMMAND_CALL__DICK')
await clean_posts(chat_id=message.chat.id, type='COMMAND_CALL__DICK', max_id=message.message_id)
@@ -66,8 +60,6 @@ async def up_dick(message: types.Message):
else:
await message.reply('Растить елду можно только в общих чатах!')
@dp.message_handler(commands = ['topdick', 'globaldick'])
async def send_topchat(message: types.Message):
if message.from_user.id in admins or message.chat.type != 'private':
@@ -86,7 +78,6 @@ async def send_topchat(message: types.Message):
else:
logging.error('вызывают хз что!')
if not dickos:
await bot.send_message(message.chat.id, '🍆 Никто ничего не нарастил! 🍌')
else:
@@ -98,7 +89,6 @@ async def send_topchat(message: types.Message):
await message.reply('Работает только в общих чатах!\n'\
'Вы можете посмотреть топ по миру /globaldick')
@dp.message_handler(commands = ['antitopdick', 'antiglobaldick'])
async def send_antitopchat(message: types.Message):
if message.from_user.id in admins or message.chat.type != 'private':
@@ -127,8 +117,6 @@ async def send_antitopchat(message: types.Message):
await message.reply('Работает только в общих чатах!\n'\
'Вы можете посмотреть антитоп по миру /antiglobaldick')
async def clean_posts(chat_id, type=None, max_id=None):
psts = postcleaner.get_posts_to_be_removed(chat_id, type, max_id)
@@ -138,9 +126,7 @@ async def clean_posts(chat_id, type=None, max_id=None):
#### TODO проверить админит ли бот
try:
await bot.delete_message( chat_id=p['chat_id'], message_id=p['msg_id'], )
await bot.delete_message(chat_id=p['chat_id'], message_id=p['msg_id'])
except Exception as e:
logging.error('ошибка удаления поста-на-удаление')
logging.error(e)

View File

@@ -5,23 +5,14 @@ from create_bot import dp, bot
@dp.message_handler(commands=['start'])
async def start_func(message: types.Message):
if message.chat.type == 'private':
lkb = InlineKeyboardMarkup(row_width=1).add(InlineKeyboardButton(text = 'Добавить в группу', callback_data='add_2_group'))
await message.answer(f'<b>Добро пожаловать, {message.from_user.full_name}!</b>\n'
'Это бот, который растит члены. Чтобы начать, добавь бота в чат'\
, reply_markup=lkb
)
# TODO добавить кнопку, по которой смогут добавлять юзера в чат
@dp.callback_query_handler(text = 'add_2_group')
async def addgroup(callback: types.CallbackQuery):
await callback.answer('жмав')

View File

@@ -22,6 +22,5 @@ async def send_time(message: types.Message):
await message.reply(f'Сегодня {cd} \nВремя: {ct2} \nДо Нового Года осталось {num}')
def register_handlers_time(dp: Dispatcher):
dp.register_message_handler(send_time)

View File

@@ -2,9 +2,7 @@ import unittest
import datetime
def rolltime(check_datetime , curr_time=datetime.datetime.now()):
last_time = datetime.datetime.strptime(check_datetime, '%Y-%m-%d %H:%M:%S')
time_to_grow = curr_time.replace(hour=10, minute=0, second=0, microsecond=0) #+ datetime.timedelta(days=0)
@@ -16,14 +14,11 @@ def rolltime(check_datetime , curr_time=datetime.datetime.now()):
# print(f'\tcurr_time : {curr_time.strftime("%Y-%m-%d %H:%M:%S")}')
# print(f'\t\tsecs diff : {timediff}')
if timediff > 86400 or (curr_time > time_to_grow and last_time < time_to_grow):
return True
else:
return False
class TestPipisa(unittest.TestCase):
def test_very_long_ago(self):
self.assertEqual(rolltime('2021-10-11 23:44:00'), True, "Пиписа прокручена очень давно. Очевидный прокрут")
@@ -42,7 +37,6 @@ class TestPipisa(unittest.TestCase):
datetime.datetime.now().replace(hour=10, minute=1, second=0, microsecond=0)
), True, "Крутилась вчера через минуту после обновления роллов. Должно пропускать ")
def test_hour_before_roll(self):
self.assertEqual(
rolltime(
@@ -79,9 +73,5 @@ class TestPipisa(unittest.TestCase):
datetime.datetime.now().replace(hour=10, minute=19, second=0, microsecond=0)
), False, "Сегодня уже открутили а хотят ещё. Фейл.")
if __name__ == "__main__":
unittest.main(verbosity=2)