예제 #1
0
파일: info.py 프로젝트: Flurrrr/baritonebot
async def setting_searcher(ctx, setting, link):
    desc1, desc2, settings = '', '', []
    for x in requests.get(link).content.decode('utf-8').split('/**')[2:-4]:
        clean = ' '.join(x.split())
        default_setting = clean.split('*/',
                                      1)[1][:-2].split(' = new Setting<>(',
                                                       1)[1]
        # Edge cases below yay \o/
        if default_setting.startswith('new ArrayList<>'):
            if '( )' in default_setting:
                default = '()'
            elif 'Item.getItem' in default_setting:
                default = '(dirt, cobblestone, netherrack, stone)'
            else:
                default = '(' + ''.join(
                    default_setting.split('Blocks.')[1:])[:-3].lower() + ')'
        elif default_setting.startswith('new Vec'):
            default = default_setting.split('3i')[1]
        else:
            default = default_setting

        set_dict = {
            'description':
            clean.split('*/')[0][2:-1].replace(' * <p> * ',
                                               '\n').replace(' * ', ' '),
            'title':
            clean.split('*/')[1][21:-2].split(' = new', 1)[0].split('> ')[1],
            'type':
            clean.split('*/')[1].split('> ', 1)[0].split('Setting<')[1],
            'default':
            default
        }
        settings.append(set_dict.copy())
    for x in settings:
        if re.search(setting.lower(), x['title'].lower()) is not None:
            add = f"**[{x['title']}](https://baritone.leijurv.com/baritone/api/Settings.html#{x['title']})** | __{x['type']}__ | *Default:* `{x['default']}`\n{x['description']}\n\n"
            if len(add) + len(desc1) <= 2048:
                desc1 += add
            else:
                if len(add) + len(desc2) <= 1959:
                    desc2 += add
                else:
                    desc2 += '*You exceeded the second embeds limit... maybe try searching for something more specific?*'
                    break
    if desc1 == '':
        desc1 = 'There was no settings found for that search :('
    em_v = discord.Embed(color=int(main.values(1), 16), description=desc1)
    em_v.set_footer(text=f'{ctx.author.name} | ID: {ctx.author.id}',
                    icon_url=ctx.author.avatar_url)
    await ctx.send(embed=em_v)
    if desc2 != '':
        em_v = discord.Embed(color=int(main.values(1), 16), description=desc2)
        em_v.set_footer(text=f'{ctx.author.name} | ID: {ctx.author.id}',
                        icon_url=ctx.author.avatar_url)
        await ctx.send(embed=em_v)
예제 #2
0
 async def on_message(self, message):
     if message.author.discriminator != '0000':
         if not message.content.lower().startswith(
                 main.values(0)) and message.author.id != main.ids(0):
             if await regex_delete(self, message) is not True:
                 await regex_respond(self, message)
                 await att_paste(message)
예제 #3
0
 async def spr(self, ctx):
     em_v = discord.Embed(
         color=int(main.values(1), 16),
         title='Top Rock/Paper/Scissors/Won/Lost/Tied leaderboard')
     main.cur.execute('SELECT rock, user_id FROM stats ORDER BY rock DESC')
     em_v.add_field(name='Rock:',
                    value=await top_formatter(self, main.cur.fetchall()))
     board = await ctx.send(embed=em_v)
     main.cur.execute(
         'SELECT paper, user_id FROM stats ORDER BY paper DESC')
     em_v.add_field(name='Paper:',
                    value=await top_formatter(self, main.cur.fetchall()))
     await board.edit(embed=em_v)
     main.cur.execute(
         'SELECT scissors, user_id FROM stats ORDER BY scissors DESC')
     em_v.add_field(name='Scissors:',
                    value=await top_formatter(self, main.cur.fetchall()))
     await board.edit(embed=em_v)
     main.cur.execute('SELECT won, user_id FROM stats ORDER BY won DESC')
     em_v.add_field(name='Won:',
                    value=await top_formatter(self, main.cur.fetchall()))
     await board.edit(embed=em_v)
     main.cur.execute('SELECT lost, user_id FROM stats ORDER BY lost DESC')
     em_v.add_field(name='Lost:',
                    value=await top_formatter(self, main.cur.fetchall()))
     await board.edit(embed=em_v)
     main.cur.execute('SELECT tied, user_id FROM stats ORDER BY tied DESC')
     em_v.add_field(name='Tied:',
                    value=await top_formatter(self, main.cur.fetchall()))
     await board.edit(embed=em_v)
