From 67f33d70099749bdabb62f3b1ebaedb566fe5b2e Mon Sep 17 00:00:00 2001 From: acaValkyrie Date: Mon, 12 Feb 2024 01:00:18 +0900 Subject: [PATCH] =?UTF-8?q?=E9=80=9A=E8=A9=B1=E9=96=8B=E5=A7=8B=E4=BB=A5?= =?UTF-8?q?=E5=A4=96=E3=81=AE=E4=BA=BA=E3=81=AE=E5=87=BA=E5=85=A5=E3=82=8A?= =?UTF-8?q?=E3=81=A7=E3=82=82=E9=80=9A=E7=9F=A5=E3=81=8C=E5=87=BA=E3=81=A6?= =?UTF-8?q?=E3=81=97=E3=81=BE=E3=81=86=E4=B8=8D=E5=85=B7=E5=90=88=E3=81=AE?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.py | 59 +++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 21 deletions(-) diff --git a/app.py b/app.py index b7bdbdc..d5430ac 100644 --- a/app.py +++ b/app.py @@ -20,29 +20,20 @@ async def on_ready(self): async def setup_hook(self) -> None: await self.tree.sync() - - async def on_voice_state_update(self, member: discord.Member, before: discord.VoiceState, after: discord.VoiceState): - if before.channel != None and not channelonoff[before.channel.id]: return - if after.channel != None and not channelonoff[after.channel.id ]: return - - # 通話終了通知 - if before.channel and len(before.channel.members) == 0 and is_call_end_notification_enabled: - if member.status == discord.Status.idle: return - channel = self.get_channel(channel_id) - embed = discord.Embed(title="通話終了", color=0x6a5acd) - embed.add_field( - name="チャンネル", value=before.channel.name, inline=False) - embed.add_field(name="通話時間", value=datetime.datetime.now( - pytz.timezone('Asia/Tokyo'))-e_time[before.channel.id], inline=False) - e_time[before.channel.id] = 0 - await channel.send(embed=embed) - return - # 通話開始通知 - is_exist_channel_before = before.channel == None + def is_call_start(self, before, after, member): + # voice state update後のチャンネルが存在しないなら通話開始ではない + if after.channel == None: return False + + # 通話開始かどうかの判断 + is_different_voice_channel = before.channel != after.channel member_count_after = len(after.channel.members) - is_start_call = is_exist_channel_before and member_count_after >= 1 - if is_start_call: + is_start_call = is_different_voice_channel and member_count_after == 1 + + return is_start_call + + async def start_call(self, before, after, member): + if self.is_call_start(before, after, member): print("voice state update2") e_time[after.channel.id] = datetime.datetime.now( pytz.timezone('Asia/Tokyo')) @@ -63,6 +54,32 @@ async def on_voice_state_update(self, member: discord.Member, before: discord.Vo except Exception as e: print(e) + async def end_call(self, before, after, member): + if before.channel != None and not channelonoff[before.channel.id]: return + if after.channel != None and not channelonoff[after.channel.id ]: return + + if before.channel and len(before.channel.members) == 0 and is_call_end_notification_enabled: + if member.status == discord.Status.idle: return + channel = self.get_channel(channel_id) + embed = discord.Embed(title="通話終了", color=0x6a5acd) + embed.add_field( + name="チャンネル", value=before.channel.name, inline=False) + embed.add_field(name="通話時間", value=datetime.datetime.now( + pytz.timezone('Asia/Tokyo'))-e_time[before.channel.id], inline=False) + e_time[before.channel.id] = 0 + await channel.send(embed=embed) + return + + async def on_voice_state_update(self, member: discord.Member, before: discord.VoiceState, after: discord.VoiceState): + if before.channel != None and not channelonoff[before.channel.id]: return + if after.channel != None and not channelonoff[after.channel.id ]: return + + # 通話開始通知 + await self.start_call(before, after, member) + + # 通話終了通知 + await self.end_call(before, after, member) + def main(): # start the client client = MyClient(intents=INTENTS)