Fix multi-page Tupperware importing
This commit is contained in:
parent
1f00c8bf3b
commit
a25e689180
@ -541,6 +541,7 @@ async def import_tupperware(conn, message, args):
|
|||||||
|
|
||||||
await client.send_message(message.channel, embed=make_default_embed("Please reply to this message with `tul!list` (or the server equivalent)."))
|
await client.send_message(message.channel, embed=make_default_embed("Please reply to this message with `tul!list` (or the server equivalent)."))
|
||||||
|
|
||||||
|
|
||||||
# Check to make sure the Tupperware response actually belongs to the correct user
|
# Check to make sure the Tupperware response actually belongs to the correct user
|
||||||
def ensure_account(tw_msg):
|
def ensure_account(tw_msg):
|
||||||
if not tw_msg.embeds:
|
if not tw_msg.embeds:
|
||||||
@ -551,9 +552,23 @@ async def import_tupperware(conn, message, args):
|
|||||||
|
|
||||||
return tw_msg.embeds[0]["title"].startswith("{}#{}".format(message.author.name, message.author.discriminator))
|
return tw_msg.embeds[0]["title"].startswith("{}#{}".format(message.author.name, message.author.discriminator))
|
||||||
|
|
||||||
|
embeds = []
|
||||||
|
|
||||||
tw_msg = await client.wait_for_message(author=tupperware_member, channel=message.channel, timeout=60.0, check=ensure_account)
|
tw_msg = await client.wait_for_message(author=tupperware_member, channel=message.channel, timeout=60.0, check=ensure_account)
|
||||||
if not tw_msg:
|
if not tw_msg:
|
||||||
return False, "Tupperware import timed out."
|
return False, "Tupperware import timed out."
|
||||||
|
embeds.append(tw_msg.embeds[0])
|
||||||
|
|
||||||
|
# Handle Tupperware pagination
|
||||||
|
if tw_msg.embeds[0]["title"].endswith("(page 1)"):
|
||||||
|
while True:
|
||||||
|
# Wait for a new message (within 1 second)
|
||||||
|
tw_msg = await client.wait_for_message(author=tupperware_member, channel=message.channel, timeout=1.0, check=ensure_account)
|
||||||
|
if not tw_msg:
|
||||||
|
# If no message, then it's probably done, so we break
|
||||||
|
break
|
||||||
|
# Otherwise add this next message to the list
|
||||||
|
embeds.append(tw_msg.embeds[0])
|
||||||
|
|
||||||
logger.debug("Importing from Tupperware...")
|
logger.debug("Importing from Tupperware...")
|
||||||
|
|
||||||
@ -565,7 +580,7 @@ async def import_tupperware(conn, message, args):
|
|||||||
system = await db.create_system(conn, system_name=None, system_hid=hid)
|
system = await db.create_system(conn, system_name=None, system_hid=hid)
|
||||||
await db.link_account(conn, system_id=system["id"], account_id=message.author.id)
|
await db.link_account(conn, system_id=system["id"], account_id=message.author.id)
|
||||||
|
|
||||||
embed = tw_msg.embeds[0]
|
for embed in embeds:
|
||||||
for field in embed["fields"]:
|
for field in embed["fields"]:
|
||||||
name = field["name"]
|
name = field["name"]
|
||||||
lines = field["value"].split("\n")
|
lines = field["value"].split("\n")
|
||||||
|
Loading…
Reference in New Issue
Block a user