Ejemplo n.º 1
0
 async def addproject(self, ctx, *, arg):
     session1 = self.bot.Session()
     try:
         arg = arg[1:]
         d = dict(x.split('=', 1) for x in arg.split(' -'))
         if "link" in d and "title" in d and "altNames" in d and "status" in d:
             try:
                 projects = searchproject(d["title"], session1)
                 raise AttributeError
             except exceptions.NoResultFound:
                 pr = Project(d["title"], d["status"] if "status" in d else "inactive", d["link"], d["altNames"])
                 if "ts" in d:
                     pr.typesetter = await searchstaff(d["ts"], ctx, session1)
                 if "rd" in d:
                     pr.redrawer = await searchstaff(d["rd"], ctx, session1)
                 if "pr" in d:
                     pr.proofreader = await searchstaff(d["pr"], ctx, session1)
                 if "tl" in d:
                     pr.translator = await searchstaff(d["tl"], ctx, session1)
                 if "icon" in d:
                     pr.icon = d["icon"]
                 if "thumbnail" in d:
                     pr.thumbnail = d["thumbnail"]
                 session1.add(pr)
                 await ctx.send(
                     "✅ Successfully added {} to projects with the status {}".format(d["title"], d["status"]))
             except AttributeError:
                 raise AttributeError
         else:
             raise MissingRequiredParameter("link, title, altNames or status")
         session1.commit()
     finally:
         session1.close()
Ejemplo n.º 2
0
 async def assign(self, ctx, *, arg):
     """Says hello"""
     session = self.bot.Session()
     try:
         arg = arg[1:]
         d = dict(x.split('=', 1) for x in arg.split(' -'))
         ts_alias = aliased(Staff)
         rd_alias = aliased(Staff)
         tl_alias = aliased(Staff)
         pr_alias = aliased(Staff)
         query = session.query(Chapter).outerjoin(ts_alias, Chapter.typesetter_id == ts_alias.id). \
             outerjoin(rd_alias, Chapter.redrawer_id == rd_alias.id). \
             outerjoin(tl_alias, Chapter.translator_id == tl_alias.id). \
             outerjoin(pr_alias, Chapter.proofreader_id == pr_alias.id). \
             join(Project, Chapter.project_id == Project.id)
         if "p" in d and "c" in d:
             project = searchproject(d["p"], session)
             record = query.filter(Chapter.project.id == project.id).filter(
                 Chapter.number == float(d["c"])).one()
         elif "id" in d:
             record = query.filter(Chapter.id == int(d["id"])).one()
         else:
             raise MissingRequiredParameter("Project and Chapter or ID")
         await ctx.send(record.id)
     finally:
         session.close()
Ejemplo n.º 3
0
    async def massaddchapter(self, ctx, *, arg):
        session1 = self.bot.Session()
        try:
            arg = arg[1:]
            d = dict(x.split('=', 1) for x in arg.split(' -'))
            if "c" in d and "p" in d:
                p = d['p']
                start_chp = int(d['c'])
            else:
                raise MissingRequiredParameter("c, p or link_raw")
            date_created = func.now()
            project = searchproject(p, session1)

            message = await ctx.send('Please paste the links, with one link per line.')

            def check(message):
                return message.author == ctx.message.author and message.channel == ctx.channel

            try:
                message2 = await self.bot.wait_for('message', timeout=30.0, check=check)
            except asyncio.TimeoutError:
                await message.edit(content='No reaction from command author. Chapters was not added.')
            else:
                content = message2.content.split('\n')
                for i, link in enumerate(content, start_chp):
                    chp = Chapter(i, link)
                    chp.date_created = date_created
                    chp.project = project
                    session1.add(chp)
                await ctx.send(f'Successfully added {str(len(content))} chapters of `{project.title}`!')
                session1.commit()
        finally:
            session1.close()
