Replace memberId and channelId with more info according to #3

Closes #3

Remove left over print() statements
This commit is contained in:
Marsn3 2025-02-07 06:37:11 +01:00
parent ef1f30443f
commit 025753882d
2 changed files with 36 additions and 16 deletions

View file

@ -1,4 +1,4 @@
# VC-stats Bot # 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).

View file

@ -24,14 +24,34 @@ class Events(Enum):
move = "move" 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: class Data:
memberId: int member: dict
channelId: int channel: dict
event: str event: str
def __init__(self, memberId: int, channelId: int, event: Events) -> None: def __init__(self, member: dict, channel: dict, event: Events) -> None:
self.memberId = memberId self.member = member
self.channelId = channelId self.channel = channel
self.event = event.value self.event = event.value
@ -48,10 +68,10 @@ async def on_ready():
@client.event @client.event
async def on_voice_state_update( 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 member = {"id": user.id, "name": user.name.capitalize(), "avatar": user.avatar.url}
channelId = None channel = {}
event = None event = None
# User didn't connect or disconnect # User didn't connect or disconnect
if before.channel is not None and after.channel is not None: 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 # Compare using id just to be safe
if before.channel.id is not after.channel.id: if before.channel.id is not after.channel.id:
event = Events("move") event = Events("move")
channelId = after.channel.id channel = {"id": after.channel.id, "name": after.channel.name}
# User didn't move # User didn't move
elif before.channel == after.channel: elif before.channel == after.channel:
# User undeafen # User undeafen
@ -74,21 +94,21 @@ async def on_voice_state_update(
# User muted # User muted
elif not before.self_mute and after.self_mute: elif not before.self_mute and after.self_mute:
event = Events("mute") event = Events("mute")
channelId = after.channel.id channel = {"id": after.channel.id, "name": after.channel.name}
# User connected or disconnected # User connected or disconnected
elif not before.channel or not after.channel: elif not before.channel or not after.channel:
# User disconnected # User disconnected
if before.channel and not after.channel: if before.channel and not after.channel:
event = Events("leave") event = Events("leave")
channelId = before.channel.id channel = {"id": before.channel.id, "name": before.channel.name}
# User connected # User connected
elif not before.channel and after.channel: elif not before.channel and after.channel:
event = Events("join") event = Events("join")
channelId = after.channel.id channel = {"id": after.channel.id, "name": after.channel.name}
if channelId and event: if channel and event:
data = Data(memberId, channelId, event) data = Data(member, channel, event)
r = requests.post( r = requests.post(
"https://api.m3.fyi/api/collections/vc_test/records", "https://api.m3.fyi/api/collections/vc_stats/records",
json=data.__dict__, json=data.__dict__,
headers={"Authorization": PB_TOKEN, "content-type": "application/json"}, headers={"Authorization": PB_TOKEN, "content-type": "application/json"},
) )