| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- import discord
- from discord.ext import commands
- from typing import Optional
- from query import user as userquery
- from common.settings import check_ignore
- class Idlerpg(commands.Cog):
- def __init__(self, bot): # Special method that is called when the cog is loaded
- self.bot = bot
- @commands.slash_command(
- name = "level",
- description="Check the level for a player.",
- brief="Get player level",
- help="View game level of player."
- )
- async def level(self, ctx: commands.Context, user: Optional[discord.User]):
- # Halt on ignore list or games channel settings.
- if await check_ignore(self.bot.pg, ctx.author, ctx.channel):
- return
- if not user:
- user = ctx.author
- level = await userquery.get_level(self.bot.pg, user.id)
- if level == 0:
- if ctx.author == user:
- await ctx.respond(f"You are not playing, join the game with `/levelup`")
- else:
- await ctx.respond(f"`{user}` is not playing.")
- else:
- xp_spent, total_xp = await userquery.get_xp(self.bot.pg, user.id)
- ability_points_spent = await userquery.get_ability_points_spent(self.bot.pg, user.id)
- coin = await userquery.get_coin(self.bot.pg, user.id)
- karma = await userquery.get_karma(self.bot.pg, user.id)
- if ctx.author == user:
- await ctx.respond(
- f"You rank at level **{level}**. (exp **{xp_spent}**/{total_xp} | abp **{ability_points_spent}**/{level * 3} | coin **{coin}** | karma **{karma}**)")
- else:
- await ctx.respond(
- f"`{user}` ranks at level **{level}**. (**{xp_spent}**/{total_xp} | abp **{ability_points_spent}**/{level * 3}) | coin **{coin}** | karma **{karma}**")
- @commands.slash_command(
- description="Check the experience points for a player.",
- brief="Get player xp",
- help="View amount of XP a game player has."
- )
- async def xp(self, ctx: commands.Context, user: Optional[discord.User]):
- # Halt on ignore list or games channel settings.
- if await check_ignore(self.bot.pg, ctx.author, ctx.channel):
- return
- if not user:
- xp_spent, total_xp = await userquery.get_xp(self.bot.pg, ctx.author.id)
- level = await userquery.get_level(self.bot.pg, ctx.author.id)
- threshold = (level + 1) * 50 + xp_spent
- if threshold < total_xp - xp_spent:
- await ctx.respond(f"You have spent {xp_spent} experience points of your {total_xp} total and can gain 3 ability points for {threshold} xp.")
- else:
- await ctx.respond(f"You have spent {xp_spent} experience points of your {total_xp} total and require {threshold - (total_xp - xp_spent)} xp to `{COMMAND_PREFIX}levelup`.")
- else:
- xp_spent, total_xp = await userquery.get_xp(self.bot.pg, user.id)
- level = await userquery.get_level(self.bot.pg, user.id)
- threshold = (level + 1) * 50 + xp_spent
- if threshold < total_xp - xp_spent:
- await ctx.respond(f"`{user}` has spent {xp_spent} of {total_xp} experience points and can level up for {threshold} xp.")
- else:
- await ctx.respond(f"`{user}` has spent {xp_spent} of {total_xp} experience points and requires {threshold - (total_xp - xp_spent)} xp to level up.")
- @commands.slash_command(
- description="Attempt to gain a level.",
- brief="Level up",
- help="Try to rank up a level in the game by spending XP."
- )
- async def levelup(self, ctx: commands.Context):
- # Halt on ignore list or games channel settings.
- if await check_ignore(self.bot.pg, ctx.author, ctx.channel):
- return
- xp_spent, total_xp = await userquery.get_xp(self.bot.pg, ctx.author.id)
- xp_available = total_xp - xp_spent
- level = await userquery.get_level(self.bot.pg, ctx.author.id)
- threshold = (level + 1) * 50 + xp_spent
- if xp_available < threshold:
- await ctx.respond(f"Not yet, you require {threshold - xp_available} more XP to level up.")
- else:
- await userquery.level_up(self.bot.pg, ctx.author.id, threshold)
- await ctx.respond(f"You have gained three ability points climbed the ranks for {threshold} XP, leaving you {xp_available - threshold} remaining.")
- @commands.slash_command(
- description="Rob another player",
- brief="Rob a player",
- help="Pursuit a robbery."
- )
- async def rob(self, ctx: commands.Context):
- # Halt on ignore list or games channel settings.
- if await check_ignore(self.bot.pg, ctx.author, ctx.channel):
- return
- if await userquery.get_theft_skill(self.bot.pg, ctx.author.id < 1):
- await ctx.respond("You do not have the `Theft` skill.")
- return
- victim_id = userquery.get_random_player(self.bot.pg)
- await ctx.respond(f"You have decided to rob{self.bot.get_user(victim_id)}, unfortunately crime has not been invited yet.")
- def setup(bot): # Called by Pycord to setup the cog
- bot.add_cog(Idlerpg(bot)) # Add the cog to the bot
|