fix (rooms): Support joining open slot.
This commit is contained in:
@@ -60,7 +60,6 @@ class TimeSlot:
|
|||||||
)
|
)
|
||||||
|
|
||||||
slots = {}
|
slots = {}
|
||||||
channel_slots = {}
|
|
||||||
|
|
||||||
_member_overwrite = discord.PermissionOverwrite(
|
_member_overwrite = discord.PermissionOverwrite(
|
||||||
view_channel=True,
|
view_channel=True,
|
||||||
@@ -233,11 +232,19 @@ class TimeSlot:
|
|||||||
"""
|
"""
|
||||||
Refresh the stored data row and reload.
|
Refresh the stored data row and reload.
|
||||||
"""
|
"""
|
||||||
self.data = next(accountability_rooms.fetch_rows_where(
|
rows = accountability_rooms.fetch_rows_where(
|
||||||
guildid=self.guild.id,
|
guildid=self.guild.id,
|
||||||
open_at=self.start_time
|
start_at=self.start_time
|
||||||
), None)
|
)
|
||||||
self.load()
|
self.data = rows[0] if rows else None
|
||||||
|
|
||||||
|
memberids = []
|
||||||
|
if self.data:
|
||||||
|
member_rows = accountability_members.fetch_rows_where(
|
||||||
|
slotid=self.data.slotid
|
||||||
|
)
|
||||||
|
memberids = [row.userid for row in member_rows]
|
||||||
|
self.load(memberids=memberids)
|
||||||
|
|
||||||
async def open(self):
|
async def open(self):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ from data.conditions import GEQ
|
|||||||
|
|
||||||
from .module import module
|
from .module import module
|
||||||
from .lib import utc_now
|
from .lib import utc_now
|
||||||
|
from .tracker import AccountabilityGuild as AGuild
|
||||||
|
from .TimeSlot import SlotMember
|
||||||
from .data import accountability_members, accountability_member_info, accountability_open_slots, accountability_rooms
|
from .data import accountability_members, accountability_member_info, accountability_open_slots, accountability_rooms
|
||||||
|
|
||||||
|
|
||||||
@@ -77,8 +79,11 @@ async def cmd_rooms(ctx):
|
|||||||
try:
|
try:
|
||||||
message = await ctx.client.wait_for('message', check=check, timeout=60)
|
message = await ctx.client.wait_for('message', check=check, timeout=60)
|
||||||
except asyncio.TimeoutError:
|
except asyncio.TimeoutError:
|
||||||
|
try:
|
||||||
await out_msg.delete()
|
await out_msg.delete()
|
||||||
await ctx.error_reply("Session timed out. No accountability bookings were cancelled.")
|
await ctx.error_reply("Session timed out. No accountability bookings were cancelled.")
|
||||||
|
except discord.HTTPException:
|
||||||
|
pass
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -163,8 +168,11 @@ async def cmd_rooms(ctx):
|
|||||||
try:
|
try:
|
||||||
message = await ctx.client.wait_for('message', check=check, timeout=60)
|
message = await ctx.client.wait_for('message', check=check, timeout=60)
|
||||||
except asyncio.TimeoutError:
|
except asyncio.TimeoutError:
|
||||||
|
try:
|
||||||
await out_msg.delete()
|
await out_msg.delete()
|
||||||
await ctx.error_reply("Session timed out. No accountability slots were booked.")
|
await ctx.error_reply("Session timed out. No accountability slots were booked.")
|
||||||
|
except discord.HTTPException:
|
||||||
|
pass
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -192,6 +200,7 @@ async def cmd_rooms(ctx):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Add the member to data, creating the row if required
|
||||||
slot_rows = accountability_rooms.fetch_rows_where(
|
slot_rows = accountability_rooms.fetch_rows_where(
|
||||||
guildid=ctx.guild.id,
|
guildid=ctx.guild.id,
|
||||||
start_at=to_book
|
start_at=to_book
|
||||||
@@ -207,6 +216,23 @@ async def cmd_rooms(ctx):
|
|||||||
*((slotid, ctx.author.id, ctx.guild_settings.accountability_price.value) for slotid in slotids),
|
*((slotid, ctx.author.id, ctx.guild_settings.accountability_price.value) for slotid in slotids),
|
||||||
insert_keys=('slotid', 'userid', 'paid')
|
insert_keys=('slotid', 'userid', 'paid')
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Handle case where the slot has already opened
|
||||||
|
aguild = AGuild.cache.get(ctx.guild.id, None)
|
||||||
|
if aguild:
|
||||||
|
if aguild.upcoming_slot and aguild.upcoming_slot.start_time in to_book:
|
||||||
|
slot = aguild.upcoming_slot
|
||||||
|
if not slot.data:
|
||||||
|
# Handle slot activation
|
||||||
|
slot._refresh()
|
||||||
|
channelid, messageid = await slot.open()
|
||||||
|
accountability_rooms.update_where(
|
||||||
|
{'channelid': channelid, 'messageid': messageid},
|
||||||
|
slotid=slot.data.slotid
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
slot.members.append(SlotMember(slot.data.slotid, ctx.author.id, ctx.guild))
|
||||||
|
await slot.update_status()
|
||||||
ctx.alion.addCoins(-cost)
|
ctx.alion.addCoins(-cost)
|
||||||
await ctx.embed_reply(
|
await ctx.embed_reply(
|
||||||
"You have booked the following accountability sessions.\n{}".format(
|
"You have booked the following accountability sessions.\n{}".format(
|
||||||
|
|||||||
Reference in New Issue
Block a user