Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to override avatar #10351

Merged
merged 3 commits into from
Feb 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions medusa/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,7 @@ def initialize(self, console_logging=True):
check_setting_int(app.CFG, 'Discord', 'discord_notify_onsubtitledownload', 0))
app.DISCORD_WEBHOOK = check_setting_str(app.CFG, 'Discord', 'discord_webhook', '', censor_log='normal')
app.DISCORD_TTS = check_setting_bool(app.CFG, 'Discord', 'discord_tts', 0)
app.DISCORD_OVERRIDE_AVATAR = check_setting_bool(app.CFG, 'Discord', 'override_avatar', 0)
app.DISCORD_NAME = check_setting_str(app.CFG, 'Discord', 'discord_name', '', censor_log='normal')

app.USE_PROWL = bool(check_setting_int(app.CFG, 'Prowl', 'use_prowl', 0))
Expand Down Expand Up @@ -1907,6 +1908,7 @@ def save_config():
new_config['Discord']['discord_notify_onsubtitledownload'] = int(app.DISCORD_NOTIFY_ONSUBTITLEDOWNLOAD)
new_config['Discord']['discord_webhook'] = app.DISCORD_WEBHOOK
new_config['Discord']['discord_tts'] = int(app.DISCORD_TTS)
new_config['Discord']['override_avatar'] = int(app.DISCORD_OVERRIDE_AVATAR)
new_config['Discord']['discord_name'] = app.DISCORD_NAME

new_config['Prowl'] = {}
Expand Down
1 change: 1 addition & 0 deletions medusa/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ def __init__(self):
self.DISCORD_NAME = 'pymedusa'
self.DISCORD_AVATAR_URL = '{base_url}/images/ico/favicon-144.png'.format(base_url=self.BASE_PYMEDUSA_URL)
self.DISCORD_TTS = False
self.DISCORD_OVERRIDE_AVATAR = False

