add structure to code
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Pavel_Duron 2022-12-05 17:22:23 +10:00
parent c0e0b51dee
commit 31abb3460a
6 changed files with 200 additions and 192 deletions

200
bot.py
View File

@ -1,208 +1,24 @@
from cgitb import text from create_bot import dp
import datetime
import logging import logging
from random import randint from aiogram import executor
from sqlalchemy import create_engine, MetaData, Table, Integer, String, \ from handlers import pipisa, time_new_year, start_help
Column, DateTime, ForeignKey, Numeric
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
from aiogram import Bot, Dispatcher, executor, types
from aiogram.types import ReplyKeyboardRemove, ReplyKeyboardMarkup, KeyboardButton
from sqdb import user, session, engine
print('Бот начал работу')
API_TOKEN = '5724991559:AAEuLvpLsgP6LHRGMSyFtQLlR5qPQUO4b_w'
logging.basicConfig(level=logging.DEBUG) logging.basicConfig(level=logging.DEBUG)
bot = Bot(token=API_TOKEN, parse_mode="HTML")
dp = Dispatcher(bot)
@dp.message_handler(commands=["chat"])
async def send_chat(message: types.Message):
await message.answer(f'{message.chat.id}')
@dp.message_handler(commands=["time"]) pipisa.register_handlers_pipisa(dp)
async def send_time(message: types.Message): time_new_year.register_handlers_time(dp)
new_year = datetime.datetime(2022, 12, 31) #дата нового года
ct = datetime.datetime.now() #датавремя
cd = datetime.datetime.now().strftime("%d/%m/%Y") #дата (д,м,г)
ct1 = ct+datetime.timedelta(hours=15) # +14 часов от сервера
ct2 = ct1.strftime('%H:%M') # форматирует датувремя просто во время(ч,м)
raznitsa = (new_year - ct).days #отнимает от нг текущее время и получаем разницу в днях
days = ['день', 'дня', 'дней'] start_help.register_handlers_StartHelp(dp)
if raznitsa % 10 == 1 and raznitsa % 100 != 11:
p = 0
elif 2 <= raznitsa % 10 <= 4 and (raznitsa % 100 < 10 or raznitsa % 100 >= 20):
p = 1
else:
p = 2
num=(str(raznitsa) + ' ' + days[p])
await message.reply(f'Сегодня {cd} \nВремя: {ct2} \nДо Нового Года осталось {num}')
#####______________________ПИПИСА БОТ БУДЕТ ЗДЕСЬ__________________________________
@dp.message_handler(commands=["dick"])
async def ident(message: types.Message):
# рандомайзер
numb = randint(-7,10)
global size_change, dick_plus, dick_minus
dick_plus = f'<b>вырос</b> 🚀 на <b>{numb}</b> см!'
dick_minus = f'<b>уменьшился</b> ✂ на <b>{abs(numb)}</b> см!'
if numb > 0:
size_change = dick_plus
else: size_change = dick_minus
####
# работа с таблицей
if session.query(user).filter(user.user_id == message.from_user.id).first():
b = session.query(user).filter(user.user_id == message.from_user.id).first()
now_time = datetime.datetime.now()
session.close()
last_time = b.datetimes
diff = now_time.day - last_time.day
if abs(diff) <= 0:
with session:
await bot.send_message(message.chat.id, f'@{message.from_user.username},🚫 вы уже крутили пипису, ее размер <b>{b.dick_size}</b> см! ')
session.close()
print(diff)
print(type(diff))
else:
with session:
a = session.query(user).filter(user.user_id == message.from_user.id).first() # запрос на поиск в таблице
a.dick_size = (a.dick_size + numb)
a.datetimes = datetime.datetime.now()
session.commit() #обновляет запись
await bot.send_message(message.chat.id, f'@{message.from_user.username}, ваш писюн {size_change}\n\
Теперь он равен <b>{a.dick_size}</b> см! ')
session.close()
else:
with session:
int_table = user(user_id = message.from_user.id, user_fullname = message.from_user.full_name, dick_size = numb, datetimes = datetime.datetime.now(),\
chat_id = message.chat.id)
session.add(int_table)
session.commit()
session.close()
await bot.send_message(message.chat.id, f'@{message.from_user.username}, ваш писюн {size_change}\n\
Теперь он равен <b>{int_table.dick_size}</b> см!')
# int_table = user(user_id = message.from_user.id, user_fullname = message.from_user.full_name, dick_size = numb) #импортирую юзер из sqdb
# session.add(int_table)
# session.commit()
#обновление
# dick_update = session.query(user).filter_by(user.user_id = message.from_user.id).update({'dick_size': user.dick_size + numb})
# session.add(dick_update)
# session.commit()
#last_size = session.query(user).filter_by(user_id = message.from_user.id).select_from(dick_size = 'dick_size: ').one()
#####______________________ПИПИСА БОТ БУДЕТ ЗДЕСЬ__________________________________
@dp.message_handler(commands=["topdick"])
async def send_topchat(message: types.Message):
with session:
changechat_id = session.query(user).filter(user.user_id == message.from_user.id).first()
chats = message.chat.id
if changechat_id.chat_id != chats:
changechat_id.chat_id = chats
session.close()
with session:
top = session.query(user.user_fullname, user.dick_size).order_by(user.dick_size.desc()).filter(user.chat_id == chats).limit(10).all()
session.close()
delimiter = ': '
# проверка на длину списка, если меньше limit, то:'''
sizelen = len(top)
if sizelen < 10:
lenminus = 10 - sizelen
top.extend(('-'*lenminus))
await bot.send_message(message.chat.id, f'🏆Топ 10 бубылд чата🏆\n\n\
🚀 {delimiter.join(map(str, top[0]))}\n\
💫 {delimiter.join(map(str, top[1]))}\n\
🍆 {delimiter.join(map(str, top[2]))}\n\
🍌 {delimiter.join(map(str, top[3]))}\n\
🐍 {delimiter.join(map(str, top[4]))}\n\
🐎 {delimiter.join(map(str, top[5]))}\n\
🌭 {delimiter.join(map(str, top[6]))}\n\
🌶 {delimiter.join(map(str, top[7]))}\n\
👌 {delimiter.join(map(str, top[8]))}\n\
💩 {delimiter.join(map(str, top[9]))}\n')
session.close()
# если все нормально и участников минимум 10'''
else:
await bot.send_message(message.chat.id, f'🏆Топ 10 бубылд чата🏆\n\n\
🚀 {delimiter.join(map(str, top[0]))}\n\
💫 {delimiter.join(map(str, top[1]))}\n\
🍆 {delimiter.join(map(str, top[2]))}\n\
🍌 {delimiter.join(map(str, top[3]))}\n\
🐍 {delimiter.join(map(str, top[4]))}\n\
🐎 {delimiter.join(map(str, top[5]))}\n\
🌭 {delimiter.join(map(str, top[6]))}\n\
🌶 {delimiter.join(map(str, top[7]))}\n\
👌 {delimiter.join(map(str, top[8]))}\n\
💩 {delimiter.join(map(str, top[9]))}\n')
session.close()
@dp.message_handler(commands=["globaldick"])
async def send_time(message: types.Message):
with session:
top_chat = session.query(user.user_fullname, user.dick_size).order_by(user.dick_size.desc()).limit(10).all()
delimiter = ': '
await bot.send_message(message.chat.id, f'🏆Топ 10 пипис в мире🏆\n\n\
1. {delimiter.join(map(str, top_chat[0]))}\n\
2. {delimiter.join(map(str, top_chat[1]))}\n\
3. {delimiter.join(map(str, top_chat[2]))}\n\
4. {delimiter.join(map(str, top_chat[3]))}\n\
5. {delimiter.join(map(str, top_chat[4]))}\n\
6. {delimiter.join(map(str, top_chat[5]))}\n\
7. {delimiter.join(map(str, top_chat[6]))}\n\
8. {delimiter.join(map(str, top_chat[7]))}\n\
9. {delimiter.join(map(str, top_chat[8]))}\n\
10. {delimiter.join(map(str, top_chat[9]))}\n')
session.close()
@dp.message_handler(commands=['start'])
async def start_func(message: types.Message):
# user_id = message.from_user.id
# user_full_name = message.from_user.full_name
# logging.INFO(f'{user_id=} {user_full_name=}', {time.asctime()})
await message.reply('похуй')
@dp.message_handler(commands=['photo'])
async def send_image(message: types.Message):
await bot.send_photo(message.chat.id, photo='https://memepedia.ru/wp-content/uploads/2018/08/ya-pidoras.jpg', reply_to_message_id=message.message_id)
@dp.message_handler(content_types=types.ContentTypes.TEXT)
async def send_faggot(message: types.Message):
print(message.text)
if message.text == 'хто я':
await bot.send_photo(message.chat.id, photo='https://www.meme-arsenal.com/memes/ecebd2339c7eab40e09874bd86a38a09.jpg')
#хуй
engine.dispose()
if __name__ == '__main__': if __name__ == '__main__':
executor.start_polling(dp, skip_updates=True) executor.start_polling(dp, skip_updates=True)