예제 #4
0
async def what_text(self, ctx, what, arep_num, desc, dontdelete=None):
    em_v = discord.Embed(color=int(main.values(1), 16), description=desc)
    em_v.set_footer(text=f'{ctx.author.name} | ID: {ctx.author.id}',
                    icon_url=ctx.author.avatar_url)
    bot_text = await ctx.send(embed=em_v)

    def check(m):
        try:
            return bot_text.id == m.reference.message_id and m.author.id == ctx.author.id
        except AttributeError:
            pass

    try:
        message = await self.bot.wait_for('message', timeout=3600, check=check)
    except asyncio.TimeoutError:
        return await cancel_new(
            ctx,
            'The new response was deleted because an hour has passed with no response',
            arep_num, dontdelete)
    else:
        if 'ignored' in desc:
            if await ig_what(ctx, message, arep_num, dontdelete) is True:
                return True
        else:
            if await text_what(ctx, message, what, arep_num,
                               dontdelete) is True:
                return True
예제 #5
0
 async def on_message_edit(self, message_before, message_after):
     if message_after.author.discriminator != '0000':
         if message_after.content != '' and message_before.content != '':
             main.stat_update(
                 r'UPDATE stats SET edited = edited + 1 WHERE user_id = %s',
                 message_after.author.id)
             if message_before.author.id != main.ids(0):
                 if str(message_before.channel.id) not in exempt_channels:
                     if message_after.content != message_before.content:  # prevent logging embeds loading
                         if message_before.guild is None:
                             jump = 'DMs**'
                         else:
                             jump = f'{message_after.channel.mention}** [(jump)](https://discord.com/channels/{message_after.guild.id}/{message_after.channel.id}/{message_after.id})'
                         em_v = discord.Embed(
                             color=int(main.values(1), 16),
                             description=f'**Message edited in {jump}')
                         em_v.add_field(name='Befored Edit:',
                                        value=message_before.content,
                                        inline=False)
                         em_v.add_field(name='After Edit:',
                                        value=message_after.content,
                                        inline=False)
                         em_v.set_footer(
                             text=
                             f'{message_after.author.name} | ID: {message_after.author.id}',
                             icon_url=message_after.author.avatar_url)
                         channel = await self.bot.fetch_channel(main.ids(3))
                         await channel.send(embed=em_v)
                         print(
                             f'{message_after.author.id} edited a message, Before: \"{message_before.content}\" After: \"{message_after.content}\"'
                         )
예제 #6
0
파일: info.py 프로젝트: Flurrrr/baritonebot
 async def serverinfo(self, ctx):
     b_guild = self.bot.get_guild(main.ids(1))
     em_v = discord.Embed(color=int(main.values(1), 16),
                          title=f'Server Information: {b_guild.name}')
     em_v.add_field(name='Owner:',
                    value=f'{b_guild.owner} (ID: {b_guild.owner_id})',
                    inline=False)
     em_v.add_field(name='Description:',
                    value=b_guild.description,
                    inline=False)
     em_v.add_field(name='Created:',
                    value=b_guild.created_at.strftime(
                        '%B %d, %Y at %I:%M:%S %p').lstrip('0').replace(
                            ' 0', ' '),
                    inline=False)
     em_v.add_field(name='Region:', value=b_guild.region, inline=False)
     em_v.add_field(name=f'Roles ({len(b_guild.roles)-1}):',
                    value=(' '.join([str(r.mention)
                                     for r in b_guild.roles][1:]) +
                           '\u200b'),
                    inline=False)
     em_v.add_field(name='Text Channels:',
                    value=str(len(b_guild.text_channels)),
                    inline=True)
     em_v.add_field(name='Voice Channels:',
                    value=str(len(b_guild.voice_channels)),
                    inline=True)
     em_v.add_field(name='Members:',
                    value=b_guild.member_count,
                    inline=True)
     em_v.set_footer(text=f'ID: {b_guild.id}')
     em_v.set_thumbnail(url=b_guild.icon_url)
     await ctx.send(embed=em_v)
