Compare commits

...

3 commits

3 changed files with 31 additions and 20 deletions

View file

@ -1,14 +1,12 @@
from utils.format_number import format_number
import yaml
import aiohttp
import json
import re
from datetime import datetime
from decimal import Decimal
from http import HTTPStatus
from decimal import Decimal, ROUND_DOWN
import aiohttp
import yaml
from utils.format_number import format_number
config = yaml.safe_load(open('config.yaml'))
@ -24,8 +22,7 @@ class Converter:
if not await self.kekkai():
await self.ddg()
number = Decimal(str(self.conv_amount))
self.conv_amount = format_number(number.quantize(Decimal('1.0000'), rounding=ROUND_DOWN))
self.conv_amount = format_number(Decimal(self.conv_amount))
async def kekkai(self) -> bool:

16
main.py
View file

@ -11,6 +11,7 @@ from aiogram import Bot, Dispatcher, Router, types
from aiogram.client.default import DefaultBotProperties
from aiogram.enums import ParseMode
from aiogram.webhook.aiohttp_server import SimpleRequestHandler, setup_application
from aiogram.filters import CommandStart
import hashlib
@ -19,6 +20,19 @@ bot = Bot(token=config['telegram_token'], default=DefaultBotProperties(parse_mod
router = Router()
@router.message(CommandStart())
async def start(message: types.Message):
get_bot = await bot.get_me()
await message.reply(
'Shirino is a telegram bot for converting fiat or cryptocurrency. '
'The example of use occurs via inline query:\n'
f'`@{get_bot.username} USD RUB` \n'
f'`@{get_bot.username} 12 USD RUB` \n\n'
'[Source Code](https://github.com/Redume/Shirino)',
parse_mode='markdown'
)
@router.inline_query()
async def currency(query: types.InlineQuery) -> None:
text = query.query.lower()
@ -87,7 +101,7 @@ async def on_startup(bot: Bot) -> None:
await bot.set_webhook(
f"{config['webhook']['base_url']}{config['webhook']['path']}",
secret_token=config['webhook']['secret_token'],
allowed_updates=['inline_query']
allowed_updates=['inline_query', 'message']
)

View file

@ -6,7 +6,7 @@ def format_number(number):
formatted_integer_part = '{:,.0f}'.format(number).replace(',', ' ')
if '.' in str(number):
fractional_part = str(number).split('.')[1]
fractional_part = str(number).split('.')[1][:3]
return formatted_integer_part + '.' + fractional_part
else:
return formatted_integer_part