mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-23 19:44:20 +00:00
Fix discord sync
This commit is contained in:
parent
9a529a572d
commit
096d8a18c4
2 changed files with 11 additions and 12 deletions
|
@ -69,12 +69,13 @@ class RoyalnetsyncCommand(rc.Command):
|
||||||
)
|
)
|
||||||
if ds_user is None:
|
if ds_user is None:
|
||||||
# Create
|
# Create
|
||||||
|
# noinspection PyProtectedMember
|
||||||
ds_user = DiscordT(
|
ds_user = DiscordT(
|
||||||
user=user,
|
user=user,
|
||||||
discord_id=ds_author.id,
|
discord_id=ds_author.id,
|
||||||
username=ds_author.name,
|
username=ds_author.name,
|
||||||
discriminator=ds_author.discriminator,
|
discriminator=ds_author.discriminator,
|
||||||
avatar_url=ds_author.avatar_url
|
avatar_url=ds_author.avatar_url._url
|
||||||
)
|
)
|
||||||
session.add(ds_user)
|
session.add(ds_user)
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -93,40 +93,38 @@ class DiscordSerf(Serf):
|
||||||
text = message.content
|
text = message.content
|
||||||
# Skip non-text messages
|
# Skip non-text messages
|
||||||
if not text:
|
if not text:
|
||||||
|
log.debug("Skipping message as it had no text")
|
||||||
return
|
return
|
||||||
# Skip non-command updates
|
# Skip non-command updates
|
||||||
if not text.startswith("!"):
|
if not text.startswith(self.prefix):
|
||||||
|
log.debug(f"Skipping message as it didn't start with {self.prefix}")
|
||||||
return
|
return
|
||||||
# Skip bot messages
|
# Skip bot messages
|
||||||
author: Union["discord.User", "discord.Member"] = message.author
|
author: Union["discord.User", "discord.Member"] = message.author
|
||||||
if author.bot:
|
if author.bot:
|
||||||
|
log.debug(f"Skipping message as it was from another bot")
|
||||||
return
|
return
|
||||||
# Find and clean parameters
|
# Find and clean parameters
|
||||||
command_text, *parameters = text.split(" ")
|
command_text, *parameters = text.split(" ")
|
||||||
# Don't use a case-sensitive command name
|
# Don't use a case-sensitive command name
|
||||||
command_name = command_text.lower()
|
command_name = command_text.lstrip(self.prefix).lower()
|
||||||
|
log.debug(f"Parsed '{command_name}' as command name")
|
||||||
# Find the command
|
# Find the command
|
||||||
try:
|
try:
|
||||||
command = self.commands[command_name]
|
command = self.commands[command_name]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
# Skip the message
|
# Skip the message
|
||||||
|
log.debug(f"Skipping message as I could not find the command {command_name}")
|
||||||
return
|
return
|
||||||
# Call the command
|
# Call the command
|
||||||
log.debug(f"Calling command '{command.name}'")
|
log.debug(f"Sending typing notification")
|
||||||
with message.channel.typing():
|
with message.channel.typing():
|
||||||
# Open an alchemy session, if available
|
|
||||||
if self.alchemy is not None:
|
|
||||||
session = await asyncify(self.alchemy.Session)
|
|
||||||
else:
|
|
||||||
session = None
|
|
||||||
# Prepare data
|
# Prepare data
|
||||||
# noinspection PyArgumentList
|
# noinspection PyArgumentList
|
||||||
data = self.Data(command=command, message=message)
|
data = self.Data(command=command, message=message)
|
||||||
# Call the command
|
# Call the command
|
||||||
|
log.debug(f"Calling {command}")
|
||||||
await self.call(command, data, parameters)
|
await self.call(command, data, parameters)
|
||||||
# Close the alchemy session
|
|
||||||
if session is not None:
|
|
||||||
await asyncify(session.close)
|
|
||||||
|
|
||||||
def client_factory(self) -> Type["discord.Client"]:
|
def client_factory(self) -> Type["discord.Client"]:
|
||||||
"""Create a custom class inheriting from :py:class:`discord.Client`."""
|
"""Create a custom class inheriting from :py:class:`discord.Client`."""
|
||||||
|
|
Loading…
Reference in a new issue