Advertisement
Tranquility3

Bit-paste

May 20th, 2021
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 29.73 KB | None | 0 0
  1. import re
  2. from datetime import datetime
  3. from copy import deepcopy
  4. from asyncio.tasks import all_tasks
  5. import emojis
  6. import asyncio
  7. import discord
  8. import math
  9. from discord.ext import commands, tasks
  10. from dateutil.relativedelta import relativedelta
  11. import mysql.connector
  12. import json
  13. import cogs._json
  14. import utils.json_loader
  15. import utils.mysql_help as conn
  16. import path
  17. import discord.utils
  18. import random
  19.  
  20.  
  21. #async def addExp(self, ctx, member=None ,value=None):
  22.  
  23. game_board_url = "http://tinypix.top/images/2021/05/05/fVNtI.png"
  24.  
  25. async def getLocation(self, ctx, location_id, game_id, players):
  26. #---------------------------------------------------------------
  27. # Find Location, linked locations and Location Instance
  28. #---------------------------------------------------------------
  29.  
  30. #Find Location
  31. sql = "SELECT * FROM arkopoly_locs WHERE id = %s" % (location_id)
  32. check= await conn.query(sql)
  33. check = check[0]
  34.  
  35. #Find linked locations
  36. sql = "SELECT id FROM arkopoly_locs WHERE loc_type = %s" % (check[2])
  37. linked_check= await conn.query(sql)
  38. linked_check = linked_check[0]
  39.  
  40. #Find location instance
  41. sql = "SELECT * FROM arkopoly_loc_instance WHERE game_id = %s AND loc_id = %s" % (game_id, location_id)
  42. instance_check= await conn.query(sql)
  43. instance_check = instance_check[0]
  44.  
  45. owner = players[instance_check[3]-1]
  46. hotel = "Yes" if instance_check[5] > 0 else "No"
  47. mortgage = "Yes" if instance_check[6] > 0 else "No"
  48.  
  49. #print("Linked locations",linked_check)
  50. location = {
  51. "id": check[0],
  52. "name": check[1],
  53. "type": check[2],
  54. "price": check[3],
  55. "mortgage": check[4],
  56. "rent": check[5],
  57. "1house": check[6],
  58. "2house": check[7],
  59. "3house": check[8],
  60. "4house": check[9],
  61. "hotel": check[10],
  62. "baseCost": check[11],
  63. "boardImg": check[12],
  64. "cardImg": check[13],
  65. "linked": linked_check,
  66. "owner": owner,
  67. "numHouses": instance_check[4],
  68. "hotel": hotel,
  69. "mortgaged": mortgage
  70.  
  71. }
  72. #print("return: ",location)
  73. return(location)
  74.  
  75.  
  76.  
  77.  
  78. class opoly(commands.Cog):
  79. def __init__(self, bot):
  80. self.bot = bot
  81.  
  82.  
  83. @commands.Cog.listener()
  84. async def on_ready(self):
  85. print(f"{self.__class__.__name__} Cog has been loaded\n-----")
  86.  
  87.  
  88.  
  89.  
  90. """
  91. Create a Arkopoly game. Command takes 3 members (plus owner)
  92. """
  93. @commands.command(
  94. name='ArkopolyCreateGame',
  95. aliases=['acg'],
  96. description="Create a game of Arkopoly",
  97.  
  98. )
  99. @commands.has_role("Game Player")
  100. @commands.has_permissions(send_messages=True)
  101. async def createArkopolyGame(self, ctx, user1: discord.Member, user2: discord.Member, user3: discord.Member):
  102. now = datetime.now()
  103. formatted_date = now.strftime('%Y-%m-%d %H:%M:%S')
  104. #Get guild and game players from command
  105. guild_id = ctx.guild.id
  106. p1_id = ctx.author.id
  107. p2_id = user1.id
  108. p3_id = user2.id
  109. p4_id = user3.id
  110. #print(user)
  111. #print(user2)
  112. #print(user3)
  113. players = [ctx.author,user1, user2, user3]
  114.  
  115. print("names: ",ctx.author.display_name, ", ",user1.display_name,", ",user2.display_name,", ",user3.display_name)
  116.  
  117. #check game owner is not running more than 1 game
  118. sql = "SELECT id FROM arkopoly_games WHERE player1 = '%s' and guild_id = %s and STATUS = %s" % (p1_id, guild_id, "started")
  119. check= await conn.query(sql)
  120. print(check)
  121. #check = int(check[0][0])
  122. #print(len(check))
  123. sql = "SELECT chips FROM Users WHERE discord_id = '%s' and guild_id = %s" % (p1_id, guild_id)
  124. chips_check= await conn.query(sql)
  125. chips_check = chips_check[0][0]
  126. print(chips_check)
  127.  
  128. if check is not None:
  129. embed = discord.Embed(
  130. title=f"You have exceeded the maximum number of LIVE games",
  131. )
  132. embed.set_thumbnail(url=self.bot.user.avatar_url)
  133. await ctx.send(embed=embed)
  134. elif chips_check<10:
  135. embed = discord.Embed(
  136. title=f"You need some chips to start a game!",
  137. )
  138. embed.set_thumbnail(url=self.bot.user.avatar_url)
  139. await ctx.send(embed=embed)
  140. else:
  141. new_value = chips_check-1
  142. sql = "UPDATE Users SET chips = %s WHERE discord_id = %s AND guild_id = %s"
  143. val = (new_value, formatted_date, ctx.author.id, guild_id)
  144. await conn.upsert(sql,val)
  145.  
  146. sql = "SELECT * FROM arkopoly_games WHERE guild_id = %s" % (guild_id)
  147. gamecheck= await conn.query(sql)
  148.  
  149.  
  150. Game_name = ctx.author.display_name + "s Arkopoly Game"
  151. category_name = 'Games Manager'
  152.  
  153.  
  154. if len(gamecheck) == 0:
  155. category_role = discord.utils.get(ctx.guild.roles, name="Game Player")
  156. overwrites = {
  157. ctx.guild.default_role: discord.PermissionOverwrite(read_messages=False),
  158. ctx.guild.me: discord.PermissionOverwrite(read_messages=True),
  159. category_role: discord.PermissionOverwrite(read_messages=True),
  160. }
  161. category = await ctx.guild.create_category(name=category_name, overwrites=overwrites)
  162.  
  163. category = discord.utils.get(ctx.guild.categories, name='Games Manager')
  164. game_role = Game_name
  165. the_role = await ctx.guild.create_role(name=game_role)
  166. for i in players:
  167. user = i
  168. await user.add_roles(the_role)
  169. overwrites = {
  170. ctx.guild.default_role: discord.PermissionOverwrite(read_messages=False),
  171. ctx.guild.me: discord.PermissionOverwrite(read_messages=True),
  172. the_role: discord.PermissionOverwrite(read_messages=True),
  173. }
  174. channel = await ctx.guild.create_text_channel(
  175. name=Game_name,
  176. overwrites=overwrites,
  177. category=self.bot.get_channel(category.id),
  178. )
  179. print("channel id: ",channel.id)
  180.  
  181.  
  182. turn = random.randint(1, 4)
  183. cash = 15000
  184. sql = "INSERT INTO arkopoly_games (guild_id, game_name, channel_id, player1, player2, player3, player4, turn, date_started, turn_datetime, credits_p1, credits_p2, credits_p3, credits_p4, pos_p1, pos_p2, pos_p3, pos_p4, STATUS) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)"
  185. val = (guild_id, Game_name, channel.id, p1_id, p2_id, p3_id, p4_id, turn, formatted_date, formatted_date, cash, cash, cash, cash, 1, 1, 1, 1, "started")
  186. await conn.upsert(sql,val)
  187. sql = "SELECT id FROM arkopoly_games WHERE player1 = '%s' and guild_id = %s and STATUS = '%s'" % (p1_id, guild_id, "started")
  188. newgamecheck= await conn.query(sql)
  189.  
  190. print("new game id: ",newgamecheck)
  191. game_id = newgamecheck[0][0]
  192.  
  193.  
  194.  
  195. counter = 1
  196. loc_id = 1
  197. while counter < 41:
  198. sql = "INSERT INTO arkopoly_loc_instance (game_id, loc_id, loc_owner, loc_houses, loc_hotels, loc_mortgaged) VALUES (%s, %s, %s, %s, %s, %s)"
  199. val = (game_id, loc_id, 0, 0, 0, 0)
  200. await conn.upsert(sql,val)
  201. loc_id += 1
  202. counter += 1
  203.  
  204. embed = discord.Embed(
  205. title=f"**{Game_name}** has started",
  206. )
  207. embed.set_thumbnail(url=self.bot.user.avatar_url)
  208. await ctx.send(embed=embed)
  209.  
  210. embed = discord.Embed(
  211. title=f"Welcome to **{Game_name}**",
  212. description=f"Game Owner:\n{ctx.author.mention}\n\nOther Players:\n{user1.mention}\n{user2.mention}\n{user3.mention}",
  213. )
  214. embed.set_thumbnail(url=self.bot.user.avatar_url)
  215. await channel.send(embed=embed)
  216.  
  217.  
  218.  
  219.  
  220. @commands.command(
  221. name='ArkopolyEndGame',
  222. aliases=['aeg'],
  223. description="End a game of Arkopoly",
  224.  
  225. )
  226. @commands.has_role("Game Player")
  227. @commands.has_permissions(send_messages=True)
  228. async def endArkopolyGame(self, ctx):
  229. channel = ctx.channel
  230. if str(ctx.channel.category) != "Games Manager":
  231. embed = discord.Embed(
  232. title=f"You can only run this command from your game channel!",
  233. )
  234. embed.set_thumbnail(url=self.bot.user.avatar_url)
  235. await channel.send(embed=embed)
  236. return
  237.  
  238. guild_id = ctx.guild.id
  239.  
  240.  
  241.  
  242. now = datetime.now()
  243. p1_id = ctx.author.id
  244. sql = "SELECT * FROM arkopoly_games WHERE player1 = '%s' and guild_id = %s and STATUS = 'started'" % (p1_id, guild_id)
  245. check= await conn.query(sql)
  246. #channel_name = ctx.channel.name
  247. #print (channel)
  248. print(check)
  249. if len(check) == 0:
  250. await channel.send("You do not own any games. Only the game owner can end a game.")
  251. else:
  252.  
  253. check = check[0]
  254.  
  255. game_id = check[0]
  256. game_name = check[2]
  257. print("Game ID: ", game_id)
  258. player1 = check[4]
  259. player2 = check[5]
  260. player3 = check[6]
  261. player4 = check[7]
  262.  
  263. players = [player1, player2, player3, player4]
  264.  
  265. embed = discord.Embed(
  266. title=f"End Game Confirmation",
  267. description =f"**Are you sure you want to end {game_name}**",
  268. )
  269. m = await channel.send(embed=embed)
  270. await m.add_reaction("✅")
  271. await m.add_reaction("🇽")
  272.  
  273. try:
  274. reaction, member = await self.bot.wait_for(
  275. "reaction_add",
  276. timeout=60,
  277. check=lambda reaction, user: user.id == ctx.author.id
  278. and reaction.message.channel == ctx.channel
  279. )
  280. except asyncio.TimeoutError:
  281. await channel.send("Confirmation Failure. Please try again.")
  282. return
  283.  
  284. if str(reaction.emoji) not in ["✅", "🇽"] or str(reaction.emoji) == "🇽":
  285. await channel.send("Cancelling attempt to end the game!")
  286. return
  287. else:
  288. print("Confirmation accepted")
  289.  
  290.  
  291. sql = """UPDATE arkopoly_games SET STATUS = %s WHERE id = %s"""
  292. val = ('ended',game_id)
  293. await conn.upsert(sql,val)
  294. print("players: ",players)
  295. for i in players:
  296. print("user id: ",i)
  297. user = ctx.guild.get_member(i)
  298. print("user to dm: ",user)
  299. channel = await user.create_dm()
  300. embed = discord.Embed(
  301. title=f"End Game Confirmation",
  302. description =f"**{ctx.author.display_name}** has ended {game_name}",
  303. )
  304. m = await channel.send(embed=embed)
  305. print(ctx.guild.roles)
  306. #find role object
  307. role_object = discord.utils.get(ctx.guild.roles, name=game_name)
  308. print(role_object)
  309. #delete role
  310.  
  311. await role_object.delete()
  312. #DELETE the channel
  313. await ctx.channel.delete()
  314.  
  315. @commands.command(
  316. name='ArkopolyMyTurn',
  317. aliases=['myturnark'],
  318. description="End a game of Arkopoly",
  319.  
  320. )
  321. @commands.has_role("Game Player")
  322. @commands.has_permissions(send_messages=True)
  323. async def ArkopolyMyTurn(self, ctx):
  324. """
  325. Process:
  326. Step 1 options
  327. 1- properties owned
  328. 2- buy houses
  329. - property to build at
  330. - quantity
  331. - pay confirmation
  332. 3- trade
  333. - property to trade
  334. - user to trade with
  335. - credits or property
  336. - trade confirmation
  337. 4- mortgage property
  338. - property to mortgage
  339. - mortgage confirmation
  340. 5- roll dice
  341. 6- buy property
  342. - buy confirmation
  343. 7- end turn
  344. - end turn confirmation
  345.  
  346.  
  347. """
  348. guild_id = ctx.guild.id
  349. channel_id = ctx.channel.id
  350. print("channel id: ",channel_id)
  351. channel = ctx.channel
  352.  
  353. #CATEGORY CHECK
  354. if str(ctx.channel.category) != "Games Manager":
  355. embed = discord.Embed(
  356. title=f"You can only run this command from your game channel!",
  357. )
  358. embed.set_thumbnail(url=self.bot.user.avatar_url)
  359. await channel.send(embed=embed)
  360. return
  361.  
  362. #FIND GAME
  363. sql = "SELECT * FROM arkopoly_games WHERE channel_id = '%s' and guild_id = %s and STATUS = 'started'" % (ctx.channel.id, guild_id)
  364. check= await conn.query(sql)
  365. print("Game Check: ",check)
  366.  
  367.  
  368. #-----------------------------------
  369. # SET GAME VARIABLES
  370. #-----------------------------------
  371. game_info = check[0]
  372.  
  373. game_id = game_info[0]
  374. game_guild_id = game_info[1]
  375. game_name = game_info[2]
  376. game_channel_id = game_info[3]
  377. player1 = ctx.guild.get_member(game_info[4])
  378. player2 = ctx.guild.get_member(game_info[5])
  379. player3 = ctx.guild.get_member(game_info[6])
  380. player4 = ctx.guild.get_member(game_info[7])
  381.  
  382.  
  383.  
  384.  
  385. game_turn = game_info[8]-1
  386. game_startDate = game_info[9]
  387. game_last_turn_date = game_info[10]
  388.  
  389. p1_cash = game_info[11]
  390. p2_cash = game_info[12]
  391. p3_cash = game_info[13]
  392. p4_cash = game_info[14]
  393.  
  394.  
  395.  
  396. p1_pos = game_info[15]
  397. p2_pos = game_info[16]
  398. p3_pos = game_info[17]
  399. p4_pos = game_info[18]
  400.  
  401. players_cash = [p1_cash, p2_cash, p3_cash, p4_cash]
  402. players = [player1, player2, player3, player4]
  403. all_players_pos = [p1_pos, p2_pos, p3_pos, p4_pos]
  404.  
  405. #----------------------------
  406. # who is still in game?
  407. #----------------------------
  408. still_in_players = []
  409. still_in_players_cash = []
  410. still_in_player_pos = []
  411. for i in players:
  412. the_list_index = players.index(i)
  413. if players_cash[the_list_index] > 0:
  414. still_in_players.append(i)
  415. still_in_player_pos.append(all_players_pos[the_list_index])
  416. still_in_players_cash.append(players_cash[the_list_index])
  417.  
  418.  
  419.  
  420. print("Starting players: ",players)
  421. print("Starting Cash: ",players_cash)
  422. print("Starting position: ",all_players_pos)
  423.  
  424. print("Still in players: ",still_in_players)
  425. print("Still in cash: ",still_in_players_cash)
  426. print("Still in positions: ",still_in_player_pos)
  427.  
  428. print("Game Turn: ",game_turn)
  429. game_status = game_info[19]
  430.  
  431. player_turn = still_in_players[game_turn]
  432. print("Player turn: ",player_turn)
  433.  
  434. player_cash_turn = still_in_players_cash[game_turn]
  435. player_pos_turn = still_in_player_pos[game_turn]
  436.  
  437. #player_turn_index = players
  438.  
  439. #--------------------------------------------------------
  440. # FIND WHERE THE PLAYERS ARE ON THE BOARD
  441. #--------------------------------------------------------
  442.  
  443. sql = "SELECT * FROM arkopoly_locs"
  444. player_pos_info= await conn.query(sql)
  445. #player_pos_info = player_pos_info[0]
  446.  
  447. p1_pos_id = player_pos_info[p1_pos-1][0]
  448. p1_pos_name = player_pos_info[p1_pos-1][1]
  449. p1_pos_type = player_pos_info[p1_pos-1][2]
  450.  
  451. p2_pos_id = player_pos_info[p2_pos-1][0]
  452. p2_pos_name = player_pos_info[p2_pos-1][1]
  453. p2_pos_type = player_pos_info[p2_pos-1][2]
  454.  
  455. p3_pos_id = player_pos_info[p3_pos-1][0]
  456. p3_pos_name = player_pos_info[p3_pos-1][1]
  457. p3_pos_type = player_pos_info[p3_pos-1][2]
  458.  
  459. p4_pos_id = player_pos_info[p4_pos-1][0]
  460. p4_pos_name = player_pos_info[p4_pos-1][1]
  461. p4_pos_type = player_pos_info[p4_pos-1][2]
  462.  
  463.  
  464.  
  465.  
  466.  
  467.  
  468.  
  469. #------------------------------------------------------
  470. # CHECK PLAYER IS ABLE TO RUN MYTURNARK COMMAND
  471. #------------------------------------------------------
  472.  
  473. if ctx.author not in still_in_players:
  474. embed = discord.Embed(
  475. title=f"You are no longer in this game!",
  476. )
  477. embed.set_thumbnail(url=self.bot.user.avatar_url)
  478. await channel.send(embed=embed)
  479. return
  480.  
  481. if ctx.author != player_turn:
  482. embed = discord.Embed(
  483. title=f"It is not your turn yet!\nIt is currently **{player_turn.display_name}'s turn**",
  484. )
  485. embed.set_thumbnail(url=self.bot.user.avatar_url)
  486. await channel.send(embed=embed)
  487. return
  488.  
  489.  
  490. #------------------------------------
  491. # CHECK WHO OWNS WHAT
  492. #------------------------------------
  493. sql = "SELECT * FROM arkopoly_loc_instance WHERE game_id = %s" % (game_id)
  494. loc_check= await conn.query(sql)
  495. #sql = "SELECT loc_id FROM arkopoly_loc_instance WHERE game_id = %s and loc_owner = 0" % (game_id)
  496. #unowned_loc_check= await conn.query(sql)
  497.  
  498. ##create player location lists
  499. unowned_loc_list = []
  500. p1_loc_list = []
  501. p2_loc_list = []
  502. p3_loc_list = []
  503. p4_loc_list = []
  504.  
  505. p1_loc_id_list =[]
  506. p2_loc_id_list =[]
  507. p3_loc_id_list =[]
  508. p4_loc_id_list =[]
  509.  
  510. #NO OWN LIST
  511. no_own = ['Start', 'Loot Box', 'Supply Crate', 'Trough Refill', 'Green Obelisk', 'Blue Obelisk', 'Red Obelisk','Gen Refill']
  512.  
  513. for i in loc_check:
  514. if i[3] == 1:
  515. p1_loc_list.append(player_pos_info[i[2]-1][1])
  516. p1_loc_id_list.append(player_pos_info[i[2]-1][0])
  517. elif i[3] == 2:
  518. p2_loc_list.append(player_pos_info[i[2]-1][1])
  519. p2_loc_id_list.append(player_pos_info[i[2]-1][0])
  520. elif i[3] == 3:
  521. p3_loc_list.append(player_pos_info[i[2]-1][1])
  522. p3_loc_id_list.append(player_pos_info[i[2]-1][0])
  523. elif i[3] == 4:
  524. p4_loc_list.append(player_pos_info[i[2]-1][1])
  525. p4_loc_id_list.append(player_pos_info[i[2]-1][0])
  526. elif i[3] == 0:
  527. loc_to_check =player_pos_info[i[2]-1][1]
  528. if loc_to_check not in no_own:
  529. unowned_loc_list.append(player_pos_info[i[2]-1][1])
  530.  
  531. ##SET LOCATION LISTS TO NONE IF THEY@RE LEN= 0
  532. if len(p1_loc_list)==0:
  533. p1_loc_list = "None"
  534. if len(p2_loc_list)==0:
  535. p2_loc_list = "None"
  536. if len(p3_loc_list)==0:
  537. p3_loc_list = "None"
  538. if len(p4_loc_list)==0:
  539. p4_loc_list = "None"
  540. if len(unowned_loc_list) ==0:
  541. unowned_loc_list = "None"
  542.  
  543. #print("P1 owned locations: ", p1_loc_list)
  544. #print("P2 owned locations: ", p2_loc_list)
  545. #print("P3 owned locations: ", p3_loc_list)
  546. #print("P4 owned locations: ", p4_loc_list)
  547.  
  548. ##### GETLocation for the Position on the player_turn
  549.  
  550. player_turn_info = await getLocation(self, ctx, player_pos_turn, game_id, players)
  551.  
  552.  
  553.  
  554. ##### CREATE MENUS EMBEDS FOR PAGINATION
  555.  
  556.  
  557. # EMBED LIST
  558. embed_list = []
  559.  
  560.  
  561. ##SETUP PAGINATION
  562. #text = [rewind, Back , Die, House, Hotel, trade, properties, Buy, Forward, Fastforward, ?, pencil]
  563. buttons = [ u"\u23EA", u"\u25C0", u"\U0001F3B2", u"\U0001F3E0", u"\U0001F3E8", u"\U0001F500", u"\U0001F4DA", u"\U0001F4DD", u"\u25B6", u"\u23E9", u"\U0001F5FA", u"\U0001F4DD"]
  564. #buttonA pencil, map, die, properties, trade
  565. buttonA =[u"\U0001F4DD",u"\U0001F46A",u"\U0001F5FA",u"\U0001F3B2",u"\U0001F4DA","\U0001F500",u"\u2753",u"\u274C"]
  566. #buttonb rewind,back,house,hotel,mortgage,cancel,forward,fastforward
  567. buttonB =[u"\u23EA", u"\u25C0", u"\u25B6", u"\u23E9", u"\U0001F3B2", u"\U0001F3E0", u"\u2753", u"\U0001F4DC",u"\u274C"]
  568. buttonC =[u"\u2705", u"\u274C"]
  569. #family emoji u"\u1F468"
  570. all_buttons = buttonA + buttonB + buttonC
  571.  
  572.  
  573. #HELP INSTRUCTSION EMBED
  574. page1 = discord.Embed(
  575. title=f"Hey {player_turn.display_name}, it is your turn!",
  576. description =f"Before you roll the dice for your turn you can view your properties, buy bases and admin bases or mortgage the properties you own.\nYou can also trade properties with other players.\n Use the reactions below to choose what you want to do.",
  577. )
  578. page1.add_field(
  579. name="Options",
  580. value= u"\U0001F4DD"+" - Game Status and your position\n"+u"\U0001F46A"+" - View info on all the players\n"+u"\U0001F5FA"+" - View the Game board\n"+u"\U0001F3B2"+" - Roll Dice (this will end your turn!)\n"+u"\U0001F4DA"+" - View your properties (Build Bases and Admin Bases and Mortgage properties\n"+u"\U0001F500"+" - Setup a trade with another player for a property\n"+u"\u2753"+" - Help\n"+u"\u274C"+" - Exit",
  581. inline=True
  582. )
  583.  
  584.  
  585.  
  586. page1.set_thumbnail(url=self.bot.user.avatar_url)
  587. #sent = await channel.send(embed=page1)
  588. embed_list.append(page1)
  589.  
  590.  
  591.  
  592. #STATUS EMBED
  593.  
  594. page2 = discord.Embed(
  595. title=f"Game Status",
  596. description =f"**__Game Name:__** {game_name}\n**Started by:** {player1}\n**Started on:** {game_startDate}\n**Players:**\n{player2}\n{player3}\n{player4}\n--------------",
  597. )
  598. page2.add_field(
  599. name=f"**{player_turn.display_name}**",
  600. value= f"**Cash:** *{player_cash_turn}*\n**Location:** *{player_pos_turn}*\n**Owned Property:** *{p1_loc_list}*\n--------------",
  601. inline=True
  602. )
  603. page2.set_image(url = player_turn_info["boardImg"])
  604. embed_list.append(page2)
  605.  
  606. #sent = await channel.send(embed=page2)
  607.  
  608. #OTHER PLAYERS
  609. page3 = discord.Embed(
  610. title=f"Other players",
  611. #description =f"**__Game Name:__** {game_name}\n**Started by:** {player1}\n**Started on:** {game_startDate}\n**Players:**\n{player2}\n{player3}\n{player4}\n--------------",
  612. )
  613. page3.add_field(
  614. name="**Player 2**",
  615. value= f"**Name:** *{player2.display_name}*\n**Cash:** *{p2_cash}*\n**Location:** *{p2_pos_name}*\n**Owned Property:** *{p2_loc_list}*\n--------------",
  616. inline=True
  617. )
  618. page3.add_field(
  619. name="**Player 3**",
  620. value= f"**Name:** *{player3.display_name}*\n**Cash:** *{p3_cash}*\n**Location:** *{p3_pos_name}*\n**Owned Property:** *{p3_loc_list}*\n--------------",
  621. inline=True
  622. )
  623. page3.add_field(
  624. name="**Player 4**",
  625. value= f"**Name:** *{player4.display_name}*\n**Cash:** *{p4_cash}*\n**Location:** *{p4_pos_name}*\n**Owned Property:** *{p4_loc_list}*\n--------------",
  626. inline=True
  627. )
  628. page3.add_field(
  629. name="**Unowned properties**",
  630. value= f"{unowned_loc_list}\n--------------",
  631. inline=True
  632. )
  633.  
  634. page3.set_thumbnail(url=self.bot.user.avatar_url)
  635. embed_list.append(page3)
  636.  
  637. #GAME BOARD
  638. page4 = discord.Embed(
  639. title=f"Game Board",
  640. #description =f"**__Game Name:__** {game_name}\n**Started by:** {player1}\n**Started on:** {game_startDate}\n**Players:**\n{player2}\n{player3}\n{player4}\n--------------",
  641. )
  642. page4.set_image(url=game_board_url)
  643. page4.set_thumbnail(url=self.bot.user.avatar_url)
  644. embed_list.append(page4)
  645.  
  646. #Dice Roll
  647. page5 = discord.Embed(
  648. title=f"Roll Dice",
  649. description =f"**Rolling the dice ends your turn. You cannot build bases or an admin bases or mortgage or trade properties once you rolled the dice.\n\nTo roll the dice tap on the **"+u"\u2705"+"\nOr "+u"\u274C"+" to exit.",
  650. )
  651. page5.set_image(url="http://tinypix.top/images/2021/05/19/iONK0.gif")
  652. page5.set_thumbnail(url=self.bot.user.avatar_url)
  653. embed_list.append(page5)
  654.  
  655. #trade
  656. page6 = discord.Embed(
  657. title=f"Trade",
  658. #description =f"**__Game Name:__** {game_name}\n**Started by:** {player1}\n**Started on:** {game_startDate}\n**Players:**\n{player2}\n{player3}\n{player4}\n--------------",
  659. )
  660. #page6.set_image(url="http://tinypix.top/images/2021/05/19/iONK0.gif")
  661. page6.set_thumbnail(url=self.bot.user.avatar_url)
  662. embed_list.append(page6)
  663.  
  664. #PROPERTIES EMBED (FOR LOOP
  665. sql = "SELECT * FROM arkopoly_locs WHERE loc_type >10"
  666. All_buyable_locs= await conn.query(sql)
  667. for location in All_buyable_locs:
  668. location_id = location[0]
  669. if location_id in p1_loc_id_list:
  670. result = await getLocation(self, ctx, location_id, game_id, players)
  671.  
  672.  
  673.  
  674. embed = discord.Embed(
  675. title=f"__My Properties__",
  676. description =f"**{result['name']}**\n**Number of bases: **{result['numHouses']}\n**Admin base:** {result['hotel']}\n**Mortgaged: **{result['mortgaged']}",
  677. )
  678.  
  679. embed.set_image(url=result["cardImg"])
  680.  
  681. embed_list.append(embed)
  682.  
  683.  
  684. current = 0
  685. msg = await ctx.send(embed = embed_list[current])
  686.  
  687. for button in buttonA:
  688. await msg.add_reaction(button)
  689.  
  690. while True:
  691. try:
  692. reaction, member = await self.bot.wait_for(
  693. "reaction_add",
  694. timeout=60,
  695. check=lambda reaction, user: user == ctx.author
  696. and reaction.emoji in all_buttons
  697. )
  698. except asyncio.TimeoutError:
  699. embed = embed_list[current]
  700. embed.set_footer(text="Timed Out.")
  701. await msg.clear_reactions()
  702. #buttonA =[u"\U0001F4DD",u"\U0001F5FA",u"\U0001F3B2",u"\U0001F4DA","\U0001F500"]
  703. # u"\u2753" - help
  704. #u"\U0001F4DD"+" - Game Status
  705. #u"\U0001F46A"+" - other players
  706. #u"\U0001F5FA"+" - Game board
  707. #u"\U0001F3B2"+" - Roll Dice
  708. #u"\U0001F4DA"+" - properties
  709. #u"\U0001F500"+" - Trade
  710.  
  711. # buttonB =[u"\u23EA", u"\u25C0", u"\U0001F3B2", u"\U0001F3E0",u"\U0001F4DC",u"\u274C", u"\u25B6", u"\u23E9"]
  712.  
  713. else:
  714. previous_page = current
  715. #Status
  716. if reaction.emoji == u"\U0001F4DD":
  717. current = 1
  718. #other players
  719. elif reaction.emoji == u"\U0001F46A":
  720. current = 2
  721. #board
  722. elif reaction.emoji == u"\U0001F5FA":
  723. current = 3
  724. #dice
  725. elif reaction.emoji == u"\U0001F3B2":
  726. current = 4
  727. #trade
  728. elif reaction.emoji == u"\U0001F500":
  729. current = 5
  730. #help
  731. elif reaction.emoji == u"\u2753":
  732. current = 0
  733.  
  734. #properties
  735. elif reaction.emoji == u"\U0001F4DA":
  736. current = 6
  737.  
  738. #rewind
  739. elif reaction.emoji == u"\u23EA":
  740. current = 6
  741. #back
  742. elif reaction.emoji == u"\u25C0":
  743. if current > 6:
  744. current -= 1
  745. #forward
  746. elif reaction.emoji == u"\u25B6":
  747. if current < len(embed_list)-1:
  748. current += 1
  749. #fastforward
  750. elif reaction.emoji == u"\u23E9":
  751. current = len(embed_list)-1
  752.  
  753.  
  754. #Dice roll
  755. #elif reaction.emoji == u"\U0001F3B2":
  756. # a=5
  757.  
  758. for button in all_buttons:
  759. await msg.remove_reaction(button, ctx.author)
  760.  
  761. if current != previous_page:
  762. await msg.edit(embed = embed_list[current])
  763. if current == 6:
  764. await msg.clear_reactions()
  765. for button in buttonB:
  766. await msg.add_reaction(button)
  767. elif current == 0:
  768. await msg.clear_reactions()
  769. for button in buttonA:
  770. await msg.add_reaction(button)
  771. elif current == 4:
  772. await msg.clear_reactions()
  773. for button in buttonC:
  774. await msg.add_reaction(button)
  775.  
  776.  
  777.  
  778.  
  779.  
  780.  
  781.  
  782.  
  783. #await getLocation(self, ctx, location_id)
  784.  
  785.  
  786.  
  787.  
  788.  
  789.  
  790.  
  791.  
  792.  
  793.  
  794.  
  795.  
  796.  
  797.  
  798.  
  799. def setup(bot):
  800. bot.add_cog(opoly(bot))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement