exclam: Add upload (!upl) command to upload files/media to chats/channels
patch ca68ae9cfb315331dd08f8033ea2270e8a93e626
Author: E. Bosch <presidev@AT@gmail.com>
Date: Sun Apr 14 22:48:30 CEST 2024
* exclam: Add upload (!upl) command to upload files/media to chats/channels
Add "upload_dir" option to define the local directory to pick the files up,
by default "~/.cache/irgramd/upload"
hunk ./exclam.py 9
+import os
hunk ./exclam.py 22
+ '!upl': (self.handle_command_upl, 1, 2, 2),
hunk ./exclam.py 144
+ )
+ return reply
+
+ async def handle_command_upl(self, file=None, caption=None, help=None):
+ if not help:
+ try:
+ file_path = os.path.join(self.tg.telegram_upload_dir, file)
+ self.tmp_tg_msg = await self.tg.telegram_client.send_file(self.tmp_telegram_id, file_path, caption=caption)
+ reply = True
+ except:
+ reply = ('Error uploading',)
+ else: # HELP.brief or HELP.desc (first line)
+ reply = (' !upl Upload a file to current channel/chat',)
+ if help == HELP.desc: # rest of HELP.desc
+ reply += \
+ (
+ ' !upl <file name> [<optional caption>]',
+ 'Upload the file referenced by <file name> to current ',
+ 'channel/chat, the file must be present in "upload"',
+ 'local directory.'
hunk ./irgramd 113
+ tornado.options.define('upload_dir', default=None, metavar='PATH', help='Directory where files to upload are picked up, default "upload" in `cache_dir`')
hunk ./telegram.py 46
+ self.upload_dir = settings['upload_dir']
hunk ./telegram.py 81
+ # Setup upload folder
+ self.telegram_upload_dir = os.path.expanduser(self.upload_dir or os.path.join(self.cache_dir, 'upload'))
+ if not os.path.exists(self.telegram_upload_dir):
+ os.makedirs(self.telegram_upload_dir)
+