Advertisement
Guest User

Daily

a guest
Mar 3rd, 2018
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.58 KB | None | 0 0
  1.     @commands.command(aliases=["payday"])
  2.     async def daily(self, ctx):
  3.         connection = await aiomysql.connect(user=config.db.user,
  4.                                             password=config.db.password,
  5.                                             host=config.db.host,
  6.                                             port=config.db.port,
  7.                                             db=config.db.database)
  8.         user = ctx.message.author
  9.         if await self.usercheck("economy", user.id) is False:
  10.             await ctx.send("You don't have a bank account 😦, use `register` to make one.")
  11.             return
  12.         else:
  13.             async with connection.cursor() as cur:
  14.                 await cur.execute(f"SELECT payday FROM economy WHERE userid = {user.id}")
  15.                 getdb = await cur.fetchone()
  16.             timenow = datetime.datetime.utcfromtimestamp(time.time()).strftime("%d")
  17.             timecheck = datetime.datetime.utcfromtimestamp(int(getdb[0])).strftime("%d")
  18.             if timecheck == timenow:
  19.                 tomorrow = datetime.datetime.replace(datetime.datetime.now() + datetime.timedelta(days=1),
  20.                                                      hour=0, minute=0, second=0)
  21.                 delta = tomorrow - datetime.datetime.now()
  22.                 timeleft = time.strftime("%H", time.gmtime(delta.seconds))
  23.                 await ctx.send(f"Wait another {timeleft} hours before using daily again...")
  24.                 return
  25.             async with connection.cursor() as cur:
  26.                 await cur.execute(f"SELECT balance FROM economy WHERE userid = {user.id}")
  27.                 eco = await cur.fetchone()
  28.             eco = int(eco[0])
  29.  
  30.             # Voters X3 Payday #############################
  31.             url = "https://discordbots.org/api/bots/310039170792030211/votes"
  32.             async with aiohttp.ClientSession(headers={"Authorization": config.dbots.key}) as cs:
  33.                 async with cs.get(url) as r:
  34.                     res = await r.json()
  35.             for x in res:
  36.                 if str(x['id']) == str(ctx.message.author.id):
  37.                     async with connection.cursor() as cur:
  38.                         await cur.execute(f"UPDATE economy SET balance = {eco + 7500} WHERE userid = {user.id}")
  39.                         await connection.commit()
  40.                         await cur.execute(f"UPDATE economy SET payday = {int(time.time())} WHERE userid = {user.id}")
  41.                         await connection.commit()
  42.                     embed = discord.Embed(color=0xDEADBF,
  43.                                           title="Daily Credits",
  44.                                           description="Recieved 2500 + 5000 Daily credits - Voter Bonus!")
  45.                     await ctx.send(embed=embed)
  46.                     break
  47.             #################################################
  48.             else:
  49.                 async with connection.cursor() as cur:
  50.                     await cur.execute(f"UPDATE economy SET balance = {eco + 2500} WHERE userid = {user.id}")
  51.                     await connection.commit()
  52.                     await cur.execute(f"UPDATE economy SET payday = {int(time.time())} WHERE userid = {user.id}")
  53.                     await connection.commit()
  54.                 embed = discord.Embed(color=0xDEADBF,
  55.                                       title="Daily Credits",
  56.                                       description="Recieved 2500 Daily credits!")
  57.                 embed.set_footer(text="Pssst voting will give you 3 times the daily bonus OwO, vote with .vote")
  58.                 await ctx.send("Received 2500 credits!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement