-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from Bitnik212/deploy/develop
Deploy develop version
- Loading branch information
Showing
16 changed files
with
283 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# This is a basic workflow to help you get started with Actions | ||
|
||
name: CI | ||
|
||
# Controls when the workflow will run | ||
on: | ||
# Triggers the workflow on push or pull request events but only for the master branch | ||
pull_request: | ||
branches: [ deploy/develop ] | ||
|
||
# Allows you to run this workflow manually from the Actions tab | ||
workflow_dispatch: | ||
|
||
# A workflow run is made up of one or more jobs that can run sequentially or in parallel | ||
jobs: | ||
# This workflow contains a single job called "build" | ||
build: | ||
# The type of runner that the job will run on | ||
runs-on: python:3.10 | ||
|
||
# Steps represent a sequence of tasks that will be executed as part of the job | ||
steps: | ||
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Build and push Docker images | ||
uses: docker/build-push-action@v2.10.0 | ||
|
||
- name: Login to DockerHub | ||
uses: docker/login-action@v1 | ||
with: | ||
username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
password: ${{ secrets.DOCKERHUB_TOKEN }} | ||
|
||
- name: Build and push | ||
uses: docker/build-push-action@v2 | ||
with: | ||
context: . | ||
push: true | ||
tags: bitnik212/cocksizebot:latest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
venv | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import logging | ||
|
||
from aiogram import Bot | ||
from aiogram.contrib.fsm_storage.memory import MemoryStorage | ||
from aiogram.dispatcher import Dispatcher | ||
from aiogram.utils import executor | ||
|
||
from app.Config import Config | ||
from app.CommandRouter import CommandRouter | ||
|
||
|
||
class CocksizeBot: | ||
def __init__(self): | ||
self.__config = Config() | ||
self.init_logging() | ||
self.bot = Bot(token=self.__config.telegram_token) | ||
self.storage = MemoryStorage() | ||
self.dispatcher = Dispatcher(bot=self.bot, storage=self.storage) | ||
self.router = CommandRouter(self.dispatcher) | ||
self.router.register_commands() | ||
self.router.register_inline_commands() | ||
|
||
async def on_startup(self, dispatcher: Dispatcher): | ||
await self.router.register_commands_names() | ||
|
||
def init_logging(self): | ||
if self.__config.debug: | ||
logging.basicConfig(level=logging.DEBUG) | ||
else: | ||
logging.basicConfig(level=logging.INFO) | ||
|
||
|
||
if __name__ == '__main__': | ||
bot = CocksizeBot() | ||
executor.start_polling(bot.dispatcher, on_startup=bot.on_startup) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from aiogram import Dispatcher, types | ||
|
||
from app.handlers.InlineHandler import InlineHandler | ||
from app.commands.Command import Command | ||
from app.commands.MyCockSizeCommand import MyCockSizeCommand | ||
from app.commands.HelloCommand import HelloCommand | ||
|
||
|
||
class CommandRouter: | ||
|
||
def __init__(self, dispatcher: Dispatcher): | ||
self.dispatcher: Dispatcher = dispatcher | ||
self.commands: list[id(Command)] = [HelloCommand, MyCockSizeCommand] | ||
self.registered_commands: list[id(Command)] = [] | ||
self.commands_names: list[types.BotCommand] = [] | ||
self.inline_handler = InlineHandler(self.registered_commands).handler | ||
|
||
def register_commands(self): | ||
for command in self.commands: | ||
inited_command = command(self.dispatcher) | ||
inited_command.register( | ||
handler=inited_command.handler, | ||
commands=inited_command.name) | ||
self.registered_commands.append(inited_command) | ||
self.commands_names.append(types.BotCommand(inited_command.name, inited_command.description)) | ||
|
||
async def register_commands_names(self): | ||
""" | ||
Регистрация команд бота так, чтобы их можно было увидеть в контекстном меню | ||
""" | ||
await self.dispatcher.bot.set_my_commands(self.commands_names) | ||
|
||
def register_inline_commands(self): | ||
self.dispatcher.register_inline_handler(callback=self.inline_handler) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from dotenv import dotenv_values | ||
from pathlib import Path | ||
|
||
|
||
class Config: | ||
def __init__(self): | ||
self.ENV_FILENAME = ".env" | ||
self.env_file_path = self.project_root_folder / self.ENV_FILENAME | ||
self.__env = dotenv_values(self.env_file_path) | ||
|
||
@property | ||
def project_root_folder(self) -> Path: | ||
return Path(".").absolute() | ||
|
||
@property | ||
def telegram_token(self) -> str: | ||
return self.__env['TELEGRAM_TOKEN'] | ||
|
||
@property | ||
def inline_query_cache_time(self) -> int: | ||
return int(self.__env["INLINE_QUERY_CACHE_TIME"]) | ||
|
||
@property | ||
def debug(self) -> bool: | ||
raw_string = self.__env["DEBUG"] | ||
print(raw_string) | ||
return raw_string.lower() == "true" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from aiogram import Dispatcher, types | ||
from aiogram.types import InputMessageContent | ||
|
||
|
||
class Command: | ||
def __init__(self, dispatcher: Dispatcher): | ||
self.dispatcher: Dispatcher = dispatcher | ||
self.title: str or None = None | ||
"""Название команды""" | ||
self.name: str or None = None | ||
"""Уникальный путь команды. По нему вызываются команды""" | ||
self.description: str or None = None | ||
"""Описание команды""" | ||
self.inline_support: bool = False | ||
"""Поддерживается ли inline команда""" | ||
|
||
async def handler(self, **kwargs): | ||
""" | ||
:param kwargs: | ||
:return: | ||
""" | ||
pass | ||
|
||
def inline_handler(self, query: types.InlineQuery) -> InputMessageContent: | ||
pass | ||
|
||
def register(self, handler, commands: list[str]): | ||
self.dispatcher.register_message_handler(callback=handler, commands=commands) | ||
|
||
def register_inline(self, inline_handler): | ||
self.dispatcher.register_inline_handler(callback=inline_handler) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from app.commands.Command import Command | ||
from aiogram import types, Dispatcher | ||
|
||
|
||
class HelloCommand(Command): | ||
|
||
def __init__(self, dispatcher: Dispatcher): | ||
super().__init__(dispatcher) | ||
self.name = "hello" | ||
self.description = "привет" | ||
|
||
async def handler(self, message: types.Message): | ||
await message.answer("Привет") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from random import Random | ||
|
||
from aiogram import Dispatcher, types | ||
from aiogram.types import InputMessageContent | ||
|
||
from app.commands.Command import Command | ||
|
||
|
||
class MyCockSizeCommand(Command): | ||
def __init__(self, dispatcher: Dispatcher): | ||
super().__init__(dispatcher) | ||
self.MAX_SIZE = 40 | ||
self.MIN_SIZE = 4 | ||
self.name = "mycocksize" | ||
self.title = "My cock size" | ||
self.description = "Share your cock size" | ||
self.inline_support = True | ||
|
||
async def handler(self, message: types.Message): | ||
await message.answer(self.my_cock_size) | ||
|
||
def inline_handler(self, query: types.InlineQuery) -> InputMessageContent: | ||
return InputMessageContent(message_text=self.my_cock_size) | ||
|
||
@property | ||
def my_cock_size(self) -> str: | ||
cock_size = str(Random().randint(self.MIN_SIZE, self.MAX_SIZE)) | ||
return "My cock size is " + cock_size + " cm" |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import hashlib | ||
|
||
from aiogram import types | ||
from aiogram.types import InlineQueryResultArticle, InputTextMessageContent | ||
|
||
from app.Config import Config | ||
from app.commands.Command import Command | ||
|
||
|
||
class InlineHandler: | ||
|
||
def __init__(self, commands: list[id(Command)]): | ||
self.__commands: list[id(Command)] = commands | ||
self.config = Config() | ||
|
||
async def handler(self, query: types.InlineQuery): | ||
if query.query == "/": | ||
await query.bot.answer_inline_query( | ||
query.id, | ||
results=self.get_commands_names_result(query), | ||
cache_time=self.config.inline_query_cache_time, | ||
is_personal=True | ||
) | ||
|
||
def get_commands_names_result(self, query: types.InlineQuery) -> list[InlineQueryResultArticle]: | ||
""" | ||
Получение готового ответа для пустого запроса. Список всех команд. | ||
:return: Список всех команд | ||
""" | ||
result: list[InlineQueryResultArticle] = [] | ||
for command in self.__commands: | ||
title: str = command.title | ||
if command.inline_support: | ||
result.append(InlineQueryResultArticle( | ||
id=hashlib.md5(title.encode()).hexdigest(), | ||
title=title, | ||
description=command.description, | ||
input_message_content=command.inline_handler(query) | ||
)) | ||
if not result: | ||
result.append(InlineQueryResultArticle( | ||
id="1", | ||
title="Нет результатов", | ||
input_message_content=InputTextMessageContent("Нет результатов") | ||
)) | ||
return result |
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
FROM python:3.10 | ||
# set work directory | ||
WORKDIR /app/ | ||
# copy project | ||
COPY . /app/ | ||
# install dependencies | ||
RUN pip install -r requirements.txt | ||
# run app | ||
CMD ["python", "Bot.py"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
aiogram==2.19 | ||
aiohttp==3.8.1 | ||
aiosignal==1.2.0 | ||
async-timeout==4.0.2 | ||
attrs==21.4.0 | ||
Babel==2.9.1 | ||
certifi==2021.10.8 | ||
charset-normalizer==2.0.12 | ||
frozenlist==1.3.0 | ||
idna==3.3 | ||
multidict==6.0.2 | ||
python-dotenv==0.19.2 | ||
pytz==2021.3 | ||
yarl==1.7.2 |