예제 #7
0
 async def messages(self, ctx):
     em_v = discord.Embed(
         color=int(main.values(1), 16),
         title='Top Messages/Edits/Deletes/Responses leaderboard')
     main.cur.execute(
         'SELECT messages, user_id FROM stats ORDER BY messages DESC')
     em_v.add_field(name='Messages:',
                    value=await top_formatter(self, main.cur.fetchall()))
     board = await ctx.send(embed=em_v)
     main.cur.execute(
         'SELECT edited, user_id FROM stats ORDER BY edited DESC')
     em_v.add_field(name='Edits:',
                    value=await top_formatter(self, main.cur.fetchall()))
     await board.edit(embed=em_v)
     main.cur.execute(
         'SELECT deleted, user_id FROM stats ORDER BY deleted DESC')
     em_v.add_field(name='Deletes:',
                    value=await top_formatter(self, main.cur.fetchall()))
     await board.edit(embed=em_v)
     main.cur.execute(
         'SELECT triggered_responses, user_id FROM stats ORDER BY triggered_responses DESC'
     )
     em_v.add_field(name='Respones:',
                    value=await top_formatter(self, main.cur.fetchall()))
     await board.edit(embed=em_v)
예제 #8
0
 async def cringe(self, ctx):
     em_v = discord.Embed(color=int(main.values(1), 16),
                          title=':camera_with_flash:')
     main.cur.execute(
         'SELECT cringe_link FROM cringe ORDER BY RANDOM() LIMIT 1')
     em_v.set_image(url=str(str(main.cur.fetchone())[2:-3]))
     em_v.set_footer(text=f'{ctx.author.name} | ID: {ctx.author.id}',
                     icon_url=ctx.author.avatar_url)
     await ctx.send(embed=em_v)
예제 #9
0
    async def edit(self, ctx, num: int = None):
        if num is None:
            return await main.error_embed(
                ctx, 'You need to give a response number to edit')
        if num <= 0:
            return await main.error_embed(
                ctx, 'You need to give a **positive non zero** number')
        main.cur.execute('SELECT * FROM response WHERE rep_number=%s', (num, ))
        response = main.cur.fetchone()
        if response is not None:
            em_v = discord.Embed(color=int(main.values(1), 16),
                                 title='What would you like to edit?',
                                 description=' \
              \u2022 :one: The title \
              \n\u2022 :two: The description \
              \n\u2022 :three: The regex \
              \n\u2022 :four: Delete the message or not \
              \n\u2022 :five: Ignored roles')
            em_v.set_footer(text=f'{ctx.author.name} | ID: {ctx.author.id}',
                            icon_url=ctx.author.avatar_url)
            bot_edit = await ctx.send(embed=em_v)
            for i in ['1️⃣', '2️⃣', '3️⃣', '4️⃣', '5️⃣']:
                await bot_edit.add_reaction(i)

            def check(ereaction, euser):
                return bot_edit.id == ereaction.message.id and euser.id == ctx.author.id

            try:
                reaction = await self.bot.wait_for('reaction_add',
                                                   timeout=300,
                                                   check=check)
            except asyncio.TimeoutError:
                return await main.error_embed(ctx, '', 'don\'t delete')
            else:
                if str(reaction[0]) == '1️⃣':
                    return await what_text(self, ctx, 'title', num, title_desc,
                                           'don\'t delete')
                if str(reaction[0]) == '2️⃣':
                    return await what_text(self, ctx, 'description', num,
                                           desc_desc, 'don\'t delete')
                if str(reaction[0]) == '3️⃣':
                    return await what_text(self, ctx, 'regex', num, regex_desc,
                                           'don\'t delete')
                if str(reaction[0]) == '4️⃣':
                    return await do_delete(self, ctx, num, 'don\'t delete')
                if str(reaction[0]) == '5️⃣':
                    return await what_text(self, ctx, 'ignore', num,
                                           ignorerole_desc, 'don\'t delete')
                print(f'{ctx.author.id} edited response #{num}')
        else:
            await main.error_embed(ctx,
                                   'There is no response with that number')
