From e99df225220fa771500b3512a68f68e9d09b9d0f Mon Sep 17 00:00:00 2001 From: snipe_blaze <72265661+notsniped@users.noreply.github.com> Date: Sun, 31 Jul 2022 10:22:17 +0530 Subject: [PATCH 1/6] Trigger an AFK alert when an AFK user is mentioned --- main.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/main.py b/main.py index 027a9b26..d074b0ec 100644 --- a/main.py +++ b/main.py @@ -117,6 +117,12 @@ async def on_message(ctx): if z in str(ctx.author.id): pass else: items[str(ctx.author.id)][str(z)] = 0 save() + uList = list() + for x in user_presence[str(ctx.guild.id)].keys(): uList.append(x) + for i in uList: + if i in ctx.content and not message.author.bot: + user = client.get_user(i) + ctx.channel.send(f"{user.display_name} went AFK {user_presence[str(ctx.guild.id)][str(ctx.author.id)]['exctime']}: {user_presence[str(ctx.guild.id)][str(ctx.author.id)]['response']}") if str(ctx.author.id) in user_presence[str(ctx.guild.id)]: del user_presence[str(ctx.guild.id)][str(ctx.author.id)] save() From 43b57426a601aec58522584a9b784658c840c62f Mon Sep 17 00:00:00 2001 From: snipe_blaze <72265661+notsniped@users.noreply.github.com> Date: Sun, 31 Jul 2022 10:24:15 +0530 Subject: [PATCH 2/6] Floor AFK UNIX timestamp value The value isn't rounded in the AFK database, so it will have to be rounded while being outputted for Discord to read it. --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index d074b0ec..9c3acce0 100644 --- a/main.py +++ b/main.py @@ -122,7 +122,7 @@ async def on_message(ctx): for i in uList: if i in ctx.content and not message.author.bot: user = client.get_user(i) - ctx.channel.send(f"{user.display_name} went AFK {user_presence[str(ctx.guild.id)][str(ctx.author.id)]['exctime']}: {user_presence[str(ctx.guild.id)][str(ctx.author.id)]['response']}") + ctx.channel.send(f"{user.display_name} went AFK {math.floor(user_presence[str(ctx.guild.id)][str(ctx.author.id)]['exctime'])}: {user_presence[str(ctx.guild.id)][str(ctx.author.id)]['response']}") if str(ctx.author.id) in user_presence[str(ctx.guild.id)]: del user_presence[str(ctx.guild.id)][str(ctx.author.id)] save() From cf62e953223a9a5ebed16c1abdbe1aa19436ccb3 Mon Sep 17 00:00:00 2001 From: snipe_blaze <72265661+notsniped@users.noreply.github.com> Date: Sun, 31 Jul 2022 10:28:35 +0530 Subject: [PATCH 3/6] Fix a typo --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index 9c3acce0..2d485698 100644 --- a/main.py +++ b/main.py @@ -120,7 +120,7 @@ async def on_message(ctx): uList = list() for x in user_presence[str(ctx.guild.id)].keys(): uList.append(x) for i in uList: - if i in ctx.content and not message.author.bot: + if i in ctx.content and not ctx.author.bot: user = client.get_user(i) ctx.channel.send(f"{user.display_name} went AFK {math.floor(user_presence[str(ctx.guild.id)][str(ctx.author.id)]['exctime'])}: {user_presence[str(ctx.guild.id)][str(ctx.author.id)]['response']}") if str(ctx.author.id) in user_presence[str(ctx.guild.id)]: From cc0a2a3be28806fe02c053a4698427d07bed6bad Mon Sep 17 00:00:00 2001 From: snipe_blaze <72265661+notsniped@users.noreply.github.com> Date: Sun, 31 Jul 2022 10:42:12 +0530 Subject: [PATCH 4/6] Fix db key retrieval and add Discord timestamp triggers Name display has been temporarily removed because I wasn't able to figure out `user:list` --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index 2d485698..0e89b443 100644 --- a/main.py +++ b/main.py @@ -122,7 +122,7 @@ async def on_message(ctx): for i in uList: if i in ctx.content and not ctx.author.bot: user = client.get_user(i) - ctx.channel.send(f"{user.display_name} went AFK {math.floor(user_presence[str(ctx.guild.id)][str(ctx.author.id)]['exctime'])}: {user_presence[str(ctx.guild.id)][str(ctx.author.id)]['response']}") + await ctx.channel.send(f"That user went AFK : {user_presence[str(ctx.guild.id)][str(i)]['response']}") if str(ctx.author.id) in user_presence[str(ctx.guild.id)]: del user_presence[str(ctx.guild.id)][str(ctx.author.id)] save() From b288c414aeadef7d0094bbc768b1c675027ec164 Mon Sep 17 00:00:00 2001 From: snipe_blaze <72265661+notsniped@users.noreply.github.com> Date: Sun, 31 Jul 2022 10:46:49 +0530 Subject: [PATCH 5/6] Add suitable Discord timestamp formatting --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index 0e89b443..628d3f5c 100644 --- a/main.py +++ b/main.py @@ -122,7 +122,7 @@ async def on_message(ctx): for i in uList: if i in ctx.content and not ctx.author.bot: user = client.get_user(i) - await ctx.channel.send(f"That user went AFK : {user_presence[str(ctx.guild.id)][str(i)]['response']}") + await ctx.channel.send(f"That user went AFK : {user_presence[str(ctx.guild.id)][str(i)]['response']}") if str(ctx.author.id) in user_presence[str(ctx.guild.id)]: del user_presence[str(ctx.guild.id)][str(ctx.author.id)] save() From 91da3079d569030acb13ef28514647134ec05cd4 Mon Sep 17 00:00:00 2001 From: snipe_blaze <72265661+notsniped@users.noreply.github.com> Date: Sun, 31 Jul 2022 11:09:59 +0530 Subject: [PATCH 6/6] Convert string id to int Turns out that an id as `client.get_user()` argument can't be a string. It needs to be an int otherwise it literally won't return anything --- main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 628d3f5c..e00264db 100644 --- a/main.py +++ b/main.py @@ -121,8 +121,8 @@ async def on_message(ctx): for x in user_presence[str(ctx.guild.id)].keys(): uList.append(x) for i in uList: if i in ctx.content and not ctx.author.bot: - user = client.get_user(i) - await ctx.channel.send(f"That user went AFK : {user_presence[str(ctx.guild.id)][str(i)]['response']}") + fetch_user = client.get_user(id(i)) + await ctx.channel.send(f"{fetch_user.display_name} went AFK : {user_presence[str(ctx.guild.id)][str(i)]['response']}") if str(ctx.author.id) in user_presence[str(ctx.guild.id)]: del user_presence[str(ctx.guild.id)][str(ctx.author.id)] save()