From a763de43353906eecfd8fc9049f581c99ceb8ec1 Mon Sep 17 00:00:00 2001 From: csasq Date: Mon, 12 Aug 2024 17:25:30 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B0=D0=B7=D1=80=D0=B0=D0=B1=D0=BE?= =?UTF-8?q?=D1=82=D0=B0=D0=BD=20=D0=BD=D0=B0=D0=B1=D1=80=D0=BE=D1=81=D0=BE?= =?UTF-8?q?=D0=BA=20=D1=87=D0=B0=D1=82-=D0=B1=D0=BE=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot/__init__.py | 1 + bot/main.py | 143 +++++++++++++++++++++++++++++++++++++++++++++ config/__init__.py | 1 + config/main.py | 19 ++++++ database.sql | 9 +++ main.py | 7 +++ requirements.txt | 3 + 7 files changed, 183 insertions(+) create mode 100644 bot/__init__.py create mode 100644 bot/main.py create mode 100644 config/__init__.py create mode 100644 config/main.py create mode 100644 database.sql create mode 100644 main.py create mode 100644 requirements.txt diff --git a/bot/__init__.py b/bot/__init__.py new file mode 100644 index 0000000..c64e361 --- /dev/null +++ b/bot/__init__.py @@ -0,0 +1 @@ +from .main import dp, bot diff --git a/bot/main.py b/bot/main.py new file mode 100644 index 0000000..e798908 --- /dev/null +++ b/bot/main.py @@ -0,0 +1,143 @@ +import asyncio + +from aiogram import Bot, Dispatcher +from aiogram.client.default import DefaultBotProperties +from aiogram.enums import ParseMode +from aiogram.filters import CommandStart +from aiogram.types import Message, Poll, InputPollOption +from apscheduler.schedulers.asyncio import AsyncIOScheduler + +import config + + +dp = Dispatcher() +loop = asyncio.get_event_loop() + + +@dp.message(CommandStart()) +async def command_start_handler( + message: Message, +): + print(message.chat.id) + await message.answer('Чат успешно зарегистрирован!') + + +bot = Bot( + token=config.Telegram.token, + default=DefaultBotProperties( + parse_mode=ParseMode.HTML, + ), +) + +scheduler = AsyncIOScheduler() + + +async def send_mood_poll() -> Poll: + await bot.send_poll( + chat_id=-1002246469549, + question='Оцените свое состояние на текущую минуту', + options=[ + InputPollOption( + text='😄', + ), + InputPollOption( + text='🤪', + ), + InputPollOption( + text='🫠', + ), + InputPollOption( + text='☠️', + ), + InputPollOption( + text='🤡', + ), + InputPollOption( + text='😟', + ), + InputPollOption( + text='😩', + ), + InputPollOption( + text='😡', + ), + ], + is_anonymous=False, + allows_multiple_answers=False, + is_closed=False, + disable_notification=True, + ) + + +async def send_dinner_poll() -> Poll: + message = await bot.send_poll( + chat_id=-1002246469549, + question='Какие у вас планы на обед?', + options=[ + InputPollOption( + text='🍽️ Пойду в общепит', + ), + InputPollOption( + text='📦 Хочу заказать в офис', + ), + InputPollOption( + text='🥪 Всё своё ношу с собой', + ), + InputPollOption( + text='😴 Хочу спать', + ), + ], + is_anonymous=False, + allows_multiple_answers=False, + is_closed=False, + disable_notification=True, + ) + return message.poll + + +async def send_dinner_delivery_poll() -> Poll: + await bot.send_poll( + chat_id=-1002246469549, + question='Где будем заказывать?', + options=[ + InputPollOption( + text='Dark Side', + ), + InputPollOption( + text='Самокат', + ), + InputPollOption( + text='...', + ), + InputPollOption( + text='...', + ), + ], + is_anonymous=False, + allows_multiple_answers=False, + is_closed=False, + disable_notification=True, + ) + + +async def on_startup( + dispatcher: Dispatcher, +): + scheduler.add_job( + func=send_mood_poll, + trigger='cron', + day_of_week='mon-fri', + hour=17, + minute=14, + ) + scheduler.add_job( + func=send_dinner_poll, + trigger='cron', + day_of_week='mon-fri', + hour=17, + minute=17, + ) + scheduler.start() + + +dp.startup.register(on_startup) diff --git a/config/__init__.py b/config/__init__.py new file mode 100644 index 0000000..1306899 --- /dev/null +++ b/config/__init__.py @@ -0,0 +1 @@ +from .main import Telegram diff --git a/config/main.py b/config/main.py new file mode 100644 index 0000000..1737336 --- /dev/null +++ b/config/main.py @@ -0,0 +1,19 @@ +from configparser import RawConfigParser +import os + + +cwd = os.getcwd() +config = RawConfigParser() +config.read( + filenames=os.path.join( + cwd, + 'config.ini', + ), +) + + +class Telegram: + token = config.get( + section='Telegram', + option='token', + ) diff --git a/database.sql b/database.sql new file mode 100644 index 0000000..10cec9f --- /dev/null +++ b/database.sql @@ -0,0 +1,9 @@ +create table polls ( + id bigint not null, + date date not null, + is_complete boolean default false not null, + primary key (id) +); + +create table mood_polls () inherits (polls); +create table dinner_polls () inherits (polls); diff --git a/main.py b/main.py new file mode 100644 index 0000000..4f5265b --- /dev/null +++ b/main.py @@ -0,0 +1,7 @@ +import asyncio + +from bot import bot, dp + + +if __name__ == "__main__": + asyncio.run(dp.run_polling(bot)) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..b10bb02 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +aiogram +APScheduler +psycopg[binary]