Skip to content

Commit

Permalink
fixed richest, added afk, some other bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
2vw committed Mar 7, 2024
1 parent 65cb5c5 commit 090a3b9
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 31 deletions.
2 changes: 1 addition & 1 deletion cogs/economy.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ async def work(ctx):
async def richest(ctx):
lb = []
count = 0
d = userdb.find().sort([("levels.totalxp", pymongo.DESCENDING)]).limit(10)
d = userdb.find().sort([("economy.total", pymongo.DESCENDING)]).limit(10)
for doc in (await d.to_list(length=10)):
total = doc['economy']['wallet'] + doc['economy']['bank']
count += 1
Expand Down
49 changes: 41 additions & 8 deletions cogs/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,8 @@ async def suggest(ctx, *, message):
description="Get your personal line of prefixes!",
)
async def prefixes(ctx):
if userdb.find_one({'userid':ctx.author.id}):
prefixes = userdb.find_one({'userid':ctx.author.id})['prefixes']
if (await userdb.find_one({'userid':ctx.author.id})):
prefixes = (await userdb.find_one({'userid':ctx.author.id}))['prefixes']
embed = voltage.SendableEmbed(
title="Your prefixes!",
description=f"Your prefixes are:{sep} ```{sep}{f'{sep}'.join(prefixes)}{sep}```",
Expand All @@ -365,14 +365,14 @@ async def prefixes(ctx):
description="Add a prefix to your personal line of prefixes!",
)
async def addprefix(ctx, *, prefix):
if userdb.find_one({'userid':ctx.author.id}):
if (await userdb.find_one({'userid':ctx.author.id})):
if prefix[0] == " ":
return await ctx.send("Prefix cannot start with a space!")
elif any(x in prefix for x in userdb.find_one({'userid':ctx.author.id})['prefixes']):
elif any(x in prefix for x in (await userdb.find_one({'userid':ctx.author.id}))['prefixes']):
return await ctx.send("This prefix is already in your list of prefixes!")
else:
userdb.update_one({'userid':ctx.author.id}, {'$push':{'prefixes':prefix}})
prefixes = userdb.find_one({'userid':ctx.author.id})['prefixes']
await userdb.update_one({'userid':ctx.author.id}, {'$push':{'prefixes':prefix}})
prefixes = (await userdb.find_one({'userid':ctx.author.id}))['prefixes']
embed = voltage.SendableEmbed(
title="Added a new prefix to your list!",
description=f"Added `{prefix}` to your list of {len(prefixes)}!{sep}To see your prefixes, type `m!prefixes` or alternatively; mention me!",
Expand All @@ -388,10 +388,10 @@ async def addprefix(ctx, *, prefix):
description="Remove a prefix from your personal line of prefixes!",
)
async def removeprefix(ctx, *, prefix):
if userdb.find_one({'userid':ctx.author.id}):
if (await userdb.find_one({'userid':ctx.author.id})):
if len((await userdb.find_one({'userid':ctx.author.id})['prefixes'])) > 1 :
if prefix in (await userdb.find_one({'userid':ctx.author.id}))['prefixes']:
userdb.update_one({'userid':ctx.author.id}, {'$pull':{'prefixes':prefix}})
await userdb.update_one({'userid':ctx.author.id}, {'$pull':{'prefixes':prefix}})
prefixes = (await userdb.find_one({'userid':ctx.author.id}))['prefixes']
embed = voltage.SendableEmbed(
title="Removed a prefix from your list!",
Expand Down Expand Up @@ -514,6 +514,39 @@ async def familyfriendly(ctx, toggle):
)
await ctx.reply(embed=embed)

@utility.command(name="afk", description="Set your AFK status!", aliases=["awayfromkeyboard", 'brb'])
async def afk(ctx, *, reason: str = None):
if (await userdb.find_one({'userid': ctx.author.id})):
await userdb.update_one(
{
'userid': ctx.author.id
},
{
'$set': {
f'status.afk.{ctx.server.id}': {
f'reason': reason,
f'lastseen': int(time.time()),
f'afk': True
}
}
}
)
embed = voltage.SendableEmbed(
title=ctx.author.display_name,
icon_url=ctx.author.display_avatar.url,
description=f"Set your AFK status to:{sep}{reason}",
color="#00FF00"
)
await ctx.reply(embed=embed)
else:
embed = voltage.SendableEmbed(
title=ctx.author.display_name,
icon_url=ctx.author.display_avatar.url,
description="Please create an account with `m!add`!",
color="#dc3545",
)
await ctx.reply(embed=embed)

@utility.command(name="inbox", description="View your inbox!")
async def inbox(ctx, page: int = 1):
notifications_per_page = 5
Expand Down
65 changes: 43 additions & 22 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,28 +135,25 @@ async def serverupdate():

import time

"""for i in await userdb.find({}):
userdb.bulk_write(
[
pymongo.UpdateOne(
{'userid':i['userid']},
{'$set':{'notifications.inbox': {
"1":{
"message": f"Welcome to Mecha, {i['username']}!{sep}To get started, type `m!help` in this server to get started!",
"date": time.time(),
"title": "Welcome To Mecha!",
"type": "bot",
"read": False
async def upd():
for i in (await userdb.find({})):
userdb.bulk_write(
[
pymongo.UpdateOne(
{'userid':i['userid']},
{'$set':
{
"status.afk": {}
}
}
}}}
),
]
)
print(f"Updated {i['username']}!")
"""
),
]
)
print(f"Updated {i['username']}!")


async def update_level(user:voltage.User):
if await userdb.find_one({'userid':user.id}):
if (await userdb.find_one({'userid':user.id})):
user_data = await userdb.find_one({'userid':user.id})
lvl = user_data['levels']['level']
xp = user_data['levels']['xp']
Expand Down Expand Up @@ -302,8 +299,8 @@ async def get_user(user: voltage.User):

async def give_xp(user: voltage.User, xp:int):
await userdb.update_one(
{"userid": user.id},
{"$inc": {"levels.xp": xp}}
{"userid": user.id},
{"$inc": {"levels.xp": xp}}
)

prefixes = ["m!"]
Expand Down Expand Up @@ -451,8 +448,31 @@ async def stayon():
await channel.send(embed=embed)
await asyncio.sleep(60*60)
i += 1


async def afkCheck(message):
try:
if (await userdb.find_one({"userid": message.author.id})):
if (await userdb.find_one({"userid": message.author.id}))['status']['afk'][message.server.id]['afk']:
if (await userdb.find_one({"userid": message.author.id}))['status']['afk'][message.server.id]['lastseen'] + 2 < int(time.time()):
await userdb.update_one(
{"userid": message.author.id},
{"$set": {"status.afk.{}".format(message.server.id): {"afk": False}}}
)
embed = voltage.SendableEmbed(
title="AFK!",
description=f"Welcome back, {message.author.mention}!{sep}I've removed your AFK status!",
colour="#00ff00",
icon_url=message.author.avatar.url
)
await message.reply(embed=embed, delete_after=5)
else:
return "TooEarly"
else:
return "NotAfk"
else:
return "DoesntExist"
except:
return

@client.listen("ready")
async def ready():
Expand Down Expand Up @@ -554,6 +574,7 @@ async def on_message(message):
if message.channel.id == message.author.id:
return
asyncio.create_task(levelstuff(message)) # pièce de résistance
asyncio.create_task(afkCheck(message))
asyncio.create_task(loggingstuff(message))
await client.handle_commands(message) # so everything else doesnt trip over its clumsy ass selves."

Expand Down

0 comments on commit 090a3b9

Please sign in to comment.