diff --git a/royalpack/commands/__init__.py b/royalpack/commands/__init__.py index a48a5292..73d1ad3c 100644 --- a/royalpack/commands/__init__.py +++ b/royalpack/commands/__init__.py @@ -22,7 +22,7 @@ from .help import HelpCommand from .leagueoflegends import LeagueoflegendsCommand from .magickfiorygi import MagickfiorygiCommand from .magicktreasure import MagicktreasureCommand -# from .matchmaking import MatchmakingCommand +from .matchmaking import MatchmakingCommand from .ping import PingCommand from .pmots import PmotsCommand from .dog import DogCommand @@ -63,7 +63,7 @@ available_commands = [ LeagueoflegendsCommand, MagickfiorygiCommand, MagicktreasureCommand, - # MatchmakingCommand, + MatchmakingCommand, PingCommand, PmotsCommand, DogCommand, diff --git a/royalpack/commands/matchmaking.py b/royalpack/commands/matchmaking.py index 53f9fcb6..b4b8fbd3 100644 --- a/royalpack/commands/matchmaking.py +++ b/royalpack/commands/matchmaking.py @@ -70,13 +70,14 @@ class MatchmakingCommand(rc.Command): async def run(self, args: rc.CommandArgs, data: rc.CommandData) -> None: """Handle a matchmaking command call.""" - author = await data.get_author(error_if_none=True) # Parse the arguments, either with the standard syntax or with the Proto syntax dt, title, description = self._parse_args(args) # Add the MMEvent to the database async with data.session_acm() as session: + author = await data.find_author(session=session, required=True) + mmevent: MMEvent = self.alchemy.get(MMEvent)(creator=author, datetime=dt, title=title, @@ -85,8 +86,8 @@ class MatchmakingCommand(rc.Command): session.add(mmevent) await ru.asyncify(session.commit) - # Create and run a task for the newly created MMEvent - task = MMTask(mmevent.mmid, command=self) - task.start() + # Create and run a task for the newly created MMEvent + task = MMTask(mmevent.mmid, command=self) + task.start() await data.reply(f"🚩 Matchmaking creato!") diff --git a/royalpack/events/discord_cv.py b/royalpack/events/discord_cv.py index d71c3b0f..1f3bcfa0 100644 --- a/royalpack/events/discord_cv.py +++ b/royalpack/events/discord_cv.py @@ -28,7 +28,6 @@ class DiscordCvEvent(rc.HeraldEvent): guild: discord.Guild = client.get_guild(guild_id) members: List[Union[discord.User, discord.Member]] = guild.members - channels: List[discord.VoiceChannel] = guild.voice_channels results = [] @@ -88,6 +87,5 @@ class DiscordCvEvent(rc.HeraldEvent): "id": guild.id, "name": guild.name, "members": results, - "channels": channels, } } diff --git a/royalpack/utils/__init__.py b/royalpack/utils/__init__.py index 6604ef62..1ef17ba0 100644 --- a/royalpack/utils/__init__.py +++ b/royalpack/utils/__init__.py @@ -1,5 +1,5 @@ -# from .mmtask import MMTask +from .mmtask import MMTask __all__ = [ - # "MMTask", + "MMTask", ] diff --git a/royalpack/utils/mmtask.py b/royalpack/utils/mmtask.py index b00dc5c1..4295100e 100644 --- a/royalpack/utils/mmtask.py +++ b/royalpack/utils/mmtask.py @@ -310,14 +310,17 @@ class MMTask: return InKM(rows) def register_telegram_keyboard(self, inkm: InKM): - # noinspection PyListCreation + assert isinstance(self.command.serf, rst.TelegramSerf) royalnet_keyboard = self.royalnet_keyboard for x, row in enumerate(inkm.inline_keyboard): for y, key in enumerate(row): key: InKB - self.command.serf.register_keyboard_key(key.callback_data, key=royalnet_keyboard[x][y]) + self.command.serf.register_keyboard_key(key.callback_data, + key=royalnet_keyboard[x][y], + command=self.command) def unregister_telegram_keyboard(self, inkm: InKM): + assert isinstance(self.command.serf, rst.TelegramSerf) for row in inkm.inline_keyboard: for key in row: key: InKB @@ -332,14 +335,15 @@ class MMTask: @property def telegram_channel_id(self): - return self.command.config["Matchmaking"]["mm_telegram_channel_id"] + return self.command.config["matchmaking"]["channel_id"] @property def telegram_group_id(self): - return self.command.config["Matchmaking"]["mm_telegram_group_id"] + return self.command.config["matchmaking"]["group_id"] @contextlib.asynccontextmanager async def telegram_channel_message(self): + assert isinstance(self.command.serf, rst.TelegramSerf) # Generate the InlineKeyboardMarkup inkm = self.telegram_keyboard @@ -385,6 +389,9 @@ class MMTask: async def telegram_channel_message_update(self): log.debug(f"Updating message for: {self.mmid}") + + assert isinstance(self.command.serf, rst.TelegramSerf) + try: await ru.asyncify( self.command.serf.client.edit_message_text, @@ -399,6 +406,8 @@ class MMTask: log.warning(f"TelegramError during update: {e}") async def telegram_group_message_start(self): + assert isinstance(self.command.serf, rst.TelegramSerf) + await self.command.serf.api_call( self.command.serf.client.send_message, chat_id=self.telegram_group_id, @@ -408,6 +417,8 @@ class MMTask: ) async def telegram_group_message_delete(self): + assert isinstance(self.command.serf, rst.TelegramSerf) + await self.command.serf.api_call( self.command.serf.client.send_message, chat_id=self.telegram_group_id,