mirror of
https://github.com/SickGear/SickGear.git
synced 2024-12-01 00:43:37 +00:00
Change improve Slack notifier.
This commit is contained in:
parent
c2fcf37498
commit
87ac49322a
8 changed files with 144 additions and 144 deletions
|
@ -110,6 +110,7 @@
|
||||||
* Add warn icon indicator of abandoned IDs to "Manage" menu bar and "Manage/Show Processes" menu item
|
* Add warn icon indicator of abandoned IDs to "Manage" menu bar and "Manage/Show Processes" menu item
|
||||||
* Add shows that have no replacement ID can be ignored at "Manage/Show Processes", the menu bar warn icon hides if all are ignored
|
* Add shows that have no replacement ID can be ignored at "Manage/Show Processes", the menu bar warn icon hides if all are ignored
|
||||||
* Change FreeBSD initscript to use command_interpreter
|
* Change FreeBSD initscript to use command_interpreter
|
||||||
|
* Add Slack notifier
|
||||||
|
|
||||||
|
|
||||||
[develop changelog]
|
[develop changelog]
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 1.1 KiB |
|
@ -1683,77 +1683,29 @@
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</div><!-- /trakt component-group //-->
|
</div><!-- /trakt component-group //-->
|
||||||
|
|
||||||
<div class="component-group clearfix">
|
<div class="component-group">
|
||||||
<div class="component-group-desc">
|
<div class="component-group-desc">
|
||||||
<img class="notifier-icon" src="$sbRoot/images/notifiers/slack.png" alt="" title="Trakt" />
|
<img class="notifier-icon" src="$sbRoot/images/notifiers/slack.png" alt="" title="Slack" />
|
||||||
<h3><a href="http://slack.com/" rel="noreferrer" onclick="window.open('${sickbeard.ANON_REDIRECT}' + this.href, '_blank'); return false;">Slack</a></h3>
|
<h3><a href="<%= anon_url('https://slack.com/') %>" rel="noreferrer" onclick="window.open(this.href, '_blank'); return false;">Slack</a></h3>
|
||||||
<p>Team communication for the 21st century.</p>
|
<p>Team, group, and direct communication.</p>
|
||||||
</div>
|
</div>
|
||||||
<fieldset class="component-group-list">
|
<fieldset class="component-group-list">
|
||||||
<div class="field-pair">
|
<div class="field-pair">
|
||||||
<input type="checkbox" class="enabler" name="use_slack" id="use_slack" #if $sickbeard.USE_SLACK then "checked=\"checked\"" else ""# />
|
<label for="use_slack">
|
||||||
<label class="clearfix" for="use_slack">
|
|
||||||
<span class="component-title">Enable</span>
|
<span class="component-title">Enable</span>
|
||||||
<span class="component-desc">Should Sick Beard send Slack notifications?</span>
|
<span class="component-desc">
|
||||||
|
<input type="checkbox" class="enabler" name="use_slack" id="use_slack" #if $sickbeard.USE_SLACK then 'checked="checked"' else ''#>
|
||||||
|
<p>should SickGear send Slack notifications ?</p>
|
||||||
|
</span>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="content_use_slack">
|
<div id="content_use_slack">
|
||||||
<div class="field-pair">
|
|
||||||
<label class="nocheck clearfix">
|
|
||||||
<span class="component-title">Slack API Key:</span>
|
|
||||||
<input type="text" name="slack_access_token" id="slack_access_token" value="$sickbeard.SLACK_ACCESS_TOKEN" size="35" />
|
|
||||||
</label>
|
|
||||||
<label class="nocheck clearfix">
|
|
||||||
<span class="component-title"> </span>
|
|
||||||
<span class="component-desc">Get your key at: <a href="https://api.slack.com/web" rel="noreferrer" onclick="window.open('${sickbeard.ANON_REDIRECT}' + this.href, '_blank'); return false;">https://api.slack.com/web</a></span>
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
<div class="field-pair">
|
|
||||||
<label class="nocheck clearfix">
|
|
||||||
<span class="component-title">Slack Channel</span>
|
|
||||||
<input type="text" name="slack_channel" id="slack_channel" value="$sickbeard.SLACK_CHANNEL" size="35" />
|
|
||||||
</label>
|
|
||||||
<label class="nocheck clearfix">
|
|
||||||
<span class="component-title"> </span>
|
|
||||||
<span class="component-desc">Channel Sick Beard should send notifications to.</span>
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
<div class="field-pair">
|
|
||||||
<label class="nocheck clearfix">
|
|
||||||
<span class="component-title">Send as User</span>
|
|
||||||
<input type="checkbox" class="enabler" name="slack_as_user" id="slack_as_user" #if $sickbeard.SLACK_AS_USER then "checked=\"checked\"" else ""# />
|
|
||||||
</label>
|
|
||||||
<label class="nocheck clearfix">
|
|
||||||
<span class="component-title"> </span>
|
|
||||||
<span class="component-desc">Send notification as your user (otherwise send as name and icon below).</span>
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
<div class="field-pair">
|
|
||||||
<label class="nocheck clearfix">
|
|
||||||
<span class="component-title">Slack Bot Name</span>
|
|
||||||
<input type="text" name="slack_bot_name" id="slack_bot_name" value="$sickbeard.SLACK_BOT_NAME" size="35" />
|
|
||||||
</label>
|
|
||||||
<label class="nocheck clearfix">
|
|
||||||
<span class="component-title"> </span>
|
|
||||||
<span class="component-desc">Name of the bot that will send the notifications.</span>
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
<div class="field-pair">
|
|
||||||
<label class="nocheck clearfix">
|
|
||||||
<span class="component-title">Slack Bot Icon URL</span>
|
|
||||||
<input type="text" name="slack_icon_url" id="slack_icon_url" value="$sickbeard.SLACK_ICON_URL" size="35" />
|
|
||||||
</label>
|
|
||||||
<label class="nocheck clearfix">
|
|
||||||
<span class="component-title"> </span>
|
|
||||||
<span class="component-desc">URL to an image to use as the icon for this bot.</span>
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
<div class="field-pair">
|
<div class="field-pair">
|
||||||
<label for="slack_notify_onsnatch">
|
<label for="slack_notify_onsnatch">
|
||||||
<span class="component-title">Notify on snatch</span>
|
<span class="component-title">Notify on snatch</span>
|
||||||
<span class="component-desc">
|
<span class="component-desc">
|
||||||
<input type="checkbox" name="slack_notify_onsnatch" id="slack_notify_onsnatch" #if $sickbeard.SLACK_NOTIFY_ONSNATCH then 'checked="checked"' else ''# />
|
<input type="checkbox" name="slack_notify_onsnatch" id="slack_notify_onsnatch" #if $sickbeard.SLACK_NOTIFY_ONSNATCH then 'checked="checked"' else ''#>
|
||||||
<p>send a notification when a download starts ?</p>
|
<p>send a notification when a download starts ?</p>
|
||||||
</span>
|
</span>
|
||||||
</label>
|
</label>
|
||||||
|
@ -1762,16 +1714,78 @@
|
||||||
<label for="slack_notify_ondownload">
|
<label for="slack_notify_ondownload">
|
||||||
<span class="component-title">Notify on download</span>
|
<span class="component-title">Notify on download</span>
|
||||||
<span class="component-desc">
|
<span class="component-desc">
|
||||||
<input type="checkbox" name="slack_notify_ondownload" id="slack_notify_ondownload" #if $sickbeard.SLACK_NOTIFY_ONDOWNLOAD then 'checked="checked"' else ''# />
|
<input type="checkbox" name="slack_notify_ondownload" id="slack_notify_ondownload" #if $sickbeard.SLACK_NOTIFY_ONDOWNLOAD then 'checked="checked"' else ''#>
|
||||||
<p>send a notification when a download finishes ?</p>
|
<p>send a notification when a download finishes ?</p>
|
||||||
</span>
|
</span>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="field-pair">
|
||||||
|
<label for="slack_notify_onsubtitledownload">
|
||||||
|
<span class="component-title">Notify on subtitle download</span>
|
||||||
|
<span class="component-desc">
|
||||||
|
<input type="checkbox" name="slack_notify_onsubtitledownload" id="slack_notify_onsubtitledownload" #if $sickbeard.SLACK_NOTIFY_ONSUBTITLEDOWNLOAD then 'checked="checked"' else ''#>
|
||||||
|
<p>send a notification when subtitles are downloaded ?</p>
|
||||||
|
</span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="field-pair">
|
||||||
|
<label for="slack_channel">
|
||||||
|
<span class="component-title">Slack channel</span>
|
||||||
|
<span class="component-desc">
|
||||||
|
<input type="text" name="slack_channel" id="slack_channel" value="$sickbeard.SLACK_CHANNEL" class="form-control input-sm input250">
|
||||||
|
<span style="float:left">channel to send notifications to</span>
|
||||||
|
</span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div class="field-pair">
|
||||||
|
<label for="slack_as_user">
|
||||||
|
<span class="component-title">Post as authed user</span>
|
||||||
|
<span class="component-desc">
|
||||||
|
<input type="checkbox" class="viewIf" name="slack_as_user" id="slack_as_user" #if $sickbeard.SLACK_AS_USER then 'checked="checked"' else ''#>
|
||||||
|
<p>send notifications using the profile name and photo of the access token</p>
|
||||||
|
</span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div class="hide_if_slack_as_user">
|
||||||
|
<div class="field-pair">
|
||||||
|
<label for="slack_bot_name">
|
||||||
|
<span class="component-title">Post as a custom name</span>
|
||||||
|
<span class="component-desc">
|
||||||
|
<input type="text" name="slack_bot_name" id="slack_bot_name" value="$sickbeard.SLACK_BOT_NAME" class="form-control input-sm input250">
|
||||||
|
<p>blank for 'SickGear'</p>
|
||||||
|
</span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div class="field-pair">
|
||||||
|
<label for="slack_icon_url">
|
||||||
|
<span class="component-title">Custom icon image url</span>
|
||||||
|
<span class="component-desc">
|
||||||
|
<input type="text" name="slack_icon_url" id="slack_icon_url" value="$sickbeard.SLACK_ICON_URL" class="form-control input-sm input250">
|
||||||
|
<p>blank for SickGear image</p>
|
||||||
|
</span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="field-pair">
|
||||||
|
<label for="slack_access_token">
|
||||||
|
<span class="component-title">Slack oauth access token</span>
|
||||||
|
<span class="component-desc">
|
||||||
|
<input type="text" name="slack_access_token" id="slack_access_token" value="$sickbeard.SLACK_ACCESS_TOKEN" class="form-control input-sm input350">
|
||||||
|
<div class="clear-left"><p>1. <a href="<%= anon_url('https://api.slack.com/apps/new') %>" rel="noreferrer" onclick="window.open(this.href, '_blank'); return false;">create a Slack app</a> name for SickGear and select a workspace<br>
|
||||||
|
2. under the 'Features' section of the left sidebar, click 'OAuth & Perms'<br>
|
||||||
|
3. scroll page to section 'Scopes' and open the menu 'Select Permission Scopes'<br>
|
||||||
|
4. in the 'Chat' menu section, select 'Send messages as <em class="grey-text">appname</em>' - (<em class="grey-text">set in step 1</em>)<br>
|
||||||
|
5. also, in the 'Chat' menu section, select 'Send messages as user'<br>
|
||||||
|
6. after 'Save', go to page top, click 'Install App to Workspace'<br>
|
||||||
|
7. click 'Authorize' to view the 'OAuth Access Token', paste it to the above field</p></div>
|
||||||
|
</span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
<div class="testNotification" id="testSlack-result">Click below to test.</div>
|
<div class="testNotification" id="testSlack-result">Click below to test.</div>
|
||||||
<input type="button" class="btn" value="Test Slack" id="testSlack" />
|
<input type="button" class="btn" value="Test Slack" id="testSlack" />
|
||||||
<input type="submit" class="btn config_submitter" value="Save Changes" />
|
<input type="submit" class="btn config_submitter" value="Save Changes" />
|
||||||
</div><!-- /content_use_slack //-->
|
</div><!-- /content_use_slack //-->
|
||||||
|
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</div><!-- /slack component-group //-->
|
</div><!-- /slack component-group //-->
|
||||||
|
|
||||||
|
|
|
@ -434,23 +434,30 @@
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#testSlack").click(function () {
|
$('#testSlack').click(function () {
|
||||||
var slack_access_token = $("#slack_access_token").val();
|
var channel = '#slack_channel', slack_channel = $(channel).val(),
|
||||||
var slack_channel = $("#slack_channel").val();
|
slack_as_user = $('#slack_as_user').prop('checked'),
|
||||||
var slack_as_user = $("#slack_as_user").attr('checked');
|
slack_bot_name = $('#slack_bot_name').val(), slack_icon_url = $('#slack_icon_url').val(),
|
||||||
var slack_bot_name = $("#slack_bot_name").val();
|
access_token = '#slack_access_token', slack_access_token = $(access_token).val();
|
||||||
var slack_icon_url = $("#slack_icon_url").val();
|
|
||||||
if (!slack_access_token || !slack_channel || !(slack_as_user || slack_bot_name)) {
|
$(channel + ', ' + access_token).removeClass('warning');
|
||||||
$("#testSlack-result").html("Please fill out the necessary fields above.");
|
if (!slack_channel || !slack_access_token) {
|
||||||
return;
|
$('#testSlack-result').html('Please fill out the necessary fields above.');
|
||||||
|
if (!slack_channel)
|
||||||
|
$(channel).addClass('warning');
|
||||||
|
if (!slack_access_token)
|
||||||
|
$(access_token).addClass('warning');
|
||||||
|
} else {
|
||||||
|
$(this).prop('disabled', true);
|
||||||
|
$('#testSlack-result').html(loading);
|
||||||
|
$.get(sbRoot + '/home/testSlack', {
|
||||||
|
'channel': slack_channel, 'as_user': slack_as_user,
|
||||||
|
'bot_name': slack_bot_name, 'icon_url': slack_icon_url, 'access_token': slack_access_token})
|
||||||
|
.done(function (data) {
|
||||||
|
$('#testSlack-result').html(data);
|
||||||
|
$('#testSlack').prop('disabled', false);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
$(this).prop("disabled", true);
|
|
||||||
$("#testSlack-result").html(loading);
|
|
||||||
$.get(sbRoot + "/home/testSlack", {'accessToken': slack_access_token, 'channel': slack_channel, 'as_user': slack_as_user, 'bot_name': slack_bot_name, 'icon_url': slack_icon_url})
|
|
||||||
.done(function (data) {
|
|
||||||
$("#testSlack-result").html(data);
|
|
||||||
$("#testSlack").prop("disabled", false);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
function get_pushbullet_devices (msg) {
|
function get_pushbullet_devices (msg) {
|
||||||
|
|
|
@ -421,11 +421,12 @@ PUSHBULLET_DEVICE_IDEN = None
|
||||||
USE_SLACK = False
|
USE_SLACK = False
|
||||||
SLACK_NOTIFY_ONSNATCH = False
|
SLACK_NOTIFY_ONSNATCH = False
|
||||||
SLACK_NOTIFY_ONDOWNLOAD = False
|
SLACK_NOTIFY_ONDOWNLOAD = False
|
||||||
SLACK_ACCESS_TOKEN = None
|
SLACK_NOTIFY_ONSUBTITLEDOWNLOAD = False
|
||||||
SLACK_CHANNEL = None
|
SLACK_CHANNEL = None
|
||||||
SLACK_AS_USER = False
|
SLACK_AS_USER = False
|
||||||
SLACK_BOT_NAME = None
|
SLACK_BOT_NAME = None
|
||||||
SLACK_ICON_URL = None
|
SLACK_ICON_URL = None
|
||||||
|
SLACK_ACCESS_TOKEN = None
|
||||||
|
|
||||||
USE_EMAIL = False
|
USE_EMAIL = False
|
||||||
EMAIL_OLD_SUBJECTS = None
|
EMAIL_OLD_SUBJECTS = None
|
||||||
|
@ -640,7 +641,8 @@ def initialize(console_logging=True):
|
||||||
USE_TRAKT, TRAKT_CONNECTED_ACCOUNT, TRAKT_ACCOUNTS, TRAKT_MRU, TRAKT_VERIFY, \
|
USE_TRAKT, TRAKT_CONNECTED_ACCOUNT, TRAKT_ACCOUNTS, TRAKT_MRU, TRAKT_VERIFY, \
|
||||||
TRAKT_USE_WATCHLIST, TRAKT_REMOVE_WATCHLIST, TRAKT_TIMEOUT, TRAKT_METHOD_ADD, TRAKT_START_PAUSED, \
|
TRAKT_USE_WATCHLIST, TRAKT_REMOVE_WATCHLIST, TRAKT_TIMEOUT, TRAKT_METHOD_ADD, TRAKT_START_PAUSED, \
|
||||||
TRAKT_SYNC, TRAKT_DEFAULT_INDEXER, TRAKT_REMOVE_SERIESLIST, TRAKT_UPDATE_COLLECTION, \
|
TRAKT_SYNC, TRAKT_DEFAULT_INDEXER, TRAKT_REMOVE_SERIESLIST, TRAKT_UPDATE_COLLECTION, \
|
||||||
USE_SLACK, SLACK_NOTIFY_ONSNATCH, SLACK_NOTIFY_ONDOWNLOAD, SLACK_ACCESS_TOKEN, SLACK_CHANNEL, SLACK_AS_USER, SLACK_BOT_NAME, SLACK_ICON_URL, \
|
USE_SLACK, SLACK_NOTIFY_ONSNATCH, SLACK_NOTIFY_ONDOWNLOAD, SLACK_NOTIFY_ONSUBTITLEDOWNLOAD, \
|
||||||
|
SLACK_CHANNEL, SLACK_AS_USER, SLACK_BOT_NAME, SLACK_ICON_URL, SLACK_ACCESS_TOKEN, \
|
||||||
USE_EMAIL, EMAIL_NOTIFY_ONSNATCH, EMAIL_NOTIFY_ONDOWNLOAD, EMAIL_NOTIFY_ONSUBTITLEDOWNLOAD, EMAIL_FROM, \
|
USE_EMAIL, EMAIL_NOTIFY_ONSNATCH, EMAIL_NOTIFY_ONDOWNLOAD, EMAIL_NOTIFY_ONSUBTITLEDOWNLOAD, EMAIL_FROM, \
|
||||||
EMAIL_HOST, EMAIL_PORT, EMAIL_TLS, EMAIL_USER, EMAIL_PASSWORD, EMAIL_LIST, EMAIL_OLD_SUBJECTS
|
EMAIL_HOST, EMAIL_PORT, EMAIL_TLS, EMAIL_USER, EMAIL_PASSWORD, EMAIL_LIST, EMAIL_OLD_SUBJECTS
|
||||||
# Anime Settings
|
# Anime Settings
|
||||||
|
@ -1046,11 +1048,12 @@ def initialize(console_logging=True):
|
||||||
USE_SLACK = bool(check_setting_int(CFG, 'Slack', 'use_slack', 0))
|
USE_SLACK = bool(check_setting_int(CFG, 'Slack', 'use_slack', 0))
|
||||||
SLACK_NOTIFY_ONSNATCH = bool(check_setting_int(CFG, 'Slack', 'slack_notify_onsnatch', 0))
|
SLACK_NOTIFY_ONSNATCH = bool(check_setting_int(CFG, 'Slack', 'slack_notify_onsnatch', 0))
|
||||||
SLACK_NOTIFY_ONDOWNLOAD = bool(check_setting_int(CFG, 'Slack', 'slack_notify_ondownload', 0))
|
SLACK_NOTIFY_ONDOWNLOAD = bool(check_setting_int(CFG, 'Slack', 'slack_notify_ondownload', 0))
|
||||||
SLACK_ACCESS_TOKEN = check_setting_str(CFG, 'Slack', 'slack_access_token', '')
|
SLACK_NOTIFY_ONSUBTITLEDOWNLOAD = bool(check_setting_int(CFG, 'Slack', 'slack_notify_onsubtitledownload', 0))
|
||||||
SLACK_CHANNEL = check_setting_str(CFG, 'Slack', 'slack_channel', '')
|
SLACK_CHANNEL = check_setting_str(CFG, 'Slack', 'slack_channel', '')
|
||||||
SLACK_AS_USER = bool(check_setting_int(CFG, 'Slack', 'slack_as_user', 0))
|
SLACK_AS_USER = bool(check_setting_int(CFG, 'Slack', 'slack_as_user', 0))
|
||||||
SLACK_BOT_NAME = check_setting_str(CFG, 'Slack', 'slack_bot_name', '')
|
SLACK_BOT_NAME = check_setting_str(CFG, 'Slack', 'slack_bot_name', '')
|
||||||
SLACK_ICON_URL = check_setting_str(CFG, 'Slack', 'slack_icon_url', '')
|
SLACK_ICON_URL = check_setting_str(CFG, 'Slack', 'slack_icon_url', '')
|
||||||
|
SLACK_ACCESS_TOKEN = check_setting_str(CFG, 'Slack', 'slack_access_token', '')
|
||||||
|
|
||||||
USE_EMAIL = bool(check_setting_int(CFG, 'Email', 'use_email', 0))
|
USE_EMAIL = bool(check_setting_int(CFG, 'Email', 'use_email', 0))
|
||||||
EMAIL_OLD_SUBJECTS = bool(check_setting_int(CFG, 'Email', 'email_old_subjects',
|
EMAIL_OLD_SUBJECTS = bool(check_setting_int(CFG, 'Email', 'email_old_subjects',
|
||||||
|
@ -1844,11 +1847,12 @@ def save_config():
|
||||||
new_config['Slack']['use_slack'] = int(USE_SLACK)
|
new_config['Slack']['use_slack'] = int(USE_SLACK)
|
||||||
new_config['Slack']['slack_notify_onsnatch'] = int(SLACK_NOTIFY_ONSNATCH)
|
new_config['Slack']['slack_notify_onsnatch'] = int(SLACK_NOTIFY_ONSNATCH)
|
||||||
new_config['Slack']['slack_notify_ondownload'] = int(SLACK_NOTIFY_ONDOWNLOAD)
|
new_config['Slack']['slack_notify_ondownload'] = int(SLACK_NOTIFY_ONDOWNLOAD)
|
||||||
new_config['Slack']['slack_access_token'] = SLACK_ACCESS_TOKEN
|
new_config['Slack']['slack_notify_onsubtitledownload'] = int(SLACK_NOTIFY_ONSUBTITLEDOWNLOAD)
|
||||||
new_config['Slack']['slack_channel'] = SLACK_CHANNEL
|
new_config['Slack']['slack_channel'] = SLACK_CHANNEL
|
||||||
new_config['Slack']['slack_as_user'] = int(SLACK_AS_USER)
|
new_config['Slack']['slack_as_user'] = int(SLACK_AS_USER)
|
||||||
new_config['Slack']['slack_bot_name'] = SLACK_BOT_NAME
|
new_config['Slack']['slack_bot_name'] = SLACK_BOT_NAME
|
||||||
new_config['Slack']['slack_icon_url'] = SLACK_ICON_URL
|
new_config['Slack']['slack_icon_url'] = SLACK_ICON_URL
|
||||||
|
new_config['Slack']['slack_access_token'] = SLACK_ACCESS_TOKEN
|
||||||
|
|
||||||
new_config['Email'] = {}
|
new_config['Email'] = {}
|
||||||
new_config['Email']['use_email'] = int(USE_EMAIL)
|
new_config['Email']['use_email'] = int(USE_EMAIL)
|
||||||
|
|
|
@ -61,9 +61,9 @@ nma_notifier = nma.NMA_Notifier()
|
||||||
pushalot_notifier = pushalot.PushalotNotifier()
|
pushalot_notifier = pushalot.PushalotNotifier()
|
||||||
pushbullet_notifier = pushbullet.PushbulletNotifier()
|
pushbullet_notifier = pushbullet.PushbulletNotifier()
|
||||||
# social
|
# social
|
||||||
slack_notifier = slack.SlackNotifier()
|
|
||||||
twitter_notifier = tweet.TwitterNotifier()
|
twitter_notifier = tweet.TwitterNotifier()
|
||||||
trakt_notifier = trakt.TraktNotifier()
|
trakt_notifier = trakt.TraktNotifier()
|
||||||
|
slack_notifier = slack.SlackNotifier()
|
||||||
email_notifier = emailnotify.EmailNotifier()
|
email_notifier = emailnotify.EmailNotifier()
|
||||||
|
|
||||||
notifiers = [
|
notifiers = [
|
||||||
|
@ -83,9 +83,9 @@ notifiers = [
|
||||||
nma_notifier,
|
nma_notifier,
|
||||||
pushalot_notifier,
|
pushalot_notifier,
|
||||||
pushbullet_notifier,
|
pushbullet_notifier,
|
||||||
slack_notifier,
|
|
||||||
twitter_notifier,
|
twitter_notifier,
|
||||||
trakt_notifier,
|
trakt_notifier,
|
||||||
|
slack_notifier,
|
||||||
email_notifier,
|
email_notifier,
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
#
|
#
|
||||||
# This file is part of SickGear.
|
# This file is part of SickGear.
|
||||||
#
|
#
|
||||||
# Thanks to: mallen86
|
# Thanks to: mallen86, generica
|
||||||
#
|
#
|
||||||
# SickGear is free software: you can redistribute it and/or modify
|
# SickGear is free software: you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
@ -17,74 +17,50 @@
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with SickGear. If not, see <http://www.gnu.org/licenses/>.
|
# along with SickGear. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import json
|
|
||||||
import sickbeard
|
import sickbeard
|
||||||
|
from sickbeard import common, logger
|
||||||
|
|
||||||
from sickbeard import logger, common
|
|
||||||
|
|
||||||
class SlackNotifier:
|
class SlackNotifier:
|
||||||
|
def __init__(self):
|
||||||
|
self.sg_logo_url = 'https://raw.githubusercontent.com/SickGear/SickGear/master' + \
|
||||||
|
'/gui/slick/images/ico/apple-touch-icon-precomposed.png'
|
||||||
|
|
||||||
def _send_to_slack(self, message, accessToken, channel, as_user, bot_name, icon_url):
|
def _notify(self, msg, channel='', as_user=False, bot_name='', icon_url='', access_token='', force=False):
|
||||||
SLACK_ENDPOINT = "https://slack.com/api/chat.postMessage"
|
custom = (force and not as_user) or (not (force or sickbeard.SLACK_AS_USER))
|
||||||
|
resp = (sickbeard.USE_SLACK or force) and sickbeard.helpers.getURL(
|
||||||
|
url='https://slack.com/api/chat.postMessage',
|
||||||
|
post_data=dict(
|
||||||
|
[('text', msg), ('token', (access_token, sickbeard.SLACK_ACCESS_TOKEN)[not access_token]),
|
||||||
|
('channel', (channel, sickbeard.SLACK_CHANNEL)[not channel]), ('as_user', not custom)] +
|
||||||
|
([], [('username', (bot_name, sickbeard.SLACK_BOT_NAME or 'SickGear')[not bot_name]),
|
||||||
|
('icon_url', (icon_url, sickbeard.SLACK_ICON_URL or self.sg_logo_url)[not icon_url])])[custom]),
|
||||||
|
json=True)
|
||||||
|
|
||||||
data = {}
|
result = resp and resp['ok'] or resp['error']
|
||||||
data["token"] = accessToken
|
if True is not result:
|
||||||
data["channel"] = channel
|
logger.log(u'Slack failed sending message, response: "%s"' % resp['error'], logger.ERROR)
|
||||||
data["username"] = bot_name
|
return result
|
||||||
data["text"] = message
|
|
||||||
data["icon_url"] = icon_url
|
|
||||||
data["as_user"] = as_user
|
|
||||||
|
|
||||||
urlResp = sickbeard.helpers.getURL(url=SLACK_ENDPOINT, post_data=data)
|
def _notify_str(self, pre_text, post_text):
|
||||||
if urlResp:
|
return self._notify('%s: %s' % (common.notifyStrings[pre_text].strip('#: '), post_text))
|
||||||
resp = json.loads(urlResp)
|
|
||||||
else:
|
|
||||||
return False
|
|
||||||
|
|
||||||
# if ("error" in resp):
|
def test_notify(self, channel, as_user, bot_name, icon_url, access_token):
|
||||||
# raise Exception(resp["error"])
|
return self._notify('This is a test notification from SickGear',
|
||||||
|
channel, as_user, bot_name, icon_url, access_token, force=True)
|
||||||
if (resp["ok"] == True):
|
|
||||||
logger.log(u"Slack: Succeeded sending message.", logger.MESSAGE)
|
|
||||||
return True
|
|
||||||
|
|
||||||
logger.log(u"Slack: Failed sending message: " + resp["error"], logger.ERROR)
|
|
||||||
return False
|
|
||||||
|
|
||||||
def _notify(self, message, accessToken='', channel='', as_user='', bot_name='', icon_url='', force=False):
|
|
||||||
# suppress notifications if the notifier is disabled but the notify options are checked
|
|
||||||
if not sickbeard.USE_SLACK and not force:
|
|
||||||
return False
|
|
||||||
|
|
||||||
if not accessToken:
|
|
||||||
accessToken = sickbeard.SLACK_ACCESS_TOKEN
|
|
||||||
if not channel:
|
|
||||||
channel = sickbeard.SLACK_CHANNEL
|
|
||||||
if not as_user:
|
|
||||||
as_user = sickbeard.SLACK_AS_USER
|
|
||||||
if not bot_name:
|
|
||||||
bot_name = sickbeard.SLACK_BOT_NAME
|
|
||||||
if not icon_url:
|
|
||||||
icon_url = sickbeard.SLACK_ICON_URL
|
|
||||||
|
|
||||||
return self._send_to_slack(message, accessToken, channel, as_user, bot_name, icon_url)
|
|
||||||
|
|
||||||
##############################################################################
|
|
||||||
# Public functions
|
|
||||||
##############################################################################
|
|
||||||
|
|
||||||
def notify_snatch(self, ep_name):
|
def notify_snatch(self, ep_name):
|
||||||
if sickbeard.SLACK_NOTIFY_ONSNATCH:
|
return sickbeard.SLACK_NOTIFY_ONSNATCH and self._notify_str(common.NOTIFY_SNATCH, ep_name)
|
||||||
self._notify(common.notifyStrings[common.NOTIFY_SNATCH] + ': ' + ep_name)
|
|
||||||
|
|
||||||
def notify_download(self, ep_name):
|
def notify_download(self, ep_name):
|
||||||
if sickbeard.SLACK_NOTIFY_ONDOWNLOAD:
|
return sickbeard.SLACK_NOTIFY_ONDOWNLOAD and self._notify_str(common.NOTIFY_DOWNLOAD, ep_name)
|
||||||
self._notify(common.notifyStrings[common.NOTIFY_DOWNLOAD] + ': ' + ep_name)
|
|
||||||
|
|
||||||
def test_notify(self, accessToken, channel, as_user, bot_name, icon_url):
|
def notify_subtitle_download(self, ep_name, lang):
|
||||||
return self._notify("This is a test notification from SickGear", accessToken, channel, as_user, bot_name, icon_url, force=True)
|
return sickbeard.SLACK_NOTIFY_ONSUBTITLEDOWNLOAD and \
|
||||||
|
self._notify_str(common.NOTIFY_SUBTITLE_DOWNLOAD, '%s: %s' % (ep_name, lang))
|
||||||
|
|
||||||
|
def notify_git_update(self, new_version='??'):
|
||||||
|
return self._notify_str(common.NOTIFY_GIT_UPDATE_TEXT, new_version)
|
||||||
|
|
||||||
def update_library(self, ep_obj):
|
|
||||||
pass
|
|
||||||
|
|
||||||
notifier = SlackNotifier
|
notifier = SlackNotifier
|
||||||
|
|
|
@ -1150,14 +1150,12 @@ class Home(MainHandler):
|
||||||
|
|
||||||
return notifiers.pushbullet_notifier.get_devices(accessToken)
|
return notifiers.pushbullet_notifier.get_devices(accessToken)
|
||||||
|
|
||||||
def testSlack(self, accessToken=None, channel=None, as_user=False, bot_name=None, icon_url=None):
|
def testSlack(self, access_token=None, channel=None, as_user=False, bot_name=None, icon_url=None):
|
||||||
self.set_header('Cache-Control', 'max-age=0,no-cache,no-store')
|
self.set_header('Cache-Control', 'max-age=0,no-cache,no-store')
|
||||||
|
|
||||||
result = notifiers.slack_notifier.test_notify(accessToken, channel, as_user, bot_name, icon_url)
|
result = notifiers.slack_notifier.test_notify(channel, 'true' == as_user, bot_name, icon_url, access_token)
|
||||||
if result:
|
return ('Error sending notification, Slack response: "%s"' % result,
|
||||||
return "Slack notification succeeded. Check your Slack clients to make sure it worked"
|
'Successful test notice sent. (Note: Slack clients display icon once in a sequence)')[True is result]
|
||||||
else:
|
|
||||||
return "Error sending Slack notification"
|
|
||||||
|
|
||||||
def viewchanges(self):
|
def viewchanges(self):
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue