Пример #1
0
 async def changeGenre(story: Story):
     for genreName in targetGenre:
         try:
             story.removeGenre(genreName)
             print(f"Removed {genreName} genre from {story.cite()}.")
         except NotFoundException:
             fail(A.removeGenre.errorNotFound(story.cite(), genreName))
Пример #2
0
 async def changeReason(story: Story):
     try:
         story.setRatingReason(newReason,
                               ignoreMax=isModerator(ctx.author))
         print(f"Set rating reason of {story.cite()} to {newReason}.")
     except MaxLenException:
         fail(A.setRatingReason.errorLen(newReason))
Пример #3
0
 async def changeGenre(story: Story):
     for genreName in newGenre:
         try:
             story.addGenre(genreName.capitalize())
             print(f"Added {genreName} genre to {story.cite()}.")
         except InvalidNameException:
             fail(A.addGenre.errorInvalid(genreName))
         except DuplicateException:
             fail(A.addGenre.errorDup(story.cite(), genreName))
Пример #4
0
 async def changeLink(story: Story):
     try:
         story.addLink(linkSiteAbbr,
                       linkURL,
                       ignoreMax=isModerator(ctx.author))
     except InvalidNameException:
         fail(A.addLink.errorInvalid(story.cite(), linkSiteAbbr))
     except DuplicateException:
         fail(A.addLink.errorDup(story.cite(), linkSiteAbbr))
     except MaxLenException:
         fail(A.addLink.errorLen(len(linkURL)))
Пример #5
0
 async def changeCharacter(story: Story):
     try:
         story.removeCharacter(targetCharSpecies, targetCharName)
         print(
             f"Removed character with species {targetCharSpecies} and name {targetCharName} from {story.cite()}."
         )
     except NotFoundException:
         fail(
             A.removeCharacter.errorNorFound(story.cite(),
                                             targetCharSpecies,
                                             targetCharName))
Пример #6
0
 async def changeCharacter(story: Story):
     try:
         story.addCharacter(newCharSpecies,
                            newCharName,
                            ignoreMax=isModerator(ctx.author))
         print(
             f"Added character with species {newCharSpecies} and name {newCharName} to {story.cite()}."
         )
     except DuplicateException:
         fail(
             A.addCharacter.errorDup(story.cite(), newCharSpecies,
                                     newCharName))
     except MaxSpeciesLenException:
         fail(A.addCharacter.errorLenSpecies(len(newCharSpecies)))
     except MaxNameLenException:
         fail(A.addCharacter.errorLenName(len(newCharName)))
Пример #7
0
def newFromText(text: str):
    lines = text.split("\n")
    getter = lambda i: lines[i].split(":", 1)[1].strip()
    title = getter(0)
    genres = [(genre, ) for genre in getter(1).split(", ") if genre]
    ratingRaw = getter(2).split("(", 1)
    rating = ratingRaw[0].strip()
    reason = ""
    if len(ratingRaw) == 2:
        reason = ratingRaw[1][:-1].strip()
    charsRaw = getter(3)
    chars: list[Character] = []
    for left, right in charsPat.findall(charsRaw):
        char = (right if right else left, left if right else None)
        chars.append(char)
    summary = []
    endSum = False
    i = 6  # the index of the first line of the summary
    while not endSum:
        if lines[i].startswith("```"):
            endSum = True
        elif lines[i].startswith("**Links**:"):
            endSum = True
        else:
            summary.append(lines[i])
        i += 1
    summary = "\n".join(summary)
    links = []
    while i < len(lines):
        linksMatch = linkPat.search(lines[i])
        if linksMatch:
            links.append((linksMatch.group(1), linksMatch.group(2)))
        i += 1

    return Story(title, genres, rating, reason, chars, summary, links)
Пример #8
0
    async def addStory(self, ctx: commands.Context, *storyTitle: str):
        # not kwarg so it works with multi
        storyTitle = " ".join(storyTitle)
        author = await getAuthorFromContext(ctx)

        now = time.time()
        isNewPost = False
        try:
            post = await self.getPost(ctx)
        except laprOSException:
            print("Creating new post.")
            archive = getArchiveFromContext(ctx)
            post = archive.createPost(author.id)

            last = self.addStoryCooldown
            diff = now - last
            print(diff)
            diff = (60 * 10) - diff
            if diff > 0:
                mins = round(diff / 60, 2)
                fail(A.addStory.errorCooldown(mins))
            isNewPost = True

        try:
            newStory = Story()
            newStory.setTitle(storyTitle, ignoreMax=isModerator(ctx.author))
            post.addStory(newStory)
            post.focusByTitle(newStory.title)
        except MaxLenException:
            fail(A.addStory.errorLen(len(storyTitle)))
            return
        except DuplicateException:
            fail(A.addStory.errorDup(storyTitle))
            return
        await self.updatePost(ctx)
        if isinstance(ctx.channel, discord.DMChannel):
            if not post.messageID in self.dmPosts:
                await self.getMyPost(ctx)

        if isNewPost:
            self.addStoryCooldown = now
Пример #9
0
 async def changeLink(story: Story):
     try:
         story.removeLink(targetSiteAbbr)
     except NotFoundException:
         fail(A.removeLink.errorNotFound(story.cite(), targetSiteAbbr))
Пример #10
0
 async def changeSummary(story: Story):
     try:
         story.setSummary(newSummary, ignoreMax=isModerator(ctx.author))
         print(f"Set summary of {story.cite()} to:\n{newSummary}")
     except MaxLenException:
         fail(A.setSummary.errorLen(len(newSummary)))
Пример #11
0
 async def changeRating(story: Story):
     try:
         story.setRating(newRating)
         print(f"Set rating of {story.cite()} to {newRating}.")
     except InvalidNameException:
         fail(A.setRating.errorInvalid(story.cite(), newRating))
Пример #12
0
 async def changeTitle(story: Story):
     try:
         story.setTitle(newTitle, ignoreMax=isModerator(ctx.author))
     except MaxLenException:
         fail(A.setTitle.errorLen(len(newTitle)))
Пример #13
0
 def match(story: Story):
     return story.getGenre(genre)
Пример #14
0
 def match(story: Story):
     return story.hasCharacter(species)