-
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.
- Loading branch information
Showing
11 changed files
with
125 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,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() | ||
|
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,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) |
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,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 |
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,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) |
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,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 |
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,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("Привет") |
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,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.
Empty file.
Empty file.
Empty file.