Skip to content
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
1 change: 1 addition & 0 deletions database/levels.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
65 changes: 65 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
with open('database/items.json', 'r') as f: items = json.load(f)
with open('config/shop.json', 'r') as f: shopitem = json.load(f)
with open('database/presence.json', 'r') as f: user_presence = json.load(f)
with open('database/levels.json', 'r') as f: levels = json.load(f)

#Pre-Initialization Commands
def timenow(): datetime.datetime.now().strftime("%H:%M:%S")
Expand All @@ -39,6 +40,7 @@ def save():
with open('database/warnings.json', 'w+') as f: json.dump(warnings, f, indent=4)
with open('database/items.json', 'w+') as f: json.dump(items, f, indent=4)
with open('database/presence.json', 'w+') as f: json.dump(user_presence, f, indent=4)
with open('database/levels.json', 'w+') as f: json.dump(levels, f, indent=4)

if not os.path.isdir("logs"):
os.mkdir('logs')
Expand Down Expand Up @@ -82,6 +84,7 @@ async def on_message(ctx):
if str(ctx.author.id) not in warnings: warnings[str(ctx.guild.id)] = {}
if str(ctx.author.id) not in warnings[str(ctx.guild.id)]: warnings[str(ctx.guild.id)][str(ctx.author.id)] = []
if str(ctx.author.id) not in items: items[str(ctx.author.id)] = {}
if str(ctx.author.id) not in levels: levels[str(ctx.author.id)] = {"xp": 0, "level": 0}
for z in shopitem:
if z in items[str(ctx.author.id)]: pass
else: items[str(ctx.author.id)][str(z)] = 0
Expand All @@ -98,6 +101,22 @@ async def on_message(ctx):
m1 = await ctx.channel.send(f"Welcome back {ctx.author.mention}. Your AFK has been removed.")
await asyncio.sleep(5)
await m1.delete()
if not ctx.author.bot:
levels[str(ctx.author.id)]["xp"] += randint(1, 5)
# if levelupchannel[str(message.guild.id)] == 0:
# channelid = message.channel
# else:
# channelid = client.get_channel(levelupchannel[str(message.guild.id)])
# ^ Saving for later when server-based leveling implementation is added
xpreq = 0
for level in range(int(levels[str(ctx.author.id)]["level"])):
xpreq += 50
if xpreq >= 5000: break
if levels[str(ctx.author.id)]["xp"] >= xpreq:
levels[str(ctx.author.id)]["xp"] = 0
levels[str(ctx.author.id)]["level"] += 1
await ctx.channel.send(f"{ctx.author.mention}, you are now level **{levels[str(message.guild.id)][str(message.author.id)]}**. Nice!")
save()

#Error handler
@client.event
Expand Down Expand Up @@ -902,6 +921,52 @@ async def afk_mod_remove(ctx:SlashContext, user:discord.User):
except KeyError:
return await ctx.send("That user isn't AFK.", hidden=True)

@slash.slash(
name="rank",
description="Shows your rank or another user's rank",
options=[
create_option(name="user", description="Who's rank do you want to view?", option_type=6, required=False)
]
)
async def rank(ctx:SlashContext, user:discord.User=None):
if user == None: user = ctx.author.id
try:
localembed = discord.Embed(title="{user.display_name}'s rank", color=discord.Color.random())
localembed.add_field(name="Level", value=levels[str(user.id)]["level"])
localembed.add_field(name="XP", value=levels[str(user.id)]["xp"])
localembed.set_footer(text="Keep chatting to earn levels!", icon_url=ctx.author.avatar_url)
except KeyError: return await ctx.send("Looks like that user isn't indexed yet. Try again later.", hidden=True)

@slash.slash(
name="edit_rank",
description="Edits a user's rank. (DEV ONLY)",
options=[
create_option(name="user", description="Who's rank do you want to edit?", option_type=6, required=True),
create_option(name="new_rank", decription="The new rank you want to set for the user", option_type=4, required=True)
]
)
async def edit_rank(ctx:SlashContext, user:discord.User, new_rank:int):
if ctx.author.id != 738290097170153472: return await ctx.send("This command isn't for you.", hidden=True)
try:
levels[str(user.id)]["level"] = new_rank
await ctx.reply(f"{user.display_name}\'s rank successfully edited. `New Rank: {levels[str(user.id)]['level']}`")
except KeyError: return await ctx.reply("That user isn't indexed yet.", hidden=True)

@slash.slash(
name="edit_xp",
description="Edits a user's XP. (DEV ONLY)",
options=[
create_option(name="user", description="Who's rank do you want to edit?", option_type=6, required=True),
create_option(name="new_xp", decription="The new xp count you want to set for the user", option_type=4, required=True)
]
)
async def edit_rank(ctx:SlashContext, user:discord.User, new_xp:int):
if ctx.author.id != 738290097170153472: return await ctx.send("This command isn't for you.", hidden=True)
try:
levels[str(user.id)]["xp"] = new_xp
await ctx.reply(f"{user.display_name}\'s XP count successfully edited. `New XP: {levels[str(user.id)]['xp']}`")
except KeyError: return await ctx.reply("That user isn't indexed yet.", hidden=True)

# Initialization
utils.ping.host()
client.run(api.auth.get_token())
Expand Down