Ejemplo n.º 4
0
 async def note(self, ctx, *, arg):
     session = self.bot.Session()
     try:
         arg = arg[1:]
         d = dict(x.split('=', 1) for x in arg.split(' -'))
         proj = searchproject(d["p"], session)
         note = session.query(Chapter).filter(proj.id == Chapter.project_id).filter(Chapter.number == int(d["c"])).one()
         await ctx.send(note.notes)
     finally:
         session.close()
Ejemplo n.º 5
0
 async def addnote(self, ctx, *, arg):
     session = self.bot.Session()
     try:
         arg = arg[1:]
         d = dict(x.split('=', 1) for x in arg.split(' -'))
         if "p" in d and "c" in d and "note" in d:
             query = session.query(Chapter)
             proj = searchproject(d["p"], session)
             record = query.filter(Chapter.project_id == proj.id).filter(Chapter.number == int(d["c"])).one()
             record.notes = strx(record.notes)+("{}\n".format(d["note"]))
             await ctx.message.add_reaction("👍")
             session.commit()
     finally:
         session.close()
Ejemplo n.º 6
0
    async def project(self, ctx: CstmContext, *, flags: AddProjectFlags):
        """
        Description
        ==============
        Add a project to the database.

        Required Role
        =====================
        Role `Akashi's Minions`.

        Arguments
        ===========
        Required
        ---------
        :title:
            | Title of the Project. [:doc:`/Types/text`]
        :link:
            | Link to the project on box. [:doc:`/Types/text`]
        :thumbnail:
            | Link to large picture for the entry in the status board.  [:doc:`/Types/text`]

        Optional
        ------------
        :icon:
            | Link to small Image for the status board in the upper left corner.  [:doc:`/Types/text`]
        :ts, rd, pr, tl:
            | Default staff for the project.  [:doc:`/Types/staff`]
        :status:
            | Current status of the project, defaults to "active".  [:doc:`/Types/text`]
        :altnames:
            | Aliases for the project, divided by comma.  [:doc:`/Types/text`]
        """
        session = ctx.session
        if searchproject(flags.title, session):
            raise ProjectAlreadyExists()

        pr = Project(flags.title, flags.status, flags.link, flags.altnames)
        pr.tl = flags.tl
        pr.rd = flags.rd
        pr.ts = flags.ts
        pr.pr = flags.pr
        pr.icon = flags.icon
        pr.thumbnail = flags.thumbnail  # type: ignore
        session.add(pr)
        await ctx.prompt_and_commit(
            text=f"Do you really want to add the project {pr.title}")
Ejemplo n.º 7
0
 def __init__(self, bot: discord.ext.commands.Bot,
              ctx: discord.ext.commands.Context, arg: str):
     self.bot = bot
     self.ctx = ctx
     self.session = self.bot.Session()
     arg = arg[1:]
     d = dict(x.split('=', 1) for x in arg.split(' -'))
     if "link" not in d:
         raise MissingRequiredParameter("Link")
     if "id" not in d and "p" in d and "c" in d:
         ts_alias = aliased(Staff)
         rd_alias = aliased(Staff)
         tl_alias = aliased(Staff)
         pr_alias = aliased(Staff)
         query = self.session.query(Chapter).outerjoin(ts_alias, Chapter.typesetter_id == ts_alias.id). \
             outerjoin(rd_alias, Chapter.redrawer_id == rd_alias.id). \
             outerjoin(tl_alias, Chapter.translator_id == tl_alias.id). \
             outerjoin(pr_alias, Chapter.proofreader_id == pr_alias.id). \
             join(Project, Chapter.project_id == Project.id)
         proj = searchproject(d["p"], self.session)
         self.chapter = query.filter(Chapter.project_id == proj.id).filter(
             float(d["c"]) == Chapter.number).one()
     elif "id" in d:
         ts_alias = aliased(Staff)
         rd_alias = aliased(Staff)
         tl_alias = aliased(Staff)
         pr_alias = aliased(Staff)
         query = self.session.query(Chapter).outerjoin(ts_alias, Chapter.typesetter_id == ts_alias.id). \
             outerjoin(rd_alias, Chapter.redrawer_id == rd_alias.id). \
             outerjoin(tl_alias, Chapter.translator_id == tl_alias.id). \
             outerjoin(pr_alias, Chapter.proofreader_id == pr_alias.id). \
             join(Project, Chapter.project_id == Project.id)
         self.chapter = query.filter(int(d["id"]) == Chapter.id).one()
     else:
         raise MissingRequiredParameter("Project and Chapter or ID")
     if "note" in d:
         self.chapter.notes = f'{self.chapter.notes if self.chapter.notes else ""}\n{d.get("note")}'
     self.message = discord.AllowedMentions(everyone=False,
                                            roles=False,
                                            users=False)
     self.link = d.get("link")