예제 #10
0
 async def coin(self, ctx):
     em_v = discord.Embed(color=int(main.values(1), 16),
                          title='Top Heads/Tails leaderboard')
     main.cur.execute(
         'SELECT heads, user_id FROM stats ORDER BY heads DESC')
     em_v.add_field(name='Heads:',
                    value=await top_formatter(self, main.cur.fetchall()))
     board = await ctx.send(embed=em_v)
     main.cur.execute(
         'SELECT tails, user_id FROM stats ORDER BY tails DESC')
     em_v.add_field(name='Tails:',
                    value=await top_formatter(self, main.cur.fetchall()))
     await board.edit(embed=em_v)
예제 #11
0
async def regex_respond(self, message):
    b_guild = self.bot.get_guild(main.ids(1))
    main.cur.execute('SELECT * FROM response WHERE delete=false')
    match_regex = main.cur.fetchall()
    for x in match_regex:
        if re.search(x[0], message.content.lower()) is not None:
            main.stat_update(
                r'UPDATE stats SET triggered_responses = triggered_responses + 1 WHERE user_id = %s',
                message.author.id)
            if (b_guild.get_member(main.ids(0))
                    in message.mentions) or (message.content.startswith('!')):
                title = '' if x[1].lower() == 'none' else x[1]
                desc = '' if x[2].lower() == 'none' else x[2]
                await main.channel_embed(message.channel, title, desc)
                print(
                    f'{message.author.id} manually triggered response #{x[5]}')
                if message.guild is not None:
                    await message.delete()
            elif role_check(self, message.author.id, x[4]) is not True:
                title = '' if x[1].lower() == 'none' else x[1]
                desc = '' if x[2].lower() == 'none' else x[2]
                print(f'{message.author.id} triggered response #{x[5]}')
                em_v = discord.Embed(color=int(main.values(1), 16),
                                     title=title,
                                     description=desc)
                em_v.set_footer(
                    text=f'{message.author.name} | ID: {message.author.id}',
                    icon_url=message.author.avatar_url)
                auto_response = await message.channel.send(embed=em_v)
                await auto_response.add_reaction('🗑️')

                def check(dreaction, duser):
                    try:
                        return (auto_response.id == dreaction.message.id) and (
                            duser.id == message.author.id
                            or staffr_check(self, duser.id) is True)
                    except AttributeError:
                        pass

                try:
                    reaction, user = await self.bot.wait_for('reaction_add',
                                                             timeout=1800,
                                                             check=check)
                except asyncio.TimeoutError:
                    pass
                else:
                    if str(reaction) == '🗑️' and user.id != int(main.ids(0)):
                        try:
                            await auto_response.delete()
                        except AttributeError:
                            pass
