mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 18:57:06 +00:00
Add Direct Message support for Discord integration (#33692)
* Update notify.py * Update notify.py * Update notify.py Added a comment * Update notify.py * Update notify.py * Update notify.py * Update notify.py * Update notify.py
This commit is contained in:
parent
32499dc8fe
commit
c651ce06c5
@ -39,7 +39,6 @@ class DiscordNotificationService(BaseNotificationService):
|
|||||||
"""Check if a file exists on disk and is in authorized path."""
|
"""Check if a file exists on disk and is in authorized path."""
|
||||||
if not self.hass.config.is_allowed_path(filename):
|
if not self.hass.config.is_allowed_path(filename):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return os.path.isfile(filename)
|
return os.path.isfile(filename)
|
||||||
|
|
||||||
async def async_send_message(self, message, **kwargs):
|
async def async_send_message(self, message, **kwargs):
|
||||||
@ -52,7 +51,6 @@ class DiscordNotificationService(BaseNotificationService):
|
|||||||
if ATTR_TARGET not in kwargs:
|
if ATTR_TARGET not in kwargs:
|
||||||
_LOGGER.error("No target specified")
|
_LOGGER.error("No target specified")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
data = kwargs.get(ATTR_DATA) or {}
|
data = kwargs.get(ATTR_DATA) or {}
|
||||||
|
|
||||||
if ATTR_IMAGES in data:
|
if ATTR_IMAGES in data:
|
||||||
@ -67,7 +65,6 @@ class DiscordNotificationService(BaseNotificationService):
|
|||||||
images.append(image)
|
images.append(image)
|
||||||
else:
|
else:
|
||||||
_LOGGER.warning("Image not found: %s", image)
|
_LOGGER.warning("Image not found: %s", image)
|
||||||
|
|
||||||
# pylint: disable=unused-variable
|
# pylint: disable=unused-variable
|
||||||
@discord_bot.event
|
@discord_bot.event
|
||||||
async def on_ready():
|
async def on_ready():
|
||||||
@ -75,19 +72,19 @@ class DiscordNotificationService(BaseNotificationService):
|
|||||||
try:
|
try:
|
||||||
for channelid in kwargs[ATTR_TARGET]:
|
for channelid in kwargs[ATTR_TARGET]:
|
||||||
channelid = int(channelid)
|
channelid = int(channelid)
|
||||||
channel = discord_bot.get_channel(channelid)
|
channel = discord_bot.get_channel(
|
||||||
|
channelid
|
||||||
|
) or discord_bot.get_user(channelid)
|
||||||
|
|
||||||
if channel is None:
|
if channel is None:
|
||||||
_LOGGER.warning("Channel not found for id: %s", channelid)
|
_LOGGER.warning("Channel not found for id: %s", channelid)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Must create new instances of File for each channel.
|
# Must create new instances of File for each channel.
|
||||||
files = None
|
files = None
|
||||||
if images:
|
if images:
|
||||||
files = []
|
files = []
|
||||||
for image in images:
|
for image in images:
|
||||||
files.append(discord.File(image))
|
files.append(discord.File(image))
|
||||||
|
|
||||||
await channel.send(message, files=files)
|
await channel.send(message, files=files)
|
||||||
except (discord.errors.HTTPException, discord.errors.NotFound) as error:
|
except (discord.errors.HTTPException, discord.errors.NotFound) as error:
|
||||||
_LOGGER.warning("Communication error: %s", error)
|
_LOGGER.warning("Communication error: %s", error)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user