Feature update

Support added for:
- Redtext
- Invasions (Reactors, Catalysts)
- Gifts From The Lotus
To use these features, check out the config
This commit is contained in:
Emperor 2020-06-15 05:15:10 -04:00
parent 13db830043
commit a74eeb65b4
No known key found for this signature in database
GPG Key ID: 725765E199BB6A5F
2 changed files with 198 additions and 56 deletions

View File

@ -102,51 +102,58 @@ async def arby_post_task():
if request_arby() == OldArbi: ## prevents duplicate posting if request_arby() == OldArbi: ## prevents duplicate posting
pass pass
else: else:
guild = bot.get_guild(guildid) for i in servers:
content = '' # prepares empty string, final string will post with multiple mentions try:
# ~~ Factions guild = bot.get_guild(i['serverid'])
for y in factions: except:
if y in CurrentArbi['solnodedata']['enemy']: pass
try: content = '' # prepares empty string, final string will post with multiple mentions
role = discord.utils.get(guild.roles, name=str(y)) # ~~ Factions
content+=' '+role.mention for y in factions:
except: if y in CurrentArbi['solnodedata']['enemy']:
pass try:
## ~~ Mission types role = discord.utils.get(guild.roles, name=str(y))
for y in mtypes: content+=' '+role.mention
if y in CurrentArbi['solnodedata']['type']: except:
try: pass
role = discord.utils.get(guild.roles, name=str(y)) ## ~~ Mission types
content+=' '+role.mention for y in mtypes:
except: if y in CurrentArbi['solnodedata']['type']:
pass try:
for f in factions: role = discord.utils.get(guild.roles, name=str(y))
if f in CurrentArbi['solnodedata']['enemy']: content+=' '+role.mention
try: except:
role = discord.utils.get(guild.roles, name=str(f)+' '+str(y)) pass
content+=' '+role.mention for f in factions:
except: if f in CurrentArbi['solnodedata']['enemy']:
pass try:
# ~~ Dark sector bonus role = discord.utils.get(guild.roles, name=str(f)+' '+str(y))
x = '' content+=' '+role.mention
if CurrentArbi['solnodedata']['dark_sector'] == True: except:
x = 'Dark Sector (+{})'.format(CurrentArbi['solnodedata']['bonus']) pass
# ~~ Node mentions # ~~ Dark sector bonus
try: x = ''
role = discord.utils.get(guild.roles, name=str(CurrentArbi['solnodedata']['node'])) if CurrentArbi['solnodedata']['dark_sector'] == True:
content+=' '+role.mention x = 'Dark Sector (+{})'.format(CurrentArbi['solnodedata']['bonus'])
arb = discord.Embed(title=CurrentArbi['solnodedata']['type'] + " - " + CurrentArbi['solnodedata']['enemy'], ### making discord embed here # ~~ Node mentions
description=CurrentArbi['solnodedata']['node']+' ('+CurrentArbi['solnodedata']['planet']+')\n'+x, try:
colour=discord.Colour(0xf1c40f)) role = discord.utils.get(guild.roles, name=str(CurrentArbi['solnodedata']['node']))
except: content+=' '+role.mention
arb = discord.Embed(title=CurrentArbi['solnodedata']['type'] + " - " + CurrentArbi['solnodedata']['enemy'], ### making discord embed here arb = discord.Embed(title=CurrentArbi['solnodedata']['type'] + " - " + CurrentArbi['solnodedata']['enemy'], ### making discord embed here
description=CurrentArbi['solnodedata']['node']+' ('+CurrentArbi['solnodedata']['planet']+')\n'+x, description=CurrentArbi['solnodedata']['node']+' ('+CurrentArbi['solnodedata']['planet']+')\n'+x,
colour=discord.Colour(0x900f0f)) colour=discord.Colour(0xf1c40f))
arb.set_thumbnail(url='https://i.imgur.com/2Lyw9yo.png') except:
arb.set_footer(text=CurrentArbi['solnodedata']['tileset']) arb = discord.Embed(title=CurrentArbi['solnodedata']['type'] + " - " + CurrentArbi['solnodedata']['enemy'], ### making discord embed here
async with aiohttp.ClientSession() as session: description=CurrentArbi['solnodedata']['node']+' ('+CurrentArbi['solnodedata']['planet']+')\n'+x,
webhook = Webhook.from_url(arbyhook, adapter=AsyncWebhookAdapter(session)) colour=discord.Colour(0x900f0f))
await webhook.send(username="Arbitration", avatar_url='https://cdn.discordapp.com/avatars/705812867781492777/0f0d8efa6759afa9d2bb2618d59dd306.png?size=128',content=content, embed=arb) ### sending embed to channel arb.set_thumbnail(url='https://i.imgur.com/2Lyw9yo.png')
arb.set_footer(text=CurrentArbi['solnodedata']['tileset'])
try:
async with aiohttp.ClientSession() as session:
webhook = Webhook.from_url(i['arbywebhook'], adapter=AsyncWebhookAdapter(session))
await webhook.send(username="Arbitration", avatar_url='https://cdn.discordapp.com/avatars/705812867781492777/0f0d8efa6759afa9d2bb2618d59dd306.png?size=128',content=content, embed=arb) ### sending embed to channel
except:
pass
OldArbi = request_arby() ### setting old arbi to the one that was just posted, so it doesnt send duplicate OldArbi = request_arby() ### setting old arbi to the one that was just posted, so it doesnt send duplicate
@bot.event @bot.event

