Replace discord.py with nextcord (#66540)
* Replace discord.py with nextcord * Typing tweak * Another pip check decrease :)
This commit is contained in:
parent
23a22d1860
commit
cb03db8df4
4 changed files with 19 additions and 16 deletions
|
@ -2,7 +2,7 @@
|
||||||
"domain": "discord",
|
"domain": "discord",
|
||||||
"name": "Discord",
|
"name": "Discord",
|
||||||
"documentation": "https://www.home-assistant.io/integrations/discord",
|
"documentation": "https://www.home-assistant.io/integrations/discord",
|
||||||
"requirements": ["discord.py==1.7.3"],
|
"requirements": ["nextcord==2.0.0a8"],
|
||||||
"codeowners": [],
|
"codeowners": [],
|
||||||
"iot_class": "cloud_push",
|
"iot_class": "cloud_push",
|
||||||
"loggers": ["discord"]
|
"loggers": ["discord"]
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
"""Discord platform for notify component."""
|
"""Discord platform for notify component."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import os.path
|
import os.path
|
||||||
|
|
||||||
import discord
|
import nextcord
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.notify import (
|
from homeassistant.components.notify import (
|
||||||
|
@ -48,8 +50,8 @@ class DiscordNotificationService(BaseNotificationService):
|
||||||
|
|
||||||
async def async_send_message(self, message, **kwargs):
|
async def async_send_message(self, message, **kwargs):
|
||||||
"""Login to Discord, send message to channel(s) and log out."""
|
"""Login to Discord, send message to channel(s) and log out."""
|
||||||
discord.VoiceClient.warn_nacl = False
|
nextcord.VoiceClient.warn_nacl = False
|
||||||
discord_bot = discord.Client()
|
discord_bot = nextcord.Client()
|
||||||
images = None
|
images = None
|
||||||
embedding = None
|
embedding = None
|
||||||
|
|
||||||
|
@ -59,13 +61,13 @@ class DiscordNotificationService(BaseNotificationService):
|
||||||
|
|
||||||
data = kwargs.get(ATTR_DATA) or {}
|
data = kwargs.get(ATTR_DATA) or {}
|
||||||
|
|
||||||
embed = None
|
embeds: list[nextcord.Embed] = []
|
||||||
if ATTR_EMBED in data:
|
if ATTR_EMBED in data:
|
||||||
embedding = data[ATTR_EMBED]
|
embedding = data[ATTR_EMBED]
|
||||||
fields = embedding.get(ATTR_EMBED_FIELDS) or []
|
fields = embedding.get(ATTR_EMBED_FIELDS) or []
|
||||||
|
|
||||||
if embedding:
|
if embedding:
|
||||||
embed = discord.Embed(**embedding)
|
embed = nextcord.Embed(**embedding)
|
||||||
for field in fields:
|
for field in fields:
|
||||||
embed.add_field(**field)
|
embed.add_field(**field)
|
||||||
if ATTR_EMBED_FOOTER in embedding:
|
if ATTR_EMBED_FOOTER in embedding:
|
||||||
|
@ -74,11 +76,12 @@ class DiscordNotificationService(BaseNotificationService):
|
||||||
embed.set_author(**embedding[ATTR_EMBED_AUTHOR])
|
embed.set_author(**embedding[ATTR_EMBED_AUTHOR])
|
||||||
if ATTR_EMBED_THUMBNAIL in embedding:
|
if ATTR_EMBED_THUMBNAIL in embedding:
|
||||||
embed.set_thumbnail(**embedding[ATTR_EMBED_THUMBNAIL])
|
embed.set_thumbnail(**embedding[ATTR_EMBED_THUMBNAIL])
|
||||||
|
embeds.append(embed)
|
||||||
|
|
||||||
if ATTR_IMAGES in data:
|
if ATTR_IMAGES in data:
|
||||||
images = []
|
images = []
|
||||||
|
|
||||||
for image in data.get(ATTR_IMAGES):
|
for image in data.get(ATTR_IMAGES, []):
|
||||||
image_exists = await self.hass.async_add_executor_job(
|
image_exists = await self.hass.async_add_executor_job(
|
||||||
self.file_exists, image
|
self.file_exists, image
|
||||||
)
|
)
|
||||||
|
@ -95,15 +98,15 @@ class DiscordNotificationService(BaseNotificationService):
|
||||||
channelid = int(channelid)
|
channelid = int(channelid)
|
||||||
try:
|
try:
|
||||||
channel = await discord_bot.fetch_channel(channelid)
|
channel = await discord_bot.fetch_channel(channelid)
|
||||||
except discord.NotFound:
|
except nextcord.NotFound:
|
||||||
try:
|
try:
|
||||||
channel = await discord_bot.fetch_user(channelid)
|
channel = await discord_bot.fetch_user(channelid)
|
||||||
except discord.NotFound:
|
except nextcord.NotFound:
|
||||||
_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 = [discord.File(image) for image in images] if images else None
|
files = [nextcord.File(image) for image in images] if images else []
|
||||||
await channel.send(message, files=files, embed=embed)
|
await channel.send(message, files=files, embeds=embeds)
|
||||||
except (discord.HTTPException, discord.NotFound) as error:
|
except (nextcord.HTTPException, nextcord.NotFound) as error:
|
||||||
_LOGGER.warning("Communication error: %s", error)
|
_LOGGER.warning("Communication error: %s", error)
|
||||||
await discord_bot.close()
|
await discord_bot.close()
|
||||||
|
|
|
@ -565,9 +565,6 @@ directv==0.4.0
|
||||||
# homeassistant.components.discogs
|
# homeassistant.components.discogs
|
||||||
discogs_client==2.3.0
|
discogs_client==2.3.0
|
||||||
|
|
||||||
# homeassistant.components.discord
|
|
||||||
discord.py==1.7.3
|
|
||||||
|
|
||||||
# homeassistant.components.steamist
|
# homeassistant.components.steamist
|
||||||
discovery30303==0.2.1
|
discovery30303==0.2.1
|
||||||
|
|
||||||
|
@ -1099,6 +1096,9 @@ nexia==0.9.13
|
||||||
# homeassistant.components.nextcloud
|
# homeassistant.components.nextcloud
|
||||||
nextcloudmonitor==1.1.0
|
nextcloudmonitor==1.1.0
|
||||||
|
|
||||||
|
# homeassistant.components.discord
|
||||||
|
nextcord==2.0.0a8
|
||||||
|
|
||||||
# homeassistant.components.niko_home_control
|
# homeassistant.components.niko_home_control
|
||||||
niko-home-control==0.2.1
|
niko-home-control==0.2.1
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ PIP_CACHE=$1
|
||||||
|
|
||||||
# Number of existing dependency conflicts
|
# Number of existing dependency conflicts
|
||||||
# Update if a PR resolve one!
|
# Update if a PR resolve one!
|
||||||
DEPENDENCY_CONFLICTS=10
|
DEPENDENCY_CONFLICTS=9
|
||||||
|
|
||||||
PIP_CHECK=$(pip check --cache-dir=$PIP_CACHE)
|
PIP_CHECK=$(pip check --cache-dir=$PIP_CACHE)
|
||||||
LINE_COUNT=$(echo "$PIP_CHECK" | wc -l)
|
LINE_COUNT=$(echo "$PIP_CHECK" | wc -l)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue