From 7432d53050f50d4d7d39d21c753839ccea77020f Mon Sep 17 00:00:00 2001 From: Noam Date: Sun, 19 Sep 2021 19:56:49 +0300 Subject: [PATCH 1/4] Build egg using Docker --- .dockerignore | 1 + Dockerfile | 11 +++++++++++ 2 files changed, 12 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..2640f89 --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +config2.glade \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f65df59 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +FROM python:2.7.18-alpine3.11 AS base + +RUN mkdir -p /usr/src/app +RUN mkdir -p /output +WORKDIR /usr/src/app + +COPY telegramer /usr/src/app/telegramer +COPY setup.py /usr/src/app/setup.py +COPY LICENSE /usr/src/app/LICENSE + +RUN python setup.py bdist_egg From 61ca283e12a86e00e019db91bf54fdebbbfc8e22 Mon Sep 17 00:00:00 2001 From: Noam Date: Fri, 7 Jan 2022 18:25:38 +0200 Subject: [PATCH 2/4] Lint, fix TORRENTNAME formatting, markdown for all custom messages --- telegramer/core.py | 18 +--- telegramer/data/config.glade | 4 +- telegramer/data/telegramer.js | 184 +++++++++++++++++----------------- 3 files changed, 99 insertions(+), 107 deletions(-) diff --git a/telegramer/core.py b/telegramer/core.py index df303d6..36672e1 100755 --- a/telegramer/core.py +++ b/telegramer/core.py @@ -105,8 +105,8 @@ def filter(self, message): "urllib3_proxy_kwargs_password": "", "regex_exp": {}, "categories": {}, - "message_added": "Added Torrent *TORRENTNAME*", - "message_finished": "Finished Downloading *TORRENTNAME*", + "message_added": "Added Torrent **TORRENTNAME**", + "message_finished": "Finished Downloading **TORRENTNAME**", "minimum_speed": int(-1), "user_timer": int(60) } @@ -1068,11 +1068,7 @@ def on_torrent_added(self, torrent_id): message = "{}".format(user_message.replace("TORRENTNAME", torrent_status["name"])) log.info(prelog() + 'Sending torrent added message to ' + str(self.notifylist)) - # Disable Markdown for custom messages - if custom_message: - return self.telegram_send(message, to=self.notifylist) - else: - return self.telegram_send(message, to=self.notifylist, parse_mode='Markdown') + return self.telegram_send('{}'.format(message), to=self.notifylist, parse_mode='Markdown') except Exception as e: log.error(prelog() + 'Error in alert %s' % str(e)) @@ -1101,12 +1097,8 @@ def on_torrent_finished(self, torrent_id): message = "{}".format(user_message.replace("TORRENTNAME", torrent_status["name"])) log.info(prelog() + 'Sending torrent finished message to ' + str(self.notifylist)) - # Disable Markdown for custom messages - if custom_message: - return self.telegram_send(message, to=self.notifylist) - else: - return self.telegram_send(message, to=self.notifylist, parse_mode='Markdown') - except Exception, e: + return self.telegram_send('{}'.format(message), to=self.notifylist, parse_mode='Markdown') + except Exception as e: log.error(prelog() + 'Error in alert %s' % str(e) + '\n' + traceback.format_exc()) diff --git a/telegramer/data/config.glade b/telegramer/data/config.glade index 7345918..64f7f09 100644 --- a/telegramer/data/config.glade +++ b/telegramer/data/config.glade @@ -250,7 +250,7 @@ Message to send when new torrents are added 80 - Added Torrent *TORRENTNAME* + Added Torrent **TORRENTNAME** True False False @@ -286,7 +286,7 @@ Message to send when torrents finish downloading 80 - Finished Downloading *TORRENTNAME* + Finished Downloading **TORRENTNAME** True False False diff --git a/telegramer/data/telegramer.js b/telegramer/data/telegramer.js index adad212..2f41c65 100755 --- a/telegramer/data/telegramer.js +++ b/telegramer/data/telegramer.js @@ -59,28 +59,28 @@ TelegramerPanel = Ext.extend(Ext.form.FormPanel, { }); this.opts.bind('telegram_token', fieldset.add({ fieldLabel: _('Telegram bot token'), - anchor:'100%', + anchor: '100%', name: 'telegram_token', autoWidth: true, value: 'Contact @BotFather and create a bot' })); this.opts.bind('telegram_user', fieldset.add({ fieldLabel: _('Telegram user ID'), - anchor:'100%', + anchor: '100%', name: 'telegram_user', autoWidth: true, value: 'Contact @MyIDbot' })); this.opts.bind('telegram_users', fieldset.add({ fieldLabel: _('Additional IDs'), - anchor:'100%', + anchor: '100%', name: 'telegram_users', autoWidth: true, value: 'IDs should be comma-separated' })); this.opts.bind('telegram_users_notify', fieldset.add({ fieldLabel: _('Notify IDs'), - anchor:'100%', + anchor: '100%', name: 'telegram_users_notify', autoWidth: true, value: 'IDs should be comma-separated' @@ -100,11 +100,11 @@ TelegramerPanel = Ext.extend(Ext.form.FormPanel, { })); this.opts.bind('message_added', fieldset.add({ fieldLabel: _('Torrent Added Message'), - anchor:'100%', + anchor: '100%', name: 'message_added', id: 'message_added', autoWidth: true, - value: 'Added Torrent *TORRENTNAME*' + value: 'Added Torrent **TORRENTNAME**' })); this.opts.bind('telegram_notify_finished', fieldset.add({ fieldLabel: _(''), @@ -115,11 +115,11 @@ TelegramerPanel = Ext.extend(Ext.form.FormPanel, { })); this.opts.bind('message_finished', fieldset.add({ fieldLabel: _('Torrent Finished Message'), - anchor:'100%', + anchor: '100%', name: 'message_finished', id: 'message_finished', autoWidth: true, - value: 'Finished Downloading *TORRENTNAME*' + value: 'Finished Downloading **TORRENTNAME**' })); fieldset = this.add({ xtype: 'fieldset', @@ -129,7 +129,7 @@ TelegramerPanel = Ext.extend(Ext.form.FormPanel, { }); this.opts.bind('cat1', fieldset.add({ fieldLabel: _('Category 1'), - anchor:'100%', + anchor: '100%', name: 'cat1', id: 'cat1', autoWidth: true, @@ -137,7 +137,7 @@ TelegramerPanel = Ext.extend(Ext.form.FormPanel, { })); this.opts.bind('dir1', fieldset.add({ fieldLabel: _('Directory 1'), - anchor:'100%', + anchor: '100%', name: 'dir1', id: 'dir1', autoWidth: true, @@ -145,7 +145,7 @@ TelegramerPanel = Ext.extend(Ext.form.FormPanel, { })); this.opts.bind('cat2', fieldset.add({ fieldLabel: _('Category 2'), - anchor:'100%', + anchor: '100%', name: 'cat2', id: 'cat2', autoWidth: true, @@ -153,7 +153,7 @@ TelegramerPanel = Ext.extend(Ext.form.FormPanel, { })); this.opts.bind('dir2', fieldset.add({ fieldLabel: _('Directory 2'), - anchor:'100%', + anchor: '100%', name: 'dir2', id: 'dir2', autoWidth: true, @@ -161,7 +161,7 @@ TelegramerPanel = Ext.extend(Ext.form.FormPanel, { })); this.opts.bind('cat3', fieldset.add({ fieldLabel: _('Category 3'), - anchor:'100%', + anchor: '100%', name: 'cat3', id: 'cat3', autoWidth: true, @@ -169,7 +169,7 @@ TelegramerPanel = Ext.extend(Ext.form.FormPanel, { })); this.opts.bind('dir3', fieldset.add({ fieldLabel: _('Directory 3'), - anchor:'100%', + anchor: '100%', name: 'dir3', id: 'dir3', autoWidth: true, @@ -183,7 +183,7 @@ TelegramerPanel = Ext.extend(Ext.form.FormPanel, { }); this.opts.bind('minimum_speed', fieldset.add({ fieldLabel: _('Minimum download speed (KB/s) -1 means no minimum'), - anchor:'100%', + anchor: '100%', name: 'minimum_speed', id: 'minimum_speed', autoWidth: true, @@ -191,7 +191,7 @@ TelegramerPanel = Ext.extend(Ext.form.FormPanel, { })); this.opts.bind('user_timer', fieldset.add({ fieldLabel: _('Check for slow torrents every... (seconds)'), - anchor:'100%', + anchor: '100%', name: 'user_timer', id: 'user_timer', autoWidth: true, @@ -228,9 +228,9 @@ TelegramerPanel = Ext.extend(Ext.form.FormPanel, { xtype: 'container', layout: 'hbox', items: [{ - xtype: 'button', - text: 'Test', - }] + xtype: 'button', + text: 'Test', + }] }); this.teleReloader = this.add({ fieldLabel: _(''), @@ -238,9 +238,9 @@ TelegramerPanel = Ext.extend(Ext.form.FormPanel, { xtype: 'container', layout: 'hbox', items: [{ - xtype: 'button', - text: 'Reload', - }] + xtype: 'button', + text: 'Reload', + }] }); this.teleTester.getComponent(0).setHandler(this.teleTest, this); @@ -258,62 +258,62 @@ TelegramerPanel = Ext.extend(Ext.form.FormPanel, { deluge.client.telegramer.restart_telegramer(); }, - onPreferencesShow: function () { + onPreferencesShow: function() { deluge.client.telegramer.get_config({ - success: function (config) { - if (!Ext.isEmpty(config['telegram_token'])) { - config['telegram_token'] = config['telegram_token']; - } - if (!Ext.isEmpty(config['telegram_user'])) { - config['telegram_user'] = config['telegram_user']; - } - if (!Ext.isEmpty(config['telegram_users'])) { - config['telegram_users'] = config['telegram_users']; - } - if (!Ext.isEmpty(config['telegram_users_notify'])) { - config['telegram_users_notify'] = config['telegram_users_notify']; - } - if (!Ext.isEmpty(config['telegram_notify_added'])) { - config['telegram_notify_added'] = config['telegram_notify_added']; - } - if (!Ext.isEmpty(config['telegram_notify_finished'])) { - config['telegram_notify_finished'] = config['telegram_notify_finished']; - } - if (!Ext.isEmpty(config['minimum_speed'])) { - config['minimum_speed'] = config['minimum_speed']; - } - if (!Ext.isEmpty(config['user_timer'])) { - config['user_timer'] = config['user_timer']; - } - if (!Ext.isEmpty(config['proxy_url'])) { - config['proxy_url'] = config['proxy_url'] - } - if (!Ext.isEmpty(config['urllib3_proxy_kwargs_username'])) { - config['urllib3_proxy_kwargs_username'] = config['urllib3_proxy_kwargs_username'] - } - if (!Ext.isEmpty(config['urllib3_proxy_kwargs_password'])) { - config['urllib3_proxy_kwargs_password'] = config['urllib3_proxy_kwargs_password'] - } - if (!Ext.isEmpty(config['cat1'])) { - config['cat1'] = config['cat1']; - } - if (!Ext.isEmpty(config['cat2'])) { - config['cat2'] = config['cat2']; - } - if (!Ext.isEmpty(config['cat3'])) { - config['cat3'] = config['cat3']; - } - if (!Ext.isEmpty(config['dir1'])) { - config['dir1'] = config['dir1']; - } - if (!Ext.isEmpty(config['dir2'])) { - config['dir2'] = config['dir2']; - } - if (!Ext.isEmpty(config['dir3'])) { - config['dir3'] = config['dir3']; - } - //Ext.getCmp("mycheck").checked; - this.opts.set(config); + success: function(config) { + if (!Ext.isEmpty(config['telegram_token'])) { + config['telegram_token'] = config['telegram_token']; + } + if (!Ext.isEmpty(config['telegram_user'])) { + config['telegram_user'] = config['telegram_user']; + } + if (!Ext.isEmpty(config['telegram_users'])) { + config['telegram_users'] = config['telegram_users']; + } + if (!Ext.isEmpty(config['telegram_users_notify'])) { + config['telegram_users_notify'] = config['telegram_users_notify']; + } + if (!Ext.isEmpty(config['telegram_notify_added'])) { + config['telegram_notify_added'] = config['telegram_notify_added']; + } + if (!Ext.isEmpty(config['telegram_notify_finished'])) { + config['telegram_notify_finished'] = config['telegram_notify_finished']; + } + if (!Ext.isEmpty(config['minimum_speed'])) { + config['minimum_speed'] = config['minimum_speed']; + } + if (!Ext.isEmpty(config['user_timer'])) { + config['user_timer'] = config['user_timer']; + } + if (!Ext.isEmpty(config['proxy_url'])) { + config['proxy_url'] = config['proxy_url'] + } + if (!Ext.isEmpty(config['urllib3_proxy_kwargs_username'])) { + config['urllib3_proxy_kwargs_username'] = config['urllib3_proxy_kwargs_username'] + } + if (!Ext.isEmpty(config['urllib3_proxy_kwargs_password'])) { + config['urllib3_proxy_kwargs_password'] = config['urllib3_proxy_kwargs_password'] + } + if (!Ext.isEmpty(config['cat1'])) { + config['cat1'] = config['cat1']; + } + if (!Ext.isEmpty(config['cat2'])) { + config['cat2'] = config['cat2']; + } + if (!Ext.isEmpty(config['cat3'])) { + config['cat3'] = config['cat3']; + } + if (!Ext.isEmpty(config['dir1'])) { + config['dir1'] = config['dir1']; + } + if (!Ext.isEmpty(config['dir2'])) { + config['dir2'] = config['dir2']; + } + if (!Ext.isEmpty(config['dir3'])) { + config['dir3'] = config['dir3']; + } + //Ext.getCmp("mycheck").checked; + this.opts.set(config); }, scope: this, }); @@ -322,19 +322,19 @@ TelegramerPanel = Ext.extend(Ext.form.FormPanel, { var changed = this.opts.getDirty(); if (!Ext.isObjectEmpty(changed)) { if (!Ext.isEmpty(changed['telegram_token'])) { - changed['telegram_token'] = changed['telegram_token']; + changed['telegram_token'] = changed['telegram_token']; } if (!Ext.isEmpty(changed['telegram_user'])) { - changed['telegram_user'] = changed['telegram_user']; + changed['telegram_user'] = changed['telegram_user']; } if (!Ext.isEmpty(changed['telegram_users'])) { - changed['telegram_users'] = changed['telegram_users']; + changed['telegram_users'] = changed['telegram_users']; } if (!Ext.isEmpty(changed['telegram_notify_added'])) { - changed['telegram_notify_added'] = changed['telegram_notify_added']; + changed['telegram_notify_added'] = changed['telegram_notify_added']; } if (!Ext.isEmpty(changed['telegram_notify_finished'])) { - changed['telegram_notify_finished'] = changed['telegram_notify_finished']; + changed['telegram_notify_finished'] = changed['telegram_notify_finished']; } if (!Ext.isEmpty(changed['minimum_speed'])) { changed['minimum_speed'] = changed['minimum_speed']; @@ -343,31 +343,31 @@ TelegramerPanel = Ext.extend(Ext.form.FormPanel, { changed['user_timer'] = changed['user_timer']; } if (!Ext.isEmpty(changed['proxy_url'])) { - changed['proxy_url'] = changed['proxy_url'] + changed['proxy_url'] = changed['proxy_url'] } if (!Ext.isEmpty(changed['urllib3_proxy_kwargs_username'])) { - changed['urllib3_proxy_kwargs_username'] = changed['urllib3_proxy_kwargs_username'] + changed['urllib3_proxy_kwargs_username'] = changed['urllib3_proxy_kwargs_username'] } if (!Ext.isEmpty(changed['urllib3_proxy_kwargs_password'])) { - changed['urllib3_proxy_kwargs_password'] = changed['urllib3_proxy_kwargs_password'] + changed['urllib3_proxy_kwargs_password'] = changed['urllib3_proxy_kwargs_password'] } if (!Ext.isEmpty(changed['cat1'])) { - changed['cat1'] = changed['cat1']; + changed['cat1'] = changed['cat1']; } if (!Ext.isEmpty(changed['cat2'])) { - changed['cat2'] = changed['cat2']; + changed['cat2'] = changed['cat2']; } if (!Ext.isEmpty(changed['cat3'])) { - changed['cat3'] = changed['cat3']; + changed['cat3'] = changed['cat3']; } if (!Ext.isEmpty(changed['dir1'])) { - changed['dir1'] = changed['dir1']; + changed['dir1'] = changed['dir1']; } if (!Ext.isEmpty(changed['dir2'])) { - changed['dir2'] = changed['dir2']; + changed['dir2'] = changed['dir2']; } if (!Ext.isEmpty(changed['dir3'])) { - changed['dir3'] = changed['dir3']; + changed['dir3'] = changed['dir3']; } deluge.client.telegramer.set_config(changed, { success: this.onSetConfig, @@ -394,4 +394,4 @@ TelegramerPlugin = Ext.extend(Deluge.Plugin, { } }); -Deluge.registerPlugin('Telegramer', TelegramerPlugin); +Deluge.registerPlugin('Telegramer', TelegramerPlugin); \ No newline at end of file From d1efa76af88e93fdfd3533510aa63a5cdd46a311 Mon Sep 17 00:00:00 2001 From: Noam Date: Fri, 7 Jan 2022 19:32:33 +0200 Subject: [PATCH 3/4] Add build.sh, bump version, fix TORRENTNAME formatting --- build.sh | 8 ++++++++ setup.py | 2 +- telegramer/data/config.glade | 4 ++-- telegramer/data/telegramer.js | 4 ++-- 4 files changed, 13 insertions(+), 5 deletions(-) create mode 100755 build.sh diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..a79f16c --- /dev/null +++ b/build.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash + +docker build --no-cache -t telegramer.build . \ + && docker run -v $(pwd)/out:/tmp/out --rm -i telegramer.build sh -s << COMMANDS +python setup.py bdist_egg +chown -R $(id -u):$(id -g) dist +cp -ar dist/ /tmp/out/ +COMMANDS diff --git a/setup.py b/setup.py index 4109a13..1df357f 100755 --- a/setup.py +++ b/setup.py @@ -46,7 +46,7 @@ __plugin_name__ = "Telegramer" __author__ = "Noam" __author_email__ = "noamgit@gmail.com" -__version__ = "1.2.1.7" +__version__ = "1.3.1" __url__ = "https://github.com/noam09" __license__ = "GPLv3" __description__ = "Control Deluge using Telegram" diff --git a/telegramer/data/config.glade b/telegramer/data/config.glade index 64f7f09..7345918 100644 --- a/telegramer/data/config.glade +++ b/telegramer/data/config.glade @@ -250,7 +250,7 @@ Message to send when new torrents are added 80 - Added Torrent **TORRENTNAME** + Added Torrent *TORRENTNAME* True False False @@ -286,7 +286,7 @@ Message to send when torrents finish downloading 80 - Finished Downloading **TORRENTNAME** + Finished Downloading *TORRENTNAME* True False False diff --git a/telegramer/data/telegramer.js b/telegramer/data/telegramer.js index 2f41c65..a3af9e0 100755 --- a/telegramer/data/telegramer.js +++ b/telegramer/data/telegramer.js @@ -104,7 +104,7 @@ TelegramerPanel = Ext.extend(Ext.form.FormPanel, { name: 'message_added', id: 'message_added', autoWidth: true, - value: 'Added Torrent **TORRENTNAME**' + value: 'Added Torrent *TORRENTNAME*' })); this.opts.bind('telegram_notify_finished', fieldset.add({ fieldLabel: _(''), @@ -119,7 +119,7 @@ TelegramerPanel = Ext.extend(Ext.form.FormPanel, { name: 'message_finished', id: 'message_finished', autoWidth: true, - value: 'Finished Downloading **TORRENTNAME**' + value: 'Finished Downloading *TORRENTNAME*' })); fieldset = this.add({ xtype: 'fieldset', From dfa5d1dea12b5fec0714a6573053bb5e8730967b Mon Sep 17 00:00:00 2001 From: Noam Date: Fri, 7 Jan 2022 19:35:30 +0200 Subject: [PATCH 4/4] Fix TORRENTNAME formatting --- telegramer/core.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/telegramer/core.py b/telegramer/core.py index 36672e1..b39cedf 100755 --- a/telegramer/core.py +++ b/telegramer/core.py @@ -105,8 +105,8 @@ def filter(self, message): "urllib3_proxy_kwargs_password": "", "regex_exp": {}, "categories": {}, - "message_added": "Added Torrent **TORRENTNAME**", - "message_finished": "Finished Downloading **TORRENTNAME**", + "message_added": "Added Torrent *TORRENTNAME*", + "message_finished": "Finished Downloading *TORRENTNAME*", "minimum_speed": int(-1), "user_timer": int(60) }