예제 #12
0
파일: rule.py 프로젝트: Flurrrr/baritonebot
 async def rules(self, ctx):
     em_v = discord.Embed(color=int(main.values(1), 16), title='Rules')
     em_v.set_footer(text=f'{ctx.author.name} | ID: {ctx.author.id}',
                     icon_url=ctx.author.avatar_url)
     em_v.set_thumbnail(url='https://bigrat.monster/media/noanime.gif')
     main.cur.execute(
         'SELECT ROW_NUMBER () OVER ( ORDER BY rules_number ) rowNum, rules_number, rules_title, rules_description FROM rules'
     )
     main.db.commit()
     rules = main.cur.fetchall()
     for row in rules:
         field_title = f'**{row[1]} )** {row[2]}'
         field_value = row[3]
         em_v.add_field(name=field_title, value=field_value, inline=False)
     await ctx.send(embed=em_v)
예제 #13
0
파일: info.py 프로젝트: Flurrrr/baritonebot
async def info_embed(ctx, member, title, field1, field2, field3, value):
    em_v = discord.Embed(color=int(main.values(1), 16), title=title)
    em_v.add_field(name='Mention:', value=member.mention, inline=True)
    em_v.add_field(name='Status:', value=field1, inline=True)
    em_v.add_field(name='Created:',
                   value=member.created_at.strftime(
                       '%B %d, %Y at %I:%M:%S %p').lstrip('0').replace(
                           ' 0', ' '),
                   inline=False)
    em_v.add_field(name='Joined:', value=field2, inline=False)
    em_v.add_field(name=field3, value=value, inline=False)
    em_v.set_author(name=f'{member.name}#{member.discriminator}',
                    icon_url=member.avatar_url)
    em_v.set_footer(text=f'ID: {member.id}')
    em_v.set_thumbnail(url=member.avatar_url)
    await ctx.send(embed=em_v)
예제 #14
0
파일: info.py 프로젝트: Flurrrr/baritonebot
 async def info(self, ctx):
     em_v = discord.Embed(
         color=int(main.values(1), 16),
         description=f'Current prefix: `{main.values(0)}`'
         f'\n\n__**Info:**__'
         f'\n\u2022 Made by bigdata#0001'
         f'\n\u2022 Written in [python](https://www.python.org/) using the [discord.py](https://github.com/Rapptz/discord.py) library'
         f'\n\u2022 Uses a [PostgreSQL](https://www.postgresql.org/) database'
         f'\n\n__**Links:**__'
         f'\n\u2022 [Bot source code on GitHub](https://github.com/Flurrrr/baritonebot)'
         f'\n\u2022 [Main Baritone GitHub repo](https://github.com/cabaletta/baritone)'
         f'\n\u2022 [Invite to Baritone discord server](https://discord.gg/s6fRBAUpmr)'
     )
     em_v.set_author(name='Baritone Bot',
                     url='https://github.com/Flurrrr/baritonebot',
                     icon_url=self.bot.user.avatar_url)
     em_v.set_footer(text=f'{ctx.author.name} | ID: {ctx.author.id}',
                     icon_url=ctx.author.avatar_url)
     await ctx.send(embed=em_v)
예제 #15
0
async def do_delete(self, ctx, arep_num, dontdelete=None):
    em_v = discord.Embed(color=int(main.values(1), 16),
                         description=' \
        Do you want this to delete the message if it matches the regex? \
        \n\u2022 🟢 for yes \
        \n\u2022 🔴 for no \
        \n\u2022 ❌ to cancel')
    em_v.set_footer(text=f'{ctx.author.name} | ID: {ctx.author.id}',
                    icon_url=ctx.author.avatar_url)
    bot_delete = await ctx.send(embed=em_v)
    for i in ['🟢', '🔴', '❌']:
        await bot_delete.add_reaction(i)

    def check(dreaction, duser):
        try:
            return bot_delete.id == dreaction.message.id and duser.id == ctx.author.id
        except AttributeError:
            pass

    try:
        reaction = await self.bot.wait_for('reaction_add',
                                           timeout=300,
                                           check=check)
    except asyncio.TimeoutError:
        return await cancel_new(
            ctx,
            'The new response was deleted because 5 minutes has passed with no reaction',
            arep_num, dontdelete)
    else:
        if str(reaction[0]) == '🟢':  # green circle emote
            main.cur.execute(
                'UPDATE response SET delete=true WHERE rep_number=%s',
                (arep_num, ))
            main.db.commit()
            return True
        if str(reaction[0]) == '🔴':  # red circle emote
            main.cur.execute(
                'UPDATE response SET delete=false WHERE rep_number=%s',
                (arep_num, ))
            main.db.commit()
            return True
        if str(reaction[0]) == '❌':
            await cancel_new(ctx, 'no', arep_num, dontdelete)
