Example #1
0
async def render_latex(ctx, *, raw_latex=''):
    if not guild_config.getltx(ctx) or not raw_latex:
        return
    with ctx.channel.typing():
        if (image := await grab_latex(default_preamble, default_postamble,
                                      raw_latex)) is None:
            await ctx.send(
                'D--> Your latex code is beneighth contempt. Try again.')
            return
        # Send the image to the latex channel and embed.
        latex_channel = bot.get_channel(773594582175973376)
        msg_id = hex(member_stalker.member_data['latex_count'])[2:]
        member_stalker.member_data['latex_count'] += 1
        await latex_channel.send(
            f'`@{ctx.author}`: UID {ctx.author.id}: MID {msg_id}',
            file=dc.File(io.BytesIO(await image.read()), 'latex.png'))
        async for msg in latex_channel.history(limit=16):
            if msg.content.split()[-1] == msg_id:
                latex_att = msg.attachments[0]
                break
        embed = dc.Embed(
            color=ctx.author.color,
            timestamp=datetime.utcnow(),
        )
        embed.set_author(
            name=f'D--> Latex render for {ctx.author}',
            icon_url=url_bank.latex_icon,
        )
        embed.set_image(url=latex_att.url)
        await ctx.send(embed=embed)
Example #2
0
async def grab_avatar(user):
    avy_channel = bot.get_channel(avy_chid)
    with open('avatar.png', mode='wb') as avatarfile:
        try:
            await user.avatar_url.save(avatarfile)
        except dc.NotFound:
            return url_bank.null_avatar
    msg_id = hex(member_stalker.member_data['avatar_count'])[2:]
    member_stalker.member_data['avatar_count'] += 1
    with open('avatar.png', mode='rb') as avatarfile:
        await avy_channel.send(f'`@{user}`: UID {user.id}: MID {msg_id}',
                               file=dc.File(avatarfile))
    async for msg in avy_channel.history(limit=16):
        if msg.content.split()[-1] == msg_id:
            return msg.attachments[0].url
 async def on_ready(self):
     print(response_bank.process_reacts)
     # This is a horrible f*****g way of granting all the pending roles. Too bad!
     for chn_id, msg_dict in self.data.items():
         channel = bot.get_channel(chn_id)
         for msg_id, emoji_dict in msg_dict.items():
             try:
                 msg = await channel.fetch_message(msg_id)
             except (AttributeError, dc.NotFound): # This message entry will be cleared when the bot closes.
                 emoji_dict.clear()
                 continue
             for react in msg.reactions:
                 if (emoji_id := get_react_id(react)) in emoji_dict:
                     role = msg.guild.get_role(emoji_dict[emoji_id])
                     members = [m async for m in react.users() if m.id != bot.user.id]
                     await process_role_grant(self.bot, msg, react, role, members)
Example #4
0
async def suggest_to_dev(ctx, *, suggestion: str):
    suggestions = bot.get_channel(suggest_chid)
    suggest_id = ctx.message.id
    embed = dc.Embed(
        color=dc.Color.red(),
        description=suggestion,
        timestamp=datetime.utcnow(),
    )
    embed.set_author(name=f'{ctx.author} suggests:')
    embed.add_field(
        name='**Message ID:**',
        value=f'`{suggest_id}`',
        inline=False,
    )
    await suggestions.send(embed=embed)
    await ctx.send(f'D--> Your suggestion has been noted.')
    stored_suggestions.add_suggestion(suggest_id, ctx.author.id,
                                      ctx.channel.id)
Example #5
0
async def response_from_dev(ctx, msg_id: int, *, response: str):
    if ctx.author.id not in CONST_AUTHOR:
        return
    try:
        channel, member = stored_suggestions.get_suggestion(bot, msg_id)
    except KeyError:
        await ctx.send('D--> Suggestion does not exist.')
        return
    async for msg in bot.get_channel(suggest_chid).history(limit=None):
        if msg.author.id != bot.user.id:
            continue
        if not msg.embeds:
            continue
        embed = msg.embeds[0]
        suggestion = embed.description
        if not embed.fields:
            continue
        if embed.fields[0].value == f'`{msg_id}`':
            break
    else:
        await ctx.send('D--> Suggestion does not exist.')
        stored_suggestions.remove_suggestion(msg_id)
        return
    embed = dc.Embed(
        color=member.color,
        description=response,
        timestamp=datetime.utcnow(),
    )
    embed.set_author(
        name='D--> In response to your suggestion, the devs say:',
        icon_url=bot.user.avatar_url,
    )
    embed.add_field(
        name='Suggestion:',
        value=suggestion,
        inline=False,
    )
    await channel.send(f'{member.mention}', embed=embed)
    stored_suggestions.remove_suggestion(msg_id)