Accept language directly

This commit is contained in:
Davte 2020-08-20 15:50:53 +02:00
parent 7233f9e478
commit e29bb08b7b
Signed by: Davte
GPG Key ID: 209AE674A0007425
2 changed files with 9 additions and 5 deletions

View File

@ -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.6.11" __version__ = "2.6.12"
__maintainer__ = "Davide Testa" __maintainer__ = "Davide Testa"
__contact__ = "t.me/davte" __contact__ = "t.me/davte"

View File

@ -1609,8 +1609,9 @@ async def dummy_coroutine(*args, **kwargs):
return return
async def send_csv_file(bot, chat_id, query, caption=None, async def send_csv_file(bot, chat_id: int, query: str, caption: str = None,
file_name='File.csv', user_record=None, update=None): file_name: str = 'File.csv', language: str = None,
user_record=None, update=None):
"""Run a query on `bot` database and send result as CSV file to `chat_id`. """Run a query on `bot` database and send result as CSV file to `chat_id`.
Optional parameters `caption` and `file_name` may be passed to this Optional parameters `caption` and `file_name` may be passed to this
@ -1618,6 +1619,9 @@ async def send_csv_file(bot, chat_id, query, caption=None,
""" """
if update is None: if update is None:
update = dict() update = dict()
if language is None:
language = bot.get_language(update=update,
user_record=user_record)
try: try:
with bot.db as db: with bot.db as db:
record = db.query( record = db.query(
@ -1633,14 +1637,14 @@ async def send_csv_file(bot, chat_id, query, caption=None,
except Exception as e: except Exception as e:
text = "{message}\n{e}".format( text = "{message}\n{e}".format(
message=bot.get_message('admin', 'query_button', 'error', message=bot.get_message('admin', 'query_button', 'error',
user_record=user_record, update=update), language=language),
e=e e=e
) )
for x, y in {'&lt;': '<', '\n': '\r\n'}.items(): for x, y in {'&lt;': '<', '\n': '\r\n'}.items():
text = text.replace(x, y) text = text.replace(x, y)
if len(text) == 0: if len(text) == 0:
text = bot.get_message('admin', 'query_button', 'empty_file', text = bot.get_message('admin', 'query_button', 'empty_file',
user_record=user_record, update=update) language=language)
with io.BytesIO(text.encode('utf-8')) as f: with io.BytesIO(text.encode('utf-8')) as f:
f.name = file_name f.name = file_name
return await bot.send_document( return await bot.send_document(