telegram: `delete()` on `leave=False`

- also misc minor tidy
This commit is contained in:
Casper da Costa-Luis 2021-06-20 13:54:17 +01:00
parent f1071d7d03
commit c36a011c3a
No known key found for this signature in database
GPG Key ID: F5126E5FBD2512AD
2 changed files with 13 additions and 11 deletions

View File

@ -63,17 +63,15 @@ class TelegramIO(MonoWorker):
return future
def delete(self):
"""Deletes internal `message_id`."""
try:
res = self.submit(
self.session.post,
self.API + '%s/deleteMessage' % self.token,
data=dict(
chat_id=self.chat_id,
message_id=self.message_id))
future = self.submit(
self.session.post, self.API + '%s/deleteMessage' % self.token,
data={'chat_id': self.chat_id, 'message_id': self.message_id})
except Exception as e:
tqdm_auto.write(str(e))
else:
return res
return future
class tqdm_telegram(tqdm_auto):
@ -125,8 +123,12 @@ class tqdm_telegram(tqdm_auto):
if not self.disable:
self.tgio.write("")
def delete(self):
self.tgio.delete()
def close(self):
if self.disable:
return
super(tqdm_telegram, self).close()
if not (self.leave or (self.leave is None and self.pos == 0)):
self.tgio.delete()
def ttgrange(*args, **kwargs):

View File

@ -113,10 +113,10 @@ class tqdm_rich(std_tqdm): # pragma: no cover
self._prog.__enter__()
self._task_id = self._prog.add_task(self.desc or "", **d)
def close(self, *args, **kwargs):
def close(self):
if self.disable:
return
super(tqdm_rich, self).close(*args, **kwargs)
super(tqdm_rich, self).close()
self._prog.__exit__(None, None, None)
def clear(self, *_, **__):