Advertisement
Guest User

Untitled

a guest
May 26th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.16 KB | None | 0 0
  1.  
  2.  
  3. import discord, sys, os
  4. from discord.ext import commands
  5. import requests, json
  6. import asyncio, f_string, itertools
  7. client = commands.Bot(command_prefix='!')
  8.  
  9. steelReq = [0, 0, 0, 0, 8000, 9600, 11200, 12800, 14400, 28438, 31281, 34125, 36969, 42656, 45500, 24344, 51188, 54031, 56875, 59719, 62563, 65406, 68250, 71094, 73938, 76781, 79625, 82469, 85313, 88156, 91000, 93844, 96688, 99531, 102631, 105731, 108831, 111931, 115031]
  10. aluReq = [0, 0, 0, 0, 2700, 3240, 3780, 4320, 4860, 16200, 17820, 19440, 21060, 22680, 24300, 25920, 27540, 29160, 30780, 32400, 34020, 35640, 37260, 38880, 40500, 42120, 43740, 45360, 46980, 48600, 50220, 51840, 53460, 55080, 56700, 58400, 60100, 61800, 63500, 65200]
  11. gasReq = [0, 0, 0, 0, 5000, 6000, 7000, 8000, 9000, 21375, 23513, 25650, 27788, 29925, 32063, 34200, 36338, 38475, 40613, 42750, 44888, 47025, 49163, 51300, 53438, 55575, 57713, 59850, 61988, 64125, 66263, 68400, 70538, 72675, 74813, 77013, 79213, 81413, 83613, 85813]
  12. muniReq = [0, 0, 0, 0, 5000, 6000, 7000, 8000, 9000, 27225, 29948, 32670, 35393, 38115, 40838, 43560, 46283, 49005, 51728, 54450, 57173, 59895, 62618, 65340, 68063, 70785, 73508, 76230, 78953, 81657, 84398, 87120, 89843, 92565, 95288, 98788, 102288, 105788, 109288, 112788]
  13. uraReq = [0, 0, 0, 0, 168, 202, 235, 269, 302, 504, 554, 605, 655, 706, 936, 998, 1061, 1123, 1186, 1248, 1310, 1373, 1435, 1498, 1560, 1622, 1685, 1747, 1810, 1872, 1934, 1997, 2080, 2150, 2210, 2270, 2330, 2390, 2460, 2520]
  14. foodReq = [0, 0, 0, 0, 5000, 6000, 7000, 8000, 9000, 20000, 22000, 24000, 26000, 28000, 45000, 48000, 51000, 54000, 57000, 80000, 84000, 88000, 92000, 96000, 100000, 104000, 108000, 112000, 116000, 120000, 124000, 128000, 132000, 136000, 140000, 144000, 148000, 152000, 156000, 160000]
  15.  
  16. def WarData():
  17. fetchedData = requests.get("https://politicsandwar.com/api/wars/?alliance_id=3427&key=83407056b13bc6")
  18. fetchedData = fetchedData.json()
  19. NewData = (fetchedData["wars"])
  20. #with open('data.txt', 'w') as outfile:
  21. #json.dump(NewData, outfile)
  22. with open('data.txt') as json_file:
  23. oldData = json.load(json_file)
  24. war_ids = set()
  25. NewWars = []
  26. for x in range(0,100):
  27. war_ids.add(oldData[x]['warID'])
  28. for x in range(0,100):
  29. if NewData[x]['warID'] not in war_ids:
  30. NewWars.append(NewData[x])
  31. with open('data.txt', 'w') as outfile:
  32. json.dump(NewData, outfile)
  33. return NewWars
  34.  
  35. def MemberData(leaderName):
  36. fetchedData = requests.get("https://politicsandwar.com/api/alliance-members/?allianceid=3427&key=83407056b13bc6")
  37. fetchedData = fetchedData.json()
  38. memberInfo = fetchedData["nations"]
  39. for x in range(0, len(memberInfo)):
  40. if leaderName == (memberInfo[x]["leader"]):
  41.  
  42. return (memberInfo[x])
  43. break
  44. else:
  45. return("Error, leader not found. Check capitilsation and punctuation")
  46.  
  47. def RequirementCheck(Data):
  48. steel, alu, gas, muni, ura, food, cityNum = float(Data["steel"]), float(Data["aluminum"]), float(Data["munitions"]), float(Data["gasoline"]), float(Data["uranium"]), float(Data["food"]), int(Data["cities"])
  49. tanks, ships, planes = float(Data["tanks"]), float(Data["ships"]), float(Data["aircraft"])
  50. sReq = steelReq[(cityNum - 1)]
  51. if (steel + tanks) >= sReq:
  52. sToPass = "Met"
  53. else:
  54. sToPass = str(round(sReq - steel - tanks))
  55. aReq = aluReq[(cityNum - 1)]
  56. if (alu + planes) >= aReq:
  57. aToPass = "Met"
  58. else:
  59. aToPass = str(round(aReq - alu - planes))
  60. gReq = gasReq[(cityNum - 1)]
  61. if gas >= gReq:
  62. gToPass = "Met"
  63. else:
  64. gToPass = str(round(gReq - gas))
  65. mReq = muniReq[(cityNum - 1)]
  66. if muni >= mReq:
  67. mToPass = "Met"
  68. else:
  69. mToPass = str(round(mReq - muni))
  70. uReq = uraReq[(cityNum - 1)]
  71. if ura >= uReq:
  72. uToPass = "Met"
  73. else:
  74. uToPass = str(round(uReq - ura))
  75. fReq = foodReq[(cityNum - 1)]
  76. if food >= fReq:
  77. fToPass = "Met"
  78. else:
  79. fToPass = str(round(fReq - food))
  80. return(sToPass, aToPass, gToPass, mToPass, uToPass, fToPass, str(cityNum))
  81.  
  82. #class MyClient(discord.Client):
  83. #def __init__(self, *args, **kwargs):
  84. #super().__init__(*args, **kwargs)
  85.  
  86. # create the background task and run it in the background
  87. #self.bg_task = self.loop.create_task(self.my_background_task())
  88. @client.event
  89. async def on_ready():
  90. print('Logged in as')
  91. print(client.user.name)
  92. print(client.user.id)
  93. print('------')
  94. counter = 0
  95. async def my_background_task():
  96. await client.wait_until_ready()
  97. counter = 0
  98. channel = client.get_channel(260846693992497152) # my id = 577158475780587541
  99. while not client.is_closed():
  100. counter += 1
  101.  
  102. #await channel.send(counter)
  103.  
  104. NewWars = WarData()
  105. #statement = str(len(NewWars)) + " new wars"
  106. #await channel.send(statement)
  107. for x in range(0,len(NewWars)):
  108. WarID = str(NewWars[x]['warID'])
  109. Attacker = str(NewWars[x]['attackerID'])
  110. AttackerAA = str(NewWars[x]['attackerAA'])
  111. DefenderAA = str(NewWars[x]['defenderAA'])
  112. Defender = str(NewWars[x]['defenderID'])
  113. Date = (NewWars[x]['date'])
  114. await channel.send("<@&412713650592284674> <@&234318490297696266>")
  115. embed = discord.Embed(description="<@Deputy Minister> <@Minister>", color=0x008000)
  116. embed.add_field(name = "Timeline link: ", value = ("https://politicsandwar.com/nation/war/timeline/war=" + WarID))
  117. embed.add_field(name = "Attacker: ", value = ("https://politicsandwar.com/nation/id=" + Attacker))
  118. embed.add_field(name = "Attacking alliance: ", value = AttackerAA)
  119. embed.add_field(name = "Defender: ", value = ("https://politicsandwar.com/nation/id=" + Defender))
  120. embed.add_field(name = "Defender alliiance: ", value = DefenderAA)
  121. embed.add_field(name = "Time of Attack: ", value = Date)
  122. await channel.send(embed = embed)
  123. #await channel.send(counter)
  124. await asyncio.sleep(999999)
  125. #ToDisplay = (f"```Timeline link: https://politicsandwar.com/nation/war/timeline/war={WarID} \n Attacker: https://politicsandwar.com/nation/id={Attacker} \n Attacker Alliance: {AttackerAA} \n Defender Alliance: {DefenderAA} \n Defender: https://politicsandwar.com/nation/id={Defender} \n Time: {Date} \n```")
  126. #await channel.send(ToDisplay)
  127.  
  128.  
  129.  
  130. #await channel.send(counter)
  131.  
  132. # task runs every 60 seconds
  133. @client.event
  134. async def on_command_error(ctx, error):
  135. if isinstance(error, CommandNotFound):
  136. return
  137. raise error
  138.  
  139. @client.command(pass_context=True)
  140. #async def ping(*args):
  141. # channel = client.get_channel(352933035169284096)
  142. # await channel.send("Pong!")
  143.  
  144. @client.command()
  145. async def WarCheck(ctx, *, content:str):
  146. channel = client.get_channel(352933035169284096)
  147. leaderName = content
  148. Data = MemberData(leaderName)
  149. if Data != ("Error, leader not found. Check capitilsation and punctuation"):
  150. Pass = RequirementCheck(Data)
  151. steel, alu, gas, muni, ura, food, cityNum = Pass[0], Pass[1], Pass[2], Pass[3], Pass[4], Pass[5], Pass[6]
  152. embed = discord.Embed(description = "War chest", color = 0x008000)
  153. embed.add_field(name = "Steel: ", value = steel)
  154. embed.add_field(name = "Aluminium: ", value = alu)
  155. embed.add_field(name = "Gasoline: ", value = gas)
  156. embed.add_field(name = "Munitions: ", value = muni)
  157. embed.add_field(name = "Uranium: ", value = ura)
  158. embed.add_field(name = "Food: ", value = food)
  159. embed.add_field(name = "Cities: ", value = cityNum)
  160. await channel.send(embed = embed)
  161. else:
  162. await channel.send(Data)
  163.  
  164.  
  165.  
  166.  
  167. #client = MyClient()
  168.  
  169. #client.run('NTgxMTM3NTE1NzA5MjAyNDMy.XOa4mg.NYXGLRCScV76y0CwvDV9UYPVbrY') #Real Bot: NTc3MTU4MDc0NTExNTIzODQx.XNg-hQ.-zcdm2DI6zYv-RrLfRwxPMnJCr0
  170. client.loop.create_task(my_background_task())
  171. client.run('NTgxMTM3NTE1NzA5MjAyNDMy.XOa4mg.NYXGLRCScV76y0CwvDV9UYPVbrY')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement