From 185866b7213653cb8bc8df9493dc722e0926dd33 Mon Sep 17 00:00:00 2001 From: Alexander Terry Date: Sat, 8 Jun 2024 12:59:50 -0800 Subject: [PATCH] add more logging --- alexBot/cogs/smartHome.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/alexBot/cogs/smartHome.py b/alexBot/cogs/smartHome.py index 009c1ac..95c4d41 100644 --- a/alexBot/cogs/smartHome.py +++ b/alexBot/cogs/smartHome.py @@ -11,9 +11,11 @@ from aiomqtt.types import PayloadType from discord.ext import tasks + from ..tools import Cog, get_json, render_voiceState if TYPE_CHECKING: + from alexBot.cogs.voicePrivVC import VoicePrivVC from alexBot.cogs.mqttDispatcher import HomeAssistantIntigreation from bot import Bot @@ -115,6 +117,8 @@ async def on_ha_vc_control(self, userId: int, command: str): return member = targets[0].get_member(user.id) + assert member + assert member.voice try: if command == 'mute': await member.edit(mute=not member.voice.mute) @@ -127,7 +131,7 @@ async def on_ha_vc_control(self, userId: int, command: str): return async def update_mqtt_state(self, member: discord.Member, after: discord.VoiceState): - mqtt: HomeAssistantIntigreation = self.bot.get_cog("HomeAssistantIntigreation") + mqtt: HomeAssistantIntigreation = self.bot.get_cog("HomeAssistantIntigreation") # type: ignore jsonblob = {"state_str": render_voiceState(member)} for key in ['self_deaf', 'self_mute', 'self_stream', 'self_video', 'mute', 'deaf']: @@ -138,7 +142,7 @@ async def update_mqtt_state(self, member: discord.Member, after: discord.VoiceSt async def on_voice_state_update( self, member: discord.Member, before: discord.VoiceState, after: discord.VoiceState ): - channel: discord.VoiceChannel = before.channel or after.channel + channel: discord.VoiceChannel = before.channel or after.channel # type: ignore if before.channel and after.channel and before.channel == after.channel: log.debug(f"no one moved in {channel.name}") # no one moved, check if user acted on is notifiable @@ -176,7 +180,7 @@ async def on_voice_state_update( else: return - voiceLog = self.bot.get_cog('VoiceLog') + voiceLog: VoicePrivVC = self.bot.get_cog('VoiceLog') if voiceLog: if voiceLog.beingShaken.get(member.id) is not None: return # ignore person being shaken @@ -260,6 +264,14 @@ async def send_notification(self, user_id: int, title: str, members: List[discor ) as r: log.debug(f"webhook response: {r.status}") + @Cog.listener() + async def on_member_update(self, before: discord.Member, after: discord.Member): + if after.id in USER_TO_HA_DEVICE: + if before.status != after.status: + mqtt: HomeAssistantIntigreation = self.bot.get_cog("HomeAssistantIntigreation") # type: ignore + blob = {"status": after.status.value, "mobile": after.is_on_mobile()} + await mqtt.mqttPublish(f"discord/{after.id}/status", json.dumps(blob)) + async def setup(bot: "Bot"): await bot.add_cog(PhoneMonitor(bot))