1
0

games.py 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. from discord.ext import commands
  2. import discord
  3. import random
  4. from typing import Optional
  5. 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
  6. #from local_settings import COMMAND_PREFIX
  7. from common.settings import check_ignore
  8. async def setup(bot: commands.Bot):
  9. await bot.add_cog(Games(bot))
  10. class Games(commands.Cog):
  11. """Gaming commands."""
  12. def __init__(self, bot: commands.Bot):
  13. self.bot = bot
  14. # @commands.command(
  15. # description="Check the level for a player.",
  16. # brief="Get player level",
  17. # help="View game level of player."
  18. # )
  19. # async def level(self, ctx: commands.Context, user: Optional[discord.User]):
  20. # # Halt on ignore list or games channel settings.
  21. # if await check_ignore(self.bot.pg, ctx.author, ctx.channel):
  22. # return
  23. #
  24. # if not user:
  25. # user = ctx.author
  26. # level = await get_level(self.bot.pg, user.id)
  27. #
  28. # if level == 0:
  29. # if ctx.author == user:
  30. # await ctx.send(f"You are not playing, join the game with `/levelup`")
  31. # else:
  32. # await ctx.send(f"`{user}` is not playing.")
  33. # else:
  34. # xp_spent, total_xp = await get_xp(self.bot.pg, user.id)
  35. # ability_points_spent = await get_ability_points_spent(self.bot.pg, user.id)
  36. # coin = await get_coin(self.bot.pg, user.id)
  37. # karma = await get_karma(self.bot.pg, user.id)
  38. # if ctx.author == user:
  39. # await ctx.send(f"You rank at level **{level}**. (exp **{xp_spent}**/{total_xp} | abp **{ability_points_spent}**/{level * 3} | coin **{coin}** | karma **{karma}**)")
  40. # else:
  41. # await ctx.send(f"`{user}` ranks at level **{level}**. (**{xp_spent}**/{total_xp} | abp **{ability_points_spent}**/{level * 3}) | coin **{coin}** | karma **{karma}**")
  42. #
  43. # @commands.command(
  44. # description="Check the experience points for a player.",
  45. # brief="Get player xp",
  46. # help="View amount of XP a game player has."
  47. # )
  48. # async def xp(self, ctx: commands.Context, user: Optional[discord.User]):
  49. # # Halt on ignore list or games channel settings.
  50. # if await check_ignore(self.bot.pg, ctx.author, ctx.channel):
  51. # return
  52. #
  53. # if not user:
  54. # xp_spent, total_xp = await get_xp(self.bot.pg, ctx.author.id)
  55. # level = await get_level(self.bot.pg, ctx.author.id)
  56. # threshold = (level + 1) * 50 + xp_spent
  57. # if threshold < total_xp - xp_spent:
  58. # 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.")
  59. # else:
  60. # 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`.")
  61. # else:
  62. # xp_spent, total_xp = await get_xp(self.bot.pg, user.id)
  63. # level = await get_level(self.bot.pg, user.id)
  64. # threshold = (level + 1) * 50 + xp_spent
  65. # if threshold < total_xp - xp_spent:
  66. # await ctx.send(f"`{user}` has spent {xp_spent} of {total_xp} experience points and can level up for {threshold} xp.")
  67. # else:
  68. # 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.")
  69. #
  70. # @commands.command(
  71. # description="Attempt to gain a level.",
  72. # brief="Level up",
  73. # help="Try to rank up a level in the game by spending XP."
  74. # )
  75. # async def levelup(self, ctx: commands.Context):
  76. # # Halt on ignore list or games channel settings.
  77. # if await check_ignore(self.bot.pg, ctx.author, ctx.channel):
  78. # return
  79. #
  80. # xp_spent, total_xp = await get_xp(self.bot.pg, ctx.author.id)
  81. # xp_available = total_xp - xp_spent
  82. # level = await get_level(self.bot.pg, ctx.author.id)
  83. # threshold = (level + 1) * 50 + xp_spent
  84. # if xp_available < threshold:
  85. # await ctx.send(f"Not yet, you require {threshold - xp_available} more XP to level up.")
  86. # else:
  87. # await level_up(self.bot.pg, ctx.author.id, threshold)
  88. # await ctx.send(f"You have gained three ability points climbed the ranks for {threshold} XP, leaving you {xp_available - threshold} remaining.")
  89. # await increment_all_coin(self.bot.pg)
  90. #
  91. # @commands.command(
  92. # description="Rob another player",
  93. # brief="Rob a player",
  94. # help="Pursuit a robbery."
  95. # )
  96. # async def rob(self, ctx: commands.Context):
  97. # # Halt on ignore list or games channel settings.
  98. # if await check_ignore(self.bot.pg, ctx.author, ctx.channel):
  99. # return
  100. #
  101. # if get_theft_skill(self.bot.pg, ctx.author.id < 1):
  102. # await ctx.send("You do not have the `Theft` skill.")
  103. # return
  104. #
  105. # victim_id = get_random_player(self.bot.pg)
  106. # await ctx.send(f"You have decided to rob{self.bot.get_user(victim_id)}, unfortunately crime has not been invited yet.")
  107. #
  108. # @commands.command(
  109. # description="Simulate dice rolls.",
  110. # brief="Roll dice",
  111. # help="Roll two dice."
  112. # )
  113. # async def dice(self, ctx: commands.Context, amount: Optional[int], sides: Optional[int]):
  114. # # Halt on ignore list or games channel settings.
  115. # if await check_ignore(self.bot.pg, ctx.author, ctx.channel):
  116. # return
  117. #
  118. # if not amount:
  119. # amount = 2
  120. # if not sides:
  121. # sides = 6
  122. #
  123. # if amount < 1:
  124. # await ctx.send("You want me to roll less than one die? How!?")
  125. # elif amount > 25:
  126. # await ctx.send("I can not hold so many dice at one time.")
  127. # elif sides < 2:
  128. # await ctx.send("A die has physical minimum of 2 sides. Don't ask for impossible objects.")
  129. # elif sides > 256:
  130. # await ctx.send("My tiny hands can not handle such large dice. Even if both are virtual.")
  131. # else:
  132. # embed = discord.Embed(title = "Dice roll", description=f"Rolling {amount} dice, with {sides} sides.")
  133. # while amount > 0:
  134. # embed.insert_field_at(0, name=f"Die {amount}", value=random.randint(1, sides), inline=True)
  135. # amount -= 1
  136. # await ctx.send(embed=embed)
  137. #
  138. # @commands.command(
  139. # description="Ask the magic 8-ball.",
  140. # brief="Pose question",
  141. # help="Simulate the iconic 8-ball gimmic.",
  142. # name="8ball"
  143. # )
  144. # async def eightball(self, ctx: commands.Context, *, question: str = None):
  145. # # Halt on ignore list or games channel settings.
  146. # if await check_ignore(self.bot.pg, ctx.author, ctx.channel):
  147. # return
  148. #
  149. # if not question:
  150. # messages = [
  151. # "Don't forget to ask a question...",
  152. # "Hey, that's not a question!",
  153. # "What would you like to know?",
  154. # "You want me to predict nothing?",
  155. # "Are you intentionally not asking a question?",
  156. # "Ask a question you tease!",
  157. # "You will die alone.",
  158. # ]
  159. # elif question.strip().count(" ") == 0:
  160. # messages = [
  161. # "What?",
  162. # "That is not a question",
  163. # "Can you use more than one word?",
  164. # "What is the question?",
  165. # "Sorry?"
  166. # ]
  167. # elif question.strip()[-1] != "?":
  168. # messages = [
  169. # "Did you forget to end with a question mark?",
  170. # "Is that a statement or question?",
  171. # "Don't questions usually end with a question mark?",
  172. # "Don't forget to use punctuation."
  173. # ]
  174. # else:
  175. # messages = [
  176. # "Yes.",
  177. # "No.",
  178. # "Affirmative.",
  179. # "No way!",
  180. # "Negative.",
  181. # "Positive.",
  182. # "Correct.",
  183. # "Incorrect.",
  184. # "Likely",
  185. # "Unlikely",
  186. # "Maybe.",
  187. # "Definately!",
  188. # "Perhaps?",
  189. # "Most indubitably.",
  190. # "Does the pope shit in the woods?",
  191. # "When hell freezes over.",
  192. # "Only between 9 and 5.",
  193. # "Only just before you die.",
  194. # "ERROR: Probability failure.",
  195. # "Ask again later.",
  196. # "I don't know.",
  197. # "Unpredictable.",
  198. # "Unknown",
  199. # ]
  200. # await ctx.send(random.choice(messages))