Working on calc command
This commit is contained in:
@@ -131,6 +131,33 @@ def get_calc_buttons() -> OrderedDict:
|
|||||||
symbol='⬅️',
|
symbol='⬅️',
|
||||||
order='F2',
|
order='F2',
|
||||||
)
|
)
|
||||||
|
buttons['('] = dict(
|
||||||
|
value='(',
|
||||||
|
symbol='(️',
|
||||||
|
order='A5',
|
||||||
|
)
|
||||||
|
buttons[')'] = dict(
|
||||||
|
value=')',
|
||||||
|
symbol=')️',
|
||||||
|
order='B5',
|
||||||
|
)
|
||||||
|
buttons['m'] = dict(
|
||||||
|
value=')',
|
||||||
|
symbol=')️',
|
||||||
|
order='C5',
|
||||||
|
)
|
||||||
|
|
||||||
|
buttons['u'] = dict(
|
||||||
|
value=')',
|
||||||
|
symbol=')️',
|
||||||
|
order='D5',
|
||||||
|
)
|
||||||
|
|
||||||
|
buttons['d'] = dict(
|
||||||
|
value=')',
|
||||||
|
symbol=')️',
|
||||||
|
order='E5',
|
||||||
|
)
|
||||||
return buttons
|
return buttons
|
||||||
|
|
||||||
|
|
||||||
@@ -176,7 +203,7 @@ def get_calculator_keyboard(additional_data: list = None):
|
|||||||
for code, button in sorted(calc_buttons.items(),
|
for code, button in sorted(calc_buttons.items(),
|
||||||
key=lambda b: b[1]['order'])
|
key=lambda b: b[1]['order'])
|
||||||
],
|
],
|
||||||
4
|
5
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -344,9 +371,9 @@ async def calculate_session(bot: Bot,
|
|||||||
|
|
||||||
async def _calculate_command(bot: Bot,
|
async def _calculate_command(bot: Bot,
|
||||||
update: dict,
|
update: dict,
|
||||||
|
user_record: OrderedDict,
|
||||||
language: str,
|
language: str,
|
||||||
command_name: str = 'calc'):
|
command_name: str = 'calc'):
|
||||||
reply_markup = None
|
|
||||||
if 'reply_to_message' in update:
|
if 'reply_to_message' in update:
|
||||||
update = update['reply_to_message']
|
update = update['reply_to_message']
|
||||||
command_aliases = [command_name]
|
command_aliases = [command_name]
|
||||||
@@ -364,7 +391,13 @@ async def _calculate_command(bot: Bot,
|
|||||||
)
|
)
|
||||||
reply_markup = get_calculator_keyboard()
|
reply_markup = get_calculator_keyboard()
|
||||||
else:
|
else:
|
||||||
# TODO: make a new calc record
|
record_id = bot.db['calculations'].insert(
|
||||||
|
dict(
|
||||||
|
user_id=user_record['id'],
|
||||||
|
created=datetime.datetime.now(),
|
||||||
|
expression=text
|
||||||
|
)
|
||||||
|
)
|
||||||
text = bot.get_message(
|
text = bot.get_message(
|
||||||
'useful_tools', 'calculate_command', 'result',
|
'useful_tools', 'calculate_command', 'result',
|
||||||
language=language,
|
language=language,
|
||||||
@@ -372,6 +405,7 @@ async def _calculate_command(bot: Bot,
|
|||||||
expressions=text,
|
expressions=text,
|
||||||
language=language)
|
language=language)
|
||||||
)
|
)
|
||||||
|
reply_markup = get_calculator_keyboard(additional_data=[record_id])
|
||||||
await bot.send_message(text=text,
|
await bot.send_message(text=text,
|
||||||
update=update,
|
update=update,
|
||||||
reply_markup=reply_markup)
|
reply_markup=reply_markup)
|
||||||
@@ -547,9 +581,10 @@ def init(telegram_bot: Bot, useful_tools_messages=None):
|
|||||||
if key in ('description', 'help_section',
|
if key in ('description', 'help_section',
|
||||||
'language_labelled_commands')},
|
'language_labelled_commands')},
|
||||||
authorization_level='everybody')
|
authorization_level='everybody')
|
||||||
async def calculate_command(bot, update, language):
|
async def calculate_command(bot, update, user_record, language):
|
||||||
return await _calculate_command(bot=bot,
|
return await _calculate_command(bot=bot,
|
||||||
update=update,
|
update=update,
|
||||||
|
user_record=user_record,
|
||||||
language=language,
|
language=language,
|
||||||
command_name='calc')
|
command_name='calc')
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user