Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
9385401154 | |||
0153290272 | |||
4d74b255d2 | |||
1719dfbe75 | |||
f47d62fea2 |
@ -3,10 +3,10 @@
|
|||||||
__author__ = "Davide Testa"
|
__author__ = "Davide Testa"
|
||||||
__email__ = "davide@davte.it"
|
__email__ = "davide@davte.it"
|
||||||
__license__ = "GNU General Public License v3.0"
|
__license__ = "GNU General Public License v3.0"
|
||||||
__version__ = "1.2.3"
|
__version__ = "1.2.6"
|
||||||
__maintainer__ = "Davide Testa"
|
__maintainer__ = "Davide Testa"
|
||||||
__contact__ = "t.me/davte"
|
__contact__ = "t.me/davte"
|
||||||
|
|
||||||
from . import ciclopi
|
from . import ciclopi, messages
|
||||||
|
|
||||||
__all__ = [ciclopi]
|
__all__ = ['ciclopi', 'messages']
|
||||||
|
@ -8,6 +8,7 @@ import asyncio
|
|||||||
import datetime
|
import datetime
|
||||||
import inspect
|
import inspect
|
||||||
import math
|
import math
|
||||||
|
from collections import OrderedDict
|
||||||
|
|
||||||
# Third party modules
|
# Third party modules
|
||||||
from typing import Union
|
from typing import Union
|
||||||
@ -527,7 +528,9 @@ def _get_stations(data, location):
|
|||||||
return stations
|
return stations
|
||||||
|
|
||||||
|
|
||||||
async def set_ciclopi_location(bot, update, user_record):
|
async def set_ciclopi_location(bot: davtelepot.bot.Bot,
|
||||||
|
update: dict, user_record: OrderedDict,
|
||||||
|
language: str):
|
||||||
"""Take a location update and store it as CicloPi place.
|
"""Take a location update and store it as CicloPi place.
|
||||||
|
|
||||||
CicloPi stations will be sorted by distance from this place.
|
CicloPi stations will be sorted by distance from this place.
|
||||||
@ -553,7 +556,8 @@ async def set_ciclopi_location(bot, update, user_record):
|
|||||||
)
|
)
|
||||||
# Remove individual text message handler which was set to catch `/cancel`
|
# Remove individual text message handler which was set to catch `/cancel`
|
||||||
bot.remove_individual_text_message_handler(telegram_id)
|
bot.remove_individual_text_message_handler(telegram_id)
|
||||||
return await _ciclopi_command(bot, update, user_record)
|
return await _ciclopi_command(bot=bot, update=update,
|
||||||
|
user_record=user_record, language=language)
|
||||||
|
|
||||||
|
|
||||||
async def cancel_ciclopi_location(bot, update, user_record):
|
async def cancel_ciclopi_location(bot, update, user_record):
|
||||||
@ -577,21 +581,16 @@ async def cancel_ciclopi_location(bot, update, user_record):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# The service is currently suspended: code is unreachable of course
|
async def _ciclopi_command(bot: davtelepot.bot.Bot, update: dict,
|
||||||
# noinspection PyUnreachableCode,PyUnusedLocal
|
user_record: OrderedDict,
|
||||||
async def _ciclopi_command(bot: davtelepot.bot.Bot, update, user_record, sent_message=None,
|
language: str,
|
||||||
|
sent_message=None,
|
||||||
show_all=False):
|
show_all=False):
|
||||||
if ('ciclopi' not in bot.shared_data
|
if ('ciclopi' not in bot.shared_data
|
||||||
or 'is_working' not in bot.shared_data['ciclopi']
|
or 'is_working' not in bot.shared_data['ciclopi']
|
||||||
or not bot.shared_data['ciclopi']['is_working']):
|
or not bot.shared_data['ciclopi']['is_working']):
|
||||||
return {
|
return bot.get_message('ciclopi', 'service_unavailable',
|
||||||
'text': {
|
language=language)
|
||||||
'it': "⚠️ Il servizio è momentaneamente sospeso a causa dell'emergenza COVID-19🦠\n"
|
|
||||||
"#stiamoacasa 🏠",
|
|
||||||
'en': "⚠️ The service is currently suspended due to COVID-19 emergency.🦠\n"
|
|
||||||
"#stayathome 🏠"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
chat_id = update['chat']['id']
|
chat_id = update['chat']['id']
|
||||||
default_stations_to_show = 5
|
default_stations_to_show = 5
|
||||||
stations = []
|
stations = []
|
||||||
@ -1102,7 +1101,9 @@ async def _ciclopi_button_limit(bot, update, user_record, arguments):
|
|||||||
return result, text, reply_markup
|
return result, text, reply_markup
|
||||||
|
|
||||||
|
|
||||||
async def _ciclopi_button_show(bot, update, user_record, arguments):
|
async def _ciclopi_button_show(bot: davtelepot.bot.Bot, update: dict,
|
||||||
|
user_record: OrderedDict, language: str,
|
||||||
|
arguments: list):
|
||||||
result, text, reply_markup = '', '', None
|
result, text, reply_markup = '', '', None
|
||||||
fake_update = update['message']
|
fake_update = update['message']
|
||||||
fake_update['from'] = update['from']
|
fake_update['from'] = update['from']
|
||||||
@ -1115,7 +1116,8 @@ async def _ciclopi_button_show(bot, update, user_record, arguments):
|
|||||||
show_all=(
|
show_all=(
|
||||||
True if len(arguments) == 1 and arguments[0] == 'all'
|
True if len(arguments) == 1 and arguments[0] == 'all'
|
||||||
else False
|
else False
|
||||||
)
|
),
|
||||||
|
language=language
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
return result, text, reply_markup
|
return result, text, reply_markup
|
||||||
@ -1477,7 +1479,7 @@ async def _ciclopi_button_favourites(bot, update, user_record, arguments):
|
|||||||
return result, text, reply_markup
|
return result, text, reply_markup
|
||||||
|
|
||||||
|
|
||||||
async def _ciclopi_button_setpos(bot, update, user_record):
|
async def _ciclopi_button_setpos(bot, update, user_record, language):
|
||||||
result, text, reply_markup = '', '', None
|
result, text, reply_markup = '', '', None
|
||||||
chat_id = (
|
chat_id = (
|
||||||
update['message']['chat']['id'] if 'message' in update
|
update['message']['chat']['id'] if 'message' in update
|
||||||
@ -1490,7 +1492,8 @@ async def _ciclopi_button_setpos(bot, update, user_record):
|
|||||||
)
|
)
|
||||||
bot.set_individual_location_handler(
|
bot.set_individual_location_handler(
|
||||||
await async_wrapper(
|
await async_wrapper(
|
||||||
set_ciclopi_location
|
set_ciclopi_location,
|
||||||
|
language=language
|
||||||
),
|
),
|
||||||
update
|
update
|
||||||
)
|
)
|
||||||
@ -1544,7 +1547,9 @@ _ciclopi_button_routing_table = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async def _ciclopi_button(bot, update, user_record, data):
|
async def _ciclopi_button(bot: davtelepot.bot.Bot, update: dict,
|
||||||
|
user_record: OrderedDict, language: str,
|
||||||
|
data: list):
|
||||||
command, *arguments = data
|
command, *arguments = data
|
||||||
if command in _ciclopi_button_routing_table:
|
if command in _ciclopi_button_routing_table:
|
||||||
handler = _ciclopi_button_routing_table[command]
|
handler = _ciclopi_button_routing_table[command]
|
||||||
@ -1553,6 +1558,7 @@ async def _ciclopi_button(bot, update, user_record, data):
|
|||||||
for name, value in {'bot': bot,
|
for name, value in {'bot': bot,
|
||||||
'update': update,
|
'update': update,
|
||||||
'user_record': user_record,
|
'user_record': user_record,
|
||||||
|
'language': language,
|
||||||
'arguments': arguments
|
'arguments': arguments
|
||||||
}.items()
|
}.items()
|
||||||
if name in inspect.signature(handler).parameters
|
if name in inspect.signature(handler).parameters
|
||||||
@ -1578,6 +1584,7 @@ async def check_service_status(bot: davtelepot.bot.Bot,
|
|||||||
|
|
||||||
Store service status in `bot.shared_data['ciclopi']`.
|
Store service status in `bot.shared_data['ciclopi']`.
|
||||||
"""
|
"""
|
||||||
|
# TODO: adapt interval to events (check 1 minute after first
|
||||||
if isinstance(interval, datetime.timedelta):
|
if isinstance(interval, datetime.timedelta):
|
||||||
interval = interval.total_seconds()
|
interval = interval.total_seconds()
|
||||||
while 1:
|
while 1:
|
||||||
@ -1658,9 +1665,15 @@ def init(telegram_bot: davtelepot.bot.Bot, ciclopi_messages=None,
|
|||||||
),
|
),
|
||||||
help_section=telegram_bot.messages['ciclopi']['help'],
|
help_section=telegram_bot.messages['ciclopi']['help'],
|
||||||
authorization_level='everybody')
|
authorization_level='everybody')
|
||||||
async def ciclopi_command(bot, update, user_record):
|
async def ciclopi_command(bot: davtelepot.bot.Bot, update: dict,
|
||||||
return await _ciclopi_command(bot, update, user_record)
|
user_record: OrderedDict, language: str):
|
||||||
|
return await _ciclopi_command(bot=bot, update=update,
|
||||||
|
user_record=user_record, language=language)
|
||||||
|
|
||||||
@telegram_bot.button(prefix='ciclopi:///', separator='|', authorization_level='everybody')
|
@telegram_bot.button(prefix='ciclopi:///', separator='|', authorization_level='everybody')
|
||||||
async def ciclopi_button(bot, update, user_record, data):
|
async def ciclopi_button(bot: davtelepot.bot.Bot, update: dict,
|
||||||
return await _ciclopi_button(bot=bot, update=update, user_record=user_record, data=data)
|
user_record: OrderedDict, language: str,
|
||||||
|
data: list):
|
||||||
|
return await _ciclopi_button(bot=bot, update=update,
|
||||||
|
user_record=user_record, language=language,
|
||||||
|
data=data)
|
||||||
|
@ -449,7 +449,11 @@ default_ciclopi_messages = {
|
|||||||
'it': "Annulla",
|
'it': "Annulla",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
},
|
||||||
|
'service_unavailable': {
|
||||||
|
'it': "⚠ Il servizio è momentaneamente sospeso, riprova più tardi! ⚠",
|
||||||
|
'en': "⚠ The service is currently unavailable, try again later! ⚠"
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
default_help_messages = {
|
default_help_messages = {
|
||||||
|
@ -7,10 +7,10 @@ configuration_file="$this_script_directory/my_config.sh";
|
|||||||
passwords_file="$this_script_directory/ciclopibot/data/passwords.py";
|
passwords_file="$this_script_directory/ciclopibot/data/passwords.py";
|
||||||
|
|
||||||
# Create intermediate path for passwords_file, if it does not exist
|
# Create intermediate path for passwords_file, if it does not exist
|
||||||
mkdir -r "$this_script_directory/ciclopibot/data/";
|
mkdir -p "$this_script_directory/ciclopibot/data/";
|
||||||
|
|
||||||
read -r "Enter a name for your virtual environment
|
echo "Enter a name for your virtual environment";
|
||||||
" venv_name;
|
read venv_name;
|
||||||
python3 -m venv "$venv_name";
|
python3 -m venv "$venv_name";
|
||||||
"$venv_name"/bin/pip install -r "$this_script_directory/requirements.txt";
|
"$venv_name"/bin/pip install -r "$this_script_directory/requirements.txt";
|
||||||
|
|
||||||
@ -18,7 +18,8 @@ python3 -m venv "$venv_name";
|
|||||||
# Other systems may require a different path.
|
# Other systems may require a different path.
|
||||||
echo "python_virtual_environment=\"$(pwd)/$venv_name/bin\";" >> "$configuration_file";
|
echo "python_virtual_environment=\"$(pwd)/$venv_name/bin\";" >> "$configuration_file";
|
||||||
echo "python_script=\"$this_script_directory/ciclopibot/bot.py\";" >> "$configuration_file";
|
echo "python_script=\"$this_script_directory/ciclopibot/bot.py\";" >> "$configuration_file";
|
||||||
read -r "Enter a valid Telegram bot token " bot_token;
|
echo "Enter a valid Telegram bot token";
|
||||||
|
read bot_token;
|
||||||
echo "bot_token = \"$bot_token\"" >> "$passwords_file";
|
echo "bot_token = \"$bot_token\"" >> "$passwords_file";
|
||||||
|
|
||||||
# Run bot
|
# Run bot
|
||||||
|
Loading…
x
Reference in New Issue
Block a user