diff --git a/src/bot/README.md b/src/bot/README.md index 2190098..9cc1507 100644 --- a/src/bot/README.md +++ b/src/bot/README.md @@ -1,4 +1,4 @@ # VC-stats Bot -Bot to automatically send vc events (Mute/Deafen/Connects) to db for further processing with [VC-stats frontend](../frontend). +Bot to automatically send vc events (Mute/Deafen/Connects) to db for further processing with [VC-stats Frontend](../frontend). diff --git a/src/bot/bot.py b/src/bot/bot.py index 56ba98b..91cbee6 100644 --- a/src/bot/bot.py +++ b/src/bot/bot.py @@ -24,14 +24,34 @@ class Events(Enum): move = "move" +class Channel: + name: str + id: int + + def __init__(self, id: int, name: str) -> None: + self.id = id + self.name = name + + +class Member: + name: str + id: int + avatar: str + + def __init__(self, id: int, name: str, avatar: str) -> None: + self.id = id + self.name = name + self.avatar = avatar + + class Data: - memberId: int - channelId: int + member: dict + channel: dict event: str - def __init__(self, memberId: int, channelId: int, event: Events) -> None: - self.memberId = memberId - self.channelId = channelId + def __init__(self, member: dict, channel: dict, event: Events) -> None: + self.member = member + self.channel = channel self.event = event.value @@ -48,10 +68,10 @@ async def on_ready(): @client.event async def on_voice_state_update( - member: discord.Member, before: discord.VoiceState, after: discord.VoiceState + user: discord.Member, before: discord.VoiceState, after: discord.VoiceState ): - memberId = member.id - channelId = None + member = {"id": user.id, "name": user.name.capitalize(), "avatar": user.avatar.url} + channel = {} event = None # User didn't connect or disconnect if before.channel is not None and after.channel is not None: @@ -59,7 +79,7 @@ async def on_voice_state_update( # Compare using id just to be safe if before.channel.id is not after.channel.id: event = Events("move") - channelId = after.channel.id + channel = {"id": after.channel.id, "name": after.channel.name} # User didn't move elif before.channel == after.channel: # User undeafen @@ -74,21 +94,21 @@ async def on_voice_state_update( # User muted elif not before.self_mute and after.self_mute: event = Events("mute") - channelId = after.channel.id + channel = {"id": after.channel.id, "name": after.channel.name} # User connected or disconnected elif not before.channel or not after.channel: # User disconnected if before.channel and not after.channel: event = Events("leave") - channelId = before.channel.id + channel = {"id": before.channel.id, "name": before.channel.name} # User connected elif not before.channel and after.channel: event = Events("join") - channelId = after.channel.id - if channelId and event: - data = Data(memberId, channelId, event) + channel = {"id": after.channel.id, "name": after.channel.name} + if channel and event: + data = Data(member, channel, event) r = requests.post( - "https://api.m3.fyi/api/collections/vc_test/records", + "https://api.m3.fyi/api/collections/vc_stats/records", json=data.__dict__, headers={"Authorization": PB_TOKEN, "content-type": "application/json"}, )