Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import discord, sys, os
- from discord.ext import commands
- import requests, json
- import asyncio, f_string, itertools
- client = commands.Bot(command_prefix='!')
- 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]
- 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]
- 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]
- 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]
- 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]
- 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]
- def WarData():
- fetchedData = requests.get("https://politicsandwar.com/api/wars/?alliance_id=3427&key=83407056b13bc6")
- fetchedData = fetchedData.json()
- NewData = (fetchedData["wars"])
- #with open('data.txt', 'w') as outfile:
- #json.dump(NewData, outfile)
- with open('data.txt') as json_file:
- oldData = json.load(json_file)
- war_ids = set()
- NewWars = []
- for x in range(0,100):
- war_ids.add(oldData[x]['warID'])
- for x in range(0,100):
- if NewData[x]['warID'] not in war_ids:
- NewWars.append(NewData[x])
- with open('data.txt', 'w') as outfile:
- json.dump(NewData, outfile)
- return NewWars
- def MemberData(leaderName):
- fetchedData = requests.get("https://politicsandwar.com/api/alliance-members/?allianceid=3427&key=83407056b13bc6")
- fetchedData = fetchedData.json()
- memberInfo = fetchedData["nations"]
- for x in range(0, len(memberInfo)):
- if leaderName == (memberInfo[x]["leader"]):
- return (memberInfo[x])
- break
- else:
- return("Error, leader not found. Check capitilsation and punctuation")
- def RequirementCheck(Data):
- 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"])
- tanks, ships, planes = float(Data["tanks"]), float(Data["ships"]), float(Data["aircraft"])
- sReq = steelReq[(cityNum - 1)]
- if (steel + tanks) >= sReq:
- sToPass = "Met"
- else:
- sToPass = str(round(sReq - steel - tanks))
- aReq = aluReq[(cityNum - 1)]
- if (alu + planes) >= aReq:
- aToPass = "Met"
- else:
- aToPass = str(round(aReq - alu - planes))
- gReq = gasReq[(cityNum - 1)]
- if gas >= gReq:
- gToPass = "Met"
- else:
- gToPass = str(round(gReq - gas))
- mReq = muniReq[(cityNum - 1)]
- if muni >= mReq:
- mToPass = "Met"
- else:
- mToPass = str(round(mReq - muni))
- uReq = uraReq[(cityNum - 1)]
- if ura >= uReq:
- uToPass = "Met"
- else:
- uToPass = str(round(uReq - ura))
- fReq = foodReq[(cityNum - 1)]
- if food >= fReq:
- fToPass = "Met"
- else:
- fToPass = str(round(fReq - food))
- return(sToPass, aToPass, gToPass, mToPass, uToPass, fToPass, str(cityNum))
- #class MyClient(discord.Client):
- #def __init__(self, *args, **kwargs):
- #super().__init__(*args, **kwargs)
- # create the background task and run it in the background
- #self.bg_task = self.loop.create_task(self.my_background_task())
- @client.event
- async def on_ready():
- print('Logged in as')
- print(client.user.name)
- print(client.user.id)
- print('------')
- counter = 0
- async def my_background_task():
- await client.wait_until_ready()
- counter = 0
- channel = client.get_channel(260846693992497152) # my id = 577158475780587541
- while not client.is_closed():
- counter += 1
- #await channel.send(counter)
- NewWars = WarData()
- #statement = str(len(NewWars)) + " new wars"
- #await channel.send(statement)
- for x in range(0,len(NewWars)):
- WarID = str(NewWars[x]['warID'])
- Attacker = str(NewWars[x]['attackerID'])
- AttackerAA = str(NewWars[x]['attackerAA'])
- DefenderAA = str(NewWars[x]['defenderAA'])
- Defender = str(NewWars[x]['defenderID'])
- Date = (NewWars[x]['date'])
- await channel.send("<@&412713650592284674> <@&234318490297696266>")
- embed = discord.Embed(description="<@Deputy Minister> <@Minister>", color=0x008000)
- embed.add_field(name = "Timeline link: ", value = ("https://politicsandwar.com/nation/war/timeline/war=" + WarID))
- embed.add_field(name = "Attacker: ", value = ("https://politicsandwar.com/nation/id=" + Attacker))
- embed.add_field(name = "Attacking alliance: ", value = AttackerAA)
- embed.add_field(name = "Defender: ", value = ("https://politicsandwar.com/nation/id=" + Defender))
- embed.add_field(name = "Defender alliiance: ", value = DefenderAA)
- embed.add_field(name = "Time of Attack: ", value = Date)
- await channel.send(embed = embed)
- #await channel.send(counter)
- await asyncio.sleep(999999)
- #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```")
- #await channel.send(ToDisplay)
- #await channel.send(counter)
- # task runs every 60 seconds
- @client.event
- async def on_command_error(ctx, error):
- if isinstance(error, CommandNotFound):
- return
- raise error
- @client.command(pass_context=True)
- #async def ping(*args):
- # channel = client.get_channel(352933035169284096)
- # await channel.send("Pong!")
- @client.command()
- async def WarCheck(ctx, *, content:str):
- channel = client.get_channel(352933035169284096)
- leaderName = content
- Data = MemberData(leaderName)
- if Data != ("Error, leader not found. Check capitilsation and punctuation"):
- Pass = RequirementCheck(Data)
- steel, alu, gas, muni, ura, food, cityNum = Pass[0], Pass[1], Pass[2], Pass[3], Pass[4], Pass[5], Pass[6]
- embed = discord.Embed(description = "War chest", color = 0x008000)
- embed.add_field(name = "Steel: ", value = steel)
- embed.add_field(name = "Aluminium: ", value = alu)
- embed.add_field(name = "Gasoline: ", value = gas)
- embed.add_field(name = "Munitions: ", value = muni)
- embed.add_field(name = "Uranium: ", value = ura)
- embed.add_field(name = "Food: ", value = food)
- embed.add_field(name = "Cities: ", value = cityNum)
- await channel.send(embed = embed)
- else:
- await channel.send(Data)
- #client = MyClient()
- #client.run('NTgxMTM3NTE1NzA5MjAyNDMy.XOa4mg.NYXGLRCScV76y0CwvDV9UYPVbrY') #Real Bot: NTc3MTU4MDc0NTExNTIzODQx.XNg-hQ.-zcdm2DI6zYv-RrLfRwxPMnJCr0
- client.loop.create_task(my_background_task())
- client.run('NTgxMTM3NTE1NzA5MjAyNDMy.XOa4mg.NYXGLRCScV76y0CwvDV9UYPVbrY')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement