mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-23 19:44:20 +00:00
Fix more summon bugs
This commit is contained in:
parent
2a8a9de832
commit
47a45a2552
5 changed files with 24 additions and 15 deletions
|
@ -58,7 +58,15 @@ class DiscordBot:
|
||||||
elif len(matching_channels) > 1:
|
elif len(matching_channels) > 1:
|
||||||
return SummonError("Multiple channels with a matching name found")
|
return SummonError("Multiple channels with a matching name found")
|
||||||
matching_channel = matching_channels[0]
|
matching_channel = matching_channels[0]
|
||||||
await matching_channel.connect()
|
try:
|
||||||
|
await matching_channel.connect()
|
||||||
|
except discord.errors.ClientException:
|
||||||
|
# Move to the selected channel, instead of connecting
|
||||||
|
for voice_client in self.bot.voice_clients:
|
||||||
|
voice_client: discord.VoiceClient
|
||||||
|
if voice_client.guild != matching_channel.guild:
|
||||||
|
continue
|
||||||
|
await voice_client.move_to(matching_channel)
|
||||||
return SummonSuccessful()
|
return SummonSuccessful()
|
||||||
|
|
||||||
self.network: RoyalnetLink = RoyalnetLink(master_server_uri, master_server_secret, "discord", network_handler)
|
self.network: RoyalnetLink = RoyalnetLink(master_server_uri, master_server_secret, "discord", network_handler)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import typing
|
import typing
|
||||||
from ..utils import Command, Call
|
from ..utils import Command, Call
|
||||||
from ..network import Message, ErrorMessage
|
from ..network import Message
|
||||||
|
|
||||||
|
|
||||||
class SummonMessage(Message):
|
class SummonMessage(Message):
|
||||||
|
@ -12,8 +12,9 @@ class SummonSuccessful(Message):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class SummonError(ErrorMessage):
|
class SummonError(Message):
|
||||||
pass
|
def __init__(self, reason: str):
|
||||||
|
self.reason: str = reason
|
||||||
|
|
||||||
|
|
||||||
class SummonCommand(Command):
|
class SummonCommand(Command):
|
||||||
|
@ -32,4 +33,4 @@ class SummonCommand(Command):
|
||||||
elif isinstance(response, SummonSuccessful):
|
elif isinstance(response, SummonSuccessful):
|
||||||
await call.reply(f"✅ Mi sono connesso in [c]#{channel_name}[/c].")
|
await call.reply(f"✅ Mi sono connesso in [c]#{channel_name}[/c].")
|
||||||
return
|
return
|
||||||
raise Exception(f"wtf is this: {response}")
|
raise TypeError(f"Received unexpected response type while summoning the bot: {response.__class__.__name__}")
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
from .messages import Message, ErrorMessage, InvalidSecretEM, InvalidDestinationEM, InvalidPackageEM
|
from .messages import Message, ServerErrorMessage, InvalidSecretEM, InvalidDestinationEM, InvalidPackageEM
|
||||||
from .packages import Package
|
from .packages import Package
|
||||||
from .royalnetlink import RoyalnetLink, NetworkError, NotConnectedError, NotIdentifiedError
|
from .royalnetlink import RoyalnetLink, NetworkError, NotConnectedError, NotIdentifiedError
|
||||||
from .royalnetserver import RoyalnetServer
|
from .royalnetserver import RoyalnetServer
|
||||||
|
|
||||||
__all__ = ["Message",
|
__all__ = ["Message",
|
||||||
"ErrorMessage",
|
"ServerErrorMessage",
|
||||||
"InvalidSecretEM",
|
"InvalidSecretEM",
|
||||||
"InvalidDestinationEM",
|
"InvalidDestinationEM",
|
||||||
"InvalidPackageEM",
|
"InvalidPackageEM",
|
||||||
|
|
|
@ -7,17 +7,17 @@ class IdentifySuccessfulMessage(Message):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class ErrorMessage(Message):
|
class ServerErrorMessage(Message):
|
||||||
def __init__(self, reason):
|
def __init__(self, reason):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.reason = reason
|
self.reason = reason
|
||||||
|
|
||||||
|
|
||||||
class InvalidSecretEM(ErrorMessage):
|
class InvalidSecretEM(ServerErrorMessage):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class InvalidPackageEM(ErrorMessage):
|
class InvalidPackageEM(ServerErrorMessage):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ import functools
|
||||||
import typing
|
import typing
|
||||||
import pickle
|
import pickle
|
||||||
import logging as _logging
|
import logging as _logging
|
||||||
from .messages import Message, ErrorMessage
|
from .messages import Message, ServerErrorMessage
|
||||||
from .packages import Package
|
from .packages import Package
|
||||||
|
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
|
@ -21,9 +21,9 @@ class NotIdentifiedError(Exception):
|
||||||
|
|
||||||
|
|
||||||
class NetworkError(Exception):
|
class NetworkError(Exception):
|
||||||
def __init__(self, error_msg: ErrorMessage, *args):
|
def __init__(self, error_msg: ServerErrorMessage, *args):
|
||||||
super().__init__(*args)
|
super().__init__(*args)
|
||||||
self.error_msg: ErrorMessage = error_msg
|
self.error_msg: ServerErrorMessage = error_msg
|
||||||
|
|
||||||
|
|
||||||
class PendingRequest:
|
class PendingRequest:
|
||||||
|
@ -98,7 +98,7 @@ class RoyalnetLink:
|
||||||
await self.websocket.send(f"Identify {self.nid}:{self.link_type}:{self.secret}")
|
await self.websocket.send(f"Identify {self.nid}:{self.link_type}:{self.secret}")
|
||||||
response_package = await self.receive()
|
response_package = await self.receive()
|
||||||
response = response_package.data
|
response = response_package.data
|
||||||
if isinstance(response, ErrorMessage):
|
if isinstance(response, ServerErrorMessage):
|
||||||
raise NetworkError(response, "Server returned error while identifying self")
|
raise NetworkError(response, "Server returned error while identifying self")
|
||||||
self.identify_event.set()
|
self.identify_event.set()
|
||||||
log.info(f"Identified successfully!")
|
log.info(f"Identified successfully!")
|
||||||
|
@ -119,7 +119,7 @@ class RoyalnetLink:
|
||||||
await request.event.wait()
|
await request.event.wait()
|
||||||
result: Message = request.data
|
result: Message = request.data
|
||||||
log.debug(f"Received response: {request} -> {result}")
|
log.debug(f"Received response: {request} -> {result}")
|
||||||
if isinstance(result, ErrorMessage):
|
if isinstance(result, ServerErrorMessage):
|
||||||
raise NetworkError(result, "Server returned error while requesting something")
|
raise NetworkError(result, "Server returned error while requesting something")
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue