Ejemplo n.º 1
0
    async def ban(self, ctx, *, msg):
        parser = Arguments(allow_abbrev=True, prog='sudo ban')
        parser.add_argument('user', type=choices.user(ctx.message.server))

        await self.bot.send_typing(ctx.message.channel)
        args = await parser.do_parse(self.bot, msg)

        if not args:
            return

        self.con.execute('DELETE FROM users WHERE id = ?', (args.user.id,))
        await self.bot.ban(ctx.message.server.get_member(args.user.id), 7)
        await self.bot.add_reaction(ctx.message, '\U00002705')
Ejemplo n.º 2
0
    async def unregister(self, ctx, *, msg):
        parser = Arguments(allow_abbrev=True, prog='sudo register')
        parser.add_argument('user', type=choices.user(ctx.message.server), help='The Discord user you wish to unlink a Nitro Type account from.')

        await self.bot.send_typing(ctx.message.channel)
        args = await parser.do_parse(self.bot, msg)

        if not args:
            return

        nitro_name = nt_name_for_discord_id(args.user.id, self.con)
        if not nitro_name:
            await self.bot.say('That user does not have a Nitro Type account associated with their Discord account.')
            return

        self.con.execute('DELETE FROM users WHERE id = ?', (args.user.id,))
        await self.bot.add_reaction(ctx.message, '\U00002705')
        await self.bot.replace_roles(args.user, *list(filter(lambda r: r.name not in env['ROLE_NAMES'], args.user.roles)))
Ejemplo n.º 3
0
    async def team(self, ctx, *, msg):
        """
        {
            "usage": "team tag",
            "cooldown": 30,
            "arguments": [
                {
                    "name": "tag",
                    "type": "string",
                    "value": "The tag of the team you wish to retrieve information for."
                }
            ]
        }
        """
        parser = Arguments(allow_abbrev=True, prog='stats')
        parser.add_argument('tag', help='Does stuff')

        await self.bot.send_typing(ctx.message.channel)
        args = await parser.do_parse(self.bot, msg)

        if not args:
            return

        t = await Team.get(args.tag)

        if not t:
            await self.bot.say('A Nitro Type team with that tag does not exist.')
            return

        founded_on = t.created_at.strftime('%b %d, %Y').replace(' 0', ' ')

        e = discord.Embed(colour=t.tag_colour)
        e.description = u'\u200B' if not t.other_requirements else t.other_requirements
        e.set_author(name=t.display_name, url=t.url, icon_url='')
        e.add_field(name='Enrollment', value=f'{t.enrollment.capitalize()}\n**Speed: **{t.min_speed}\n**Level: **{t.min_level}')
        e.add_field(name='About', value=f'**Founded On: **{founded_on}\n**Captain: **{t.captain_display_name or t.captain_username}\n**Member Count: **{t.member_count}')
        t.board_season.add_field(e)
        t.board_daily.add_field(e)
        t.board_weekly.add_field(e)
        t.board_monthly.add_field(e)
        await self.bot.say(None, embed=e)
Ejemplo n.º 4
0
    async def register(self, ctx, *, msg):
        parser = Arguments(allow_abbrev=True, prog='sudo register')
        parser.add_argument('user', type=choices.user(ctx.message.server), help='The Discord user you wish to associate a Nitro Type account to.')
        parser.add_argument('username', help='The Nitro Type account you with to associate the Discord account with.')

        await self.bot.send_typing(ctx.message.channel)
        args = await parser.do_parse(self.bot, msg)

        if not args:
            return

        c = self.con.cursor()
        c.execute('SELECT * FROM users WHERE id = ? OR nitro_name LIKE ? LIMIT 1', (args.user.id, args.username))
        u = c.fetchone()

        if u:
            if u['id'] == args.user.id:
                await self.bot.say('That user already has a Nitro Type account associated with their Discord account.')
            elif u['nitro_name'].lower() == args.username.lower():
                await self.bot.say('That Nitro Type account is already associated to another\'s Discord account.')
            return

        racer = await Racer.get(args.username)
        if not racer:
            await self.bot.say(f'A Nitro Type account with the user name **{args.username}** does not exist.')
            return

        self.con.execute('INSERT INTO users VALUES (?, ?)', (args.user.id, racer.username))
        await self.bot.add_reaction(ctx.message, '\U00002705')
        await racer.apply_roles(self.bot, args.user)
Ejemplo n.º 5
0
    async def racer(self, ctx, *, msg=''):
        """
        {
            "usage": "racer [user]",
            "cooldown": 30,
            "arguments": [
                {
                    "name": "user",
                    "type": "mention | int",
                    "value": "The user you wish to get a racer card for. If omitted racer information with be retrieved for command user."
                }
            ]
        }
        """

        parser = Arguments(allow_abbrev=True, prog='racer')
        parser.add_argument('user', type=choices.nt_user(ctx.message.server), default=ctx.message.author, nargs='?')

        await self.bot.send_typing(ctx.message.channel)
        args = await parser.do_parse(self.bot, msg)

        if not args:
            return

        try:
            racer = await self._get_racer(args.user)
        except Exception as e:
            await self.bot.say(str(e))
            return

        e = racer.setup_embed()
        e.add_field(name='Current Car', value=f"{racer.car.name}", inline=False)
        e.add_field(name='Money', value=f"${racer.money:,}")
        e.add_field(name='Nitros Owned', value=f"{racer.nitros:,}")
        e.add_field(name='Level', value=racer.level)
        e.add_field(name='Profile Views', value=f'{racer.profile_views:,}')
        await self.bot.say(None, embed=e)
Ejemplo n.º 6
0
    async def _help(self, ctx, *, msg=''):
        """
        {
            "usage": "help [command] [--page|-p num]",
            "cooldown": 10,
            "arguments": [
                {
                    "name": "command",
                    "type": "string",
                    "value": "The command you need help with. Leave blank this would if you want to see a list of commands."
                }
            ],
            "options": [
                {
                    "name": "--page|p",
                    "type": "int",
                    "value": "The help page you wish to retrieve. Starts at 1."
                }
            ]
        }
        """
        parser = Arguments(allow_abbrev=False, prog='help')
        parser.add_argument('command', nargs='?')
        parser.add_argument('-p', '--page', type=int, default=1)

        await self.bot.send_typing(ctx.message.channel)
        args = await parser.do_parse(self.bot, msg)

        if not args:
            return

        e = discord.Embed()
        if not args.command:
            if Meta.write_help_to_embed(self.bot, args.page, e):
                m = await self.bot.say(None, embed=e)
                await self.bot.add_reaction(m, '\U000025c0')
                await self.bot.add_reaction(m, '\U000025b6')
            return

        cmd = self.bot.commands.get(args.command)
        if not cmd or cmd.hidden:
            await self.bot.say('Command not found.')

        j = json.loads(cmd.help)
        e.title = cmd.name.capitalize()
        e.description = cmd.description + u'\n\u200B'
        e.add_field(name='Usage', value=f'!{j["usage"]}')

        if cmd.aliases:
            e.add_field(name='Aliases', value=', '.join(cmd.aliases))

        e.add_field(name='Cooldown', value=f'{j.get("cooldown", 0)} Seconds')

        for a in j.get('arguments', []):
            e.add_field(name=f'{a["name"]}: {a["type"]}',
                        value=a['value'],
                        inline=False)

        for a in j.get('options', []):
            e.add_field(name=f'{a["name"]}: {a["type"]}',
                        value=a['value'],
                        inline=False)

        await self.bot.say(None, embed=e)
Ejemplo n.º 7
0
import importlib
import sys

from util import Arguments

if __name__ == '__main__':

    args = Arguments()

    player = args.get('player', 'agent')
    screen = args.get('screen', 'medium')
    steps = args.get_int('steps', None)
    train = args.get('train', None)
    speed = args.get('speed', 'fast' if train else 'slow')
    restart = args.get_int('restart', None)
    output = args.get('output', 'graphics')

    from frogger.settings import settings
    settings['use_graphics'] = (output.lower() != 'text')

    from frogger.frogger import Frogger
    game = Frogger(screen)

    if player != 'human':
        agent_module = importlib.import_module(player)
        agent = agent_module.Agent(train=train)
        game.add_agent(agent)

    scores = game.run(steps=steps, speed=speed, restart=restart)
    print('\t'.join([str(score) for score in scores]))
Ejemplo n.º 8
0
    async def stats(self, ctx, *, msg=''):
        """
        {
            "usage": "stats [user]",
            "cooldown": 30,
            "arguments": [
                {
                    "name": "user",
                    "type": "mention | int",
                    "value": "The user you wish to get stats for. If omitted stats information with be retrieved for command user."
                }
            ]
        }
        """

        parser = Arguments(allow_abbrev=True, prog='stats')
        parser.add_argument('user', type=choices.nt_user(ctx.message.server), default=ctx.message.author, nargs='?')

        await self.bot.send_typing(ctx.message.channel)
        args = await parser.do_parse(self.bot, msg)

        if not args:
            return

        try:
            racer = await self._get_racer(args.user)
        except Exception as e:
            await self.bot.say(str(e))
            return

        e = racer.setup_embed()
        e.add_field(name='Member Since', value=racer.created_at.strftime('%b %d, %Y at %I:%M %p').replace(' 0', ' '))
        e.add_field(name='Avg Speed', value=f'{racer.avg_speed:,} WPM')
        e.add_field(name='Highest Speed', value=f'{racer.highest_speed:,} WPM')
        e.add_field(name='Longest Session', value=f'{racer.longest_session:,}')
        e.add_field(name='Races Played', value=f'{racer.total_races:,}')
        e.add_field(name='Nitros Used', value=f'{racer.nitros_used:,}')
        e.add_field(name='Money', value=f'**Earned: **${racer.money_earned:,}\n**Spent: **${racer.money_spent:,}')
        e.add_field(name='Medals', value=f'\U0001f947 x{racer.medals_gold:,}\n\U0001f948 x{racer.medals_silver:,}\n\U0001f949 x{racer.medals_bronze:,}')
        racer.board_daily.add_field(e)
        racer.board_weekly.add_field(e)
        racer.board_monthly.add_field(e)
        racer.board_season.add_field(e)

        # Creating the racing log graph
        fig = plt.figure()
        count = len(racer.races)
        medals = fig.add_subplot(111, facecolor='#00000000', xticklabels=[''] * count, yticklabels=[''] * count, frameon=None)
        line = fig.add_subplot(111, facecolor='#00000000', xticklabels=[''] * count, yticklabels=[''] * count, frameon=None)

        for i, race in enumerate(racer.races):
            medals.scatter(i, race.wpm, color=race.medal_colour)

        line.plot(range(count), [race.wpm for race in racer.races], zorder=0)
        fig.subplots_adjust(bottom=0.38, top=0.61, right=1, left=0)

        with BytesIO() as buf:
            plt.savefig(buf, bbox_inches='tight', facecolor='#00000000', format='PNG')
            plt.close()
            link = await upload_to_imgur(buf)

            if link:
                e.set_image(url=link)

        await self.bot.say(None, embed=e)