Replace memberId and channelId with more info according to #3
Closes #3 Remove left over print() statements
This commit is contained in:
parent
ef1f30443f
commit
025753882d
2 changed files with 36 additions and 16 deletions
|
|
@ -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).
|
||||
|
||||
|
|
|
|||
|
|
@ -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"},
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue