Skip to content
This repository was archived by the owner on Feb 7, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions cogs/afk.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Imports
import discord
import json
import time
from discord import option, ApplicationContext, SlashCommandGroup
from discord.ext import commands

# Variables
with open("database/presence.json", 'r') as f: presence = json.load(f)

def save():
with open("database/presence.json", 'w+') as f: presence = json.dump(presence, f)

# Functions
def get_presence(user_id: int, guild_id: int) -> dict:
"""Returns a `dict` of the specified user's current AFK status in the guild."""
if str(user_id) in presence[str(guild_id)]:
return {
"afk": True,
"response": presence[str(guild_id)][str(user_id)]['response'],
"time": presence[str(guild_id)][str(user_id)]['time']
}
else:
return False

# Commands
class Presence(commands.Cog):
def __init__(self, bot):
self.bot = bot

afk_system = SlashCommandGroup("afk", "Commands for interacting with the AFK system.")

@afk_system.command(
name="set",
description="Sets your AFK status with a custom response"
)
@option(name="response", description="What do you want your AFK response to be?", type=str, default="I'm AFK")
async def afk_set(self, ctx: ApplicationContext, response:str="I'm AFK"):
exctime = time.time()
if str(ctx.guild.id) not in presence: presence[str(ctx.guild.id)] = {}
presence[str(ctx.guild.id)][str(ctx.author.id)] = {"type": "afk", "time": exctime, "response": response}
save()
localembed = discord.Embed(title=f"{ctx.author.display_name} is now AFK.", description=f"Response: {response}", color=discord.Color.dark_orange())
await ctx.respond(embed=localembed)

@afk_system.command(
name="remove",
description="Removes your AFK status"
)
async def afk_remove(self, ctx: ApplicationContext):
try:
del presence[str(ctx.guild.id)][str(ctx.author.id)]
save()
await ctx.respond(f"Alright {ctx.author.mention}, I've removed your AFK.")
except KeyError: return await ctx.respond("You weren't previously AFK.", ephemeral=True)

@afk_system.command(
name="mod_remove",
description="Removes an AFK status for someone else"
)
@option(name="user", description="Whose AFK status do you want to remove?", type=discord.User)
async def afk_mod_remove(self, ctx: ApplicationContext, user:discord.User):
if not ctx.author.guild_permissions.manage_messages: return await ctx.respond("You don't have the required permissions to use this.", ephemeral=True)
try:
del presence[str(ctx.guild.id)][str(user.id)]
save()
await ctx.respond(f"{user.display_name}'s AFK has been removed.")
except KeyError: return await ctx.respond("That user isn't AFK.", ephemeral=True)

# Cog Initialization
def setup(bot): bot.add_cog(Presence(bot))
32 changes: 32 additions & 0 deletions cogs/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
import discord
import os
import psutil
import math
import framework.isobot.embedengine
from discord import option, ApplicationContext
from discord.ext import commands
from cogs.economy import get_wallet, get_bank, get_user_networth, get_user_count
from cogs.levelling import get_level, get_xp
from cogs.afk import get_presence

# Variables
color = discord.Color.random()
Expand Down Expand Up @@ -48,6 +50,36 @@ async def embedbuilder(self, ctx: ApplicationContext, title: str, description: s
await ctx.respond("Embed Built!", ephemeral=True)
await ctx.channel.send(embed=framework.isobot.embedengine.embed(title, description, image=image_url, thumbnail=thumbnail_url, color=color, footer_text=footer_text, footer_img=footer_icon_url))

@commands.slash_command(
name='whoami',
description='Shows information on a user'
)
@option(name="user", description="Who do you want to know about?", type=discord.User, default=None)
async def whoami(self, ctx: ApplicationContext, user: discord.User=None):
if user == None: user = ctx.author
username = user
displayname = user.display_name
registered = user.joined_at.strftime("%b %d, %Y, %T")
pfp = user.avatar
localembed_desc = f"`AKA` {displayname}"
presence = get_presence(ctx.author.id, ctx.guild.id)
if presence != False: localembed_desc += f"\n`🌙 AFK` {presence['response']} - <t:{math.floor(presence['time'])}>"
localembed = discord.Embed(
title=f'User Info on {username}',
description=localembed_desc
)
localembed.set_thumbnail(url=pfp)
localembed.add_field(name='Username', value=username, inline=True)
localembed.add_field(name='Display Name', value=displayname, inline=True)
localembed.add_field(name='Joined Discord on', value=registered, inline=False)
localembed.add_field(name='Avatar URL', value=f"[here!]({pfp})", inline=True)
role_render = ""
for p in user.roles:
if p != user.roles[0]: role_render += f"<@&{p.id}> "
localembed.add_field(name='Roles', value=role_render, inline=False)
localembed.add_field(name="Net worth", value=f"{get_user_networth(user.id)} coins", inline=False)
await ctx.respond(embed=localembed)

@commands.slash_command(
name="profile",
description="Shows basic stats about your isobot profile, or someone else's profile stats"
Expand Down
82 changes: 12 additions & 70 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,35 +239,6 @@ async def help(ctx: ApplicationContext, command:str=None):
await user.send(embed=localembed)
await ctx.respond("Check your direct messages.", ephemeral=True)

@client.slash_command(
name='whoami',
description='Shows information on a user'
)
@option(name="user", description="Who do you want to know about?", type=discord.User, default=None)
async def whoami(ctx: ApplicationContext, user: discord.User=None):
if user == None: user = ctx.author
username = user
displayname = user.display_name
registered = user.joined_at.strftime("%b %d, %Y, %T")
pfp = user.avatar
localembed_desc = f"`AKA` {displayname}"
if str(user.id) in presence[str(ctx.guild.id)]: localembed_desc += f"\n`🌙 AFK` {presence[str(ctx.guild.id)][str(user.id)]['response']} - <t:{floor(presence[str(ctx.guild.id)][str(user.id)]['time'])}>"
localembed = discord.Embed(
title=f'User Info on {username}',
description=localembed_desc
)
localembed.set_thumbnail(url=pfp)
localembed.add_field(name='Username', value=username, inline=True)
localembed.add_field(name='Display Name', value=displayname, inline=True)
localembed.add_field(name='Joined Discord on', value=registered, inline=False)
localembed.add_field(name='Avatar URL', value=f"[here!]({pfp})", inline=True)
role_render = ""
for p in user.roles:
if p != user.roles[0]: role_render += f"<@&{p.id}> "
localembed.add_field(name='Roles', value=role_render, inline=False)
localembed.add_field(name="Net worth", value=f"{get_user_networth(user.id)} coins", inline=False)
await ctx.respond(embed=localembed)

# DevTools commands
@client.slash_command(
name='sync',
Expand Down Expand Up @@ -330,46 +301,6 @@ async def reload(ctx: ApplicationContext, cog: str):
await ctx.respond(embed=discord.Embed(description=f"{cog} cog successfully reloaded.", color=discord.Color.green()))
except: await ctx.respond(embed=discord.Embed(description=f"{cog} cog not found.", color=discord.Color.red()))

# AFK System Commands
afk_system = client.create_group("afk", "Commands for interacting with the built-in AFK system.")

@afk_system.command(
name="set",
description="Sets your AFK status with a custom response"
)
@option(name="response", description="What do you want your AFK response to be?", type=str, default="I'm AFK")
async def afk_set(ctx: ApplicationContext, response:str="I'm AFK"):
exctime = time.time()
if str(ctx.guild.id) not in presence: presence[str(ctx.guild.id)] = {}
presence[str(ctx.guild.id)][str(ctx.author.id)] = {"type": "afk", "time": exctime, "response": response}
save()
localembed = discord.Embed(title=f"{ctx.author.display_name} is now AFK.", description=f"Response: {response}", color=discord.Color.dark_orange())
await ctx.respond(embed=localembed)

@afk_system.command(
name="remove",
description="Removes your AFK status"
)
async def afk_remove(ctx: ApplicationContext):
try:
del presence[str(ctx.guild.id)][str(ctx.author.id)]
save()
await ctx.respond(f"Alright {ctx.author.mention}, I've removed your AFK.")
except KeyError: return await ctx.respond("You weren't previously AFK.", ephemeral=True)

@afk_system.command(
name="mod_remove",
description="Removes an AFK status for someone else"
)
@option(name="user", description="Whose AFK status do you want to remove?", type=discord.User)
async def afk_mod_remove(ctx: ApplicationContext, user:discord.User):
if not ctx.author.guild_permissions.manage_messages: return await ctx.respond("You don't have the required permissions to use this.", ephemeral=True)
try:
del presence[str(ctx.guild.id)][str(user.id)]
save()
await ctx.respond(f"{user.display_name}'s AFK has been removed.")
except KeyError: return await ctx.respond("That user isn't AFK.", ephemeral=True)

# IsoCoins commands
isocoin_system = client.create_group("isocoin", "Commands related to the IsoCoin rewards system.")

Expand Down Expand Up @@ -400,7 +331,18 @@ async def isocoin_shop(ctx: ApplicationContext):
await ctx.respond("IsoCoin shop is coming soon! Check back later for new items.")

# Initialization
active_cogs = ["economy", "maths", "moderation", "reddit", "minigames", "automod", "isobank", "levelling", "fun"]
active_cogs = [
"economy",
"maths",
"moderation",
"reddit",
"minigames",
"automod",
"isobank",
"levelling",
"fun",
"afk"
]
i = 1
cog_errors = 0
for x in active_cogs:
Expand Down