account for exceeding max number of characters in message
This commit is contained in:
parent
c3bba4bb20
commit
66c9bdada0
2 changed files with 32 additions and 13 deletions
|
|
@ -9,7 +9,7 @@ import utils as u
|
||||||
# from pyzxz import ZeroXZero
|
# from pyzxz import ZeroXZero
|
||||||
|
|
||||||
def setup(bot: bot.Bot):
|
def setup(bot: bot.Bot):
|
||||||
async def send_collage(ctx: nerimity.Context, entity: str, size: str = "3x3", timeframe: str = "7day", username: str = None):
|
async def send_collage(ctx: nerimity.Context, entity: str, size: str, timeframe: str, username: str):
|
||||||
temp_msg = None
|
temp_msg = None
|
||||||
|
|
||||||
if 'x' not in size:
|
if 'x' not in size:
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,8 @@ import utils as u
|
||||||
|
|
||||||
def setup(bot: bot.Bot):
|
def setup(bot: bot.Bot):
|
||||||
async def send_top(ctx: nerimity.Context, entity: str, timeframe: str, username: str, countstr: str):
|
async def send_top(ctx: nerimity.Context, entity: str, timeframe: str, username: str, countstr: str):
|
||||||
|
temp_msg = None
|
||||||
|
|
||||||
try: count = int(countstr)
|
try: count = int(countstr)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
await ctx.send(u.error_msg("Please input a valid number for `count`."))
|
await ctx.send(u.error_msg("Please input a valid number for `count`."))
|
||||||
|
|
@ -47,9 +49,11 @@ def setup(bot: bot.Bot):
|
||||||
|
|
||||||
case _:
|
case _:
|
||||||
timeframe = "7day"
|
timeframe = "7day"
|
||||||
period = "in the past week (default)"
|
period = "in the past week"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
temp_msg = await ctx.send(f"Generating top {entity}s list for **{username}**...")
|
||||||
|
|
||||||
user = bot.lastfm.get_user(username)
|
user = bot.lastfm.get_user(username)
|
||||||
msg_content = ""
|
msg_content = ""
|
||||||
|
|
||||||
|
|
@ -57,23 +61,35 @@ def setup(bot: bot.Bot):
|
||||||
case "artist":
|
case "artist":
|
||||||
top_list = user.get_top_artists(period=timeframe, limit=count)
|
top_list = user.get_top_artists(period=timeframe, limit=count)
|
||||||
for index, i in enumerate(top_list):
|
for index, i in enumerate(top_list):
|
||||||
msg_content += f"\n{index+1}. [{i.item.get_name(properly_capitalized=True)}]({i.item.get_url()}) | {i.weight} plays"
|
entry = f"\n{index+1}. [{i.item.get_name(properly_capitalized=True)}]({i.item.get_url()}) | {i.weight} plays"
|
||||||
|
if len(msg_content) + len(entry) < 2000:
|
||||||
|
msg_content += entry
|
||||||
|
|
||||||
case "album":
|
case "album":
|
||||||
top_list = user.get_top_albums(period=timeframe, limit=count)
|
top_list = user.get_top_albums(period=timeframe, limit=count)
|
||||||
for index, i in enumerate(top_list):
|
for index, i in enumerate(top_list):
|
||||||
msg_content += f"\n{index+1}. [{i.item.get_title(properly_capitalized=True)}]({i.item.get_url()}) by [{i.item.get_artist().get_name(properly_capitalized=True)}]({i.item.get_artist().get_url()}) | {i.weight} plays"
|
entry = f"\n{index+1}. **{i.item.get_title(properly_capitalized=True)}** by [{i.item.get_artist().get_name(properly_capitalized=True)}]({i.item.get_artist().get_url()}) | {i.weight} plays"
|
||||||
|
if len(msg_content) + len(entry) < 2000:
|
||||||
|
msg_content += entry
|
||||||
|
|
||||||
case "track":
|
case "track":
|
||||||
top_list = user.get_top_tracks(period=timeframe, limit=count)
|
top_list = user.get_top_tracks(period=timeframe, limit=count)
|
||||||
for index, i in enumerate(top_list):
|
for index, i in enumerate(top_list):
|
||||||
msg_content += f"\n{index+1}. [{i.item.get_title(properly_capitalized=True)}]({i.item.get_url()}) by [{i.item.get_artist().get_name(properly_capitalized=True)}]({i.item.get_artist().get_url()}) | {i.weight} plays"
|
entry = f"\n{index+1}. **{i.item.get_title(properly_capitalized=True)}** by [{i.item.get_artist().get_name(properly_capitalized=True)}]({i.item.get_artist().get_url()}) | {i.weight} plays"
|
||||||
|
if len(msg_content) + len(entry) < 2000:
|
||||||
|
msg_content += entry
|
||||||
|
|
||||||
msg_head = f"Top {len(top_list)} {entity}s {period} for [{username}]({user.get_url()}):\n"
|
msg_head = f"Top {len(top_list)} {entity}s {period} for [{username}]({user.get_url()}):\n"
|
||||||
|
|
||||||
msg = msg_head + msg_content
|
msg = msg_head + msg_content
|
||||||
if requested is True:
|
if len(msg) > 2000:
|
||||||
msg += f"\n### Requested by [@:{ctx.author.id}]"
|
await ctx.send(msg_head)
|
||||||
|
await ctx.send(msg_content)
|
||||||
|
return
|
||||||
|
|
||||||
|
requested_msg = f"\n\n###### (requested by [@:{ctx.author.id}])"
|
||||||
|
if requested is True and len(msg) + len(requested_msg) < 1940:
|
||||||
|
msg += requested_msg
|
||||||
|
|
||||||
await ctx.send(msg)
|
await ctx.send(msg)
|
||||||
|
|
||||||
|
|
@ -86,35 +102,38 @@ def setup(bot: bot.Bot):
|
||||||
await ctx.send(u.error_msg(f"Unknown error:\n`{e}`"))
|
await ctx.send(u.error_msg(f"Unknown error:\n`{e}`"))
|
||||||
return
|
return
|
||||||
|
|
||||||
|
finally:
|
||||||
|
if temp_msg: temp_msg.delete()
|
||||||
|
|
||||||
@bot.command(name="topartists", aliases=["ta","topartist"])
|
@bot.command(name="topartists", aliases=["ta","topartist"])
|
||||||
@bot.slash_command(name="topartists", description="Generate a list of your most played artists.")
|
@bot.slash_command(name="topartists", description="Generate a list of your most played artists.")
|
||||||
async def topartists(ctx: nerimity.Context, timeframe: str = "7day", username: str = None, countstr: str = "10"):
|
async def topartists(ctx: nerimity.Context, timeframe: str = "7day", username: str = None, count: str = "10"):
|
||||||
await send_top(
|
await send_top(
|
||||||
ctx = ctx,
|
ctx = ctx,
|
||||||
entity = "artist",
|
entity = "artist",
|
||||||
timeframe = timeframe,
|
timeframe = timeframe,
|
||||||
username = username,
|
username = username,
|
||||||
countstr = countstr
|
countstr = count
|
||||||
)
|
)
|
||||||
|
|
||||||
@bot.command(name="topalbums", aliases=["t","top","topalbum"])
|
@bot.command(name="topalbums", aliases=["t","top","topalbum"])
|
||||||
@bot.slash_command(name="topalbums", description="Generate a list of your most played albums.")
|
@bot.slash_command(name="topalbums", description="Generate a list of your most played albums.")
|
||||||
async def topalbums(ctx: nerimity.Context, timeframe: str = "7day", username: str = None, countstr: str = "10"):
|
async def topalbums(ctx: nerimity.Context, timeframe: str = "7day", username: str = None, count: str = "10"):
|
||||||
await send_top(
|
await send_top(
|
||||||
ctx = ctx,
|
ctx = ctx,
|
||||||
entity = "album",
|
entity = "album",
|
||||||
timeframe = timeframe,
|
timeframe = timeframe,
|
||||||
username = username,
|
username = username,
|
||||||
countstr = countstr
|
countstr = count
|
||||||
)
|
)
|
||||||
|
|
||||||
@bot.command(name="toptracks", aliases=["tt","toptrack"])
|
@bot.command(name="toptracks", aliases=["tt","toptrack"])
|
||||||
@bot.slash_command(name="toptracks", description="Generate a list of your most played songs.")
|
@bot.slash_command(name="toptracks", description="Generate a list of your most played songs.")
|
||||||
async def toptracks(ctx: nerimity.Context, timeframe: str = "7day", username: str = None, countstr: str = "10"):
|
async def toptracks(ctx: nerimity.Context, timeframe: str = "7day", username: str = None, count: str = "10"):
|
||||||
await send_top(
|
await send_top(
|
||||||
ctx = ctx,
|
ctx = ctx,
|
||||||
entity = "track",
|
entity = "track",
|
||||||
timeframe = timeframe,
|
timeframe = timeframe,
|
||||||
username = username,
|
username = username,
|
||||||
countstr = countstr
|
countstr = count
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue