From ef4be976fb678a449f08a15261e478aef27bf281 Mon Sep 17 00:00:00 2001 From: yuki Date: Thu, 9 Oct 2025 00:13:35 -0300 Subject: [PATCH] create post and post removal commands --- commands/admin.py | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/commands/admin.py b/commands/admin.py index 0baa993..69c733b 100644 --- a/commands/admin.py +++ b/commands/admin.py @@ -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}`"))