From e1cc8d00bbdec6cb0a52949d8623f17f85ae1943 Mon Sep 17 00:00:00 2001 From: Krzysztof Jagiello Date: Tue, 30 Jun 2015 19:01:16 +0200 Subject: [PATCH 1/4] Slack notifications. Highly customizable slack notifications plugin. --- couchpotato/core/notifications/slack.py | 126 ++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 couchpotato/core/notifications/slack.py diff --git a/couchpotato/core/notifications/slack.py b/couchpotato/core/notifications/slack.py new file mode 100644 index 0000000..89224bd --- /dev/null +++ b/couchpotato/core/notifications/slack.py @@ -0,0 +1,126 @@ +import json +from couchpotato.core.logger import CPLog +from couchpotato.core.notifications.base import Notification + +log = CPLog(__name__) +autoload = 'Slack' + + +class Slack(Notification): + url = 'https://slack.com/api/chat.postMessage' + required_confs = ('token', 'channel',) + + def notify(self, message='', data=None, listener=None): + for key in self.required_confs: + if not self.conf(key): + log.warning('Slack notifications are enabled, but ' + '"{0}" is not specified.'.format(key)) + return False + + data = data or {} + message = message.strip() + + if self.conf('include_imdb') and 'identifier' in data: + template = ' http://www.imdb.com/title/{0[identifier]}/' + message += template.format(data) + + payload = { + 'token': self.conf('token'), + 'text': message, + 'username': self.conf('bot_name'), + 'unfurl_links': self.conf('include_imdb'), + 'as_user': self.conf('as_user'), + 'icon_url': self.conf('icon_url'), + 'icon_emoji': self.conf('icon_emoji') + } + + channels = self.conf('channels').split(',') + for channel in channels: + payload['channel'] = channel.strip() + response = self.urlopen(self.url, data=payload) + response = json.loads(response) + if not response['ok']: + log.warning('Notification sending to Slack has failed. Error ' + 'code: %s.', response['error']) + return False + return True + + +config = [{ + 'name': 'slack', + 'groups': [ + { + 'tab': 'notifications', + 'list': 'notification_providers', + 'name': 'slack', + 'options': [ + { + 'name': 'enabled', + 'default': 0, + 'type': 'enabler', + }, + { + 'name': 'token', + 'description': ( + 'Your Slack authentication token.', + 'Can be created at https://api.slack.com/web' + ) + }, + { + 'name': 'channels', + 'description': ( + 'Channel to send notifications to.', + 'Can be a public channel, private group or IM ' + 'channel. Can be an encoded ID or a name ' + '(staring with a hashtag, e.g. #general). ' + 'Separate with commas in order to notify multiple ' + 'channels. It is however recommended to send ' + 'notifications to only one channel due to ' + 'the Slack API rate limits.' + ) + }, + { + 'name': 'include_imdb', + 'default': True, + 'type': 'bool', + 'descrpition': 'Include a link to the movie page on IMDB.' + }, + { + 'name': 'bot_name', + 'description': 'Name of bot.', + 'default': 'CouchPotato', + 'advanced': True, + }, + { + 'name': 'as_user', + 'description': 'Send message as the authentication token ' + ' user.', + 'default': False, + 'type': 'bool', + 'advanced': True + }, + { + 'name': 'icon_url', + 'description': 'URL to an image to use as the icon for ' + 'notifications.', + 'advanced': True, + }, + { + 'name': 'icon_emoji', + 'description': ( + 'Emoji to use as the icon for notifications.', + 'Overrides icon_url' + ), + 'advanced': True, + }, + { + 'name': 'on_snatch', + 'default': 0, + 'type': 'bool', + 'advanced': True, + 'description': 'Also send message when movie is snatched.', + }, + ], + } + ], +}] From 6cf3b5b6c8a115ff9988f042941745de545d8970 Mon Sep 17 00:00:00 2001 From: Krzysztof Jagiello Date: Tue, 30 Jun 2015 20:16:50 +0200 Subject: [PATCH 2/4] Corrected name of the required config parameter --- couchpotato/core/notifications/slack.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/couchpotato/core/notifications/slack.py b/couchpotato/core/notifications/slack.py index 89224bd..5da8456 100644 --- a/couchpotato/core/notifications/slack.py +++ b/couchpotato/core/notifications/slack.py @@ -8,7 +8,7 @@ autoload = 'Slack' class Slack(Notification): url = 'https://slack.com/api/chat.postMessage' - required_confs = ('token', 'channel',) + required_confs = ('token', 'channels',) def notify(self, message='', data=None, listener=None): for key in self.required_confs: From 5a2de0f9fc29d14cb63dbdc49bd79062957c7240 Mon Sep 17 00:00:00 2001 From: Brandon Schneider Date: Fri, 3 Jul 2015 01:32:52 -0500 Subject: [PATCH 3/4] Update renamer.py Correct small typo. --- couchpotato/core/plugins/renamer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/couchpotato/core/plugins/renamer.py b/couchpotato/core/plugins/renamer.py index aa983b1..2874983 100755 --- a/couchpotato/core/plugins/renamer.py +++ b/couchpotato/core/plugins/renamer.py @@ -1447,7 +1447,7 @@ config = [{ 'default': 'link', 'type': 'dropdown', 'values': [('Link', 'link'), ('Copy', 'copy'), ('Move', 'move')], - 'description': 'See above. It is prefered to use link when downloading torrents as it will save you space, while still beeing able to seed.', + 'description': 'See above. It is prefered to use link when downloading torrents as it will save you space, while still being able to seed.', 'advanced': True, }, { From 734e4203099db4cf1ae9fde78afa2e4ac8bbf27b Mon Sep 17 00:00:00 2001 From: Brandon Schneider Date: Fri, 3 Jul 2015 01:52:03 -0500 Subject: [PATCH 4/4] Update base.py Correct more grammar. --- couchpotato/core/plugins/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/couchpotato/core/plugins/base.py b/couchpotato/core/plugins/base.py index dc5a5f7..57a31e2 100644 --- a/couchpotato/core/plugins/base.py +++ b/couchpotato/core/plugins/base.py @@ -145,7 +145,7 @@ class Plugin(object): f.close() os.chmod(path, Env.getPermission('file')) except: - log.error('Unable writing to file "%s": %s', (path, traceback.format_exc())) + log.error('Unable to write file "%s": %s', (path, traceback.format_exc())) if os.path.isfile(path): os.remove(path)