(cmd_now): Wording updates and clear pathway.

This commit is contained in:
2022-01-12 09:02:26 +02:00
parent 1629a34ea1
commit d1f27ca826

View File

@@ -2,6 +2,7 @@ from cmdClient import Context
from cmdClient.checks import in_guild from cmdClient.checks import in_guild
from core import Lion from core import Lion
from wards import is_guild_admin
from ..module import module from ..module import module
@@ -13,22 +14,53 @@ MAX_TAG_LENGTH = 10
"now", "now",
group="Statistics", group="Statistics",
desc="What are you working on?", desc="What are you working on?",
aliases=('studying', 'workingon') aliases=('studying', 'workingon'),
flags=('clear', 'new')
) )
@in_guild() @in_guild()
async def cmd_now(ctx: Context): async def cmd_now(ctx: Context, flags):
""" """
Usage``: Usage``:
{prefix}now [tag] {prefix}now [tag]
{prefix}now @mention {prefix}now @mention
{prefix}now --clear
Description: Description:
Describe the subject or goal you are working on this session with, for example, `{prefix}now Maths`. Describe the subject or goal you are working on this session with, for example, `{prefix}now Maths`.
Mention someone else to view what they are working on! Mention someone else to view what they are working on!
Flags::
clear: Remove your current tag.
Examples: Examples:
> {prefix}now Biology > {prefix}now Biology
> {prefix}now {ctx.author.mention} > {prefix}now {ctx.author.mention}
""" """
if ctx.args: if flags['clear']:
if ctx.msg.mentions and is_guild_admin(ctx.author):
# Assume an admin is trying to clear another user's tag
for target in ctx.msg.mentions:
lion = Lion.fetch(ctx.guild.id, target.id)
if lion.session:
lion.session.data.tag = None
if len(ctx.msg.mentions) == 1:
await ctx.embed_reply(
f"Cleared session tags for {ctx.msg.mentions[0].mention}."
)
else:
await ctx.embed_reply(
f"Cleared session tags for:\n{', '.join(target.mention for target in ctx.msg.mentions)}."
)
else:
# Assume the user is clearing their own session tag
if (session := ctx.alion.session):
session.data.tag = None
await ctx.embed_reply(
"Removed your session study tag!"
)
else:
await ctx.embed_reply(
"You aren't studying right now, so there is nothing to clear!"
)
elif ctx.args:
if ctx.msg.mentions: if ctx.msg.mentions:
# Assume peeking at user's current session # Assume peeking at user's current session
@@ -48,14 +80,14 @@ async def cmd_now(ctx: Context):
return await ctx.embed_reply( return await ctx.embed_reply(
"Thanks for asking!\n" "Thanks for asking!\n"
f"I'm just helping out the **{student_count}** " f"I'm just helping out the **{student_count}** "
f"hardworking students currently studying across **{guild_count}** fun communities!\n" f"dedicated people currently working across **{guild_count}** fun communities!\n"
f"{tail}" f"{tail}"
) )
lion = Lion.fetch(ctx.guild.id, target.id) lion = Lion.fetch(ctx.guild.id, target.id)
if not lion.session: if not lion.session:
await ctx.embed_reply( await ctx.embed_reply(
f"{target.mention} isn't studying right now!" f"{target.mention} isn't working right now!"
) )
else: else:
duration = lion.session.duration duration = lion.session.duration
@@ -69,7 +101,7 @@ async def cmd_now(ctx: Context):
if not lion.session.data.tag: if not lion.session.data.tag:
await ctx.embed_reply( await ctx.embed_reply(
f"{target.mention} has been studying in <#{lion.session.data.channelid}> for **{dur_str}**!" f"{target.mention} has been working in <#{lion.session.data.channelid}> for **{dur_str}**!"
) )
else: else:
await ctx.embed_reply( await ctx.embed_reply(
@@ -82,7 +114,7 @@ async def cmd_now(ctx: Context):
if not (session := ctx.alion.session): if not (session := ctx.alion.session):
return await ctx.error_reply( return await ctx.error_reply(
"You aren't studying right now! Join a study channel and try again!" "You aren't working right now! Join a study channel and try again!"
) )
if len(tag) > MAX_TAG_LENGTH: if len(tag) > MAX_TAG_LENGTH:
@@ -103,7 +135,6 @@ async def cmd_now(ctx: Context):
) )
else: else:
# View current session, stats, and guide. # View current session, stats, and guide.
lines = []
if (session := ctx.alion.session): if (session := ctx.alion.session):
duration = session.duration duration = session.duration
if duration > 3600: if duration > 3600:
@@ -115,11 +146,9 @@ async def cmd_now(ctx: Context):
dur_str = "{} minutes".format(int((duration % 3600) / 60)) dur_str = "{} minutes".format(int((duration % 3600) / 60))
if not session.data.tag: if not session.data.tag:
await ctx.embed_reply( await ctx.embed_reply(
f"You have been studying in <#{session.data.channelid}> for **{dur_str}**!" f"You have been working in <#{session.data.channelid}> for **{dur_str}**!\n"
)
lines.append(
f"Describe what you are working on with " f"Describe what you are working on with "
"`{ctx.best_prefix}now <tag>`, e.g. `{ctx.best_prefix}now Maths`!" f"`{ctx.best_prefix}now <tag>`, e.g. `{ctx.best_prefix}now Maths`"
) )
else: else:
await ctx.embed_reply( await ctx.embed_reply(
@@ -128,7 +157,7 @@ async def cmd_now(ctx: Context):
) )
else: else:
await ctx.embed_reply( await ctx.embed_reply(
f"Join a study channel and describe what you are working on with e.g. `{ctx.best_prefix}now Maths!`" f"Join a study channel and describe what you are working on with e.g. `{ctx.best_prefix}now Maths`"
) )
# TODO: Favourite tags listing # TODO: Favourite tags listing