Beispiel #1
0
async def prefix_get(ctx):
    res = db.execute('SELECT prefix FROM users WHERE user_id=?',
                     (ctx.author.id, )).fetchone()
    if res is None or res['prefix'] is None:
        await ctx.send(embed=embed(ctx, description=('prefix-unset', )))
    else:
        await ctx.send(
            embed=embed(ctx, title=('prefix', ), description=res['prefix']))
Beispiel #2
0
async def add(ctx, *, word):
    m = re.search(SENTENCE_REGEX, word)
    if m:
        if re.search(SENTENCE_OK_REGEX, word):
            pass
        else:
            await ctx.send(embed=embed(ctx,
                                       title=('error', ),
                                       description=('sentence-bad-char',
                                                    word[m.start()]),
                                       color=0xff0000))
            add.reset_cooldown(ctx)
            return
    prev = db.execute('SELECT user_id FROM sentence_words \
ORDER BY rowid DESC').fetchone()
    if prev is not None:
        prev = prev[0]
        if prev == ctx.author.id:
            background(
                ctx.send(embed=embed(ctx,
                                     title=('error', ),
                                     description=('sentence-repeat', ),
                                     color=0xff0000)))
            add.reset_cooldown(ctx)
            return
    db.execute('INSERT INTO sentence_words VALUES (?, ?)',
               (word, ctx.author.id))
    if word[-1] in SENTENCE_ENDS:
        data = db.execute(
            'SELECT word, user_id FROM sentence_words').fetchall()
        words = ' '.join(word['word'] for word in data)
        users = set()
        for i in data:
            users.add(i['user_id'])
        for i in users:
            i = client.get_user(i)
            background(
                i.send(embed=embed(ctx,
                                   title=('sentence-finished-title', ),
                                   description=('sentence-finished', words),
                                   color=0xfffffe)))
        db.execute('DELETE FROM sentence_words')
        background(
            ctx.send(embed=embed(ctx,
                                 title=('sentence-ended-title', ),
                                 description=('sentence-ended', ),
                                 color=0xfffffe)))
    else:
        background(
            ctx.send(embed=embed(ctx,
                                 title=('success', ),
                                 description=('sentence-added', ),
                                 color=0x55acee)))
    dbw.commit()
Beispiel #3
0
async def _purged(ctx, count):
    msg = await ctx.send(embed=embed(ctx,
                                     title=('purge-title', ),
                                     description=('purge', count),
                                     color=0xff0000))
    await asyncio.sleep(2)
    await msg.delete()
Beispiel #4
0
async def on_command_error(ctx, exc):
    logger.error('Ignoring exception in command {}: {} {}'.format(
        ctx.command,
        type(exc).__name__, exc),
                 extra={'ctx': ctx})
    if hasattr(ctx.command, 'on_error'):
        return
    cog = ctx.cog
    if cog:
        if commands.Cog._get_overridden_method(
                cog.cog_command_error) is not None:
            return
    if isinstance(exc, (
            commands.BotMissingPermissions,
            commands.MissingPermissions,
            commands.MissingRequiredArgument,
            commands.BadArgument,
            commands.CommandOnCooldown,
    )):
        return await ctx.send(embed=embed(
            ctx, title=('error', ), description=str(exc), color=0xff0000))
    if isinstance(exc, (commands.CheckFailure, commands.CommandNotFound,
                        commands.TooManyArguments, discord.Forbidden)):
        return
    logger.error(''.join(
        traceback.format_exception(type(exc), exc, exc.__traceback__)),
                 extra={'ctx': ctx})
Beispiel #5
0
async def prefix_reset(ctx, user: discord.Member = None):
    """reset-help"""
    leuser = (user or ctx.author) if (await client.is_owner(ctx.author
                                                            )) else ctx.author
    db.execute('UPDATE users SET prefix=NULL WHERE user_id=?', (leuser.id, ))
    await ctx.send(embed=embed(ctx,
                               title=('prefix-reset-title', ),
                               description=('prefix-reset', leuser.mention),
                               color=0x0000ff))
Beispiel #6
0
async def ball(ctx, *, question: str):
    choice = sum(question.encode('utf8')) % 20
    await ctx.send(
        embed=embed(ctx,
                    description=(('8ball/a1', '8ball/a2', '8ball/a3',
                                  '8ball/a4', '8ball/a5', '8ball/a6',
                                  '8ball/a7', '8ball/a8', '8ball/a9',
                                  '8ball/a10', '8ball/u1', '8ball/u2',
                                  '8ball/u3', '8ball/u4', '8ball/u5',
                                  '8ball/n1', '8ball/n2', '8ball/n3',
                                  '8ball/n4', '8ball/n5')[choice], )))
Beispiel #7
0
async def get(ctx):
    words = db.execute('SELECT word FROM sentence_words').fetchall()
    words = ' '.join(word[0] for word in words)
    if ctx.guild is None:
        bad_words = '\1'
    else:
        res = db.execute('SELECT words_censor FROM guilds WHERE guild_id=?',
                         (ctx.guild.id, )).fetchone()
        if res is None or res[0] is None:
            bad_words = '\1'
        else:
            bad_words = res[0] or '\1'
    if re.search(bad_words, words):
        background(
            ctx.send(embed=embed(ctx,
                                 title=('error', ),
                                 description=('sentence-censored', ),
                                 color=0xff0000)))
        return
    background(
        ctx.send(embed=embed(
            ctx, title=('sentence-got', ), description=words, color=0xfffffe)))
Beispiel #8
0
async def prefix_set(ctx, *, prefix):
    """set-help"""
    res = db.execute('SELECT prefix FROM users WHERE user_id=?',
                     (ctx.author.id, )).fetchone()
    if len(prefix) > 2 and prefix[0] == prefix[-1]:
        prefix = prefix[1:-1]
    if res is None:
        db.execute('INSERT INTO users (user_id, prefix) VALUES (?, ?)',
                   (ctx.author.id, prefix))
    else:
        db.execute('UPDATE users SET prefix=? WHERE user_id=?',
                   (prefix, ctx.author.id))
    await ctx.send(embed=embed(ctx,
                               title=('prefix-set-title', ),
                               description=('prefix-set', ctx.author.mention,
                                            prefix),
                               color=0x55acee))
Beispiel #9
0
async def charinfo(ctx, *, chars: str):
    # modified from:
    # https://github.com/Rapptz/RoboDanny/blob/rewrite/cogs/meta.py#L223-L237
    if '\\' in chars:
        try:
            chars = chars.encode().decode('unicode-escape')
        except UnicodeDecodeError:
            pass  # don't convert

    def to_string(c):
        digit = f'{ord(c):x}'
        name = unicodedata.name(c, i18n(ctx, 'charname-not-found'))
        return i18n(ctx, 'charinfo', digit, name, c, json.dumps(c).strip('"'))

    msg = '\n'.join(map(to_string, chars))
    msg = i18n(ctx, 'charinfo-start') + '\n' + msg
    await ctx.send(
        embed=embed(ctx, title=('charinfo-title', ), description=msg[:2000]))
Beispiel #10
0
async def whoami(ctx):
    emb = embed(ctx,
                title=('whoami-title', ctx.author.display_name),
                description=('whoami-description', ctx.author.display_name))
    emb.set_thumbnail(url=ctx.author.avatar_url)
    things = {
        'status': i18n(ctx, 'whoami-status'),
        'activity': i18n(ctx, 'whoami-activity'),
        'id': i18n(ctx, 'whoami-id'),
        'created_at': i18n(ctx, 'whoami-created-at'),
        'joined_at': i18n(ctx, 'whoami-joined-at'),
    }
    for key, name in things.items():
        value = getattr(ctx.author, key)
        emb.add_field(name=name, value=getattr(value, 'name', value))
    role_list = []
    for role in ctx.author.roles:
        role_list.append(role.name.replace('@', '\\@'))
    emb.add_field(name=i18n(ctx, 'whoami-roles'),
                  value=', '.join(role_list),
                  inline=False)
    await ctx.send(embed=emb)
Beispiel #11
0
async def info(ctx):
    ainfo = await client.application_info()
    if cmdargs.prefix == ';':
        homepage = 'http://hkugawiki.ddns.net:8080'
    else:
        homepage = 'http://localhost:8080'
    invite = discord.utils.oauth_url(ainfo.id,
                                     permissions=discord.Permissions(
                                         send_messages=True,
                                         embed_links=True,
                                         attach_files=True,
                                         read_message_history=True,
                                         external_emojis=True))
    await ctx.send(
        embed=embed(ctx,
                    title=str(client.user),
                    description=('description', ),
                    fields=((('info-id', ), str(ainfo.id),
                             True), (('info-owner', ), str(ainfo.owner), True),
                            (('info-prefix', ), f'`{cmdargs.prefix}`', True),
                            (('info-url', ), ('info-url-url', homepage), True),
                            (('info-invite', ), ('info-inv', invite), True)),
                    color=0x55acee).set_thumbnail(url=client.user.avatar_url))
Beispiel #12
0
async def votetoban(ctx, *, user: discord.Member):
    for member in ctx.guild.members:
        if (str(member.status) == 'online') \
                and ctx.channel.permissions_for(member).ban_members \
                and not member.bot:
            await ctx.send(
                i18n(ctx, 'votetoban-ping-admin', member.mention,
                     user.mention))
            return
    DOBAN = '\U0001f6ab'
    NOBAN = '\U0001f607'
    msg = await ctx.send(embed=embed(ctx,
                                     title=('votetoban-title', user.mention),
                                     description=('votetoban-msg', DOBAN,
                                                  NOBAN),
                                     color=0))
    await msg.add_reaction(DOBAN)
    await msg.add_reaction(NOBAN)
    try:
        o, m = await ctx.bot.wait_for('member_update',
            check=lambda o, m: \
                ctx.channel.permissions_for(m).ban_members \
                and not m.bot \
                and str(m.status) == 'online',
            timeout=180.0
        )
        await msg.delete()
        await ctx.send(embed=embed(
            ctx,
            title=('votetoban-cancelled-title', ),
            description=('votetoban-cancelled', m.mention),
        ))
    except asyncio.TimeoutError:
        msg = await ctx.get_message(msg.id)
        dos = 0
        nos = 0
        for r in msg.reactions:
            if r.emoji == DOBAN:
                dos = r.count - 1
            elif r.emoji == NOBAN:
                nos = r.count - 1
        await msg.delete()
        if dos + nos < 3:
            await ctx.send(embed=embed(ctx,
                                       title=('votetoban-ended', ),
                                       description=('votetoban-few',
                                                    dos + nos),
                                       color=0xff0000))
        elif dos > nos:
            await ctx.guild.ban(user,
                                reason='Banned after vote {0} against {1} \
when admins were gone.'.format(dos, nos))
            await ctx.send(embed=embed(ctx,
                                       title=('votetoban-ended', ),
                                       description=('votetoban-banned', dos,
                                                    nos),
                                       color=0))
        else:
            await ctx.send(embed=embed(ctx,
                                       title=('votetoban-ended', ),
                                       description=('votetoban-innocent', dos,
                                                    nos),
                                       color=0x55acee))
Beispiel #13
0
async def ping(ctx):
    await ctx.send(
        embed=embed(ctx,
                    title=('ping-title', ),
                    description='{}ms'.format(round(client.latency * 1000, 3)))
    )