View File

@ -8,6 +8,11 @@ import prettytable
import datetime import datetime
import time import time
import sys import sys
from discord import Webhook, AsyncWebhookAdapter
from apscheduler.schedulers.asyncio import AsyncIOScheduler
import aiohttp
import re
sys.path.append('../') sys.path.append('../')
from config import * from config import *
@ -20,7 +25,17 @@ solNodes = requests.get('https://raw.githubusercontent.com/empdarkness/warframe-
missionTypes = requests.get('https://raw.githubusercontent.com/empdarkness/warframe-data/master/missionTypes.json').json() missionTypes = requests.get('https://raw.githubusercontent.com/empdarkness/warframe-data/master/missionTypes.json').json()
sortieData = requests.get('https://raw.githubusercontent.com/empdarkness/warframe-data/master/sortieData.json').json() sortieData = requests.get('https://raw.githubusercontent.com/empdarkness/warframe-data/master/sortieData.json').json()
lang = requests.get('https://raw.githubusercontent.com/empdarkness/warframe-data/master/languages.json').json() lang = requests.get('https://raw.githubusercontent.com/empdarkness/warframe-data/master/languages.json').json()
sched = AsyncIOScheduler() # needed cause discord.py uses async
sched.start() # starts scheduler for cron task
gftla = []
gftlb = []
af = []
bf = []
inva = []
invb = []
redtext = []
OldBaro = ""
invasionitem = ['Orokin Reactor', 'Orokin Catalyst']
class Warframe(commands.Cog): class Warframe(commands.Cog):
@ -431,7 +446,6 @@ class Warframe(commands.Cog):
async def baroerror(self, ctx, error): async def baroerror(self, ctx, error):
await ctx.send(error) await ctx.send(error)
# sortie # sortie
@bot.command(name="sortie") @bot.command(name="sortie")
async def sortie(self, ctx): async def sortie(self, ctx):
@ -451,15 +465,6 @@ class Warframe(commands.Cog):
async def sortieerror(self, ctx, error): async def sortieerror(self, ctx, error):
await ctx.send(error) await ctx.send(error)
# arbitration
@bot.command(name="arby")
async def arby(self, ctx):
CurrentArbi = requests.get('https://10o.io/kuvalog.json').json()[0] ## semlar arbitration data
timestamp = datetime.datetime.fromisoformat(CurrentArbi['start'][:-1])
arb = discord.Embed(title=CurrentArbi['solnodedata']['type'] + " - " + CurrentArbi['solnodedata']['enemy'], description=CurrentArbi['solnodedata']['tile'], colour=discord.Colour(0x900f0f), timestamp=timestamp)
arb.set_thumbnail(url='https://i.imgur.com/2Lyw9yo.png')
await ctx.send(embed=arb)
def request_sortie(): def request_sortie():
sortie = requests.get('http://content.warframe.com/dynamic/worldState.php').json()['Sorties'][0] sortie = requests.get('http://content.warframe.com/dynamic/worldState.php').json()['Sorties'][0]
sortie = {"id": sortie['_id']['$oid'], sortie = {"id": sortie['_id']['$oid'],
@ -509,5 +514,135 @@ def request_baro():
voidTrader['inventory'].append(i) voidTrader['inventory'].append(i)
return voidTrader return voidTrader
async def baro_post_task():
global OldBaro
global CurrentBaro
global voidTrader
CurrentBaro = request_baro()
if not CurrentBaro == OldBaro: ## prevents duplicate posting
if CurrentBaro['active'] == True:
for i in servers:
x = prettytable.PrettyTable(["Item", "Ducats", "Credits"])
x.sortby = "Ducats"
x.reversesort=True
for item in CurrentBaro['inventory']:
x.add_row((item["item"], item["ducats"], item["credits"]))
try:
async with aiohttp.ClientSession() as session:
webhook = Webhook.from_url(i['barowebhook'], adapter=AsyncWebhookAdapter(session))
await webhook.send(content='```'+str(x)+'```', avatar_url='https://content.warframe.com/MobileExport/Lotus/Interface/Icons/Player/BaroKiteerAvatar.png')
except:
pass
OldBaro = CurrentBaro ### setting old baro to the one that was just posted, so it doesnt send duplicate
async def gftl():
global gftla
global gftlb
gftlb = []
alerts = requests.get('https://api.warframestat.us/pc/alerts').json()
for alert in alerts:
if alert['id'] not in gftla:
if alert['mission']['description'] == 'Gift From The Lotus':
timestamp = datetime.datetime.fromisoformat(alert['expiry'][:-1])
embed = discord.Embed(title=alert['mission']['description'],
colour=discord.Colour(0x9013fe),
timestamp=timestamp)
embed.add_field(name='Node', value=alert['mission']['node'], inline=True)
embed.add_field(name='Mission Type', value=alert['mission']['type'], inline=True)
embed.add_field(name='Faction', value=alert['mission']['faction'], inline=True)
embed.add_field(name='Level', value=str(alert['mission']['minEnemyLevel'])+' - '+str(alert['mission']['maxEnemyLevel']), inline=True)
embed.add_field(name='Reward', value=alert['mission']['reward']['asString'], inline=False)
embed.set_footer(text=alert['id']+' / Ends')
for i in servers:
try:
async with aiohttp.ClientSession() as session:
webhook = Webhook.from_url(i['giftinvasionswebhook'], adapter=AsyncWebhookAdapter(session))
await webhook.send(embed=embed)
except:
pass
gftla.append(alert['id'])
gftlb.append(alert['id'])
for i in gftla:
if i not in gftlb:
gftla.remove(i)
async def rt():
global redtext
xd = requests.get('https://10o.io/EE.log').json()
y = []
for i in xd:
if (i not in redtext) and ('IRC in: :[' in i['message']):
haha = re.search("IRC in: :([^ ]+) WALLOPS \:(.*)", i['message'])
for i in servers:
try:
async with aiohttp.ClientSession() as session:
webhook = Webhook.from_url(i['redtextwebhook'], adapter=AsyncWebhookAdapter(session))
await webhook.send('```diff\n- '+haha[2]+'```')
except:
pass
redtext.append(i)
y.append(i)
for i in redtext:
if i not in y:
redtext.remove(i)
async def inv():
global inva
global invb
invasions = requests.get('https://api.warframestat.us/pc/invasions').json()
for invasion in invasions:
if invasion['id'] not in inva:
node = invasion['node']
if invasion['vsInfestation'] == True:
attackReward = 'None'
defendReward = invasion['defenderReward']['countedItems'][0]
for i in invasionitem:
if i in defendReward['type'] or i in defendReward['type']:
embed = discord.Embed(title=invasion['node'],
colour=discord.Colour(invasion['attackerReward']['color']))
embed.add_field(name=invasion['attackingFaction'], value=attackReward, inline=False)
embed.add_field(name=invasion['defendingFaction'], value=defendReward['type'], inline=False)
embed.set_author(name=invasion['desc'])
embed.set_thumbnail(url=invasion['defenderReward']['thumbnail'])
embed.set_footer(text=invasion['id'])
for i in servers:
try:
async with aiohttp.ClientSession() as session:
webhook = Webhook.from_url(i['giftinvasionswebhook'], adapter=AsyncWebhookAdapter(session))
await webhook.send(embed=embed)
except:
pass
else:
defendReward = invasion['defenderReward']['countedItems'][0]
attackReward = invasion['attackerReward']['countedItems'][0]
for i in invasionitem:
if i in defendReward['type'] or i in defendReward['type']:
embed = discord.Embed(title=invasion['node'],
colour=discord.Colour(1))
embed.add_field(name=invasion['attackingFaction'], value=attackReward['type'], inline=False)
embed.add_field(name=invasion['defendingFaction'], value=defendReward['type'], inline=False)
embed.set_author(name=invasion['desc'])
if i in defendReward['type']:
embed.set_thumbnail(url=invasion['defenderReward']['thumbnail'])
else:
embed.set_thumbnail(url=invasion['attackerReward']['thumbnail'])
embed.set_footer(text=invasion['id'])
for i in servers:
try:
async with aiohttp.ClientSession() as session:
webhook = Webhook.from_url(i['giftinvasionswebhook'], adapter=AsyncWebhookAdapter(session))
await webhook.send(embed=embed)
except:
pass
inva.append(invasion['id'])
invb.append(invasion['id'])
for i in inva:
if i not in invb:
inva.remove(i)
def setup(bot): def setup(bot):
sched.add_job(baro_post_task, trigger='cron', minute='*', id='Baro', misfire_grace_time=60, replace_existing=True) # trigger every minute, works best cus cron
sched.add_job(inv, trigger='cron', minute='*', id='Invasions', misfire_grace_time=60, replace_existing=True)
sched.add_job(gftl, trigger='cron', minute='*', id='GFTL', misfire_grace_time=60, replace_existing=True)
sched.add_job(rt, trigger='cron', minute='*', id='Redtext', misfire_grace_time=60, replace_existing=True)
bot.add_cog(Warframe(bot)) bot.add_cog(Warframe(bot))