/ping command implemented
/length command returns characters in text message even, not only in reply
This commit is contained in:
parent
a7e1b40f93
commit
82d120dc58
@ -1010,9 +1010,9 @@ default_unknown_command_message = {
|
|||||||
default_useful_tools_messages = {
|
default_useful_tools_messages = {
|
||||||
'length_command': {
|
'length_command': {
|
||||||
'description': {
|
'description': {
|
||||||
'en': "Use this command in reply to a message to get its length.",
|
'en': "Use this command in reply to a message to get its length",
|
||||||
'it': "Usa questo comando in risposta a un messaggio per sapere "
|
'it': "Usa questo comando in risposta a un messaggio per sapere "
|
||||||
"quanti caratteri contenga.",
|
"quanti caratteri contenga",
|
||||||
},
|
},
|
||||||
'help_section': {
|
'help_section': {
|
||||||
'description': {
|
'description': {
|
||||||
@ -1045,4 +1045,10 @@ default_useful_tools_messages = {
|
|||||||
"caratteri secondo i miei calcoli.</i>",
|
"caratteri secondo i miei calcoli.</i>",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
'ping_command': {
|
||||||
|
'description': {
|
||||||
|
'en': "Check if bot is online",
|
||||||
|
'it': "Verifica se il bot è online",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
@ -6,11 +6,31 @@ from collections import OrderedDict
|
|||||||
# Project modules
|
# Project modules
|
||||||
from .bot import Bot
|
from .bot import Bot
|
||||||
from .messages import default_useful_tools_messages
|
from .messages import default_useful_tools_messages
|
||||||
from .utilities import recursive_dictionary_update
|
from .utilities import get_cleaned_text, recursive_dictionary_update
|
||||||
|
|
||||||
|
|
||||||
async def _length_command(bot: Bot, update: dict, user_record: OrderedDict):
|
async def _length_command(bot: Bot, update: dict, user_record: OrderedDict):
|
||||||
if 'reply_to_message' not in update:
|
message_text = get_cleaned_text(
|
||||||
|
update=update,
|
||||||
|
bot=bot,
|
||||||
|
replace=[
|
||||||
|
alias
|
||||||
|
for alias in bot.messages[
|
||||||
|
'useful_tools'
|
||||||
|
][
|
||||||
|
'length_command'
|
||||||
|
][
|
||||||
|
'language_labelled_commands'
|
||||||
|
].values()
|
||||||
|
]
|
||||||
|
)
|
||||||
|
if message_text:
|
||||||
|
text = bot.get_message(
|
||||||
|
'useful_tools', 'length_command', 'result',
|
||||||
|
user_record=user_record, update=update,
|
||||||
|
n=len(message_text)
|
||||||
|
)
|
||||||
|
elif 'reply_to_message' not in update:
|
||||||
text = bot.get_message(
|
text = bot.get_message(
|
||||||
'useful_tools', 'length_command', 'instructions',
|
'useful_tools', 'length_command', 'instructions',
|
||||||
user_record=user_record, update=update
|
user_record=user_record, update=update
|
||||||
@ -31,6 +51,14 @@ async def _length_command(bot: Bot, update: dict, user_record: OrderedDict):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
async def _ping_command(bot: Bot, update: dict):
|
||||||
|
"""Return `pong` only in private chat."""
|
||||||
|
chat_id = bot.get_chat_id(update=update)
|
||||||
|
if chat_id < 0:
|
||||||
|
return
|
||||||
|
return "<i>Pong!</i>"
|
||||||
|
|
||||||
|
|
||||||
def init(telegram_bot: Bot, useful_tools_messages=None):
|
def init(telegram_bot: Bot, useful_tools_messages=None):
|
||||||
"""Define commands for `telegram_bot`.
|
"""Define commands for `telegram_bot`.
|
||||||
|
|
||||||
@ -59,3 +87,18 @@ def init(telegram_bot: Bot, useful_tools_messages=None):
|
|||||||
)
|
)
|
||||||
async def length_command(bot, update, user_record):
|
async def length_command(bot, update, user_record):
|
||||||
return await _length_command(bot=bot, update=update, user_record=user_record)
|
return await _length_command(bot=bot, update=update, user_record=user_record)
|
||||||
|
|
||||||
|
@telegram_bot.command(
|
||||||
|
command='/ping',
|
||||||
|
aliases=None,
|
||||||
|
reply_keyboard_button=None,
|
||||||
|
show_in_keyboard=False,
|
||||||
|
**{
|
||||||
|
key: val
|
||||||
|
for key, val in useful_tools_messages['ping_command'].items()
|
||||||
|
if key in ('description', 'help_section', 'language_labelled_commands')
|
||||||
|
},
|
||||||
|
authorization_level='everybody'
|
||||||
|
)
|
||||||
|
async def ping_command(bot, update):
|
||||||
|
return await _ping_command(bot=bot, update=update)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user