예제 #1
0
    async def end(self):
        if self.ended:
            return
        self.ended = True
        await self.preend()

        self.remove_reaction_menu()
        for x in range(len(self.messages)):
            asyncio.ensure_future(self.updatemessage(x, final=True))
        l = []
        ul = []
        for uid in self.userids:
            ul.append(
                utility.get_member_or_user(self.bot,
                                           self.context.message.guild, uid))
        if ul != []:
            ul.append(
                utility.get_member_or_user(self.bot,
                                           self.context.message.guild,
                                           self.bot.me.id))

        for k in utility.nodups(
                list(self.adddict.keys()) + list(self.removedict.keys())):
            l.append([utility.get_emoji(self.bot, str(k))] + ul)

        for m in self.messages:
            await utility.safelyclear(self.bot, m, l)
예제 #2
0
파일: Sue.py 프로젝트: RNLFoof/for-samuel
    async def getlayout(self, index, *, final=False):
        i = ""
        g = ""
        for x in self.innocentlist:
            i += basics.useremoji(
                self.bot,
                utility.get_member_or_user(self.bot, self.messages[0].guild,
                                           x))
        for x in self.guiltylist:
            g += basics.useremoji(
                self.bot,
                utility.get_member_or_user(self.bot, self.messages[0].guild,
                                           x))

        return f"""{self.suer.mention} is attempting to sue {self.suee.mention}!
예제 #3
0
    async def getlayout(self, index, *, final=False):
        ul = set()

        def getallusersandotherstuff(d, maxlevel, currentlevel):
            if maxlevel < currentlevel:
                maxlevel = currentlevel
            for i in d.values():
                print(i["subreactions"])
                ul.update(i["users"])
                maxlevel = getallusersandotherstuff(i["subreactions"],
                                                    maxlevel, currentlevel + 1)
                # for u in i["subreactions"]:
                #     getallusers(u)
            return maxlevel

        maxlevels = getallusersandotherstuff(self.reactions, 0, 0)
        s = f"[<a:hippovortex:395505717374877696>]({self.foreignmessages[0].jump_url}){'▪'*(maxlevels-1)}│"

        for u in ul:
            print(u)
            s += basics.useremoji(
                self.bot,
                utility.get_member_or_user(self.bot,
                                           self.bot.get_guild(self.guildid),
                                           u))

        def displayreactions(s, d, level, maxlevels):
            for k, i in d.items():
                s += f"\n{arrow_r*level}{k}{'▪'*(maxlevels-level-1)}│"
                print(i["users"])
                for u in ul:
                    s += "⭕" if u in i["users"] else "▪"
                s = displayreactions(s, i["subreactions"], level + 1,
                                     maxlevels)
            return s

        s = displayreactions(s, self.reactions, 0, maxlevels)
        embed = discord.Embed(type="rich",
                              description=f"ID: {self.id}\n{s}"[:2048])
        return embed
예제 #4
0
    async def cyclecomic(self, context):
        """Cycle comic manager.

        Cyclecomics being comics where, repeatedly, one person adds two panels, and then shows only the newest panel to another person. Then they add two panels and pass on only the last panel, and so on.

        Modifiers:
        new|create|add : Create a new cyclecomic.
        join|enter : Add yourself to a previously created cyclecomic.
        upload|panel|append : Add a panel to a cyclecomic on which it's your turn.
        pass|give : Make it somebody else's turn on a cycleomic on which it's your turn.
        view|show|release|spew|display : Display a completed cyclecomic.
        """
        async def SAVETODICT_give(self):
            await talking.say(
                self.context,
                f"Hey loser. You've been passed this panel ||{self.url} || by {basics.truename(self.bot,context.message.author)} as part of {q}.",
                channel=self.passonto)
            self.bot.cyclecomics[self.q]["turn"] = self.passonto.id
            basics.save(self.bot, "cyclecomics")
            self.message = "Okay, done."

        async def SAVETODICT_upload(self):
            self.bot.cyclecomics[q]["panelurls"].append(self.image)
            self.bot.cyclecomics[q]["panelcreators"].append(
                self.context.message.author.id)
            basics.save(bot, "cyclecomics")
            await talking.reply(
                context,
                f"Okay, {self.image} has been added. I'm saving the URL, not the actual image. I'm also not your mom(unless you want me to be <:blob_wink:423672830316511232>), so I'm not adding a failsafe if you delete the message and thus an attached image. It'll just not show up and you'll lose all your friends."
            )

        async def SAVETODICT_view(self):
            for n, x in enumerate(self.bot.cyclecomics[self.q]["panelurls"]):
                await talking.say(
                    self.context,
                    f"Panel {n+1}, by <@{self.bot.cyclecomics[self.q]['panelcreators'][n]}>.\n{x}"
                )
                await asyncio.sleep(30)

        bot = self.bot
        m = context.message
        q = basics.contentq(m.content, split=False)

        q, new, join, upload, give, view = basics.subcommands(
            context, q, [
                r"new|create|add", r"join|enter", r"upload|panel|append",
                r"pass|give", r"view|show|release|spew|display"
            ])

        refnum = " ".join(q.split(" ")[1:])
        q = q.split(" ")[0]
        qcaps = q
        q = q.lower()

        current = bot.cyclecomics

        if new is not None:
            for k, i in current.items():
                if i["owner"] == m.author.id != bot.rnl.id:
                    await talking.reply(
                        context,
                        "You can only create one cyclecomic at a time per server to prevent spam."
                    )
                    return
            if not q:
                await talking.reply(
                    context,
                    'Add a nickname to this comic, so that it can be identified by something besides an autogenerated number. Like, I dunno. "penis" or "Chris" or something. Six characters max, limited to numbers, letters, and underscores.'
                )
            elif not re.match(r"^\w{1,6}$", q):
                await talking.reply(
                    context,
                    'Six characters max, limited to numbers, letters, and underscores.'
                )
            else:
                if q in current:
                    await talking.reply(
                        context, f"{basics.spitback(qcaps)} is taken already!")
                else:
                    current[q] = {
                        "owner": m.author.id,
                        "turn": m.author.id,
                        "creationtime": str(datetime.datetime.utcnow().date()),
                        "panelurls": [],
                        "panelcreators": [],
                        "users": [m.author.id],
                        "qcaps": qcaps,
                        "server": m.guild.id
                    }
                    await talking.reply(
                        context,
                        f"Okay, {basics.spitback(qcaps)} is now added. People can join using `s!cc [join]{current[q]['qcaps']}`"
                    )
                    basics.save(bot, "cyclecomics")
        elif join is not None:
            if not q:
                await talking.reply(
                    context,
                    "You need to specify which cyclecomic you want to join!")
            elif q not in current:
                await talking.reply(
                    context,
                    f"{basics.spitback(qcaps)} doesn't seem to exist.")
            elif m.author.id in current[q]["users"]:
                await talking.reply(context,
                                    "You're already in this cyclecomic!")
            else:
                current[q]["users"].append(m.author.id)
                basics.save(bot, "cyclecomics")
                await talking.reply(
                    context, "Coolio, you've been added to this cyclecomic.")
        elif upload is not None:
            if not q:
                await talking.reply(
                    context,
                    "You need to specify which cyclecomic you want to add a panel to!"
                )
            elif q not in current:
                await talking.reply(
                    context,
                    f"{basics.spitback(qcaps)} doesn't seem to exist.")
            elif m.author.id not in current[q]["users"]:
                await talking.reply(
                    context,
                    f"You aren't a member of this cyclecomic. You can join with `s!cc [join]{current[q]['qcaps']}`."
                )
            elif current[q]["turn"] != m.author.id:
                await talking.reply(context,
                                    f"It's not your turn on this cyclecomic.")
            else:
                image = await utility.referenceimage(context, returnurl=True)
                if image:
                    ConfirmMessage(
                        bot,
                        validfor=datetime.timedelta(minutes=5),
                        message=
                        f"Are you sure you want to add ||{image} || to {q}?",
                        image=image,
                        q=q,
                        yesscript=SAVETODICT_upload,
                        context=context)
        elif give is not None:
            if not q:
                await talking.reply(
                    context,
                    "You need to specify which cyclecomic you want to pass off on!"
                )
            elif q not in current:
                await talking.reply(
                    context,
                    f"{basics.spitback(qcaps)} doesn't seem to exist.")
            elif m.author.id not in current[q]["users"]:
                await talking.reply(
                    context,
                    f"You aren't a member of this cyclecomic. You can join with `s!cc [join]{current[q]['qcaps']}`."
                )
            elif current[q]["turn"] != m.author.id:
                await talking.reply(context,
                                    f"It's not your turn on this cyclecomic.")
            else:
                try:
                    server = bot.get_guild(current[q]['server'])
                    u = utility.get_member_or_user(
                        bot, server, current[q]['users'][int(refnum)])
                except:
                    await talking.reply(
                        context,
                        f"I couldn't figure out who {basics.spitback(refnum)} referred to. Use s!cc {current[q]['qcaps']} and give me the reference number of the peron you want to pass to."
                    )
                else:
                    if u.id == m.author.id:
                        await talking.reply(
                            context,
                            f"*You're* {basics.truename(bot,u)}, dummy!")
                    else:
                        if current[q]['panelurls']:
                            url = current[q]['panelurls'][-1]
                        else:
                            url = "I lied. I decieved you. Nothing has been added to this cyclecomic yet."
                        ConfirmMessage(
                            bot,
                            validfor=datetime.timedelta(minutes=5),
                            message=
                            f"Are you sure you want to pass ||{url} || to {basics.truename(bot,u)}?",
                            passonto=u,
                            url=url,
                            q=q,
                            yesscript=SAVETODICT_give,
                            context=context)
        elif view is not None:
            if not q:
                await talking.reply(
                    context,
                    "You need to specify which cyclecomic you want to show!")
            elif q not in current:
                await talking.reply(
                    context,
                    f"{basics.spitback(qcaps)} doesn't seem to exist.")
            elif m.author.id != current[q]["owner"]:
                await talking.reply(
                    context,
                    f"You don't own this cyclecomic, so you can't set it off.")
            else:
                ConfirmMessage(
                    bot,
                    validfor=datetime.timedelta(minutes=5),
                    message=
                    f"Are you sure you want to display the entirety of {q}? You can't turn back. It'll be EVERYWHERE.",
                    q=q,
                    yesscript=SAVETODICT_view,
                    context=context)
        else:
            if not q:
                s = "Here's a list of cyclecomics in this server. Specify one to get more info on it.\n`"
                for x in current.keys():
                    s += f"\n{x}"
                s += "`"
                await talking.reply(context, s)
            elif q not in current:
                await talking.reply(
                    context,
                    f"{basics.spitback(qcaps)} isn't a cyclecomic on this server."
                )
            else:
                lol = [["User", "Turn", "Owner", "Panels", "Ref. #", "Status"]]
                for n, x in enumerate(current[q]["users"]):
                    u = utility.get_member_or_user(bot, m.guild, x)
                    lol.append([
                        basics.truename(bot, u), u.id == current[q]["turn"],
                        u.id == current[q]["owner"],
                        current[q]["panelcreators"].count(u.id), n,
                        aesthetic.statusemoji(bot, u)
                    ])
                SortableChart(bot,
                              validfor=datetime.timedelta(minutes=5),
                              context=context,
                              lol=lol,
                              initialsort=[1, 0])
예제 #5
0
    async def daily(self, context):
        """Opt in or out of free tokens for people you like.

        Once a day, after a random message, you'll be shown three random people and be offered to give a token to one of them.
        Use [list] to see which people have opted in and if they've gotten their token today.
        Use [dm] to toggle getting informed that you recieved a token in DMs rather than the same channel."""
        if context.message.guild.id not in self.bot.sdailylast.keys():
            self.bot.sdailylast[context.message.guild.id] = {}
            basics.save(self.bot, "sdailylast")

        bot = self.bot
        q = basics.contentq(context.message.content, split=False)
        if "[dm]" in q:
            bot = self.bot
            u = context.message.author

            if u.id in bot.dmdaily:
                bot.dmdaily.remove(u.id)
                await talking.reply(
                    context,
                    "You'll now be informed about getting a daily in the same channel."
                )
            else:
                bot.dmdaily.append(u.id)
                await talking.reply(
                    context,
                    "You'll now be informed about getting a daily in a DM.")
            basics.save(bot, "dmdaily")
            return
        if "[list]" in q:
            lol = [["User", "Last", "Today"]]
            for k, i in self.bot.sdailylast[context.message.guild.id].items():
                try:
                    m = utility.get_member_or_user(bot, context.message.guild,
                                                   int(k))
                    if m is not None:
                        lol.append([
                            basics.truename(bot, m),
                            i.replace("DEFAULT", ""),
                            i == str(datetime.utcnow().date())
                        ])
                except ValueError:
                    pass
            SortableChart(bot,
                          validfor=timedelta(minutes=10),
                          context=context,
                          lol=lol,
                          initialsort=[0, 1],
                          defaultreverse={1})
            return

        id = str(context.message.author.id)
        if id not in self.bot.sdailylast[context.message.guild.id].keys():
            if id + "DISABLED" in self.bot.sdailylast[
                    context.message.guild.id].keys():
                self.bot.sdailylast[context.message.guild.id][id] = \
                self.bot.sdailylast[context.message.guild.id][id + "DISABLED"]
                del self.bot.sdailylast[context.message.guild.id][id +
                                                                  "DISABLED"]
            else:
                self.bot.sdailylast[context.message.guild.id][id] = "DEFAULT"
            basics.save(self.bot, "sdailylast")
            await talking.reply(
                context,
                "You will now be offered once a day after a random message three potential people to give a token to. Use this command again to turn it off.",
                reaction=True)
            return
        else:
            self.bot.sdailylast[context.message.guild.id][
                id +
                "DISABLED"] = self.bot.sdailylast[context.message.guild.id][id]
            del self.bot.sdailylast[context.message.guild.id][id]
            basics.save(self.bot, "sdailylast")
            await talking.reply(
                context,
                "You've opted back out of dailies. Use this command again to pick up where you left off."
            )
            return