Skip to content

Commit

Permalink
функционал команды my cock size
Browse files Browse the repository at this point in the history
  • Loading branch information
Bitnik212 committed Mar 17, 2022
1 parent 2299c8d commit 3e664c3
Show file tree
Hide file tree
Showing 11 changed files with 125 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Bot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from aiogram import Bot
from aiogram.contrib.fsm_storage.memory import MemoryStorage
from aiogram.dispatcher import Dispatcher

from Config import Config
from CommandRouter import CommandRouter


class CocksizeBot:
def __init__(self):
config = Config()
self.bot = Bot(token=config.telegram_token)
self.storage = MemoryStorage()
self.dispatcher = Dispatcher(bot=self.bot, storage=self.storage)
self.router = CommandRouter(self.dispatcher)
self.router.register()

async def on_startup(self, dispatcher: Dispatcher):
await self.router.register_commands_names()

29 changes: 29 additions & 0 deletions CommandRouter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from aiogram import Dispatcher, types

from commands.Command import Command
from commands.MyCockSizeCommand import MyCockSizeCommand
from commands.HelloCommand import HelloCommand


class CommandRouter:

def __init__(self, dispatcher: Dispatcher):
self.dispatcher: Dispatcher = dispatcher
self.commands: list[id(Command)] = [HelloCommand, MyCockSizeCommand]
self.commands_names: list[types.BotCommand] = []

def register(self):
"""
Регистрация команд
"""
for command in self.commands:
inited_command = command(self.dispatcher)
inited_command.register(inited_command.handler, Command.get_command_names(inited_command.names))
for name in inited_command.names:
self.commands_names.append(types.BotCommand("".join(list(name.keys())), "".join(list(name.values()))))

async def register_commands_names(self):
"""
Регистрация команд бота
"""
await self.dispatcher.bot.set_my_commands(self.commands_names)
17 changes: 17 additions & 0 deletions Config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from dotenv import load_dotenv, 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 telegram_token(self) -> str:
return self.__env['TELEGRAM_TOKEN']

@property
def project_root_folder(self) -> Path:
return Path(".").absolute().parent
7 changes: 7 additions & 0 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from aiogram.utils import executor
from Bot import CocksizeBot


if __name__ == '__main__':
bot = CocksizeBot()
executor.start_polling(bot.dispatcher, on_startup=bot.on_startup)
22 changes: 22 additions & 0 deletions commands/Command.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from aiogram import Dispatcher, types


class Command:
def __init__(self, dispatcher: Dispatcher):
self.dispatcher: Dispatcher = dispatcher
self.names: list[dict[str, str]] or None = None

def register(self, handler, commands: list[str]):
self.dispatcher.register_message_handler(callback=handler, commands=commands)

@staticmethod
async def handler(**kwargs):
pass

@staticmethod
def get_command_names(command_names: list[dict[str, str]]) -> list[str]:
founded_command_names: list[str] = []
for command_name in command_names:
for name in command_name.keys():
founded_command_names.append(name)
return founded_command_names
12 changes: 12 additions & 0 deletions commands/HelloCommand.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from .Command import Command
from aiogram import types, Dispatcher


class HelloCommand(Command):
def __init__(self, dispatcher: Dispatcher):
super().__init__(dispatcher)
self.names = [{'hello': "привет"}]

@staticmethod
async def handler(message: types.Message):
await message.answer("Привет")
18 changes: 18 additions & 0 deletions commands/MyCockSizeCommand.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from random import Random

from aiogram import Dispatcher, types

from .Command import Command


class MyCockSizeCommand(Command):
def __init__(self, dispatcher: Dispatcher):
super().__init__(dispatcher)
self.names = [{'mycocksize': "My cock size"}]

@staticmethod
async def handler(message: types.Message):
random = Random(10)
await message.answer("My cock size is "+str(random.randint(1, 100)))


Empty file added commands/__init__.py
Empty file.
Empty file added handlers/__init__.py
Empty file.
Empty file added keyboards/__init__.py
Empty file.
Empty file added repository/__init__.py
Empty file.

0 comments on commit 3e664c3

Please sign in to comment.