Skip to content

Commit

Permalink
save 11/22/24
Browse files Browse the repository at this point in the history
  • Loading branch information
JaWarrior12 committed Nov 23, 2024
1 parent b26d3a7 commit 90f1805
Show file tree
Hide file tree
Showing 3 changed files with 153 additions and 10 deletions.
8 changes: 2 additions & 6 deletions cogs/econcmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@
class EconCmds(commands.Cog, name="Dredark Economy Dump Commands",description="All Commands relating to the Econ Dumps"):
def __init__(self, bot: commands.Bot):
self.bot = bot
if self.bot.application_id==975858537223847936:
if self.bot.user.id==975858537223847936:
self.exchangeRatesUpdater.start()
def cog_unload(self):
if self.bot.application_id == 975858537223847936:
if self.bot.user.id == 975858537223847936:
self.exchangeRatesUpdater.cancel()
else:
pass
Expand Down Expand Up @@ -347,10 +347,6 @@ def find_route(lst, route_no):
else:
continue
print("Exchange Rates Updated")

@exchangeRatesUpdater.before_loop
async def before_task_starts(self):
await self.wait_until_ready()

async def setup(bot: commands.Bot):
await bot.add_cog(EconCmds(bot))
149 changes: 147 additions & 2 deletions cogs/plexusSystem.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from multiprocessing.spawn import old_main_modules
import os, discord, sys
import re
from aiohttp import DataQueue
import time as timea
import traceback
Expand Down Expand Up @@ -41,6 +42,8 @@
#tz = pytz.timezone('America/New_York')
utc=timezone.utc
tmes=tme(hour=0,minute=10,tzinfo=utc)
tmes2=tme(hour=0,minute=35,tzinfo=utc)


def readPS():
return loads(open('.../NLDB/plexusSystems.json', 'r').read())
Expand All @@ -56,12 +59,14 @@ def __init__(self, bot: commands.Bot):
#print(self.bot.user.id)
if self.bot.user.id == 974045822167679087:
self.runDailyTransferReport_TimerLoop.start()
self.runDailyInventoryReport_TimerLoop.start()
print("start trackLog loop")
#pass
def cog_unload(self):
if self.bot.user.id == 974045822167679087:
#pass
self.runDailyTransferReport_TimerLoop.cancel()
self.runDailyInventoryReport_TimerLoop.cancel()
#else:
#pass

Expand All @@ -77,6 +82,13 @@ async def testRDTR(self,ctx,servers="dev",year=None,month=None,day=None):
else:
await ctx.send("This is a DEVELOPER ONLY command.")

@commands.command(name="testRDIR",help="Tests the runDailyInventoryReport script.")
async def testRDIR(self,ctx,servers="dev",year=None,month=None,day=None):
if ctx.message.author.id in developers:
await self.runDailyInventoryReport(self,servers,year,month,day)
else:
await ctx.send("This is a DEVELOPER ONLY command.")

