You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
87 lines
2.9 KiB
87 lines
2.9 KiB
8 years ago
|
from couchpotato.core.logger import CPLog
|
||
|
from couchpotato.core.notifications.base import Notification
|
||
|
import json
|
||
|
import requests
|
||
|
|
||
|
log = CPLog(__name__)
|
||
|
autoload = 'Discord'
|
||
|
|
||
|
|
||
|
class Discord(Notification):
|
||
|
required_confs = ('webhook_url',)
|
||
|
|
||
|
def notify(self, message='', data=None, listener=None):
|
||
|
for key in self.required_confs:
|
||
|
if not self.conf(key):
|
||
|
log.warning('Discord 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)
|
||
|
|
||
|
headers = {b"Content-Type": b"application/json"}
|
||
|
try:
|
||
|
r = requests.post(self.conf('webhook_url'), data=json.dumps(dict(content=message, username=self.conf('bot_name'), avatar_url=self.conf('avatar_url'))), headers=headers)
|
||
|
r.status_code
|
||
|
except Exception as e:
|
||
|
log.warning('Error Sending Discord response error code: {0}'.format(r.status_code))
|
||
|
return False
|
||
|
return True
|
||
|
|
||
|
|
||
|
config = [{
|
||
|
'name': 'discord',
|
||
|
'groups': [
|
||
|
{
|
||
|
'tab': 'notifications',
|
||
|
'list': 'notification_providers',
|
||
|
'name': 'discord',
|
||
|
'options': [
|
||
|
{
|
||
|
'name': 'enabled',
|
||
|
'default': 0,
|
||
|
'type': 'enabler',
|
||
|
},
|
||
|
{
|
||
|
'name': 'webhook_url',
|
||
|
'description': (
|
||
|
'Your Discord authentication webhook URL.',
|
||
|
'Created under channel settings.'
|
||
|
)
|
||
|
},
|
||
|
{
|
||
|
'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': 'avatar_url',
|
||
|
'description': 'URL to an image to use as the avatar for '
|
||
|
'notifications.',
|
||
|
'default': 'https://couchpota.to/media/images/couch.png',
|
||
|
'advanced': True,
|
||
|
},
|
||
|
{
|
||
|
'name': 'on_snatch',
|
||
|
'default': 0,
|
||
|
'type': 'bool',
|
||
|
'advanced': True,
|
||
|
'description': 'Also send message when movie is snatched.',
|
||
|
},
|
||
|
],
|
||
|
}
|
||
|
],
|
||
|
}]
|