Working on calc button
This commit is contained in:
@@ -5,6 +5,7 @@ import datetime
|
|||||||
import json
|
import json
|
||||||
|
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
from typing import List, Union
|
||||||
|
|
||||||
# Project modules
|
# Project modules
|
||||||
from .api import TelegramError
|
from .api import TelegramError
|
||||||
@@ -14,87 +15,122 @@ from .utilities import (get_cleaned_text, get_user, make_button,
|
|||||||
make_inline_keyboard, recursive_dictionary_update, )
|
make_inline_keyboard, recursive_dictionary_update, )
|
||||||
|
|
||||||
|
|
||||||
calc_buttons = OrderedDict()
|
def get_calc_buttons() -> OrderedDict:
|
||||||
calc_buttons[0] = dict(
|
buttons = OrderedDict()
|
||||||
|
buttons['pow'] = dict(
|
||||||
|
value='**',
|
||||||
|
symbol='**',
|
||||||
|
order='A1',
|
||||||
|
)
|
||||||
|
buttons['floordiv'] = dict(
|
||||||
|
value='//',
|
||||||
|
symbol='//',
|
||||||
|
order='A2',
|
||||||
|
)
|
||||||
|
buttons['mod'] = dict(
|
||||||
|
value='%',
|
||||||
|
symbol='mod',
|
||||||
|
order='A3',
|
||||||
|
)
|
||||||
|
buttons['info'] = dict(
|
||||||
|
value='info',
|
||||||
|
symbol='ℹ️',
|
||||||
|
order='A4',
|
||||||
|
)
|
||||||
|
buttons[0] = dict(
|
||||||
value=0,
|
value=0,
|
||||||
symbol='0️⃣',
|
symbol='0️⃣',
|
||||||
order=13
|
order='E1',
|
||||||
)
|
)
|
||||||
calc_buttons[1] = dict(
|
buttons[1] = dict(
|
||||||
value=1,
|
value=1,
|
||||||
symbol='1️⃣',
|
symbol='1️⃣',
|
||||||
order=9
|
order='D1',
|
||||||
)
|
)
|
||||||
calc_buttons[2] = dict(
|
buttons[2] = dict(
|
||||||
value=2,
|
value=2,
|
||||||
symbol='2️⃣',
|
symbol='2️⃣',
|
||||||
order=10
|
order='D2',
|
||||||
)
|
)
|
||||||
calc_buttons[3] = dict(
|
buttons[3] = dict(
|
||||||
value=3,
|
value=3,
|
||||||
symbol='3️⃣',
|
symbol='3️⃣',
|
||||||
order=11
|
order='D3',
|
||||||
)
|
)
|
||||||
calc_buttons[4] = dict(
|
buttons[4] = dict(
|
||||||
value=4,
|
value=4,
|
||||||
symbol='4️⃣',
|
symbol='4️⃣',
|
||||||
order=5
|
order='C1',
|
||||||
)
|
)
|
||||||
calc_buttons[5] = dict(
|
buttons[5] = dict(
|
||||||
value=5,
|
value=5,
|
||||||
symbol='5️⃣',
|
symbol='5️⃣',
|
||||||
order=6
|
order='C2',
|
||||||
)
|
)
|
||||||
calc_buttons[6] = dict(
|
buttons[6] = dict(
|
||||||
value=6,
|
value=6,
|
||||||
symbol='6️⃣',
|
symbol='6️⃣',
|
||||||
order=7
|
order='C3',
|
||||||
)
|
)
|
||||||
calc_buttons[7] = dict(
|
buttons[7] = dict(
|
||||||
value=7,
|
value=7,
|
||||||
symbol='7️⃣',
|
symbol='7️⃣',
|
||||||
order=1
|
order='B1',
|
||||||
)
|
)
|
||||||
calc_buttons[8] = dict(
|
buttons[8] = dict(
|
||||||
value=8,
|
value=8,
|
||||||
symbol='8️⃣',
|
symbol='8️⃣',
|
||||||
order=2
|
order='B2',
|
||||||
)
|
)
|
||||||
calc_buttons[9] = dict(
|
buttons[9] = dict(
|
||||||
value=9,
|
value=9,
|
||||||
symbol='9️⃣',
|
symbol='9️⃣',
|
||||||
order=3
|
order='B3',
|
||||||
)
|
)
|
||||||
calc_buttons['plus'] = dict(
|
buttons['plus'] = dict(
|
||||||
value='+',
|
value='+',
|
||||||
symbol='➕️',
|
symbol='➕️',
|
||||||
order=4
|
order='B4',
|
||||||
)
|
)
|
||||||
calc_buttons['minus'] = dict(
|
buttons['minus'] = dict(
|
||||||
value='-',
|
value='-',
|
||||||
symbol='➖',
|
symbol='➖',
|
||||||
order=8
|
order='C4',
|
||||||
)
|
)
|
||||||
calc_buttons['times'] = dict(
|
buttons['times'] = dict(
|
||||||
value='*',
|
value='*',
|
||||||
symbol='✖️',
|
symbol='✖️',
|
||||||
order=12
|
order='D4',
|
||||||
)
|
)
|
||||||
calc_buttons['divided'] = dict(
|
buttons['divided'] = dict(
|
||||||
value='/',
|
value='/',
|
||||||
symbol='➗',
|
symbol='➗',
|
||||||
order=16
|
order='E4',
|
||||||
)
|
)
|
||||||
calc_buttons['point'] = dict(
|
buttons['point'] = dict(
|
||||||
value='.',
|
value='.',
|
||||||
symbol='.',
|
symbol='.',
|
||||||
order=14
|
order='E2',
|
||||||
)
|
)
|
||||||
calc_buttons['enter'] = dict(
|
buttons['000'] = dict(
|
||||||
|
value='*1000',
|
||||||
|
symbol='0️⃣0️⃣0️⃣',
|
||||||
|
order='E3',
|
||||||
|
)
|
||||||
|
buttons['enter'] = dict(
|
||||||
value='\n',
|
value='\n',
|
||||||
symbol='↩',
|
symbol='✅',
|
||||||
order=15
|
order='F1',
|
||||||
)
|
)
|
||||||
|
buttons['del'] = dict(
|
||||||
|
value='del',
|
||||||
|
symbol='⬅️',
|
||||||
|
order='F2',
|
||||||
|
)
|
||||||
|
return buttons
|
||||||
|
|
||||||
|
|
||||||
|
calc_buttons = get_calc_buttons()
|
||||||
|
|
||||||
|
|
||||||
def get_calculator_keyboard():
|
def get_calculator_keyboard():
|
||||||
@@ -112,6 +148,32 @@ def get_calculator_keyboard():
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
async def _calculate_button(bot: Bot,
|
||||||
|
language: str,
|
||||||
|
data: List[Union[int, str]]):
|
||||||
|
result, text, reply_markup = '', '', None
|
||||||
|
if len(data) == 1:
|
||||||
|
input_value = data[0]
|
||||||
|
if input_value == 'del':
|
||||||
|
pass
|
||||||
|
elif input_value == 'info':
|
||||||
|
pass
|
||||||
|
elif input_value in [button['value'] for button in calc_buttons.values()]:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
pass # Error!
|
||||||
|
# Edit the update with the button if a new text is specified
|
||||||
|
if not text:
|
||||||
|
return result
|
||||||
|
return dict(
|
||||||
|
text=result,
|
||||||
|
edit=dict(
|
||||||
|
text=text,
|
||||||
|
reply_markup=reply_markup
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
async def _calculate_command(bot: Bot,
|
async def _calculate_command(bot: Bot,
|
||||||
update: dict,
|
update: dict,
|
||||||
language: str,
|
language: str,
|
||||||
@@ -286,13 +348,19 @@ def init(telegram_bot: Bot, useful_tools_messages=None):
|
|||||||
in useful_tools_messages['calculate_command'].items()
|
in useful_tools_messages['calculate_command'].items()
|
||||||
if key in ('description', 'help_section',
|
if key in ('description', 'help_section',
|
||||||
'language_labelled_commands')},
|
'language_labelled_commands')},
|
||||||
authorization_level='moderator')
|
authorization_level='everybody')
|
||||||
async def calculate_command(bot, update, language):
|
async def calculate_command(bot, update, language):
|
||||||
return await _calculate_command(bot=bot,
|
return await _calculate_command(bot=bot,
|
||||||
update=update,
|
update=update,
|
||||||
language=language,
|
language=language,
|
||||||
command_name='calc')
|
command_name='calc')
|
||||||
|
|
||||||
|
@telegram_bot.button(prefix='calc:///',
|
||||||
|
separator='|',
|
||||||
|
authorization_level='everybody')
|
||||||
|
async def calculate_button(bot, language, data):
|
||||||
|
return await _calculate_button(bot=bot, language=language, data=data)
|
||||||
|
|
||||||
@telegram_bot.command(command='/info',
|
@telegram_bot.command(command='/info',
|
||||||
aliases=None,
|
aliases=None,
|
||||||
reply_keyboard_button=None,
|
reply_keyboard_button=None,
|
||||||
@@ -301,7 +369,7 @@ def init(telegram_bot: Bot, useful_tools_messages=None):
|
|||||||
in useful_tools_messages['info_command'].items()
|
in useful_tools_messages['info_command'].items()
|
||||||
if key in ('description', 'help_section',
|
if key in ('description', 'help_section',
|
||||||
'language_labelled_commands')},
|
'language_labelled_commands')},
|
||||||
authorization_level='moderator')
|
authorization_level='everybody')
|
||||||
async def message_info_command(bot, update, language):
|
async def message_info_command(bot, update, language):
|
||||||
return await _message_info_command(bot=bot,
|
return await _message_info_command(bot=bot,
|
||||||
update=update,
|
update=update,
|
||||||
|
|||||||
Reference in New Issue
Block a user