예제 #16
0
def du_matrices(t, force, dF):
    i = int(t / main.dt)
    u = main.values(force, ts=[t])
    Fx, Fy = force[2 * i], force[2 * i + 1]
    F = np.linalg.norm([Fx, Fy])
    Vx, Vy = u[2], u[3]
    rx, ry = u[0], u[1]
    R, g, isp = main.R, main.g, main.isp

    r = np.linalg.norm([rx, ry])
    m = u[4]
    a = np.array([[0, 0, 1, 0, 0], [0, 0, 0, 1, 0],
                  [R ** 2 * g / (r ** 3) * (3 * rx ** 2 / (r ** 2) - 1), 3 * R ** 2 * g * rx * ry / (r ** 3),
                   -F / (m * isp * g), 0, 1 / m ** 2 * (F * Vx / (isp * g) - Fx)],
                  [3 * R ** 2 * g * rx * ry / (r ** 3), R ** 2 * g / (r ** 3) * (3 * ry ** 2 / (r ** 2) - 1), 0,
                   -F / (m * isp * g), 1 / m ** 2 * (F * Vy / (isp * g) - Fy)], [0, 0, 0, 0, 0]])
    b = np.array([[0, 0], [0, 0], [1 / m * (1 - Fx / (isp * g * F)), -Fy / (m * isp * g * F)],
                  [-Fx / (m * isp * g * F), 1 / m * (1 - Fy / (isp * g * F))],
                  [-Fx / (isp * g * F), -Fy / (isp * g * F)]])
    b = b @ np.array([dF[2 * i], dF[2 * i + 1]])
    return [a, b]
예제 #17
0
 async def on_message_edit(self, message_before, message_after):
     if message_after.author.discriminator != '0000':
         if not message_after.content.lower().startswith(
                 main.values(0)) and message_after.author.id != main.ids(0):
             if message_before.content != message_after.content:
                 await regex_delete(self, message_after)
예제 #18
0
import numpy as np
angles = []
dtheta = 3.14 / 100
theta = 0
F = np.zeros(int(main.T / main.dt) * 2 + 2)
modules = np.zeros(int(main.T / main.dt) + 1)
for i in range(0, int(main.T / main.dt)):
    if i<main.T/main.dt/6:
        F[2 * i], F[2 * i + 1] = np.cos(0), np.sin(0)
    else:
        F[2 * i], F[2 * i + 1] = np.cos(np.pi/2), np.sin(np.pi/2)
    modules[i] = np.linalg.norm([F[2 * i], F[2 * i + 1]])
F = F * main.g * main.isp * main.fuel / main.T
X = []
Y = []
for i in range(0,200):
    X.append(main.R * np.cos(theta))
    Y.append(main.R * np.sin(theta))
    theta += dtheta
u = main.values(F)
x = u[0]
y = u[1]
m = u[4]
t = np.linspace(0, main.T, np.size(m))
#plt.plot(t, m)
plt.plot(x, y)
plt.plot(X, Y)
plt.xlim(-10 * main.R, 10 * main.R)
plt.ylim(-10 * main.R, 10 * main.R)
plt.show()
print(main.q(main.final_values(F)))