Ejemplo n.º 8
0
    async def addchapter(self, ctx, *, arg):
        session1 = self.bot.Session()
        try:
            arg = arg[1:]
            d = dict(x.split('=', 1) for x in arg.split(' -'))
            table = PrettyTable()
            if "c" in d and "link_raw" in d and "p" in d:
                chp = Chapter(d["c"], d["link_raw"])
                chp.project = searchproject(d["p"], session1)
            elif "c" in d and "link" in d and "p" in d:
                chp = Chapter(d["c"], d["link"])
                chp.project = searchproject(d["p"], session1)
            else:
                raise MissingRequiredParameter("c, p or link_raw")
            table.add_column("Project", [chp.project.title])
            table.add_column("Chapter", [formatNumber(float(chp.number))])
            table.add_column("Raws", [chp.link_raw])
            if "ts" in d:
                chp.typesetter = await searchstaff(d["ts"], ctx, session1)
                table.add_column(fieldname="Typesetter", column=[chp.typesetter.name])
            if "rd" in d:
                chp.redrawer = await searchstaff(d["rd"], ctx, session1)
                table.add_column(fieldname="Redrawer", column=[chp.redrawer.name])
            if "pr" in d:
                chp.proofreader = await searchstaff(d["pr"], ctx, session1)
                table.add_column(fieldname="Proofreads", column=[chp.proofreader.name])
            if "tl" in d:
                chp.translator = await searchstaff(d["tl"], ctx, session1)
                table.add_column(fieldname="Translation", column=[chp.translator.name])
            if "link_ts" in d:
                chp.link_ts = d["link_ts"]
                table.add_column(fieldname="Link TS", column=[chp.link_ts])
            if "link_rd" in d:
                chp.link_rd = d["link_rd"]
                table.add_column(fieldname="Link RD", column=[chp.link_rd])
            if "link_tl" in d:
                chp.link_tl = d["link_tl"]
                table.add_column(fieldname="Link TL", column=[chp.link_tl])
            if "link_pr" in d:
                chp.link_pr = d["link_pr"]
                table.add_column(fieldname="Link PR", column=[chp.link_pr])
            chp.date_created = func.now()
            session1.add(chp)
            t = table.get_string(title="Chapter Preview")
            message = await ctx.send(file=await misc.drawimage(t))
            await message.add_reaction("✅")
            await message.add_reaction("❌")
            await asyncio.sleep(delay=0.5)

            def check(reaction, user):
                return user == ctx.message.author and (str(reaction.emoji) == '✅' or str(reaction.emoji) == '❌')

            try:
                reaction, user = await self.bot.wait_for('reaction_add', timeout=30.0, check=check)
            except asyncio.TimeoutError:
                await message.delete()
                await ctx.channel.send('No reaction from command author. Chapter was not added.')
                session1.rollback()
            else:
                if str(reaction.emoji) == "✅":
                    num = formatNumber(float(chp.number))
                    await ctx.channel.send('Sucessfully added {} {} to chapters.'.format(chp.project.title, num))
                    session1.commit()
                    await message.clear_reactions()
                else:
                    await message.delete()
                    await ctx.channel.send('Action cancelled by user.')
                    session1.rollback()
                    await message.clear_reactions()
        finally:
            session1.close()
Ejemplo n.º 9
0
 def get_project(self, session):
     conds = list()
     for arg in self.args:
         conds.append(Chapter.project_id == searchproject(arg, session).id)
     return or_(*conds)