4
create_bot.py Normal file
View File

@ -0,0 +1,4 @@
from aiogram import Bot, Dispatcher
API_TOKEN = '5724991559:AAEuLvpLsgP6LHRGMSyFtQLlR5qPQUO4b_w'
bot = Bot(token=API_TOKEN, parse_mode="HTML")
dp = Dispatcher(bot)

3
handlers/__init__.py Normal file
View File

@ -0,0 +1,3 @@
from handlers import pipisa
from handlers import time_new_year
from handlers import start_help

133
handlers/pipisa.py Normal file
View File

@ -0,0 +1,133 @@
from aiogram import types, Dispatcher
from create_bot import bot, dp
from sqdb import user, session
from random import randint
import datetime
@dp.message_handler(commands=["dick"])
async def up_dick(message: types.Message):
# рандомайзер
numb = randint(-7,10)
global size_change, dick_plus, dick_minus
dick_plus = f'<b>вырос</b> 🚀 на <b>{numb}</b> см!'
dick_minus = f'<b>уменьшился</b> ✂ на <b>{abs(numb)}</b> см!'
if numb > 0:
size_change = dick_plus
else: size_change = dick_minus
# работа с таблицей
if session.query(user).filter(user.user_id == message.from_user.id).first():
b = session.query(user).filter(user.user_id == message.from_user.id).first()
now_time = datetime.datetime.now()
session.close()
last_time = b.datetimes
diff = now_time.day - last_time.day
if abs(diff) <= 0:
with session:
await bot.send_message(message.chat.id, f'@{message.from_user.username},🚫 вы уже крутили пипису, ее размер <b>{b.dick_size}</b> см! ')
session.close()
print(diff)
print(type(diff))
else:
with session:
a = session.query(user).filter(user.user_id == message.from_user.id).first() # запрос на поиск в таблице
a.dick_size = (a.dick_size + numb)
a.datetimes = datetime.datetime.now()
session.commit() #обновляет запись
await bot.send_message(message.chat.id, f'@{message.from_user.username}, ваш писюн {size_change}\n\
Теперь он равен <b>{a.dick_size}</b> см! ')
session.close()
else:
with session:
int_table = user(user_id = message.from_user.id, user_fullname = message.from_user.full_name, dick_size = numb, datetimes = datetime.datetime.now(),\
chat_id = message.chat.id)
session.add(int_table)
session.commit()
session.close()
await bot.send_message(message.chat.id, f'@{message.from_user.username}, ваш писюн {size_change}\n\
Теперь он равен <b>{int_table.dick_size}</b> см!')
@dp.message_handler(commands=["topdick"])
async def send_topchat(message: types.Message):
with session:
changechat_id = session.query(user).filter(user.user_id == message.from_user.id).first()
chats = message.chat.id
if changechat_id.chat_id != chats:
changechat_id.chat_id = chats
session.close()
with session:
top = session.query(user.user_fullname, user.dick_size).order_by(user.dick_size.desc()).filter(user.chat_id == chats).limit(10).all()
session.close()
delimiter = ': '
# проверка на длину списка, если меньше limit, то:
sizelen = len(top)
if sizelen < 10:
lenminus = 10 - sizelen
top.extend(('-'*lenminus))
await bot.send_message(message.chat.id, f'🏆Топ 10 бубылд чата🏆\n\n\
🚀 {delimiter.join(map(str, top[0]))}\n\
💫 {delimiter.join(map(str, top[1]))}\n\
🍆 {delimiter.join(map(str, top[2]))}\n\
🍌 {delimiter.join(map(str, top[3]))}\n\
🐍 {delimiter.join(map(str, top[4]))}\n\
🐎 {delimiter.join(map(str, top[5]))}\n\
🌭 {delimiter.join(map(str, top[6]))}\n\
🌶 {delimiter.join(map(str, top[7]))}\n\
👌 {delimiter.join(map(str, top[8]))}\n\
💩 {delimiter.join(map(str, top[9]))}\n')
session.close()
# если все нормально и участников минимум 10
else:
await bot.send_message(message.chat.id, f'🏆Топ 10 бубылд чата🏆\n\n\
🚀 {delimiter.join(map(str, top[0]))}\n\
💫 {delimiter.join(map(str, top[1]))}\n\
🍆 {delimiter.join(map(str, top[2]))}\n\
🍌 {delimiter.join(map(str, top[3]))}\n\
🐍 {delimiter.join(map(str, top[4]))}\n\
🐎 {delimiter.join(map(str, top[5]))}\n\
🌭 {delimiter.join(map(str, top[6]))}\n\
🌶 {delimiter.join(map(str, top[7]))}\n\
👌 {delimiter.join(map(str, top[8]))}\n\
💩 {delimiter.join(map(str, top[9]))}\n')
session.close()
@dp.message_handler(commands=["globaldick"])
async def send_global_top(message: types.Message):
with session:
top_chat = session.query(user.user_fullname, user.dick_size).order_by(user.dick_size.desc()).limit(10).all()
delimiter = ': '
await bot.send_message(message.chat.id, f'🏆Топ 10 пипис в мире🏆\n\n\
1. {delimiter.join(map(str, top_chat[0]))}\n\
2. {delimiter.join(map(str, top_chat[1]))}\n\
3. {delimiter.join(map(str, top_chat[2]))}\n\
4. {delimiter.join(map(str, top_chat[3]))}\n\
5. {delimiter.join(map(str, top_chat[4]))}\n\
6. {delimiter.join(map(str, top_chat[5]))}\n\
7. {delimiter.join(map(str, top_chat[6]))}\n\
8. {delimiter.join(map(str, top_chat[7]))}\n\
9. {delimiter.join(map(str, top_chat[8]))}\n\
10. {delimiter.join(map(str, top_chat[9]))}\n')
session.close()
def register_handlers_pipisa(dp: Dispatcher):
dp.register_message_handler(up_dick)
dp.register_message_handler(send_topchat)
dp.register_message_handler(send_global_top)

