Compare commits

...

3 commits

Author SHA1 Message Date
0664529c70 move prefix to config.toml 2025-10-09 00:19:22 -03:00
ef4be976fb create post and post removal commands 2025-10-09 00:13:35 -03:00
e0cb8de6ec except ValueError in collage generation 2025-10-08 23:52:32 -03:00
4 changed files with 38 additions and 16 deletions

View file

@ -6,9 +6,8 @@ import utils as u
def setup(bot: bot.Bot):
@bot.command(name="echo")
async def echo(ctx: nerimity.Context, *text: str):
if not bot.is_owner(ctx.author):
print("returned")
return
if not bot.is_owner(ctx.author): return
if not text:
await ctx.send(u.error_msg("Contents are empty."))
return
@ -20,9 +19,7 @@ def setup(bot: bot.Bot):
@bot.command(name="servercount", aliases=["sc"])
async def servercount(ctx: nerimity.Context):
if not bot.is_owner(ctx.author):
print("returned")
return
if not bot.is_owner(ctx.author): return
try: await ctx.send(f"I'm in {len(bot.servers)} servers!!")
except Exception as e:
@ -31,19 +28,39 @@ def setup(bot: bot.Bot):
@bot.command(name="post")
async def post(ctx: nerimity.Context, *text: str):
if not bot.is_owner(ctx.author):
print("returned")
return
if not bot.is_owner(ctx.author): return
if not text:
await ctx.send(u.error_msg("Contents are empty."))
return
try:
await ctx.send(f"Creating post:\n```markdown\n{" ".join(text)}\n```")
# TODO: post removal command :p
# post = nerimity.Post.create_post(content=" ".join(text))
# print(post)
post = nerimity.Post.create_post(content=" ".join(text))
print(f"Posted: {post}")
await ctx.send(u.good_msg(f"Post created!!"))
except Exception as e:
print(e)
await ctx.send(u.error_msg(f"Unknown error:\n`{e}`"))
@bot.command(name="rmpost")
async def rmpost(ctx: nerimity.Context, post: str = None):
if not bot.is_owner(ctx.author): return
if not post:
await ctx.send(u.error_msg("No post ID provided."))
return
try:
post_id = int(post)
_post = nerimity.Post.get_post(post_id)
_post.delete_post()
await ctx.send("Deleted post.")
except Exception as e:
print(e)
await ctx.send(u.error_msg(f"Unknown error:\n`{e}`"))

View file

@ -15,9 +15,13 @@ async def send_collage(bot: bot.Bot, ctx: nerimity.Context, entity: str, size: s
await ctx.send(u.error_msg(f"Please provide a valid size.\nie `/chart{entity} 5x5`"))
return
if int(size.split('x')[0]) > 5 or int(size.split('x')[1]) > 5:
await ctx.send(u.error_msg("Maximum size allowed is 5x5."))
return
try:
if int(size.split('x')[0]) > 5 or int(size.split('x')[1]) > 5:
await ctx.send(u.error_msg("Maximum size allowed is 5x5."))
return
except ValueError:
await ctx.send(u.error_msg(f"Please provide a valid size.\nie `/chart{entity} 5x5`"))
if not username:
try: username = await bot.get_lastfm(ctx.author.id)

View file

@ -1,3 +1,4 @@
prefix = "!"
token = "NerimityTokenHere"
owner_id = 1234567890
api_key = "LastFmApiKeyHere"

View file

@ -6,7 +6,7 @@ with open("config.toml", "rb") as f:
config = tomllib.load(f)
bot = bot.Bot(
prefix = '!',
prefix = config['prefix'],
token = config['token'],
owner_id = config['owner_id'],
lastfm_api_key = config['api_key'],