self.USE_PROWL = False
self.PROWL_NOTIFY_ONSNATCH = False
Expand Down
18 changes: 12 additions & 6 deletions medusa/notifiers/discord.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ class Notifier(object):
https://discordapp.com
"""

def _send_discord_msg(self, title, msg, webhook=None, tts=False):
def _send_discord_msg(self, title, msg, webhook=None, tts=None, override_avatar=None):
"""Collect the parameters and send the message to the discord webhook."""
webhook = app.DISCORD_WEBHOOK if webhook is None else webhook
tts = app.DISCORD_TTS if tts is None else tts
override_avatar = app.DISCORD_OVERRIDE_AVATAR if override_avatar is None else override_avatar

log.debug('Discord in use with API webhook: {webhook}', {'webhook': webhook})

Expand All @@ -46,10 +47,12 @@ def _send_discord_msg(self, title, msg, webhook=None, tts=False):
payload = {
'content': message,
'username': app.DISCORD_NAME,
'avatar_url': app.DISCORD_AVATAR_URL,
'tts': tts
}

if override_avatar:
payload['avatar_url'] = app.DISCORD_AVATAR_URL

success = False
try:
r = requests.post(webhook, json=payload, headers=headers)
Expand Down Expand Up @@ -128,13 +131,16 @@ def notify_login(self, ipaddress=''):
title = notifyStrings[NOTIFY_LOGIN]
self._notify_discord(title, update_text.format(ipaddress))

def test_notify(self, discord_webhook=None, discord_tts=None):
def test_notify(self, discord_webhook=None, discord_tts=None, override_avatar=None):
"""Create the test notification."""
return self._notify_discord('test', 'This is a test notification from Medusa', webhook=discord_webhook, tts=discord_tts, force=True)
return self._notify_discord(
'test', 'This is a test notification from Medusa',
webhook=discord_webhook, tts=discord_tts, override_avatar=override_avatar, force=True
)

def _notify_discord(self, title='', message='', webhook=None, tts=False, force=False):
def _notify_discord(self, title='', message='', webhook=None, tts=None, override_avatar=None, force=False):
"""Validate if USE_DISCORD or Force is enabled and send."""
if not app.USE_DISCORD and not force:
return False

return self._send_discord_msg(title, message, webhook, tts)
return self._send_discord_msg(title, message, webhook, tts, override_avatar)
2 changes: 2 additions & 0 deletions medusa/server/api/v2/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ class ConfigHandler(BaseRequestHandler):
'notifiers.discord.enabled': BooleanField(app, 'USE_DISCORD'),
'notifiers.discord.webhook': StringField(app, 'DISCORD_WEBHOOK'),
'notifiers.discord.tts': BooleanField(app, 'DISCORD_TTS'),
'notifiers.discord.overrideAvatar': BooleanField(app, 'DISCORD_OVERRIDE_AVATAR'),
'notifiers.discord.notifyOnSnatch': BooleanField(app, 'DISCORD_NOTIFY_ONSNATCH'),
'notifiers.discord.notifyOnDownload': BooleanField(app, 'DISCORD_NOTIFY_ONDOWNLOAD'),
'notifiers.discord.notifyOnSubtitleDownload': BooleanField(app, 'DISCORD_NOTIFY_ONSUBTITLEDOWNLOAD'),
Expand Down Expand Up @@ -1054,6 +1055,7 @@ def data_notifiers():
section_data['discord']['notifyOnSubtitleDownload'] = bool(app.DISCORD_NOTIFY_ONSUBTITLEDOWNLOAD)
section_data['discord']['webhook'] = app.DISCORD_WEBHOOK
section_data['discord']['tts'] = bool(app.DISCORD_TTS)
section_data['discord']['overrideAvatar'] = bool(app.DISCORD_OVERRIDE_AVATAR)
section_data['discord']['name'] = app.DISCORD_NAME

section_data['twitter'] = {}
Expand Down
6 changes: 4 additions & 2 deletions medusa/server/web/home/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,10 @@ def testTelegram(telegram_id=None, telegram_apikey=None):
return 'Error sending Telegram notification: {msg}'.format(msg=message)

@staticmethod
def testDiscord(discord_webhook=None, discord_tts=False):
result, message = notifiers.discord_notifier.test_notify(discord_webhook, config.checkbox_to_value(discord_tts))
def testDiscord(discord_webhook=None, discord_tts=None, discord_override_avatar=None):
result, message = notifiers.discord_notifier.test_notify(
discord_webhook, config.checkbox_to_value(discord_tts), config.checkbox_to_value(discord_override_avatar)
)
if result:
return 'Discord notification succeeded. Check your Discord channels to make sure it worked'
else:
Expand Down
7 changes: 6 additions & 1 deletion tests/apiv2/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ def config_postprocessing():
section_data['naming']['animeNamingType'] = int_default(app.NAMING_ANIME, 3)
section_data['naming']['stripYear'] = bool(app.NAMING_STRIP_YEAR)
section_data['showDownloadDir'] = app.TV_DOWNLOAD_DIR
section_data['defaultClientPath'] = app.DEFAULT_CLIENT_PATH
section_data['processAutomatically'] = bool(app.PROCESS_AUTOMATICALLY)
section_data['postponeIfSyncFiles'] = bool(app.POSTPONE_IF_SYNC_FILES)
section_data['postponeIfNoSubs'] = bool(app.POSTPONE_IF_NO_SUBS)
Expand All @@ -432,6 +433,9 @@ def config_postprocessing():
section_data['deleteRarContent'] = bool(app.DELRARCONTENTS)
section_data['noDelete'] = bool(app.NO_DELETE)
section_data['processMethod'] = app.PROCESS_METHOD
section_data['specificProcessMethod'] = bool(app.USE_SPECIFIC_PROCESS_METHOD)
section_data['processMethodTorrent'] = app.PROCESS_METHOD_TORRENT
section_data['processMethodNzb'] = app.PROCESS_METHOD_NZB
section_data['reflinkAvailable'] = bool(pkgutil.find_loader('reflink'))
section_data['autoPostprocessorFrequency'] = int(app.AUTOPOSTPROCESSOR_FREQUENCY)
section_data['syncFiles'] = app.SYNC_FILES
Expand Down Expand Up @@ -695,6 +699,7 @@ def config_notifiers():
section_data['discord']['notifyOnSubtitleDownload'] = bool(app.DISCORD_NOTIFY_ONSUBTITLEDOWNLOAD)
section_data['discord']['webhook'] = app.DISCORD_WEBHOOK
section_data['discord']['tts'] = bool(app.DISCORD_TTS)
section_data['discord']['overrideAvatar'] = bool(app.DISCORD_OVERRIDE_AVATAR)
section_data['discord']['name'] = app.DISCORD_NAME

section_data['twitter'] = {}
Expand Down Expand Up @@ -910,7 +915,7 @@ def config_subtitles():


@pytest.mark.gen_test
async def test_config_get_postprocessing(http_client, create_url, auth_headers, config_subtitles):
async def test_config_get_subtitles(http_client, create_url, auth_headers, config_subtitles):
# given
expected = config_subtitles

Expand Down
4 changes: 3 additions & 1 deletion themes-default/slim/src/components/config-notifications.vue
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,7 @@
<config-toggle-slider v-model="notifiers.discord.notifyOnSubtitleDownload" label="Notify on subtitle download" id="discord_notify_onsubtitledownload" :explanations="['send a message when subtitles are downloaded?']" @change="save()" />
<config-textbox v-model="notifiers.discord.webhook" label="Channel webhook" id="discord_webhook" :explanations="['Add a webhook to a channel, use the returned url here']" @change="save()" />
<config-toggle-slider v-model="notifiers.discord.tts" label="Text to speech" id="discord_tts" :explanations="['Use discord text to speech feature']" @change="save()" />
<config-toggle-slider v-model="notifiers.discord.overrideAvatar" label="Override webhook avatar" id="override_avatar" :explanations="['Override Discords default avatar with a Medusa icon']" @change="save()" />
<config-textbox v-model="notifiers.discord.name" label="Bot username" id="discord_name" :explanations="['Create a username for the Discord Bot to use']" @change="save()" />

<div class="testNotification" id="testDiscord-result">Click below to test your settings.</div>
Expand Down Expand Up @@ -1603,7 +1604,8 @@ export default {
$('#testDiscord-result').html(MEDUSA.config.layout.loading);
$.get('home/testDiscord', {
discord_webhook: notifiers.discord.webhook, // eslint-disable-line camelcase
discord_tts: notifiers.discord.tts // eslint-disable-line camelcase
discord_tts: notifiers.discord.tts, // eslint-disable-line camelcase
discord_override_avatar: notifiers.discord.overrideAvatar // eslint-disable-line camelcase
}).done(data => {
$('#testDiscord-result').html(data);
$('#testDiscord').prop('disabled', false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ export const state = {
notifyOnDownload: null,
notifyOnSubtitleDownload: null,
webhook: null,
tts: null
tts: null,
overrideAvatar: null
};

export const mutations = {};
Expand Down
6 changes: 3 additions & 3 deletions themes/dark/assets/js/medusa-runtime.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions themes/light/assets/js/medusa-runtime.js

Large diffs are not rendered by default.