25
handlers/start_help.py Normal file
View File

@ -0,0 +1,25 @@
from aiogram import types, Dispatcher
from create_bot import dp, bot
@dp.message_handler(commands=['start'])
async def start_func(message: types.Message):
# user_id = message.from_user.id
# user_full_name = message.from_user.full_name
# logging.INFO(f'{user_id=} {user_full_name=}', {time.asctime()})
await message.reply('похуй')
@dp.message_handler(commands=['photo'])
async def send_image(message: types.Message):
await bot.send_photo(message.chat.id, photo='https://memepedia.ru/wp-content/uploads/2018/08/ya-pidoras.jpg', reply_to_message_id=message.message_id)
@dp.message_handler(content_types=types.ContentTypes.TEXT)
async def send_faggot(message: types.Message):
print(message.text)
if message.text == 'хто я':
await bot.send_photo(message.chat.id, photo='https://www.meme-arsenal.com/memes/ecebd2339c7eab40e09874bd86a38a09.jpg')
def register_handlers_StartHelp(dp: Dispatcher):
dp.register_message_handler(start_func)
dp.register_message_handler(send_faggot)
dp.register_message_handler(send_image)

27
handlers/time_new_year.py Normal file
View File

@ -0,0 +1,27 @@
from aiogram import types, Dispatcher
from create_bot import dp, bot
import datetime
@dp.message_handler(commands=["time"])
async def send_time(message: types.Message):
new_year = datetime.datetime(2022, 12, 31) #дата нового года
ct = datetime.datetime.now() #датавремя
cd = datetime.datetime.now().strftime("%d/%m/%Y") #дата (д,м,г)
ct1 = ct+datetime.timedelta(hours=15) # +14 часов от сервера
ct2 = ct1.strftime('%H:%M') # форматирует датувремя просто во время(ч,м)
raznitsa = (new_year - ct).days #отнимает от нг текущее время и получаем разницу в днях
days = ['день', 'дня', 'дней']
if raznitsa % 10 == 1 and raznitsa % 100 != 11:
p = 0
elif 2 <= raznitsa % 10 <= 4 and (raznitsa % 100 < 10 or raznitsa % 100 >= 20):
p = 1
else:
p = 2
num=(str(raznitsa) + ' ' + days[p])
await message.reply(f'Сегодня {cd} \nВремя: {ct2} \nДо Нового Года осталось {num}')
def register_handlers_time(dp: Dispatcher):
dp.register_message_handler(send_time)