| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206 |
- from discord.ext import commands
- import discord
- import random
- from typing import Optional
- from query.user import is_ignored, get_level, get_xp, level_up, get_ability_points_spent, increment_all_coin, get_coin, get_karma, get_theft_skill, get_random_player
- #from local_settings import COMMAND_PREFIX
- from common.settings import check_ignore
- async def setup(bot: commands.Bot):
- await bot.add_cog(Games(bot))
- class Games(commands.Cog):
- """Gaming commands."""
- def __init__(self, bot: commands.Bot):
- self.bot = bot
- # @commands.command(
- # 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 get_level(self.bot.pg, user.id)
- #
- # if level == 0:
- # if ctx.author == user:
- # await ctx.send(f"You are not playing, join the game with `/levelup`")
- # else:
- # await ctx.send(f"`{user}` is not playing.")
- # else:
- # xp_spent, total_xp = await get_xp(self.bot.pg, user.id)
- # ability_points_spent = await get_ability_points_spent(self.bot.pg, user.id)
- # coin = await get_coin(self.bot.pg, user.id)
- # karma = await get_karma(self.bot.pg, user.id)
- # if ctx.author == user:
- # await ctx.send(f"You rank at level **{level}**. (exp **{xp_spent}**/{total_xp} | abp **{ability_points_spent}**/{level * 3} | coin **{coin}** | karma **{karma}**)")
- # else:
- # await ctx.send(f"`{user}` ranks at level **{level}**. (**{xp_spent}**/{total_xp} | abp **{ability_points_spent}**/{level * 3}) | coin **{coin}** | karma **{karma}**")
- #
- # @commands.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 get_xp(self.bot.pg, ctx.author.id)
- # level = await get_level(self.bot.pg, ctx.author.id)
- # threshold = (level + 1) * 50 + xp_spent
- # if threshold < total_xp - xp_spent:
- # await ctx.send(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.send(f"You have spent {xp_spent} experience points of your {total_xp} total and require {threshold - (total_xp - xp_spent)} xp to `/levelup`.")
- # else:
- # xp_spent, total_xp = await get_xp(self.bot.pg, user.id)
- # level = await get_level(self.bot.pg, user.id)
- # threshold = (level + 1) * 50 + xp_spent
- # if threshold < total_xp - xp_spent:
- # await ctx.send(f"`{user}` has spent {xp_spent} of {total_xp} experience points and can level up for {threshold} xp.")
- # else:
- # await ctx.send(f"`{user}` has spent {xp_spent} of {total_xp} experience points and requires {threshold - (total_xp - xp_spent)} xp to level up.")
- #
- # @commands.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 get_xp(self.bot.pg, ctx.author.id)
- # xp_available = total_xp - xp_spent
- # level = await get_level(self.bot.pg, ctx.author.id)
- # threshold = (level + 1) * 50 + xp_spent
- # if xp_available < threshold:
- # await ctx.send(f"Not yet, you require {threshold - xp_available} more XP to level up.")
- # else:
- # await level_up(self.bot.pg, ctx.author.id, threshold)
- # await ctx.send(f"You have gained three ability points climbed the ranks for {threshold} XP, leaving you {xp_available - threshold} remaining.")
- # await increment_all_coin(self.bot.pg)
- #
- # @commands.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 get_theft_skill(self.bot.pg, ctx.author.id < 1):
- # await ctx.send("You do not have the `Theft` skill.")
- # return
- #
- # victim_id = get_random_player(self.bot.pg)
- # await ctx.send(f"You have decided to rob{self.bot.get_user(victim_id)}, unfortunately crime has not been invited yet.")
- #
- # @commands.command(
- # description="Simulate dice rolls.",
- # brief="Roll dice",
- # help="Roll two dice."
- # )
- # async def dice(self, ctx: commands.Context, amount: Optional[int], sides: Optional[int]):
- # # Halt on ignore list or games channel settings.
- # if await check_ignore(self.bot.pg, ctx.author, ctx.channel):
- # return
- #
- # if not amount:
- # amount = 2
- # if not sides:
- # sides = 6
- #
- # if amount < 1:
- # await ctx.send("You want me to roll less than one die? How!?")
- # elif amount > 25:
- # await ctx.send("I can not hold so many dice at one time.")
- # elif sides < 2:
- # await ctx.send("A die has physical minimum of 2 sides. Don't ask for impossible objects.")
- # elif sides > 256:
- # await ctx.send("My tiny hands can not handle such large dice. Even if both are virtual.")
- # else:
- # embed = discord.Embed(title = "Dice roll", description=f"Rolling {amount} dice, with {sides} sides.")
- # while amount > 0:
- # embed.insert_field_at(0, name=f"Die {amount}", value=random.randint(1, sides), inline=True)
- # amount -= 1
- # await ctx.send(embed=embed)
- #
- # @commands.command(
- # description="Ask the magic 8-ball.",
- # brief="Pose question",
- # help="Simulate the iconic 8-ball gimmic.",
- # name="8ball"
- # )
- # async def eightball(self, ctx: commands.Context, *, question: str = None):
- # # Halt on ignore list or games channel settings.
- # if await check_ignore(self.bot.pg, ctx.author, ctx.channel):
- # return
- #
- # if not question:
- # messages = [
- # "Don't forget to ask a question...",
- # "Hey, that's not a question!",
- # "What would you like to know?",
- # "You want me to predict nothing?",
- # "Are you intentionally not asking a question?",
- # "Ask a question you tease!",
- # "You will die alone.",
- # ]
- # elif question.strip().count(" ") == 0:
- # messages = [
- # "What?",
- # "That is not a question",
- # "Can you use more than one word?",
- # "What is the question?",
- # "Sorry?"
- # ]
- # elif question.strip()[-1] != "?":
- # messages = [
- # "Did you forget to end with a question mark?",
- # "Is that a statement or question?",
- # "Don't questions usually end with a question mark?",
- # "Don't forget to use punctuation."
- # ]
- # else:
- # messages = [
- # "Yes.",
- # "No.",
- # "Affirmative.",
- # "No way!",
- # "Negative.",
- # "Positive.",
- # "Correct.",
- # "Incorrect.",
- # "Likely",
- # "Unlikely",
- # "Maybe.",
- # "Definately!",
- # "Perhaps?",
- # "Most indubitably.",
- # "Does the pope shit in the woods?",
- # "When hell freezes over.",
- # "Only between 9 and 5.",
- # "Only just before you die.",
- # "ERROR: Probability failure.",
- # "Ask again later.",
- # "I don't know.",
- # "Unpredictable.",
- # "Unknown",
- # ]
- # await ctx.send(random.choice(messages))
|