@commands.command(name="updateTrackList",aliases=["utl"],help="Add or Remove a ship from the track list; also can display the current trck list. Functions :add/remove/list")
@commands.check_any(is_plexus_server())
async def updateTrackList(self,ctx,function,hex=None):
Expand Down Expand Up @@ -147,9 +159,9 @@ async def runDailyTransferReport(self,servers=None,year=None,month=None,day=None
month=today.month
day=today.day
PlexusServer = self.bot.get_guild(int(key))
print(PlexusServer)
#print(PlexusServer)
PlexusReportChannel = await PlexusServer.fetch_channel(int(logChannel))
print(PlexusReportChannel)
#print(PlexusReportChannel)
jsondata = lists.get_gzipped_json(f'https://pub.drednot.io/prod/econ/{int(year)}_{int(month)}_{int(day)}/log.json.gz')
shipData = lists.get_gzipped_json(f'https://pub.drednot.io/prod/econ/{int(year)}_{int(month)}_{int(day)}/ships.json.gz')
altShipData = lists.get_gzipped_json(f'https://pub.drednot.io/prod/econ/{int(year)}_{int(month)}_{int(day)}/ships.json.gz')
Expand Down Expand Up @@ -329,6 +341,139 @@ def yesterday(frmt='%Y-%m-%d', string=True):
print(e)
continue
print("Plexus Daily Transfer Report Script Finished")

@tasks.loop(time=tmes2)
async def runDailyInventoryReport_TimerLoop(self):
print("Running Daily Inventory Loop!")
await self.runDailyInventoryReport(self,None,None,None)

@staticmethod
async def runDailyInventoryReport(self,servers=None,year=None,month=None,day=None):
print("Starting Plexus Daily Inventory Report Script")
today=datetime.now(pytz.UTC)
#print(today)
if year is None:
year=today.year
month=today.month
day=today.day
data = lists.readFile("plexusSystems")
configs=lists.readdataE()
#print(data)
dumpData = lists.get_gzipped_json(f'https://pub.drednot.io/prod/econ/{int(year)}_{int(month)}_{int(day)}/ships.json.gz')
def find_ship(data, route_no):
return list(filter(lambda x: x.get("hex_code") == route_no, data))
url = "https://pub.drednot.io/prod/econ/item_schema.json"
itemSchema = loads(requests.get(url).content)
def findItemName(itemId):
return list(filter(lambda x: x.get('id') == itemId, itemSchema))
serversList=list(data.keys())
if servers=="dev":
serversList=["1031900634741473280"]
elif servers=="all":
pass
elif servers==None:
serversList=[guild.id for guild in self.bot.guilds]
else:
serversList=servers.split(",")
for key in serversList:
try:
logChannel=configs[str(key)]["inventoryLogChannel"]
shipsToLoop=data[str(key)]["inventoryList"]
log_file_name=None
logFile=None
today=datetime.now(pytz.UTC)
#print(today)
if year is None:
year=today.year
month=today.month
day=today.day
PlexusServer = self.bot.get_guild(int(key))
#print(PlexusServer)
PlexusReportChannel = await PlexusServer.fetch_channel(int(logChannel))
#print(PlexusReportChannel)
threads=PlexusReportChannel.threads
for ship in shipsToLoop:
shipData=find_ship(dumpData,ship)
if len(shipData)>0:
shipHex=ship
shipName=shipData[0]["name"]
shipColor=shipData[0]["color"]
shipItems=shipData[0]["items"]
itemNames=[]
itemCounts=[]
for item in list(shipItems.keys()):
itemName=findItemName(int(item))
itemNames.append(itemName[0]["name"])
itemCount=shipItems[item]
itemCounts.append(itemCount)
textString=""
secondCut=""
thirdCut=""
for obj in itemNames:
index=itemNames.index(obj)
nextItem=f" - Item: `{obj}`; Count: `{itemCounts[index]}`\n"
textStringLen=len(textString)
nextItemLen=len(nextItem)
if (textStringLen+nextItemLen) < 1930:
textString+=nextItem
else:
secondCutLen=len(secondCut)
if (secondCutLen+nextItemLen) < 1930:
secondCut+=nextItem
else:
thirdCut+=nextItem
fullString=f"# Inventory of {shipName} ({shipHex})\nLast Update: {month}/{day}/{year}\n{textString}"
#print(len(fullString))
def find_thread(lst, route_no):
found=[]
for z in lst:
if z.name==route_no:
found.append(z)
return found
thd=find_thread(threads,shipHex)
if len(thd)==0:
await PlexusReportChannel.create_thread(name=shipHex,content=f'Inventory Of `{shipName} ({shipHex})`')
await asyncio.sleep(0.1)
upmc=await PlexusServer.fetch_channel(logChannel)
newthread=upmc.get_thread(upmc.last_message_id)
await newthread.send(fullString)
if len(secondCut) > 1:
await newthread.send(secondCut)
if len(thirdCut) > 1:
await newthread.send(thirdCut)
else:
thrd=PlexusReportChannel.get_thread(thd[0].id)
await thrd.purge(limit=5)
#try:
await thrd.send(fullString)
if len(secondCut) > 1:
await thrd.send(secondCut)
if len(thirdCut) > 1:
await thrd.send(thirdCut)
#except:
#print("error")
else:
continue
except Exception as e:
print(e)
e_type, e_object, e_traceback = sys.exc_info()

e_filename = os.path.split(
e_traceback.tb_frame.f_code.co_filename
)[1]

e_message = str(e)

e_line_number = e_traceback.tb_lineno

print(f'exception type: {e_type}')

print(f'exception filename: {e_filename}')

print(f'exception line number: {e_line_number}')

print(f'exception message: {e_message}')
print("Plexus Daily Inventory Report Script Finished")

async def setup(bot: commands.Bot):
await bot.add_cog(PlexusCmds(bot))
Expand Down
6 changes: 4 additions & 2 deletions cogs/setupcmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@
class SetupCmds(commands.Cog, name="Server Commands",description="Server Setup Commands"):
def __init__(self, bot: commands.Bot):
self.bot = bot
self.runUpdateMemList.start()
if self.bot.user.id == 974045822167679087:
self.runUpdateMemList.start()
#self.my_console=Console(bot)
def cog_unload(self):
#print(1)
self.runUpdateMemList.cancel()
if self.bot.user.id == 974045822167679087:
self.runUpdateMemList.cancel()

def is_guild_owner():
def predicate(ctx):
Expand Down

0 comments on commit 90f1805

Please sign in to comment.