Esempio n. 1
0
    async def wormhole_list(self, ctx):
        """List all wormholes"""
        # TODO Use name & ID instead of mentions
        embed = self.get_embed(ctx=ctx, title="Wormholes")
        template = "**{mention}** ({guild}): active {active}, readonly {readonly}"

        beams = repo_b.list_names()
        for beam in beams:
            wormholes = repo_w.list_objects(beam=beam)
            value = []
            for db_w in wormholes:
                wormhole = self.bot.get_channel(db_w.discord_id)
                if wormhole is None:
                    value.append("Missing: " + str(db_w))
                    continue
                value.append(
                    template.format(
                        mention=wormhole.mention,
                        guild=wormhole.guild.name,
                        active=db_w.active,
                        readonly=db_w.readonly,
                    ))
            value = "\n".join(value)
            if len(value) == 0:
                value = "No wormholes"
            embed.add_field(name=beam, value=value, inline=False)

        await ctx.send(embed=embed)
Esempio n. 2
0
    async def announce(self, *, beam: str, message: str):
        """Send information to all channels"""
        if len(message) <= 256:
            embed = self.get_embed(title=message)
        else:
            embed = self.get_embed(description=message)

        for db_w in repo_w.list_objects(beam=beam):
            await self.bot.get_channel(db_w.discord_id).send(embed=embed)
Esempio n. 3
0
    def reconnect(self, beam: str = None):
        if beam is None:
            self.wormholes = {}
        else:
            self.wormholes[beam] = []

        wormholes = repo_w.list_objects(beam)
        for wormhole in wormholes:
            self.wormholes[beam].append(self.bot.get_channel(wormhole.discord_id))
Esempio n. 4
0
    def _get_info(self, beam_name: str, title: bool = False) -> str:
        """Get beam statistics.

        If title is True, the message has beam information.
        """
        # heading
        msg = ["**Beam __" + beam_name + "__**"] if title else []

        since = self.transferred[
            beam_name] if beam_name in self.transferred else 0
        msg += [
            f">>> **[[total]]** messages sent in total "
            f"(**{since}** since {started}); "
            f"ping **{self.bot.latency:.2f}s**",
            "",
            "Currently opened wormholes:",
        ]

        wormholes = repo_w.list_objects(beam_name)
        wormholes.sort(key=lambda x: x.messages, reverse=True)

        # loop over wormholes in current beam
        count = 0
        for wormhole in wormholes:
            count += wormhole.messages
            line = []
            # logo
            if len(wormhole.logo):
                line.append(wormhole.logo)
            # guild, channel, counter
            channel = self.bot.get_channel(wormhole.discord_id)
            if channel is None:
                continue
            line.append(
                f"**{self.sanitise(channel.guild.name)}** ({self.sanitise(channel.name)}): "
                f"**{wormhole.messages}** messages")
            # inactive, ro
            pars = []
            if wormhole.active is False:
                pars.append("inactive")
            if wormhole.readonly is True:
                pars.append("read only")
            if len(pars) > 0:
                line.append(f"({', '.join(pars)})")
            # join and send
            msg.append(" ".join(line))

        return "\n".join(msg).replace("[[total]]", str(count))
Esempio n. 5
0
    async def invites(self, ctx):
        """Get invite links"""
        await self.delete(ctx)

        result = []
        template = "{logo} **{guild}**, {name}: {link}"
        for wormhole in repo_w.list_objects(repo_w.get_attribute(ctx.channel.id, "beam")):
            if wormhole.invite is None:
                continue
            channel = self.bot.get_channel(wormhole.discord_id)
            result.append(
                template.format(
                    logo=wormhole.logo if len(wormhole.logo) else "",
                    name=channel.name,
                    guild=channel.guild.name,
                    link=wormhole.invite,
                )
            )
        result = "\n".join(result) if len(result) else "No public invites."
        await self.smart_send(ctx, content=result)