Skip to content

Commit

Permalink
nextcord.py: more fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
gbionescu committed Dec 17, 2023
1 parent b087897 commit 270dc72
Showing 1 changed file with 31 additions and 7 deletions.
38 changes: 31 additions & 7 deletions spanky/inputs/nextcord.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ def get_channel(self, target, server=None):
In case server=None, target = -1 and we are in a PM, we will return the PM channel
"""

if server is None and target == -1 and hasattr(self, "is_pm") and self.is_pm:
if server is None and target in [-1, None] and hasattr(self, "is_pm") and self.is_pm:
return self.channel._raw

if server:
Expand Down Expand Up @@ -425,6 +425,7 @@ async def async_send_message(
check_old=True,
allowed_mentions=allowed_mentions,
ephemeral=False, # EventSlash only, no effect in other event types
reply_to=None,
):
func_send_message = None
channel = None
Expand Down Expand Up @@ -489,9 +490,13 @@ async def send(*args, **kwargs):
)
return Message(old_reply._raw)

reference = None
if reply_to is not None:
reference = reply_to._raw

msg = None
reply = await func_send_message(
content=text, embed=embed, allowed_mentions=allowed_mentions
content=text, embed=embed, allowed_mentions=allowed_mentions, reference=reference
)
if type(self) is EventSlash:
msg = SlashMessage(self._raw, timeout)
Expand Down Expand Up @@ -521,6 +526,7 @@ def send_message(
check_old=True,
allowed_mentions=allowed_mentions,
ephemeral=False, # EventSlash only, no effect in other event types
reply_to=None,
):
asyncio.run_coroutine_threadsafe(
self.async_send_message(
Expand All @@ -531,6 +537,7 @@ def send_message(
check_old=check_old,
allowed_mentions=allowed_mentions,
ephemeral=ephemeral,
reply_to=reply_to,
),
bot.loop,
)
Expand Down Expand Up @@ -562,6 +569,9 @@ def send_embed(
)

def reply(self, text, **kwargs):
if not hasattr(self, "author"):
self.send_message("(unknown) " + text, **kwargs)
return
self.send_message("(%s) %s" % (self.author.name, text), **kwargs)

def send_file(self, file_path, target=-1, server=None):
Expand Down Expand Up @@ -617,7 +627,12 @@ class EventReact(DiscordUtils):
def __init__(self, event_type, user, reaction):
self.type = event_type
self.author = User(user)
self.server = Server(user.guild)
server = getattr(user, "guild", None)
if server:
self.server = Server(server)
else:
self.server = None

self.msg = Message(reaction.message)
self.channel = Channel(reaction.message.channel)
self.source = self.channel
Expand Down Expand Up @@ -918,6 +933,15 @@ async def delete_message(message):
async def clear_reactions(self):
await self._raw.clear_reactions()

async def async_edit_message(self, text=None, embed=None):
if not text and not embed:
return

if text:
await self._raw.edit(content=text)
elif embed:
await self._raw.edit(embed=embed)


class User:
def __init__(self, obj: nextcord.User | nextcord.Member):
Expand All @@ -927,10 +951,10 @@ def __init__(self, obj: nextcord.User | nextcord.Member):
self.bot = obj.bot

try:
self.avatar_url = obj.avatar.url
except:
# TODO
pass
if obj.avatar:
self.avatar_url = obj.avatar.url
except Exception as e:
print(e)

self.roles: list["Role"] = []
if hasattr(obj, "roles"):
Expand Down

0 comments on commit 270dc72

Please sign in to comment.