2025-05-07 16:44:50 +02:00
class AfkCommands :
def __init__ ( self , bot ) :
self . bot = bot
async def handle_afk_dm ( self , message ) :
""" Handle DMs when in AFK mode """
if self . bot . AFK_STATUS and message . author . id not in self . bot . AFK_NOTIFIED_USERS :
2025-05-09 21:25:14 +02:00
self . bot . AFK_NOTIFIED_USERS . append ( message . author . id )
2025-05-07 16:44:50 +02:00
await message . reply (
" Heya, I ' m not at my computer right now, if you ' re requesting something please follow <https://nohello.club>. I ' ll let you know when I ' m back :) \n \n -# This action was automated. "
)
2025-05-09 21:25:14 +02:00
await message . channel . send ( f " AFK reason: \n { self . bot . AFK_REASON } " )
2025-05-07 16:44:50 +02:00
async def cmd_afk ( self , message ) :
""" Enable AFK mode """
if not self . bot . AFK_STATUS :
self . bot . AFK_STATUS = True
2025-05-09 21:25:14 +02:00
try :
self . bot . AFK_REASON = message . content [ 5 : ]
except IndexError :
pass
finally :
if not self . bot . AFK_REASON . strip ( ) :
self . bot . AFK_REASON = " None "
2025-05-07 16:44:50 +02:00
await message . reply ( " k " )
else :
await message . reply ( " You are already in AFK mode. " , silent = True )
async def cmd_unafk ( self , message ) :
""" Disable AFK mode """
if self . bot . AFK_STATUS :
self . bot . AFK_STATUS = False
for i in self . bot . AFK_NOTIFIED_USERS :
try :
user = await self . bot . fetch_user ( i )
if user :
dm_channel = await user . create_dm ( )
await dm_channel . send ( " Hey, I ' m back, human me will take over now! " )
except Exception as e :
raise RuntimeWarning from e
2025-05-09 20:39:19 +02:00
messaged_users_string = " "
for i in self . bot . AFK_NOTIFIED_USERS :
try :
user = await self . bot . fetch_user ( i )
if user :
messaged_users_string + = f " \n \\ - { user . id } | { user . name } "
except Exception as e :
raise RuntimeWarning from e
await message . reply ( f " should work, here are the people who dmed you: " + ( messaged_users_string if messaged_users_string else " \n nobody because you ' re alone asf obvs " ) )
2025-05-07 16:44:50 +02:00
self . bot . AFK_NOTIFIED_USERS . clear ( )
else :
2025-05-09 20:39:19 +02:00
await message . reply ( " You are not in AFK mode. " , silent = True )