Advertisement
Guest User

Untitled

a guest
Jul 20th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.19 KB | None | 0 0
  1. @client.command()
  2. async def submit(ctx, member: discord.Member, score, oscore):
  3.     with open('profiles.json') as f:
  4.         profiles = json.load(f)
  5.     if member.id == ctx.author.id:
  6.         await ctx.send("wtf r u trying to do... u didnt 1v1 urself right?")
  7.     elif str(ctx.author.id) not in profiles:
  8.         await ctx.send(f"You have not registered. Do {prefix}register.")
  9.     elif str(member.id) not in profiles:
  10.         await ctx.send(f"This user has not registered. Tell them to do {prefix}register.")
  11.     else:
  12.         embed=discord.Embed(color=0x008040)
  13.         embed.add_field(name="Score Submitted", value=f"{score} (You) - {oscore} ({member.mention})", inline=False)
  14.         embed.set_footer(text="Tell your opponent to check their DMs!")
  15.         await ctx.send(embed=embed)
  16.  
  17.         # DM OPPONENT FOR CONFIRMATION
  18.         embed=discord.Embed(color=0x0080c0)
  19.         embed.add_field(name="Incoming score submission!", value=f"Received from {ctx.author.name}", inline=False)
  20.         embed.add_field(name=f"{oscore} (You) - {score} (Them)", value="React to confirm the match. This dialog will time out in 2 minutes.", inline=True)
  21.         embed.set_footer(text="DO NOT SUBMIT THIS MATCH AGAIN. ONLY ONE SUBMISSION AND CONFIRMATION IS REQUIRED.")
  22.         cmessage = await member.send(embed=embed)
  23.  
  24.         await cmessage.add_reaction("👍")
  25.        
  26.         def check(reaction, user):
  27.             return user == member and str(reaction.emoji) == '👍'
  28.  
  29.         try:
  30.             reaction, user = await client.wait_for('reaction_add', timeout=120.0, check=check)
  31.         except asyncio.TimeoutError:
  32.             await member.send("You ran out of time. Tell your opponent to submit again (or submit it yourself).")
  33.             await ctx.author.send("Your opponent did not confirm the match in time.")
  34.         else:
  35.             await member.send("Confirmed match.")
  36.             await ctx.author.send("Your opponent confirmed the match!")
  37.             #update stats time
  38.             with open('profiles.json') as f:
  39.                 profiles = json.load(f)
  40.            
  41.             # UPDATE STATS
  42.            
  43.             submitter = str(ctx.author.id)
  44.             confirmer = str(member.id)
  45.  
  46.             profiles[submitter]["games"] += 1
  47.             profiles[confirmer]["games"] += 1
  48.  
  49.             if score > oscore:
  50.                 profiles[submitter]["wins"] += 1
  51.                 profiles[confirmer]["losses"] += 1
  52.             elif oscore > score:
  53.                 profiles[confirmer]["wins"] += 1
  54.                 profiles[submitter]["losses"] += 1
  55.             else:
  56.                 profiles[submitter]["wins"] += 1
  57.                 profiles[confirmer]["wins"] += 1
  58.            
  59.             profiles[submitter]["kills"] += int(score)
  60.             profiles[submitter]["deaths"] += int(oscore)
  61.             profiles[confirmer]["kills"] += int(oscore)
  62.             profiles[confirmer]["deaths"] += int(score)
  63.  
  64.             # POINTS TIME!
  65.             profiles[submitter]["points"] += int(score) * 10
  66.             profiles[confirmer]["points"] += int(oscore) * 10
  67.  
  68.             with open('profiles.json', 'w', encoding='utf-8') as f:
  69.                 json.dump(profiles, f, ensure_ascii=False, indent=4)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement