Compare commits
No commits in common. "ba5442d854be26bc7b62d7bb180b0db0d6a30bb2" and "71958377a5efc02eeabe03511153e27489e7499d" have entirely different histories.
ba5442d854
...
71958377a5
6 changed files with 30 additions and 29 deletions
6
bot.py
6
bot.py
|
|
@ -21,14 +21,14 @@ class Bot(nerimity.Client):
|
||||||
|
|
||||||
# initialize last.fm client
|
# initialize last.fm client
|
||||||
self.lastfm = pylast.LastFMNetwork(
|
self.lastfm = pylast.LastFMNetwork(
|
||||||
api_key = lastfm_api_key,
|
api_key = lastfm_api_key,
|
||||||
api_secret = lastfm_api_secret
|
api_secret = lastfm_api_secret
|
||||||
)
|
)
|
||||||
|
|
||||||
# initialize collage generator
|
# initialize collage generator
|
||||||
self.collage_generator = CollageGenerator(
|
self.collage_generator = CollageGenerator(
|
||||||
lastfm_api_key = lastfm_api_key,
|
lastfm_api_key=lastfm_api_key,
|
||||||
lastfm_api_secret = lastfm_api_secret
|
lastfm_api_secret=lastfm_api_secret
|
||||||
)
|
)
|
||||||
|
|
||||||
# initialize catbox client
|
# initialize catbox client
|
||||||
|
|
|
||||||
|
|
@ -46,12 +46,11 @@ def setup(bot: bot.Bot):
|
||||||
return
|
return
|
||||||
|
|
||||||
match timeframe:
|
match timeframe:
|
||||||
case "a" | "all" | "alltime" | "o": timeframe = "overall"
|
case "a" | "all" | "alltime" | "o" | "overall": timeframe = "overall"
|
||||||
case "y" | "year" | "yearly": timeframe = "12month"
|
case "y" | "year" | "yearly": timeframe = "12month"
|
||||||
case "m" | "month" | "monthly": timeframe = "1month"
|
case "m" | "month" | "monthly": timeframe = "1month"
|
||||||
case "w" | "week" | "weekly": timeframe = "7day"
|
case "w" | "week" | "weekly": timeframe = "7day"
|
||||||
case "d" | "day" | "daily": timeframe = "1day"
|
case "d" | "day" | "daily": timeframe = "1day"
|
||||||
|
|
||||||
case _: "7day"
|
case _: "7day"
|
||||||
|
|
||||||
if timeframe == "1day":
|
if timeframe == "1day":
|
||||||
|
|
@ -62,11 +61,11 @@ def setup(bot: bot.Bot):
|
||||||
temp_msg = await ctx.send(f"Generating album chart for **{username}**...")
|
temp_msg = await ctx.send(f"Generating album chart for **{username}**...")
|
||||||
|
|
||||||
image = bot.collage_generator.generate(
|
image = bot.collage_generator.generate(
|
||||||
entity = "album",
|
entity = "album",
|
||||||
username = username,
|
username = username,
|
||||||
rows = int(size.split(sep="x")[0]),
|
rows = int(size.split(sep="x")[0]),
|
||||||
cols = int(size.split(sep="x")[1]),
|
cols = int(size.split(sep="x")[1]),
|
||||||
period = timeframe
|
period = timeframe
|
||||||
)
|
)
|
||||||
|
|
||||||
img_bytes = io.BytesIO()
|
img_bytes = io.BytesIO()
|
||||||
|
|
@ -87,10 +86,9 @@ def setup(bot: bot.Bot):
|
||||||
link = await bot.zxz.upload_from_bytes(img_bytes.getvalue(), "chart.png")
|
link = await bot.zxz.upload_from_bytes(img_bytes.getvalue(), "chart.png")
|
||||||
|
|
||||||
await ctx.send(u.good_msg(f"**{size}** {timeframe} chart for [{username}](https://last.fm/user/{username}) successfully generated:\n{link}"))
|
await ctx.send(u.good_msg(f"**{size}** {timeframe} chart for [{username}](https://last.fm/user/{username}) successfully generated:\n{link}"))
|
||||||
|
temp_msg.delete()
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
if temp_msg: temp_msg.delete()
|
||||||
print(e)
|
print(e)
|
||||||
await ctx.send(u.error_msg(f"I crashed and burned while generating the chart:\n`{e}`"))
|
await ctx.send(u.error_msg(f"I crashed and burned while generating the chart:\n`{e}`"))
|
||||||
|
|
||||||
finally:
|
|
||||||
if temp_msg: temp_msg.delete()
|
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,8 @@ def setup(bot: bot.Bot):
|
||||||
@bot.slash_command(name="setfm", description="Sets your Last.fm username.")
|
@bot.slash_command(name="setfm", description="Sets your Last.fm username.")
|
||||||
async def setfm(ctx: nerimity.Context, username: str = None):
|
async def setfm(ctx: nerimity.Context, username: str = None):
|
||||||
if not username:
|
if not username:
|
||||||
await ctx.send(u.error_msg("Please provide your Last.fm username.\nusage: `/fm <your last.fm username>`"))
|
await ctx.send(u.error_msg("Please provide your Last.fm username.\n\
|
||||||
|
usage: `/fm <your last.fm username>`"))
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
|
|
@ -12,10 +12,12 @@ def setup(bot: bot.Bot):
|
||||||
else:
|
else:
|
||||||
try: username = await bot.get_lastfm(ctx.author.id)
|
try: username = await bot.get_lastfm(ctx.author.id)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
await ctx.send(u.error_msg(f"Unknown database error:\n{e}"))
|
await ctx.send(u.error_msg(f"Unknown database error:\n{e}"))
|
||||||
|
|
||||||
if not username:
|
if not username:
|
||||||
await ctx.send(u.error_msg("Please provide a Last.fm username (or set yours with `/setfm`)"))
|
await ctx.send(u.error_msg("Please provide a Last.fm username (or set yours with `/setfm`)"))
|
||||||
|
print("returned")
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
@ -33,9 +35,10 @@ def setup(bot: bot.Bot):
|
||||||
track_artist = track.get_artist().get_name()
|
track_artist = track.get_artist().get_name()
|
||||||
track_artist_url = track.get_artist().get_url()
|
track_artist_url = track.get_artist().get_url()
|
||||||
|
|
||||||
np = "Now playing for" if now_playing else "Last played by"
|
if now_playing == True:
|
||||||
|
await ctx.send(f"Now playing for **{username}**: [{track_name}]({track_url}) by [{track_artist}]({track_artist_url})")
|
||||||
await ctx.send(f"{np} **{username}**: [{track_name}]({track_url}) by [{track_artist}]({track_artist_url})")
|
else:
|
||||||
|
await ctx.send(f"Last played for **{username}**: [{track_name}]({track_url}) by [{track_artist}]({track_artist_url})")
|
||||||
|
|
||||||
except IndexError:
|
except IndexError:
|
||||||
await ctx.send(u.error_msg(f"User **{username}** has no recent tracks or they're set to private."))
|
await ctx.send(u.error_msg(f"User **{username}** has no recent tracks or they're set to private."))
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,6 @@
|
||||||
import nerimity
|
import nerimity
|
||||||
|
|
||||||
import bot
|
def setup(bot):
|
||||||
|
|
||||||
def setup(bot: bot.Bot):
|
|
||||||
@bot.command(name="ping")
|
@bot.command(name="ping")
|
||||||
@bot.slash_command(name="ping", description="Ping...")
|
@bot.slash_command(name="ping", description="Ping...")
|
||||||
async def ping(ctx: nerimity.Context):
|
async def ping(ctx: nerimity.Context):
|
||||||
|
|
|
||||||
11
main.py
11
main.py
|
|
@ -5,11 +5,12 @@ import bot
|
||||||
with open("config.toml", "rb") as f:
|
with open("config.toml", "rb") as f:
|
||||||
config = tomllib.load(f)
|
config = tomllib.load(f)
|
||||||
|
|
||||||
|
# nerimity client
|
||||||
bot = bot.Bot(
|
bot = bot.Bot(
|
||||||
prefix = '!',
|
prefix = '!',
|
||||||
token = config['token'],
|
token = config['token'],
|
||||||
owner_id = config['owner_id'],
|
owner_id = config['owner_id'],
|
||||||
lastfm_api_key = config['api_key'],
|
lastfm_api_key = config['api_key'],
|
||||||
lastfm_api_secret = config['api_secret']
|
lastfm_api_secret = config['api_secret']
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -20,4 +21,4 @@ async def on_ready(params):
|
||||||
print(f"Logged in as {bot.account.username}")
|
print(f"Logged in as {bot.account.username}")
|
||||||
await bot.init_db()
|
await bot.init_db()
|
||||||
|
|
||||||
bot.run(restart_always = True)
|
bot.run()
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue