コード例 #1
0
ファイル: handlers.py プロジェクト: onionc/webapp-python3
async def api_register_user(*, email, name, passwd):
    """ 用户注册api """
    if not name or not name.strip():
        raise APIValueError('name')
    if not email or not Glo._RE_EMAIL.match(email):
        raise APIValueError('email')
    if not passwd or not Glo._RE_SHA1.match(passwd):
        raise APIValueError('passwd')
    users = await User.findAll('email=?', [email])
    if len(users) > 0:
        raise APIError('register:failed', 'email', 'Email is alrealy used.')
    uid = next_id()
    sha1_passwd = '{}:{}'.format(uid, passwd)
    user = User(
        id=uid,
        name=name.strip(),
        email=email,
        passwd=hashlib.sha1(sha1_passwd.encode('utf-8')).hexdigest(),
        image=Glo.get_avatar(hashlib.md5(email.encode('utf-8')).hexdigest())
    )
    await user.save()
    # make session cookie
    r = web.Response()
    r.set_cookie(
        Glo._COOKIE_NAME,
        Glo.user2cookie(user, 86400),
        max_age=86400,
        httponly=True
    )
    user.passwd = '****'
    r.content_type = 'application/json'
    r.body = json.dumps(user, ensure_ascii=False).encode('utf-8')
    return r
コード例 #2
0
 async def on_message_delete(self, message):
     if not isinstance(message.author, discord.Member):
         return
     if message.guild.id != self.bot.guild_id:
         return
     users = None
     roles = None
     if did_mention_other_user(message.mentions, message.author):
         users = ", ".join([str(member) for member in message.mentions])
     if message.role_mentions:
         roles = ", ".join([role.name for role in message.role_mentions])
     if not users and not roles:
         return
     embed = discord.Embed(
         description="In {}".format(message.channel.mention))
     if users is not None:
         embed.add_field(name="Users", value=users, inline=True)
     if roles is not None:
         embed.add_field(name="Roles", value=roles, inline=True)
     embed.color = 0xFF0000
     embed.title = "Message Deletion"
     embed.set_footer(text=str(message.author),
                      icon_url=get_avatar(message.author))
     channel = message.guild.get_channel(self.bot.mentions_channel_id)
     await channel.send(embed=embed)
コード例 #3
0
 async def on_message_edit(self, before, after):
     if not isinstance(before.author, discord.Member):
         return
     if before.guild.id != self.bot.guild_id:
         return
     users = removed_user_mentions(before.mentions, after.mentions)
     roles = removed_role_mentions(before.role_mentions,
                                   after.role_mentions)
     if users:
         users = ", ".join([str(member) for member in users])
     if roles:
         roles = ", ".join([role.name for role in roles])
     if not users and not roles:
         return
     embed = discord.Embed(
         description="In {}".format(before.channel.mention))
     if users:
         embed.add_field(name="Users", value=users, inline=True)
     if roles:
         embed.add_field(name="Roles", value=roles, inline=True)
     embed.color = 0xFF0000
     embed.title = "Message Edit"
     embed.set_footer(text=str(before.author),
                      icon_url=get_avatar(before.author))
     channel = before.guild.get_channel(self.bot.mentions_channel_id)
     await channel.send(embed=embed)
コード例 #4
0
ファイル: help.py プロジェクト: Elmon11/TotalFreedomBot
    async def help(self, ctx, page=1):
        'Displays the help command'
        em = discord.Embed()
        em.title = 'Help Command'
        command_list = ''
        cog_list = [c for c in self.bot.cogs.keys()]
        page_count = math.ceil(len(cog_list) / 4)

        page = int(page)
        if page > page_count or page < 1:
            await ctx.send(f'Page number \'{page}\' not found.')
            return

        cogs_needed = []
        for i in range(4):
            x = i + (int(page) - 1) * 4
            try:
                cogs_needed.append(cog_list[x])
            except IndexError:
                pass

        for cog in cogs_needed:
            command_list = ''
            for command in self.bot.get_cog(cog).get_commands():
                showcommand = True
                if command.hidden:
                    showcommand = False
                if command.parent:
                    showcommand = False
                for check in command.checks:
                    try:
                        check(ctx)
                    except:
                        showcommand = False
                if showcommand:
                    command_list += f'**{ctx.prefix}{command.name}** - {command.help}\n'
            if command_list:
                em.add_field(name=cog, value=command_list, inline=False)
        em.set_footer(text=f'Requested by {ctx.message.author}',
                      icon_url=get_avatar(ctx.message.author))
        await ctx.send(embed=em)