Track input via message of algebraic expressions as well as input via buttons.
This commit is contained in:
parent
11d07b45d6
commit
e19e022e12
@ -11,7 +11,7 @@ __author__ = "Davide Testa"
|
|||||||
__email__ = "davide@davte.it"
|
__email__ = "davide@davte.it"
|
||||||
__credits__ = ["Marco Origlia", "Nick Lee @Nickoala"]
|
__credits__ = ["Marco Origlia", "Nick Lee @Nickoala"]
|
||||||
__license__ = "GNU General Public License v3.0"
|
__license__ = "GNU General Public License v3.0"
|
||||||
__version__ = "2.5.15"
|
__version__ = "2.5.16"
|
||||||
__maintainer__ = "Davide Testa"
|
__maintainer__ = "Davide Testa"
|
||||||
__contact__ = "t.me/davte"
|
__contact__ = "t.me/davte"
|
||||||
|
|
||||||
|
@ -238,7 +238,7 @@ async def _calculate_button(bot: Bot,
|
|||||||
if command == 'parser':
|
if command == 'parser':
|
||||||
reply_markup = None
|
reply_markup = None
|
||||||
bot.set_individual_text_message_handler(
|
bot.set_individual_text_message_handler(
|
||||||
handler=_calculate_command,
|
handler=wrap_calculate_command(record_id=record_id),
|
||||||
user_id=user_record['telegram_id']
|
user_id=user_record['telegram_id']
|
||||||
)
|
)
|
||||||
elif command == 'info':
|
elif command == 'info':
|
||||||
@ -398,11 +398,26 @@ async def calculate_session(bot: Bot,
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def wrap_calculate_command(record_id: int = None, command_name: str = 'calc'):
|
||||||
|
async def wrapped_calculate_command(bot: Bot,
|
||||||
|
update: dict,
|
||||||
|
user_record: OrderedDict,
|
||||||
|
language: str,):
|
||||||
|
return await _calculate_command(bot=bot,
|
||||||
|
update=update,
|
||||||
|
user_record=user_record,
|
||||||
|
language=language,
|
||||||
|
command_name=command_name,
|
||||||
|
record_id=record_id)
|
||||||
|
return wrapped_calculate_command
|
||||||
|
|
||||||
|
|
||||||
async def _calculate_command(bot: Bot,
|
async def _calculate_command(bot: Bot,
|
||||||
update: dict,
|
update: dict,
|
||||||
user_record: OrderedDict,
|
user_record: OrderedDict,
|
||||||
language: str,
|
language: str,
|
||||||
command_name: str = 'calc'):
|
command_name: str = 'calc',
|
||||||
|
record_id: int = 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]
|
||||||
@ -420,6 +435,7 @@ async def _calculate_command(bot: Bot,
|
|||||||
)
|
)
|
||||||
reply_markup = get_calculator_keyboard()
|
reply_markup = get_calculator_keyboard()
|
||||||
else:
|
else:
|
||||||
|
if record_id is None:
|
||||||
record_id = bot.db['calculations'].insert(
|
record_id = bot.db['calculations'].insert(
|
||||||
dict(
|
dict(
|
||||||
user_id=user_record['id'],
|
user_id=user_record['id'],
|
||||||
@ -427,11 +443,25 @@ async def _calculate_command(bot: Bot,
|
|||||||
expression=text
|
expression=text
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
expression = text
|
||||||
|
else:
|
||||||
|
record = bot.db['calculations'].find_one(
|
||||||
|
id=record_id
|
||||||
|
)
|
||||||
|
expression = f"{record['expression'] or ''}\n{text}"
|
||||||
|
bot.db['calculations'].update(
|
||||||
|
dict(
|
||||||
|
id=record_id,
|
||||||
|
modified=datetime.datetime.now(),
|
||||||
|
expression=expression
|
||||||
|
),
|
||||||
|
['id']
|
||||||
|
)
|
||||||
text = bot.get_message(
|
text = bot.get_message(
|
||||||
'useful_tools', 'calculate_command', 'result',
|
'useful_tools', 'calculate_command', 'result',
|
||||||
language=language,
|
language=language,
|
||||||
expressions=evaluate_expressions(bot=bot,
|
expressions=evaluate_expressions(bot=bot,
|
||||||
expressions=text,
|
expressions=expression,
|
||||||
language=language)
|
language=language)
|
||||||
)
|
)
|
||||||
reply_markup = get_calculator_keyboard(additional_data=[record_id])
|
reply_markup = get_calculator_keyboard(additional_data=[record_id])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user