Battleorders WIP
This commit is contained in:
parent
0c5fa46e2b
commit
fc7c57abe5
@ -64,6 +64,31 @@ async def control_mention_remove(ctx, kind: str, division: str):
|
|||||||
return await ctx.send(MESSAGES["nothing_to_do"])
|
return await ctx.send(MESSAGES["nothing_to_do"])
|
||||||
|
|
||||||
|
|
||||||
|
async def control_order_set(ctx, battle_id, side):
|
||||||
|
if not DB.get_battle_order(battle_id):
|
||||||
|
side_id = None
|
||||||
|
try:
|
||||||
|
side_id = COUNTRIES[int(side)].id
|
||||||
|
except (ValueError, KeyError):
|
||||||
|
try:
|
||||||
|
side_id = [c for c in COUNTRIES.values() if side.lower() in repr(c).lower()][0].id
|
||||||
|
except IndexError:
|
||||||
|
return await ctx.send(MESSAGES["command_failed"])
|
||||||
|
DB.set_battle_order(battle_id, side_id)
|
||||||
|
return await ctx.send(f"✅ Order has been set! {COUNTIRES[side_id].name} must win")
|
||||||
|
return await ctx.send(MESSAGES["nothing_to_do"])
|
||||||
|
|
||||||
|
async def control_order_unset(ctx, battle_id):
|
||||||
|
if DB.delete_battle_order(battle_id):
|
||||||
|
return await ctx.send(f"✅ Order has been unset!")
|
||||||
|
return await ctx.send(MESSAGES["nothing_to_do"])
|
||||||
|
|
||||||
|
|
||||||
|
async def control_order(ctx, action, *args):
|
||||||
|
if action == "set":
|
||||||
|
return await control_order_set(ctx, *args)
|
||||||
|
return await ctx.send(MESSAGES["nothing_to_do"])
|
||||||
|
|
||||||
@bot.event
|
@bot.event
|
||||||
async def on_ready():
|
async def on_ready():
|
||||||
logger.info("Bot loaded")
|
logger.info("Bot loaded")
|
||||||
|
24
dbot/db.py
24
dbot/db.py
@ -20,6 +20,7 @@ class DiscordDB:
|
|||||||
self.rss_feed = self._db.table("rss_feed")
|
self.rss_feed = self._db.table("rss_feed")
|
||||||
self.channel = self._db.table("channel")
|
self.channel = self._db.table("channel")
|
||||||
self.role_mapping = self._db.table("role_mapping")
|
self.role_mapping = self._db.table("role_mapping")
|
||||||
|
self.battleorder = self._db.table("battleorder")
|
||||||
|
|
||||||
def initialize(self):
|
def initialize(self):
|
||||||
hard_tables = ["member", "player", "channel", "role_mapping"]
|
hard_tables = ["member", "player", "channel", "role_mapping"]
|
||||||
@ -59,6 +60,7 @@ class DiscordDB:
|
|||||||
|
|
||||||
self._db.create_table("division", {"division_id": int, "epic": bool, "empty": bool}, pk="id", defaults={"epic": False, "empty": False}, not_null={"division_id"})
|
self._db.create_table("division", {"division_id": int, "epic": bool, "empty": bool}, pk="id", defaults={"epic": False, "empty": False}, not_null={"division_id"})
|
||||||
self._db.create_table("rss_feed", {"timestamp": float}, pk="id", not_null={"timestamp"})
|
self._db.create_table("rss_feed", {"timestamp": float}, pk="id", not_null={"timestamp"})
|
||||||
|
self._db.create_table("battleorder", {"battle_id": int, "side": int}, pk="id", not_null={"battle_id","side"}, defaults={"side":71})
|
||||||
|
|
||||||
self._db.vacuum()
|
self._db.vacuum()
|
||||||
|
|
||||||
@ -277,3 +279,25 @@ class DiscordDB:
|
|||||||
rows = self.role_mapping.rows_where("channel_id = ? and division = ?", (ch_id, division))
|
rows = self.role_mapping.rows_where("channel_id = ? and division = ?", (ch_id, division))
|
||||||
for row in rows:
|
for row in rows:
|
||||||
return row["role_id"]
|
return row["role_id"]
|
||||||
|
|
||||||
|
def set_battle_order(self, battle_id:int, side:int):
|
||||||
|
if self.get_battle_order(battle_id):
|
||||||
|
return False
|
||||||
|
self.battleorder.insert(dict(battle_id=battle_id, side=side))
|
||||||
|
return True
|
||||||
|
|
||||||
|
def get_battle_order(self, battle_id: int = None):
|
||||||
|
if battle_id is None:
|
||||||
|
return list(sef.battleorder.rows)
|
||||||
|
try:
|
||||||
|
row = next(self.battleorder.rows_where('battle_id = ?', (battle_id,)))
|
||||||
|
return row
|
||||||
|
except StopIterationError:
|
||||||
|
return
|
||||||
|
|
||||||
|
def delete_battle_order(self, battle_id: int):
|
||||||
|
bo = self.get_battle_order(battle_id)
|
||||||
|
if bo:
|
||||||
|
DB.battleorder.delete(bo['id'])
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
Loading…
x
Reference in New Issue
Block a user