file and folder organization, removal of monoliths

This commit is contained in:
2025-11-25 14:34:32 -05:00
parent 93a5da75eb
commit f5fa1cd703
12 changed files with 188 additions and 301 deletions

Binary file not shown.

Binary file not shown.

64
cogs/assignments.py Normal file
View File

@@ -0,0 +1,64 @@
import asyncio
from discord.ext import commands
class Assignments(commands.Cog):
def __init__(self, bot, enemy_queue, active_assignments, enrolled_attackers, hit_check, reassign_delay):
self.bot = bot
self.enemy_queue = enemy_queue
self.active_assignments = active_assignments
self.enrolled_attackers = enrolled_attackers
self.HIT_CHECK_INTERVAL = hit_check
self.REASSIGN_DELAY = reassign_delay
# Start background task
bot.loop.create_task(self.monitor_assignments_loop())
def get_next_attacker(self):
if not self.enrolled_attackers:
return None
attacker = self.enrolled_attackers[0]
self.enrolled_attackers.append(self.enrolled_attackers.pop(0)) # round-robin
return attacker
async def monitor_assignments_loop(self):
await self.bot.wait_until_ready()
while not self.bot.is_closed():
now = asyncio.get_event_loop().time()
reassign_list = []
for enemy_id, data in list(self.active_assignments.items()):
elapsed = now - data["time_assigned"]
if elapsed >= self.HIT_CHECK_INTERVAL and elapsed < self.HIT_CHECK_INTERVAL + 5:
attacker_user = self.bot.get_user(data["attacker"])
if attacker_user:
try:
await attacker_user.send(
f"Reminder: You were assigned **{data['enemy']['name']}** and they are not down yet!"
)
except:
pass
if elapsed >= self.REASSIGN_DELAY:
reassign_list.append(enemy_id)
for enemy_id in reassign_list:
info = self.active_assignments.pop(enemy_id)
await self.reassign_target(info["enemy"])
await asyncio.sleep(5)
async def reassign_target(self, enemy):
attacker = self.get_next_attacker()
if attacker is None:
return
self.active_assignments[enemy["id"]] = {
"enemy": enemy,
"attacker": attacker,
"time_assigned": asyncio.get_event_loop().time()
}
attacker_user = self.bot.get_user(attacker)
if attacker_user:
try:
await attacker_user.send(f"Target reassigned to you: **{enemy['name']}**!")
except:
pass

54
cogs/commands.py Normal file
View File

@@ -0,0 +1,54 @@
from discord.ext import commands
from services.torn_api import fetch_enemy_members
from services.ffscouter import fetch_batch_stats
class HitCommands(commands.Cog):
def __init__(self, bot, enrolled_attackers, enemy_queue):
self.bot = bot
self.enrolled_attackers = enrolled_attackers
self.enemy_queue = enemy_queue
@commands.command()
async def enroll(self, ctx):
user_id = ctx.author.id
if user_id in self.enrolled_attackers:
await ctx.send("You are already enrolled.")
return
self.enrolled_attackers.append(user_id)
await ctx.send(f"{ctx.author.mention} has been enrolled in the hit rotation!")
@commands.command()
async def drop(self, ctx):
user_id = ctx.author.id
if user_id not in self.enrolled_attackers:
await ctx.send("You are not enrolled.")
return
self.enrolled_attackers.remove(user_id)
await ctx.send(f"{ctx.author.mention} has been removed from the rotation.")
@commands.command()
async def stats(self, ctx):
members = await fetch_enemy_members()
if not members:
await ctx.send("No active members found.")
return
ids = [m["id"] for m in members if m.get("status", {}).get("state") in ("Okay", "Idle")]
ff_map = await fetch_batch_stats(ids)
lines = []
for m in members:
pid = str(m["id"])
est = ff_map.get(pid, {}).get("bs_estimate_human", "?")
if m.get("status", {}).get("state") not in ("Okay", "Idle"):
continue
lines.append(f"**{m['name']}** (ID:{pid}) | Lv {m['level']} | Estimated BS: {est}")
chunk = ""
for line in lines:
if len(chunk) + len(line) > 1900:
await ctx.send(chunk)
chunk = ""
chunk += line + "\n"
if chunk:
await ctx.send(chunk)