Пример #1
0
    async def publish(self, ctx: commands.Context, subtitle):
        if not is_mod(self.bot.conn, ctx):
            await ctx.send("You're not a mod")
            return

        categories_list: list = categories.get_server_categories(
            self.bot.conn, ctx.guild.id)
        if subtitle not in categories_list:
            await ctx.send("Category {} does not exist".format(subtitle))
            return

        title: str = self.temp_posts[ctx.guild.id][0].title
        content: str = content_from_msg_list(self.temp_posts[ctx.guild.id][1])

        try:
            posts.add_post(self.bot.conn, ctx.guild.id, subtitle, title,
                           subtitle, content)
        except psycopg2.IntegrityError as err:
            await ctx.send("Error: {}".format(err))
            self.bot.conn.rollback()
            return

        create_md_file(path=blog_path.format(ctx.guild.name) +
                       "{}".format(subtitle),
                       filename="{}.md".format(title),
                       title=title,
                       subtitle=subtitle,
                       content=content)

        self.temp_posts.pop(ctx.guild.id)
        await ctx.send("Post submitted to blog")
Пример #2
0
 async def create_embed(self, ctx: commands.Context):
     if not is_mod(self.bot.conn, ctx):
         await ctx.send("You're not a mod")
         return
     self.temp_posts[ctx.guild.id] = (discord.Embed(
         color=discord.Color.from_rgb(106, 252, 228)), [])
     await ctx.send(
         "New post initiated\nSet up a **title**, the **content** and then **public** it to a category!"
     )
Пример #3
0
 async def list_categories(self, ctx: commands.Context):
     if not is_mod(self.bot.conn, ctx):
         await ctx.send("You're not a mod")
         return
     categories_list: list = categories.get_server_categories(
         self.bot.conn, ctx.guild.id)
     message: str = "Available categories:\n"
     for category in categories_list:
         message += "{}\n".format(category)
     await ctx.send(message)
Пример #4
0
 async def create_category(self, ctx: commands.Context, *args: str):
     if not is_mod(self.bot.conn, ctx):
         await ctx.send("You're not a mod")
         return
     arg: str = ' '.join(args)
     try:
         categories.add_category(self.bot.conn, ctx.guild.id, arg)
     except psycopg2.IntegrityError as err:
         await ctx.send("Error: {}".format(err))
         self.bot.conn.rollback()
         return
     await ctx.send("Category `{}` successfully created".format(arg))
Пример #5
0
 async def remove_category(self, ctx: commands.Context, *args: str):
     if not is_mod(self.bot.conn, ctx):
         await ctx.send("You're not a mod")
         return
     arg: str = ' '.join(args)
     categories_list: list = categories.get_server_categories(
         self.bot.conn, ctx.guild.id)
     if arg not in categories_list:
         await ctx.send("Category does not exist")
         return
     categories.remove_category(self.bot.conn, ctx.guild.id, arg)
     await ctx.send("Category `{}` successfully removed".format(arg))
Пример #6
0
 async def preview(self, ctx: commands.Context, subtitle):
     if not is_mod(self.bot.conn, ctx):
         await ctx.send("You're not a mod")
         return
     categories_list: list = categories.get_server_categories(
         self.bot.conn, ctx.guild.id)
     if subtitle not in categories_list:
         await ctx.send("Category {} does not exist".format(subtitle))
         return
     title: str = self.temp_posts[ctx.guild.id][0].title
     content: str = content_from_msg_list(self.temp_posts[ctx.guild.id][1])
     create_md_file(path=".",
                    filename="{}.md".format(ctx.guild.name),
                    title=title,
                    subtitle=subtitle,
                    content=content)
     await ctx.send(file=discord.File("{}.md".format(ctx.guild.name)))
     os.remove("{}.md".format(ctx.guild.name))
Пример #7
0
 async def content(self, ctx: commands.Context, *args: str):
     if not is_mod(self.bot.conn, ctx):
         await ctx.send("You're not a mod")
         return
     current_tuple: typing.Tuple[
         discord.Embed,
         typing.List[discord.Message]] = self.temp_posts[ctx.guild.id]
     for messageID in args:
         try:
             current_tuple[1].append(await ctx.channel.fetch_message(
                 int(messageID)))
         except Exception as e:
             await ctx.send(
                 "Error while adding the message with ID {}\n{}".format(
                     messageID, e))
     embed_content = '\n'.join(
         [str(message.jump_url) for message in current_tuple[1]])
     current_tuple[0].clear_fields()
     current_tuple[0].add_field(name="content", value=embed_content)
     await ctx.send(embed=current_tuple[0])
     self.temp_posts[
         ctx.guild.
         id] = current_tuple  # not sure if needed since im not doing a deep copy
Пример #8
0
 async def title(self, ctx: commands.Context, *args: str):
     if not is_mod(self.bot.conn, ctx):
         await ctx.send("You're not a mod")
         return
     self.temp_posts[ctx.guild.id][0].title = ' '.join(args)
     await ctx.send("Post edited", embed=self.temp_posts[ctx.guild.id][0])