Beispiel #1
0
    async def admin(self, ctx: Context):
        """Base command for server administrators.

        Run without arguments to view current server settings.
        MUST HAVE SERVER ADMINISTRATOR PERMISSION
        """
        if ctx.invoked_subcommand is not None:
            return

        sid = str(ctx.guild.id)
        log_status = None
        mute_role = None

        # Get the server's config values
        try:
            channel = self.bot.get_channel(int(db[sid]["log_channel"]))
            log_status = f"{db[sid]['log']}, {channel.mention}"
        except KeyError:
            log_status = "Not set up"
        try:
            role = ctx.guild.get_role(int(db[sid]["mute_role"]))
            mute_role = role.name
        except KeyError:
            mute_role = "Not set up"

        # Post them as en embed
        embed = Embed(title="Admin Info", color=0x7289DA)
        embed.add_field(name="Log", value=log_status, inline=True)
        embed.add_field(name="Mute Role", value=mute_role, inline=True)
        embed.set_footer(text=pretty_datetime(datetime.now()))

        await ctx.send(embed=embed)
Beispiel #2
0
 async def x_post(self, ctx, message: str, destination: Channel):
     """Cross-posts a message to another channel."""
     message = await self.bot.get_message(ctx.message.channel, message)
     timestamp = pretty_datetime(message.timestamp)
     header = f"{message.author.mention} - {message.channel.mention} ({timestamp}):"
     await self.bot.send_message(destination,
         f"{header}\n{message.content}")
     await self.bot.say("\U00002705")
Beispiel #3
0
    async def warns(self, ctx: Context, member: Member = None):
        """List all active warns of yourself or another member.
        Invoke without argument to view your own warns.
        Level 4 required to view other Members' warns
        """
        sid = str(ctx.guild.id)

        if member is None:
            member = ctx.author

        uid = str(member.id)

        if member is not ctx.author:
            level = get_account(ctx.guild, ctx.author)
            if level < 4:
                await ctx.send(
                    ":anger: Must be level 4 to view other users' warns.")
                return

        if sid not in warn_db:
            await ctx.send(":anger: Server has no warns.")
            return

        if uid not in warn_db[sid]:
            await ctx.send(":anger: Member has no warns.")
            return

        embed = Embed(title=f"{member.name}#{member.discriminator}'s Warns",
                      color=0xff0000)

        warn_count = len(warn_db[sid][uid])

        embed.add_field(name="Total warns",
                        value=str(warn_count),
                        inline=False)

        # Build the fields of the embed by iterating through a user's warns
        for i, w in warn_db[sid][uid].items():
            # Get the current time and the expiry time of the warn
            now = datetime.now(tz=timezone.utc)
            then = datetime.fromtimestamp(float(w["expires"]), tz=timezone.utc)
            # Get a timedelta of the difference between the times
            result = then - now
            expires = pretty_timedelta(result)
            # Add that plus the rest of the info to an embed field
            issuer = ctx.guild.get_member(int(w["issued_by"]))
            name = f"{issuer.name}#{issuer.discriminator}"

            embed.add_field(
                name=i,
                value=f"By: {name}\nReason: {w['reason']}\nExpires: {expires}",
                inline=True)

        embed.set_footer(text=pretty_datetime(datetime.now()))

        await ctx.send(embed=embed)
Beispiel #4
0
 async def move_post(self, ctx, message: str, destination: Channel):
     """Move a message to a different channel."""
     message = await self.bot.get_message(ctx.message.channel, message)
     timestamp = pretty_datetime(message.timestamp)
     here = destination.mention
     header = f"{message.author.mention} - {message.channel.mention} ({timestamp})"
     await self.bot.send_message(destination,
         f"{header} -> {here}:\n{message.content}")
     await self.bot.delete_message(message)
     await self.bot.say("\U00002705")
Beispiel #5
0
def subscribers():

    users = controller.User().get()

    click.echo("There are {} subscribers.".format(len(users)) )
    for user in users:
        click.echo("{} | {} | {} | {}".format(
            user['email'].ljust(35," "),
            helpers.pretty_datetime(user['verified']).rjust(16),
            # ",".join(list(user['preferences'])),
            ".".join(user['preferences']).ljust(22),
            user['language'] if user['language'] is not None else ""
        ))
Beispiel #6
0
async def embed_builder(action: str,
                        member: Member,
                        reason: str,
                        td: timedelta = None) -> Embed:
    embed = Embed(title=action, color=0xff0000)

    embed.add_field(name="From", value=member.guild.name)
    embed.add_field(name="Reason", value=reason, inline=False)

    try:
        embed.set_author(icon_url=member.guild.icon)
    except Exception:
        pass

    if td is not None:
        embed.add_field(name="Expires In",
                        value=pretty_timedelta(td),
                        inline=False)

    embed.set_footer(text=pretty_datetime(datetime.now()))

    return embed
Beispiel #7
0
    async def log_to_channel(self,
                             ctx: Context,
                             target: Member,
                             info: str = None):
        sid = str(ctx.guild.id)
        channel = None
        enabled = True
        action = ctx.message.content

        # Try and get the config values for the server
        if sid in db:
            try:
                channel = ctx.guild.get_channel(int(db[sid]["log_channel"]))
            except KeyError:
                channel = None
            try:
                enabled = db[sid]["log"]
            except KeyError:
                enabled = False
        else:
            channel = ctx.channel
            enabled = False

        if not enabled:
            return

        if info is None:
            info = "No extra information"

        # Log the info as an embed
        tag = f"{target.name}#{target.discriminator} ({target.id})"

        embed = Embed(title=action, color=0xff0000)
        embed.add_field(name=ctx.command.name, value=tag, inline=True)
        embed.add_field(name="Info", value=info)
        embed.set_footer(text=pretty_datetime(datetime.now()))

        await channel.send(embed=embed)
Beispiel #8
0
VERSION = "1.1b2"

# Get the database set up
db_file = "db/roles.sql"
backup = True

# Check config and make any required backup
try:
    with open("config/config.json") as cfg:
        backup = json.load(cfg)["BackupDB"]
except Exception as error:
    print(f"Error loading prefix from configuration file.\n    - {error}")

if os.path.exists(db_file) and backup:
    timestamp = pretty_datetime(datetime.now(), display="FILE")
    try:
        shutil.copyfile(db_file, f"db/backups/roles-{timestamp}.sql")
    except IOError as e:
        error_file = f"db/backups/roles-{timestamp}.sql"
        log.error(f"Unable to create file {error_file}\n    - {e}")

sql_db = SqliteDict(
    filename=db_file,
    tablename="roles",
    autocommit=True,
    encode=json.dumps,
    decode=json.loads
)

if "servers" not in sql_db: