SHARE
TWEET

Untitled

a guest Sep 17th, 2019 96 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import discord
  2. #import youtube_dl
  3. #import nacl
  4. import math
  5. import datetime
  6. import sqlite3
  7. import random
  8. import time
  9. from sqlite3 import Error
  10.  
  11. TOKEN = ''
  12.  
  13. client = discord.Client()
  14.  
  15. conn = sqlite3.connect("currency.db")
  16. cursor = conn.cursor()
  17.  
  18. '''
  19. Class Troop lists all the troops currently available in the shop for purchase along with each troop's properties.
  20.  
  21. Type = Offensive or Defensive Troop
  22. Name = Name of the Troop
  23. Dmg = The amount of damage the troop does per second
  24. Cost = How much the troop costs
  25. Desc = Description of the Troop
  26. curr = Currency needed to buy the troop (Bits or Iron)
  27. '''
  28.  
  29. class Troop():
  30.     def __init__(self, type, name, dmg, cost, desc, curr):
  31.         self._type = type
  32.         self._name = name
  33.         self._dmg = dmg
  34.         self._cost = cost
  35.         self._desc = desc
  36.         self._curr = curr
  37.  
  38. troops = [Troop("offensive", "Soldier", "1", "1000", "Infantry unit. Good for attacking in numbers.", "bits"), Troop("offensive", "Knight", "11", "10000", "Knights, as noble as they are, won't stop for anything to complete their objective.", "bits"), Troop("offensive", "Wizard", "125", "50", "Wizards shoot spells that can injure hundreds of enemies at a time.", "iron"), Troop ("offensive", "Commander", "1500", "500", "Commanders have an entire arsenal of Weapons of Mass Destruction and are not afraid to use them.","iron"), Troop("defensive", "Archer", "1", "1000", "Infantry unit. Good for defending in numbers.", "bits"), Troop("defensive", "Bishop", "11", "10000", "Bishops defend with their magical staffs.", "bits"), Troop("defensive", "Rook", "125", "50", "Rooks are beastly humans. It is said with their muscles they can stop hundreds of units.","iron"), Troop ("defensive", "Enforcer", "1500", "500","Enforcers can stop thousands of units with a clap of their hands, causing earth shattering earthquakes.", "iron")]
  39.  
  40. '''
  41. Infiltration Method:
  42.  
  43. Used when a player infiltrates another person's base. Determines if the player is able to infiltrate the base or not depending
  44. on the player's offensive damage, the opponent's defensive damage, and the health of the opponent's wall.
  45.  
  46. wall = Opponent's Wall Health
  47. odmg = Player's Offensive Damage
  48. ddmg = Opponent's Defensive Damage
  49.  
  50. The player is able to infiltrate an opponent's base if [health - (odmg - ddmg*0) - (odmg - ddmg*(1))... until odmg-ddmg*n<=0
  51. where n represents the player's nth attack] is lower or equal to 0. In other words, the opponent starts with a base health of
  52. [health]. The player then attacks with [odmg] doing that much damage to the wall. Each turn the player's [odmg] is weakened by
  53. the opponent's [ddmg], so the next attack the player does [odmg-ddmg] to the opponent's wall. This continues until the player's
  54. [odmg] reaches 0. If the opponent's wall is destroyed, the player successfully infiltrated their base, but if not, the player
  55. failed.
  56. '''
  57.  
  58. def infiltration(wall, odmg, ddmg):
  59.     if (odmg>0):
  60.         wall -= odmg
  61.         odmg -= ddmg
  62.         if wall<=0:
  63.             return True
  64.         else:
  65.             return infiltration(wall, odmg, ddmg)
  66.     else:
  67.         return False
  68.  
  69. '''
  70. These next few functions use CRUD applications to manipulate user data.
  71.  
  72. userID = ID of the current user
  73. currency = Number of bits
  74. iron = Number of iron ingots
  75. mtime = Cooldown timer for message reward every 60 seconds
  76. health = Current health of the user's wall
  77. maxhealth = Max health of the user's wall
  78. gainBits = Number of bits the user gains for each message every 60 seconds
  79. gainIron =  Number of iron ingots the user gains for each message every 60 seconds
  80. odmg = Offensive Damage
  81. ddmg = Defensive Damage
  82. cooldowntime = The amount of time left until the user can be infiltrated again
  83. cooldown = Boolean variable determining if the user is available to get infiltrated
  84. '''
  85.  
  86. # Creates a table if a table already doesn't exist
  87. def create_table():
  88.     cursor.execute("CREATE TABLE IF NOT EXISTS currency(userID TEXT, currency INTEGER, iron INTEGER, time DATE, mtime DATE, health INTEGER, maxhealth INTEGER, gainBits INTEGER, gainIron INTEGER, odmg INTEGER, ddmg INTEGER, cooldowntime DATE, cooldown INTEGER)")
  89.  
  90. # Creates a row for a unique user with default values
  91. def start_data(userID):
  92.     cursor.execute("INSERT INTO currency VALUES(" + userID + ", 10000, 0, '" + str(datetime.datetime.now()) +"', '" + str(datetime.datetime.now()) +"', 1000, 1000, 10, 0, 0, 0, '" + str(datetime.datetime.now()) + "', 1)")
  93.     conn.commit()
  94.  
  95. # Retrieves a specific value belonging to a unique user
  96. def data_retrieve(userID, selection):
  97.     cursor.execute("SELECT " + selection + " FROM currency WHERE userID = " + userID)
  98.     data = cursor.fetchall()
  99.     return data
  100.  
  101. # Edits the user's balance
  102. def data_edit(userID, num, balance, balance2):
  103.     cursor.execute("UPDATE currency SET currency = " + str(balance2 + int(balance*num)) + " WHERE userID = " + userID)
  104.     conn.commit()
  105.  
  106. # Edits a specific value belonging to a unique user
  107. def data_edita(userID, selection, new):
  108.     cursor.execute("UPDATE currency SET " + selection + "= " + str(new) + " WHERE userID = " + userID)
  109.     conn.commit()
  110.  
  111. # Daily reward. Gives the user 10 000 bits everyday.
  112. def data_editdaily(userID, balance):
  113.     cursor.execute("SELECT time FROM currency WHERE userID = " + userID)
  114.     data2 = str(cursor.fetchall()).strip("[]")
  115.     data2 = data2[2:len(data2)-3]
  116.     if ((datetime.datetime.now() - datetime.datetime.strptime(data2, "%Y-%m-%d %H:%M:%S.%f")).days>=1):
  117.         #print(str(datetime.datetime.now()))
  118.         cursor.execute("UPDATE currency SET currency = " + str(int(str(data_retrieve(userID)).strip("[]")[1:len(balance)-2])+10000) + " WHERE userID = " + userID)
  119.         cursor.execute("UPDATE currency SET time = '" + str(datetime.datetime.now()) + "' WHERE userID = " + userID)
  120.         conn.commit()
  121.         return "1"
  122.     else:
  123.         return (datetime.datetime.now() - datetime.datetime.strptime(data2, "%Y-%m-%d %H:%M:%S.%f")).seconds
  124.  
  125. # Cooldown for getting infiltrated. A cooldown determining the user is able to be attacked or not.
  126. def data_cooldown(userID):
  127.     cursor.execute("SELECT cooldowntime FROM currency WHERE userID = " + userID)
  128.     data2 = str(cursor.fetchall()).strip("[]")
  129.     data2 = data2[2:len(data2)-3]
  130.     cursor.execute("SELECT cooldown FROM currency WHERE userID = " + userID)
  131.     data3 = str(cursor.fetchall()).strip("[]")
  132.     data3 = int(data3[1:len(data3)-2])
  133.     if (data3==0 or (datetime.datetime.now()-datetime.datetime.strptime(data2, "%Y-%m-%d %H:%M:%S.%f")).days>=1):
  134.         return "1"
  135.     else:
  136.         return (datetime.datetime.now() - datetime.datetime.strptime(data2, "%Y-%m-%d %H:%M:%S.%f")).seconds
  137.  
  138. # Edits the cooldown of the user so they cannot be infiltrated in the next 24 hours
  139. def data_editcooldown(userID):
  140.     cursor.execute("UPDATE currency SET cooldown = 1 WHERE userID = " + userID)
  141.     cursor.execute("UPDATE currency SET cooldowntime = " + datetime.datetime.now() + " WHERE userID = " + userID)
  142.     cursor.commit()
  143.  
  144. # Edits the cooldown of the message reward the timer as well as reward the user with their message reward
  145. def data_message(userID, balance, curiron, bits, iron):
  146.     cursor.execute("SELECT mtime FROM currency WHERE userID = " + userID)
  147.     data2 = str(cursor.fetchall()).strip("[]")
  148.     data2 = data2[2:len(data2)-3]
  149.     now = datetime.datetime.now()
  150.     prev = datetime.datetime.strptime(data2, "%Y-%m-%d %H:%M:%S.%f")
  151.     if ((now-prev).total_seconds()>=60.00):
  152.         cursor.execute("UPDATE currency SET currency = " + str(int(balance[1:len(balance)-2])+int(bits[1:len(bits)-2])) + " WHERE userID = " + userID)
  153.         cursor.execute("UPDATE currency SET iron = " + str(int(curiron[1:len(curiron)-2])+int(iron[1:len(iron)-2])) + " WHERE userID = " + userID)
  154.         cursor.execute("UPDATE currency SET mtime = '" + str(now) + "' WHERE userID = " + userID)
  155.         conn.commit()
  156.         return "1"
  157. '''
  158. # Coroutines for Joining and Leaving Voice Channel
  159. global voice
  160. async def summon(message):
  161.     global voice
  162.     channel = message.author.voice.channel
  163.     voice = await channel.connect()
  164.  
  165. async def leave():
  166.     await voice.disconnect()
  167.  
  168. async def play(url):
  169.     pass
  170. '''
  171.  
  172. '''
  173. Before Registration:
  174.         elif (message.content[3:len(message.content)]=="music"):
  175.             embed = discord.Embed(title = "Music", description = "Everything to do with music.", color = 0x45F4E9)
  176.             embed.set_footer(text = "Listen to music while destroying your enemies. All commands begin with ec!")
  177.             await channel.send(embed = embed)
  178. '''
  179.  
  180. #balance = str(balance2 + int(balance*num))
  181.  
  182. @client.event
  183. async def on_message(message):
  184.     embed = discord.Embed(color=0x45F4E9)
  185.     channel = message.channel
  186.     balance = str(data_retrieve(str(message.author.id))).strip("[]")
  187.  
  188.     # We do not want the bot to reply to itself
  189.     if message.author == client.user:
  190.         return
  191.  
  192.     if message.author.bot:
  193.         return
  194.  
  195.     '''
  196.         Commands:
  197.        
  198.         ec!start = Gives the user all the information needed to create his own base
  199.         ec!help = Lists all commands
  200.         ec!base = Lists commands related to the user's base (rankwall, info, etc.)
  201.         ec!mini = Lists commands related to minigames (dice, coin, steal, etc.)
  202.         ec!register = Registers the user and gives them a base
  203.         ec!info = Displays the user's stats
  204.         ec!dice = The user can roll a dice. If they win their bet multipliess by 6. They lose their bet if they lose.
  205.         ec!coin = The user can throw a coin. If they win their bet multiplies by 2. They lose their bet if they lose.
  206.         ec!daily = Gives the user 10 000 bits daily if they message at least once a day.
  207.         ec!steal = The user can attempt to steal from another player with a 1/3 chance of success. Bet doubles if
  208.         successful; otherwise, the user will lose their bet to the person they are targeting.
  209.         ec!rankwall = Allows the user to upgrade their wall so it has more health
  210.         ec!rankbits = Allows the user to upgrade their message reward's bits, so everytime they meesage every 60 seconds
  211.         they get more bits
  212.         ec!rankiron = Allows the user to upgrade their message reward's iron, so everytime they message every 60 seconds
  213.         they get more iron.
  214.         ec!shop = Displays the shop and all the troops that can be purchased
  215.         ec!infiltrate = Allows the user to infiltrate another player's base to steal their goods
  216.         ec!regen = Allows the user to pay bits to generate their wall health
  217.         ec!scan =  Allows the user to see some of the stats of another player's base
  218.     '''
  219.  
  220.     # Catches all message that begin with ec!
  221.     if message.content.startswith('ec!'):
  222.         if (len(message.content)==8 and message.content[3:8] == "start"):
  223.             embed.add_field(name = "Info", value = "When you register, you start out with 10,000 bits and a wall surronding your money with 1,000 health. You can upgrade your wall, buy defenses, or buy offenses to infiltrate other users' walls and steal their money. You can also play minigames to earn more money or upgrade existing forgeries to earn more or different types of currencies.")
  224.             await channel.send(embed=embed)
  225.         elif (message.content[3:len(message.content)]=="help"):
  226.             embed = discord.Embed(title = "All Commands", description = "Speak every 60 seconds to get bits and iron. Use ec! befor each command.", color=0x45F4E9)
  227.             embed.add_field(name = "Base Basics", value = "Do ec!base for more info about these commands.", inline = False)
  228.             embed.add_field(name = "Minigames", value = "Do ec!mini for more info about these commands.", inline = False)
  229.             #embed.add_field(name = "Music", value = "Do ec!music for more info about these commands", inline = False)
  230.             #embed.set_footer(text = "Global Economy with Leaderboards.")
  231.             await channel.send(embed = embed)
  232.         elif (message.content[3:len(message.content)]=="base"):
  233.             embed = discord.Embed(title = "Base Basics", description = "Everything to do with your base.", color = 0x45F4E9)
  234.             embed.add_field(name="start", value="All the information needed to get started.", inline=False)
  235.             embed.add_field(name="register", value="Register an account and earn 10000 bits instantly.", inline=False)
  236.             embed.add_field(name="info", value="All the information about your wall, units, and potentital upgrades.",
  237.                             inline=False)
  238.             embed.add_field(name="rankwall", value="Increases the health of your wall.", inline = False)
  239.             embed.add_field(name="rankbits", value="Increases the amount of bits you earn every minute.", inline = False)
  240.             embed.add_field(name="rankiron", value="Increases the amount of iron you earn every minute.", inline = False)
  241.             embed.add_field(name="infiltrate <user>",
  242.                             value="Attemps to infiltrate the enemy user. If successful, you take half of their bits and iron. They lose all their troops. If unsuccessful, you lose all your offensive power.", inline = False)
  243.             embed.add_field(name="regen <amount>",
  244.                             value="Regens your wall by the amount specified. If over max health, restores the wall to max health. Cost is 1.5 units per unit of health.", inline = False)
  245.             embed.add_field(name="shop", value = "The shop allows you to buy troops for defending against or initiating infiltrations on the enemy.", inline = False)
  246.             embed.set_footer(text = "Start creating your base today using ec!register and join the global economy! All commands begin with ec!")
  247.             await channel.send(embed = embed)
  248.         elif (message.content[3:len(message.content)]=="mini"):
  249.             embed = discord.Embed(title = "Minigames", description = "Everything to do with minigames.", color = 0x45F4E9)
  250.             embed.add_field(name="coin <bet>", value="Flip a Coin. Replace <bet> with your bet. Win = 2x. Lose = 0x", inline = False)
  251.             embed.add_field(name="dice <bet>", value="Roll a Dice. Replace <bet> with your bet. Win = 6x. Lose = 0x", inline = False)
  252.             embed.add_field(name="steal <user> <bet>",
  253.                             value="Steal from someone. Replace <user> with the user you want to steal from. Replace <bet> with your bet. 1/3 Success.", inline = False)
  254.             embed.set_footer(text = "Fun minigames. All bets are in bits. All commands begin with ec!")
  255.             await channel.send(embed = embed)
  256.         elif (len(message.content)==11 and message.content[3:11] == "register"):
  257.             balance = str(data_retrieve(str(message.author.id))).strip("[]")
  258.             if balance[1:len(balance)-2]!="":
  259.                 embed.add_field(name = "Registration", value = "You already have an account!")
  260.                 await channel.send(embed = embed)
  261.             else:
  262.                 start_data(str(message.author.id))
  263.                 embed.add_field(name = "Registration", value = "Sucessfully registered! {0.author.mention}".format(message))
  264.                 await channel.send(embed = embed)
  265.         elif (balance[1:len(balance)-2]==""):
  266.             embed.add_field(name = "Sorry", value = "Register an account using: ec!register")
  267.             await channel.send(embed = embed)
  268.         elif (len(message.content)==7 and message.content[3:7] == "info"):
  269.             userID = str(message.author.id)
  270.             health = str(data_retrieve(userID, "health")).strip("[]")
  271.             maxhealth = str(data_retrieve(userID, "maxhealth")).strip("[]")
  272.             balance = str(data_retrieve(userID, "currency")).strip("[]")
  273.             iron = str(data_retrieve(userID, "iron")).strip("[]")
  274.             offensive = str(data_retrieve(userID, "odmg")).strip("[]")
  275.             defensive = str(data_retrieve(userID, "ddmg")).strip("[]")
  276.             gainBits = str(data_retrieve(userID, "gainBits")).strip("[]")
  277.             gainIron = str(data_retrieve(userID, "gainIron")).strip("[]")
  278.             cooldown = ""
  279.             if (data_cooldown(userID)=="1"):
  280.                 cooldown = 86400
  281.             else:
  282.                 cooldown = data_cooldown(userID)
  283.             embed.add_field(name = "Wall Health", value = "Looks like your wall is sitting at " + health[1:len(health)-2] + "/" + maxhealth[1:len(maxhealth)-2] + " health.")
  284.             embed.add_field(name = "Balance", value = "Bits and Iron", inline = False)
  285.             embed.add_field(name = "Bits", value = balance[1:len(balance)-2] + " bits", inline = True)
  286.             embed.add_field(name = "Iron", value = iron[1:len(iron)-2] + " iron", inline = True)
  287.             embed.add_field(name = "Troops", value = "Your offensive and defensive damage", inline = False)
  288.             embed.add_field(name = "Offensive Damage", value = offensive[1:len(offensive)-2] + " offensive damage", inline = True)
  289.             embed.add_field(name = "Defensive Damage", value = defensive[1:len(defensive)-2] + " defensive damage", inline = True)
  290.             embed.add_field(name = "Income", value = "The amount of bits and iron you gain every minute you talk", inline = False)
  291.             embed.add_field(name = "Bits", value = gainBits[1:len(gainBits)-2] + " bits/minute", inline = True)
  292.             embed.add_field(name = "Iron", value = gainIron[1:len(gainIron)-2] + " iron/minute", inline = True)
  293.             embed.add_field(name = "Cooldown", value = str(86400-cooldown) + " seconds", inline = False)
  294.             embed.set_footer(text = "Check available upgrades by typing ec!upgrades")
  295.             await channel.send(embed=embed)
  296.         elif (len(message.content)>=7 and message.content[3:7] == "dice"):
  297.             bet = int(message.content[7:len(message.content)])
  298.             balance = str(data_retrieve(str(message.author.id), "currency")).strip("[]")
  299.             balance = balance[1:len(balance) - 2]
  300.             balance = int(balance)
  301.             if (bet<=0):
  302.                 embed.add_field(name="Sorry", value="Your bet is not valid.")
  303.                 await channel.send(embed=embed)
  304.             elif (balance>=bet):
  305.                 embed.add_field(name = "Dice Roll", value = "Rolling Dice...")
  306.                 embed.set_image(url = "https://media1.giphy.com/media/3oGRFlpAW4sIHA02NW/giphy.gif")
  307.                 message2 = await channel.send(embed = embed)
  308.                 time.sleep(3)
  309.                 await message2.delete()
  310.                 if (random.randint(1, 6) == 6):
  311.                     embed = discord.Embed(color=0x45F4E9)
  312.                     data_edit(str(message.author.id), 5, bet, balance)
  313.                     embed.add_field(name="Congrats", value="You won " + str(bet * 6) + " bits.")
  314.                     await channel.send(embed=embed)
  315.                 else:
  316.                     embed = discord.Embed(color=0x45F4E9)
  317.                     data_edit(str(message.author.id), 1, -bet, balance)
  318.                     embed.add_field(name="You Suck", value="You just lost " + str(bet) + " bits.")
  319.                     await channel.send(embed=embed)
  320.             else:
  321.                 embed.add_field(name="Sorry", value="You do not have enough bits.")
  322.                 await channel.send(embed=embed)
  323.         elif (len(message.content)>=7 and message.content[3:7] == "coin"):
  324.             bet = int(message.content[7:len(message.content)])
  325.             balance = str(data_retrieve(str(message.author.id))).strip("[]")
  326.             balance = balance[1:len(balance)-2]
  327.             balance = int(balance)
  328.             if (bet<=0):
  329.                 embed.add_field(name = "Sorry", value = "Your bet is not valid.")
  330.                 await channel.send(embed = embed)
  331.             elif (balance>=bet):
  332.                 embed.add_field(name = "Coin Flip", value = "Flipping Coin...")
  333.                 embed.set_image(url = "https://gifimage.net/wp-content/uploads/2017/10/coin-toss-gif.gif")
  334.                 message2 = await channel.send(embed = embed)
  335.                 time.sleep(3)
  336.                 await message2.delete()
  337.                 if (random.randint(0,1)):
  338.                     embed = discord.Embed(color = 0x45F4E9)
  339.                     data_edit(str(message.author.id), 1, bet, balance)
  340.                     embed.add_field(name = "Congrats", value = "You won " + str(bet*2) + " bits.")
  341.                     await channel.send(embed = embed)
  342.                 else:
  343.                     embed = discord.Embed(color = 0x45F4E9)
  344.                     data_edit(str(message.author.id), 1, -bet, balance)
  345.                     embed.add_field(name = "You Suck", value = "You just lost " + str(bet) + " bits.")
  346.                     await channel.send(embed = embed)
  347.             else:
  348.                 embed.add_field(name = "Sorry", value = "You do not have enough bits.")
  349.                 await channel.send(embed = embed)
  350.         elif (message.content[3:8] == "daily"):
  351.             str2 = data_editdaily(str(message.author.id), balance)
  352.             if (str2=="1"):
  353.                 embed.add_field(name = "Daily", value = "You have just received 10000 bits.")
  354.                 await channel.send(embed = embed)
  355.             else:
  356.                 embed.add_field(name = "Daily", value = "You have to wait " + str(86400-str2) + " seconds before you can get your daily reward.")
  357.                 await channel.send(embed = embed)
  358.         elif (len(message.content)>=8 and message.content[3:8]=="steal"):
  359.             mentions = message.mentions
  360.             if (len(mentions)>1):
  361.                 embed.add_field(name = "Sorry", value = "You can only steal from one person at a time.")
  362.                 await channel.send(embed = embed)
  363.             else:
  364.                 otherID = str(mentions[0].id)
  365.                 otherbal = str(data_retrieve(otherID)).strip("[]")
  366.                 otherExists = True
  367.                 try:
  368.                     otherbal = int(otherbal[1:len(otherbal)-2])
  369.                 except ValueError:
  370.                     embed.add_field(name="Sorry", value="The person you are targeting doesn't have an account.")
  371.                     await channel.send(embed=embed)
  372.                     otherExists = False
  373.                 userID = str(message.author.id)
  374.                 balance = str(data_retrieve(userID, "currency")).strip("[]")
  375.                 balance = int(balance[1:len(balance)-2])
  376.                 bet = int(message.content.split(" ")[2])
  377.                 if otherExists:
  378.                     if userID == otherID:
  379.                         embed.add_field(name = "Sorry", value = "You can't steal from yourself silly.")
  380.                         await channel.send(embed = embed)
  381.                     elif bet<=0:
  382.                         embed.add_field(name = "Sorry", value = "You have to steal more than 0 bits.")
  383.                         await channel.send(embed = embed)
  384.                     elif bet>otherbal:
  385.                         embed.add_field(name = "Sorry", value = "You can't steal more than the person has unfortunately.")
  386.                         await channel.send(embed = embed)
  387.                     elif bet>balance:
  388.                         embed.add_field(name = "Sorry", value = "You need to have as many bits as you are going to steal. Extra security, you know.")
  389.                         await channel.send(embed = embed)
  390.                     else:
  391.                         embed.add_field(name = "Thievery", value = "Attempting to Steal...")
  392.                         embed.set_image(url = "http://i.imgur.com/gP9sN.gif")
  393.                         message2 = await channel.send(embed = embed)
  394.                         time.sleep(5)
  395.                         await message2.delete()
  396.                         if random.randint(0,3)==1:
  397.                             data_edit(otherID, -1, bet, otherbal)
  398.                             data_edit(userID, 1, bet, balance)
  399.                             embed = discord.Embed(color = 0x45F4E9)
  400.                             embed.add_field(name = "Nice", value = "You just stole " + str(bet) + " bits from your friend.")
  401.                             await channel.send(embed = embed)
  402.                         else:
  403.                             data_edit(otherID, 1, bet, otherbal)
  404.                             data_edit(userID, -1, bet, balance)
  405.                             embed = discord.Embed(color = 0x45F4E9)
  406.                             embed.add_field(name = "Unlucky", value = "Your friend has caught you. You run away but your friend snatches " + str(bet) + " bits from you in the process.")
  407.                             await channel.send(embed = embed)
  408.         elif (message.content[3:len(message.content)]=="rankwall"):
  409.             health = str(data_retrieve(str(message.author.id), "health")).strip("[]")
  410.             health = health[1:len(health) - 2]
  411.             health = int(health)
  412.             health *= 2
  413.             userID = str(message.author.id)
  414.             balance = str(data_retrieve(str(message.author.id))).strip("[]")
  415.             balance = balance[1:len(balance) - 2]
  416.             balance = int(balance)
  417.             if (balance>=health*25):
  418.                 data_edita(userID, "health", health)
  419.                 data_edita(userID, "maxhealth", health)
  420.                 data_edita(userID, "currency", balance-health*25)
  421.                 embed = discord.Embed(color = 0x45F4E9)
  422.                 embed.add_field(name = "Upgraded", value = "Your wall now has a max health of " + str(health))
  423.                 await channel.send(embed = embed)
  424.             else:
  425.                 embed = discord.Embed(color = 0x45F4E9)
  426.                 embed.add_field(name = "Sorry", value = "You need " + str(health*25-balance) + " more bits to upgrade your wall.")
  427.                 await channel.send(embed = embed)
  428.         elif (message.content[3:len(message.content)]=="rankbits"):
  429.             userID = str(message.author.id)
  430.             balance = str(data_retrieve(str(message.author.id), "currency")).strip("[]")
  431.             balance = balance[1:len(balance) - 2]
  432.             balance = int(balance)
  433.             gainbits = str(data_retrieve(str(message.author.id), "gainBits")).strip("[]")
  434.             gainbits = gainbits[1:len(gainbits)-2]
  435.             gainbits = int(gainbits)
  436.             gainbits *= 2
  437.             if (balance>=gainbits*25):
  438.                 data_edita(userID, "gainBits", gainbits)
  439.                 data_edita(userID, "currency", balance - gainbits * 25)
  440.                 embed = discord.Embed(color = 0x45F4E9)
  441.                 embed.add_field(name = "Upgraded", value = "You gain " + str(gainbits) + " bits now when you speak every minute.")
  442.                 await channel.send(embed = embed)
  443.             else:
  444.                 embed = discord.Embed(color = 0x45F4E9)
  445.                 embed.add_field(name = "Sorry", value = "You need " + str(gainbits*25-balance) + " more bits to upgrade the amount of bits you generate.")
  446.                 await channel.send(embed = embed)
  447.         elif (message.content[3:len(message.content)]=="rankiron"):
  448.             userID = str(message.author.id)
  449.             balance = str(data_retrieve(str(message.author.id), "currency")).strip("[]")
  450.             balance = balance[1:len(balance) - 2]
  451.             balance = int(balance)
  452.             iron = str(data_retrieve(str(message.author.id), "iron")).strip("[]")
  453.             iron = iron[1:len(str(balance))-2]
  454.             iron = int(iron)
  455.             gainiron = str(data_retrieve(str(message.author.id), "gainIron")).strip("[]")
  456.             gainiron = gainiron[1:len(str(gainiron)) - 2]
  457.             gainiron = int(gainiron)
  458.             gainiron *= 2
  459.             gainiron += 1
  460.             if (gainiron * 5000 >= 1000000):
  461.                 if (iron >= gainiron * 25):
  462.                     data_edita(userID, "gainIron", gainiron)
  463.                     data_edita(userID, "iron", iron - gainiron * 25)
  464.                     embed = discord.Embed(color=0x45F4E9)
  465.                     embed.add_field(name="Upgraded", value="You gain " + str(gainiron) + " iron now when you speak every minute.")
  466.                     await channel.send(embed=embed)
  467.                 else:
  468.                     embed = discord.Embed(color=0x45F4E9)
  469.                     embed.add_field(name="Sorry", value="You need " + str(gainiron * 25 - iron) + " more iron to upgrade the amount of iron you generate.")
  470.                     await channel.send(embed=embed)
  471.             elif (balance >= gainiron * 5000):
  472.                 data_edita(userID, "gainIron", gainiron)
  473.                 data_edita(userID, "currency", balance - gainiron * 5000)
  474.                 embed = discord.Embed(color=0x45F4E9)
  475.                 embed.add_field(name="Upgraded", value="You gain " + str(gainiron) + " iron now when you speak every minute.")
  476.                 await channel.send(embed=embed)
  477.             else:
  478.                 embed = discord.Embed(color=0x45F4E9)
  479.                 embed.add_field(name="Sorry", value="You need " + str(gainiron * 5000 - balance) + " more bits to upgrade the amount of iron you generate.")
  480.                 await channel.send(embed=embed)
  481.         elif (message.content[3:len(message.content)]=="shop"):
  482.             defensive = ""
  483.             offensive = ""
  484.             for troop in troops:
  485.                 if troop._type == "defensive":
  486.                     if defensive == "":
  487.                         defensive = troop._name
  488.                     else:
  489.                         defensive += ", " + troop._name
  490.                 else:
  491.                     if offensive == "":
  492.                         offensive = troop._name
  493.                     else:
  494.                         offensive += ", " + troop._name
  495.             embed = discord.Embed(color = 0x45F4E9)
  496.             embed.add_field(name = "Shop", value = "Buy defensive troops here to protect your base, or buy offensive troops to infiltrate others.")
  497.             embed.add_field(name = "Defensive", value = defensive)
  498.             embed.add_field(name = "Offensive", value = offensive)
  499.             embed.set_footer(text="Type ec!<troop name> to learn more.")
  500.             await channel.send(embed=embed)
  501.         elif (message.content[3:13]=="infiltrate"):
  502.             mentions = message.mentions
  503.             if (len(mentions)>1):
  504.                 embed = discord.Embed(color = 0x45F4E9)
  505.                 embed.add_field(name = "Sorry", value = "Please mention only one user.")
  506.                 await channel.sned(embed=embed)
  507.             elif (len(mentions)==1):
  508.                 otherID = str(mentions[0].id)
  509.                 otherbal = str(data_retrieve(otherID)).strip("[]")
  510.                 otherExists = True
  511.                 try:
  512.                     otherbal = int(otherbal[1:len(otherbal) - 2])
  513.                 except ValueError:
  514.                     embed = discord.Embed(color = 0x45F4E9)
  515.                     embed.add_field(name="Sorry", value="The person you are targeting doesn't have an account.")
  516.                     await channel.send(embed=embed)
  517.                     otherExists = False
  518.                 userID = str(message.author.id)
  519.                 if (otherID==userID):
  520.                     embed = discord.Embed(color = 0x45F4E9)
  521.                     embed.add_field(name = "Sorry", value = "You can't target yourself.")
  522.                     await channel.send(embed=embed)
  523.                 else:
  524.                     balance = str(data_retrieve(userID, "currency")).strip("[]")
  525.                     balance = int(balance[1:len(balance) - 2])
  526.                     iron = str(data_retrieve(userID, "iron")).strip("[]")
  527.                     iron = int(iron[1:len(iron) - 2])
  528.                     if otherExists:
  529.                         if (data_cooldown(otherID)=="1"):
  530.                             data_editcooldown(otherID)
  531.                             data_edita(userID, "cooldown", 0)
  532.                             otheriron = str(data_retrieve(otherID, "iron")).strip("[]")
  533.                             otheriron = int(otheriron[1:len(otheriron) - 2])
  534.                             enemyhealth = str(data_retrieve(otherID, "health")).strip("[]")
  535.                             enemyhealth = int(enemyhealth[1:len(enemyhealth) - 2])
  536.                             offen = str(data_retrieve(userID, "odmg")).strip("[]")
  537.                             offen = int(offen[1:len(offen) - 2])
  538.                             defen = str(data_retrieve(otherID, "ddmg")).strip("[]")
  539.                             defen = int(defen[1:len(defen) - 2])
  540.                             if infiltration(enemyhealth, offen, defen):
  541.                                 maxhealth = str(data_retrieve(otherID, "maxhealth")).strip("[]")
  542.                                 maxhealth = int(maxhealth[1:len(maxhealth) - 2])
  543.                                 data_edita(userID, "currency", balance + otherbal // 2)
  544.                                 data_edita(userID, "iron", iron + otheriron // 2)
  545.                                 data_edita(otherID, "currency", otherbal - otherbal // 2)
  546.                                 data_edita(otherID, "iron", otheriron - otheriron // 2)
  547.                                 data_edita(otherID, "odmg", 0)
  548.                                 data_edita(otherID, "ddmg", 0)
  549.                                 data_edita(otherID, "health", maxhealth)
  550.                                 embed = discord.Embed(color=0x45F4E9)
  551.                                 embed.add_field(name="Success",
  552.                                                 value="You successfully infiltrated the enemy base, earning " + str(
  553.                                                     otherbal // 2) + " bits and " + str(
  554.                                                     otheriron // 2) + " iron. All enemy troops have died as a result.")
  555.                                 await channel.send(embed=embed)
  556.                             else:
  557.                                 data_edita(userID, "odmg", 0)
  558.                                 embed = discord.Embed(color=0x45F4E9)
  559.                                 embed.add_field(name="Failure",
  560.                                                 value="You failed to infiltrate the enemy base, losing all your offensive troops.")
  561.                                 await channel.send(embed=embed)
  562.                         else:
  563.                             embed = discord.Embed(color =0x45F4E9)
  564.                             embed.add_field(name = "Sorry", value = "You have to wait " + str(86400-data_cooldown(otherID)) + " seconds before you can attack this base.")
  565.                             await channel.send(embed=embed)
  566.             else:
  567.                 embed = discord.Embed(color = 0x45F4E9)
  568.                 embed.add_field(name = "Sorry", value = "Please mention the user you want to target.")
  569.                 await channel.send(embed=embed)
  570.         elif (message.content[3:8]=="regen"):
  571.             userID = str(message.author.id)
  572.             balance = str(data_retrieve(userID, "currency")).strip("[]")
  573.             balance = balance[1:len(balance) - 2]
  574.             balance = int(balance)
  575.             health = str(data_retrieve(userID, "health")).strip("[]")
  576.             health = int(health[1:len(health)-2])
  577.             maxhealth = str(data_retrieve(userID, "maxhealth")).strip("[]")
  578.             maxhealth = int(maxhealth[1:len(maxhealth)-2])
  579.             valid = True
  580.             try:
  581.                 regen = int(message.content[9: len(message.content)])
  582.             except ValueError:
  583.                 embed = discord.Embed(embed = 0x45F4E9)
  584.                 embed.add_field(name = "Sorry", value = "Please enter a valid number for the amount of health you wish to regen")
  585.                 await channel.send(embed=embed)
  586.                 valid = False
  587.             if valid:
  588.                 if (regen==0):
  589.                     embed = discord.Embed(embed=0x45F4E9)
  590.                     embed.add_field(name="Sorry", value="Please enter a valid number for the amount of health you wish to regen")
  591.                     await channel.send(embed=embed)
  592.                 if (maxhealth-health==0):
  593.                     embed = discord.Embed(embed = 0x45F4E9)
  594.                     embed.add_field(name = "Sorry", value = "Your wall is at full health.")
  595.                     await channel.send(embed=embed)
  596.                 else:
  597.                     if regen+health>maxhealth:
  598.                         regen = maxhealth-health
  599.                     if (int(math.floor(regen * 1.5)) > balance):
  600.                         embed = discord.Embed(embed=0x45F4E9)
  601.                         embed.add_field(name="Sorry", value="You don't have enough money to regen your wall that much.")
  602.                         await channel.send(embed=embed)
  603.                     else:
  604.                         data_edita(userID, "currency", balance-int(math.floor(regen * 1.5)))
  605.                         data_edita(userID, "health", health+regen)
  606.                         embed.add_field(name = "Success", value = "The health of your wall is now " + str(health+regen))
  607.                         await channel.send(embed=embed)
  608.         elif (message.content[3:7]=="scan"):
  609.             mentions = message.mentions
  610.             if (len(mentions) > 1):
  611.                 embed = discord.Embed(color=0x45F4E9)
  612.                 embed.add_field(name="Sorry", value="Please mention only one user.")
  613.                 await channel.sned(embed=embed)
  614.             elif (len(mentions) == 1):
  615.                 otherID = str(mentions[0].id)
  616.                 otherbal = str(data_retrieve(otherID)).strip("[]")
  617.                 otherExists = True
  618.                 try:
  619.                     otherbal = int(otherbal[1:len(otherbal) - 2])
  620.                 except ValueError:
  621.                     embed = discord.Embed(color=0x45F4E9)
  622.                     embed.add_field(name="Sorry", value="The person you are scanning doesn't have an account.")
  623.                     await channel.send(embed=embed)
  624.                     otherExists = False
  625.                 userID = str(message.author.id)
  626.                 if (otherExists):
  627.                     if (otherID!=userID):
  628.                         otheriron = str(data_retrieve(otherID, "iron")).strip("[]")
  629.                         otheriron = int(otheriron[1:len(otheriron) - 2])
  630.                         enemyhealth = str(data_retrieve(otherID, "health")).strip("[]")
  631.                         enemyhealth = int(enemyhealth[1:len(enemyhealth) - 2])
  632.                         maxhealth = str(data_retrieve(otherID, "maxhealth")).strip("[]")
  633.                         maxhealth = int(maxhealth[1:len(maxhealth) - 2])
  634.                         cooldown = ""
  635.                         if (data_cooldown(otherID)=="1"):
  636.                             cooldown = 86400
  637.                         else:
  638.                             cooldown = data_cooldown(otherID)
  639.                         embed = discord.Embed(color=0x45F4E9)
  640.                         embed.add_field(name="Wall Health", value="Looks like their wall is sitting at " + str(enemyhealth) + "/" + str(maxhealth) + " health.")
  641.                         embed.add_field(name="Balance", value="Bits and Iron", inline=False)
  642.                         embed.add_field(name="Bits", value=str(otherbal) + " bits", inline=True)
  643.                         embed.add_field(name="Iron", value=str(otheriron) + " iron", inline=True)
  644.                         embed.add_field(name="Troops", value="Your offensive and defensive damage", inline=False)
  645.                         embed.add_field(name="Offensive Damage", value="??? offensive damage",
  646.                                         inline=True)
  647.                         embed.add_field(name="Defensive Damage", value="??? defensive damage",
  648.                                         inline=True)
  649.                         embed.add_field(name = "Cooldown", value = str(86400-cooldown) + " seconds", inline = False)
  650.                         embed.set_footer(text=str(mentions[0].name) + "'s Base")
  651.                         await channel.send(embed=embed)
  652.                     else:
  653.                         embed = discord.Embed(color=0x45F4E9)
  654.                         embed.add_field(name = "Sorry", value = "You can't scan yourself.")
  655.                         await channel.send(embed=embed)
  656.                 else:
  657.                     embed = discord.Embed(color=0x45F4E9)
  658.                     embed.add_field(name = "Sorry", value = "The base you are trying to scan doesn't exist.")
  659.                     await channel.send(embed=embed)
  660.             else:
  661.                 embed = discord.Embed(color=0x45F4E9)
  662.                 embed.add_field(name="Sorry", value="Please mention the user you want to scan.")
  663.                 await channel.send(embed=embed)
  664.         '''
  665.         elif (message.content[3:9]=="summon"):
  666.             await summon(message)
  667.         elif (message.content[3:8]=="leave"):
  668.             await leave()
  669.         '''
  670.         for troop in troops:
  671.             if (message.content[3:len(message.content)]==troop._name):
  672.                 embed = discord.Embed(color = 0x45F4E9)
  673.                 embed.add_field(name = troop._name, value = troop._desc)
  674.                 embed.add_field(name = "Type", value = troop._type.capitalize(), inline = False)
  675.                 embed.add_field(name = "Cost", value = troop._cost + " " + troop._curr, inline = False)
  676.                 embed.add_field(name = "Damage", value = troop._dmg + " units/second", inline = False)
  677.                 embed.add_field(name = "Buy?", value = "Type \"ec!" + troop._name + " buy <quantity>\" to buy a <quantity> number of " + troop._name.lower() + "s", inline = False)
  678.                 await channel.send(embed=embed)
  679.             if (message.content[3:int(7+len(troop._name))]==str(troop._name + " buy")):
  680.                 userID = str(message.author.id)
  681.                 balance = str(data_retrieve(str(message.author.id), "currency")).strip("[]")
  682.                 balance = balance[1:len(balance) - 2]
  683.                 balance = int(balance)
  684.                 iron = str(data_retrieve(str(message.author.id), "iron")).strip("[]")
  685.                 iron = iron[1:len(iron) - 2]
  686.                 iron = int(iron)
  687.                 quantity = int(message.content[int(7+len(troop._name)):len(message.content)])
  688.                 ddmg = str(data_retrieve(str(message.author.id), "ddmg")).strip("[]")
  689.                 ddmg = ddmg[1:len(ddmg)-2]
  690.                 ddmg = int(ddmg)
  691.                 odmg = str(data_retrieve(str(message.author.id), "odmg")).strip("[]")
  692.                 odmg = odmg[1:len(odmg)-2]
  693.                 odmg = int(odmg)
  694.                 if (troop._curr=="iron"):
  695.                     if (iron>=int(troop._cost)*quantity):
  696.                         data_edita(userID, "iron", iron-int(troop._cost)*quantity)
  697.                         if (troop._type == "defensive"):
  698.                             data_edita(userID, "ddmg", ddmg + int(troop._dmg)*quantity)
  699.                         else:
  700.                             data_edita(userID, "odmg", odmg + int(troop._dmg)*quantity)
  701.                         embed = discord.Embed(color = 0x45F4E9)
  702.                         embed.add_field(name = "Congrats", value = "You just purchased " + str(quantity) + " " + troop._name + "s for " + str(int(troop._cost)*quantity) + " " + troop._curr + ".")
  703.                         await channel.send(embed = embed)
  704.                     else:
  705.                         embed = discord.Embed(color = 0x45F4E9)
  706.                         embed.add_field(name = "Sorry", value = "You need " + str(int(troop._cost)*quantity-iron) + " more " + troop._curr + " to purchase " + str(quantity) + " of this troop.")
  707.                         await channel.send(embed = embed)
  708.                 else:
  709.                     if (balance>=int(troop._cost)*quantity):
  710.                         data_edita(userID, "currency", balance-int(troop._cost)*quantity)
  711.                         if (troop._type == "defensive"):
  712.                             data_edita(userID, "ddmg", ddmg + int(troop._dmg)*quantity)
  713.                         else:
  714.                             data_edita(userID, "odmg", odmg + int(troop._dmg)*quantity)
  715.                         embed = discord.Embed(color = 0x45F4E9)
  716.                         embed.add_field(name = "Congrats", value = "You just purchased " + str(quantity) + " " + troop._name + "s for " + str(int(troop._cost)*quantity) + " " + troop._curr + ".")
  717.                         await channel.send(embed = embed)
  718.                     else:
  719.                         embed = discord.Embed(color = 0x45F4E9)
  720.                         embed.add_field(name = "Sorry", value = "You need " + str(int(troop._cost)*quantity-balance) + " more " + troop._curr + " to purchase " + str(quantity) + " of this troop.")
  721.                         await channel.send(embed = embed)
  722.     #Users get message awards every minute
  723.     curiron = str(data_retrieve(str(message.author.id), "iron")).strip("[]")
  724.     bits = str(data_retrieve(str(message.author.id), "gainBits")).strip("[]")
  725.     iron = str(data_retrieve(str(message.author.id), "gainIron")).strip("[]")
  726.     data_message(str(message.author.id), balance, curiron, bits, iron)
  727.  
  728. @client.event
  729. async def on_ready():
  730.     print('Logged in as')
  731.     print(client.user.name)
  732.     print(client.user.id)
  733.     print('------')
  734.     await client.change_presence(activity=discord.Game(name='ec!help'))
  735.  
  736. create_table()
  737. client.run(TOKEN)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top