Send error message if database could not be sent
This commit is contained in:
		@@ -524,7 +524,7 @@ async def _stop_button(bot: Bot,
 | 
			
		||||
    return result
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
async def _send_bot_database(bot, update, user_record):
 | 
			
		||||
async def _send_bot_database(bot: Bot, user_record: OrderedDict, language: str):
 | 
			
		||||
    if not all(
 | 
			
		||||
            [
 | 
			
		||||
                bot.db_url.endswith('.db'),
 | 
			
		||||
@@ -533,20 +533,21 @@ async def _send_bot_database(bot, update, user_record):
 | 
			
		||||
    ):
 | 
			
		||||
        return bot.get_message(
 | 
			
		||||
            'admin', 'db_command', 'not_sqlite',
 | 
			
		||||
            update=update, user_record=user_record,
 | 
			
		||||
            language=language,
 | 
			
		||||
            db_type=bot.db_url.partition(':///')[0]
 | 
			
		||||
        )
 | 
			
		||||
    await bot.send_document(
 | 
			
		||||
    sent_update = await bot.send_document(
 | 
			
		||||
        chat_id=user_record['telegram_id'],
 | 
			
		||||
        document_path=extract(bot.db.url, starter='sqlite:///'),
 | 
			
		||||
        caption=bot.get_message(
 | 
			
		||||
            'admin', 'db_command', 'file_caption',
 | 
			
		||||
            update=update, user_record=user_record
 | 
			
		||||
            language=language
 | 
			
		||||
        )
 | 
			
		||||
    )
 | 
			
		||||
    return bot.get_message(
 | 
			
		||||
        'admin', 'db_command', 'db_sent',
 | 
			
		||||
        update=update, user_record=user_record
 | 
			
		||||
        'admin', 'db_command',
 | 
			
		||||
        ('error' if isinstance(sent_update, Exception) else 'db_sent'),
 | 
			
		||||
        language=language
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -1879,8 +1880,10 @@ def init(telegram_bot: Bot,
 | 
			
		||||
                          description=admin_messages[
 | 
			
		||||
                              'db_command']['description'],
 | 
			
		||||
                          authorization_level='admin')
 | 
			
		||||
    async def send_bot_database(bot, update, user_record):
 | 
			
		||||
        return await _send_bot_database(bot, update, user_record)
 | 
			
		||||
    async def send_bot_database(bot, user_record, language):
 | 
			
		||||
        return await _send_bot_database(bot=bot,
 | 
			
		||||
                                        user_record=user_record,
 | 
			
		||||
                                        language=language)
 | 
			
		||||
 | 
			
		||||
    @telegram_bot.command(command='/errors',
 | 
			
		||||
                          aliases=[],
 | 
			
		||||
 
 | 
			
		||||
@@ -37,9 +37,21 @@ default_admin_messages = {
 | 
			
		||||
        'it': "🔄 Clicka di nuovo per confermare",
 | 
			
		||||
    },
 | 
			
		||||
    'db_command': {
 | 
			
		||||
        'db_sent': {
 | 
			
		||||
            'en': "Database sent.",
 | 
			
		||||
            'it': "Database inviato.",
 | 
			
		||||
        },
 | 
			
		||||
        'description': {
 | 
			
		||||
            'en': "Ask for bot database via Telegram",
 | 
			
		||||
            'it': "Ricevi il database del bot via Telegram"
 | 
			
		||||
            'it': "Ricevi il database del bot via Telegram",
 | 
			
		||||
        },
 | 
			
		||||
        'error': {
 | 
			
		||||
            'en': "Error sending database.",
 | 
			
		||||
            'it': "Errore durante l'invio del database.",
 | 
			
		||||
        },
 | 
			
		||||
        'file_caption': {
 | 
			
		||||
            'en': "Here is bot database.",
 | 
			
		||||
            'it': "Ecco il database!"
 | 
			
		||||
        },
 | 
			
		||||
        'not_sqlite': {
 | 
			
		||||
            'en': "Only SQLite databases may be sent via Telegram, since they "
 | 
			
		||||
@@ -49,14 +61,6 @@ default_admin_messages = {
 | 
			
		||||
                  "in quanto composti di un solo file.\n"
 | 
			
		||||
                  "Questo bot ha invece un database `{db_type}`."
 | 
			
		||||
        },
 | 
			
		||||
        'file_caption': {
 | 
			
		||||
            'en': "Here is bot database.",
 | 
			
		||||
            'it': "Ecco il database!"
 | 
			
		||||
        },
 | 
			
		||||
        'db_sent': {
 | 
			
		||||
            'en': "Database sent.",
 | 
			
		||||
            'it': "Database inviato."
 | 
			
		||||
        }
 | 
			
		||||
    },
 | 
			
		||||
    'error': {
 | 
			
		||||
        'text': {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user