Ejemplo n.º 1
0
    async def on_message(self, message):
        logger.debug(message.content)
        if message.author == self.bot.user:
            return

        if self.game_mode:
            invalid_input_flag = False
            try:
                if message.content[:2].lower() == "up" and int(
                        message.content[-1]) <= 5:
                    for i in range(int(message.content[-1])):
                        await self.keyboard.send_keyboard_input(GAMEBOY_UP)
                elif message.content[:4].lower() == "down" and int(
                        message.content[-1]) <= 5:
                    for i in range(int(message.content[-1])):
                        await self.keyboard.send_keyboard_input(GAMEBOY_DOWN)
                elif message.content[:4].lower() == "left" and int(
                        message.content[-1]) <= 5:
                    for i in range(int(message.content[-1])):
                        await self.keyboard.send_keyboard_input(GAMEBOY_LEFT)
                elif message.content[:5].lower() == "right" and int(
                        message.content[-1]) <= 5:
                    for i in range(int(message.content[-1])):
                        await self.keyboard.send_keyboard_input(GAMEBOY_RIGHT)
                elif message.content.lower() == "a":
                    await self.keyboard.send_keyboard_input(GAMEBOY_A)
                elif message.content.lower() == "b":
                    await self.keyboard.send_keyboard_input(GAMEBOY_B)
                elif message.content.lower() == "l":
                    await self.keyboard.send_keyboard_input(GAMEBOY_L)
                elif message.content.lower() == "r":
                    await self.keyboard.send_keyboard_input(GAMEBOY_R)
                elif message.content.lower() == "select":
                    await self.keyboard.send_keyboard_input(GAMEBOY_SELECT)
                elif message.content.lower() == "start":
                    await self.keyboard.send_keyboard_input(GAMEBOY_START)
                else:
                    logger.debug("Invalid game input!")
                    invalid_input_flag = True
                await asyncio.sleep(0.4)

                # m +c - exit
                if not invalid_input_flag:
                    take_screenshot("gb.png")
                    await message.channel.send(file=discord.File('gb.png'))
                # game_channel = self.bot.get_channel(GAMEBOY_TEST_CHANNEL_ID)
                # await game_channel.send(file=discord.File('gb.png'))
            except ValueError as vale:
                logger.exception(vale)
                await message.channel.send("```Empty/Invalid entry```")
            except Exception as e:
                logger.exception(e)
Ejemplo n.º 2
0
    def poll(self):
        self.bmp = take_screenshot()
        self.controller_data = self.controller.read()
        self.update_plot()

        if self.recording == True:
            self.save_data()
Ejemplo n.º 3
0
    def do_GET(self):

        ### determine manual override
        manual_override = real_controller.manual_override()

        if (not manual_override):

            ## Look
            bmp = take_screenshot()
            vec = prepare_image(bmp)

            ## Think
            joystick = model.y.eval(session=sess,
                                    feed_dict={
                                        model.x: [vec],
                                        model.keep_prob: 1.0
                                    })[0]

        else:
            joystick = real_controller.read()
            joystick[
                1] *= -1  # flip y (this is in the config when it runs normally)

        ## Act

        ### calibration
        output = [
            int(joystick[0] * 80),
            int(joystick[1] * 80),
            int(round(joystick[2])),
            int(round(joystick[3])),
            int(round(joystick[4])),
        ]

        ### print to console
        if (manual_override):
            cprint("Manual: " + str(output), 'yellow')
        else:
            cprint("AI: " + str(output), 'green')

        ### respond with action
        self.send_response(200)
        self.send_header("Content-type", "text/plain")
        self.end_headers()
        self.wfile.write(output)
        return
Ejemplo n.º 4
0
    def do_GET(self):
        global gas
        ### determine manual override
        manual_override = real_controller.manual_override()

        if (not manual_override):

            ## Look
            image = take_screenshot()
            vec = prepare_image(image)


            ## Think
            joystick = model.y.eval(session=sess, feed_dict={model.x: [vec], model.keep_prob: 1.0})[0]
            steer = joystick[0]
            print steer
            gas = 1 - gas
            # gas = 1
            # joystick[1] =  gas # slow down a bit
            ####### amplification
            # steer = amp(int(steer * 80))
            steer = int(steer * 80)
            # print steer
            Y_axis = 0


        else:
            joystick = real_controller.read()
            joystick[1] *= -1 # flip y (this is in the config when it runs normally)
            steer = int(joystick[0] * 80)
            gas = int(joystick[2])
            Y_axis = int(joystick[1] * 80)
        # joystick[1] =  0 # Y axis
        # joystick[3] =  0 # X button
        # joystick[4] =  0 # RB button



        ## Act


        output = [
            steer,
            gas,
            Y_axis
            # joystick[0], # LEFT RIGHT ANALOG
            # joystick[1], #  UP DOWN ANALOG
            # joystick[2], # A
            # joystick[3], # X
            # joystick[4], # RB
        ]

        ### print to console
        if (manual_override):
            cprint("Manual: " + str(output), 'yellow')
        else:
            cprint("AI: " + str(output), 'green')
        # TODO: include other buttons as in controller.c (input-bot)
        json_output = ControllerState()
        json_output.X_AXIS = steer
        json_output.Y_AXIS = Y_axis
        json_output.A_BUTTON = gas

        self.send_response(200)
        self.send_header("Content-type", "text/plain")
        self.end_headers()
        self.wfile.write(json.dumps(json_output.__dict__))
        return
Ejemplo n.º 5
0
    async def game(self, ctx, arg=None):
        if not arg:
            await ctx.send('```Usage:\n'
                           '{}game on : to activate game mode\n'
                           '{}game off : to deactivate game mode\n'
                           '{}game savestate : to save game state\n'
                           '{}game loadstate : to load game state\n```'.format(
                               COMMAND_PREFIX, COMMAND_PREFIX, COMMAND_PREFIX,
                               COMMAND_PREFIX))
            return

        if arg.lower() == "on":
            if not self.game_mode:
                async with ctx.typing():
                    await ctx.send(
                        "Starting game. Please wait. This might take upto a minute"
                    )
                    self.game_mode = True
                    logger.debug("Starting game")
                    await self.keyboard.send_keyboard_input(
                        "emulationstation", True)
                    logger.debug("Starting game engine...")
                    await asyncio.sleep(30)
                    logger.debug("Done")
                    await asyncio.sleep(1)
                    logger.debug("Starting GBA...")
                    await self.keyboard.send_keyboard_input(GAMEBOY_A)
                    logger.debug("Done")
                    await asyncio.sleep(1)
                    logger.debug("Starting Pokemon...")
                    await self.keyboard.send_keyboard_input(GAMEBOY_A)
                    await asyncio.sleep(25)
                    logger.debug("Done")
                    await self.load_game_state()
                    await asyncio.sleep(1)
                    logger.debug("Taking screenshot...")
                    take_screenshot("gb.png")
                    logger.debug("Game ready to play")
                    await ctx.send("Game ready to play")
                    await asyncio.sleep(1)
                    await ctx.send('```GAME MODE ACTIVATED!```')
                    await ctx.send(
                        '```Available Keys:\n'
                        '   up <number>: to move up\n'
                        '   down <number>: to move down\n'
                        '   left <number>: to move left\n'
                        '   right <number>: to move right\n'
                        '   a : to press A\n'
                        '   b : to press B\n'
                        '   select: to press Select\n'
                        '   start: to press Start\n```'.format(COMMAND_PREFIX))
                    # game_channel = self.bot.get_channel(GAMEBOY_TEST_CHANNEL_ID)
                    await ctx.send(file=discord.File('gb.png'))
                    logger.debug("Done")
            else:
                await ctx.send("Game is already running")
        elif arg.lower() == "off":
            if self.game_mode:
                async with ctx.typing():
                    await ctx.send('Stopping game safely. Please wait.')
                    await self.save_game_state()
                    logger.debug("Stopping game")
                    await self.keyboard.send_keyboard_shortcut(
                        [GAMEBOY_HOTKEY, GAMEBOY_START])
                    logger.debug("Done")
                    await asyncio.sleep(10)
                    logger.debug("Stopping Retropie")
                    '''
                    send_keyboard_input("v")  # Menu
                    await asyncio.sleep(1)
                    send_keyboard_input(GAMEBOY_UP)  # up
                    await asyncio.sleep(1)
                    send_keyboard_input("v")  # QUIT
                    await asyncio.sleep(1)
                    send_keyboard_input(GAMEBOY_UP)  # QUIT emu
                    await asyncio.sleep(1)
                    send_keyboard_input("v")  #
                    await asyncio.sleep(1)
                    logger.debug("Done")
                    await asyncio.sleep(10)
                    '''
                    logger.debug("Killing retroarch")
                    os.system("sudo kill $(pidof retroarch)")
                    logger.debug("Done")
                    await asyncio.sleep(10)
                    logger.debug("Killing emulationstation")
                    os.system("sudo kill $(pidof emulationstation)")
                    logger.debug("Done")
                    await asyncio.sleep(10)
                    # logger.debug("Taking screenshot...")
                    # take_screenshot("gb.png")
                    self.game_mode = False
                    logger.debug("Done")
                    await ctx.send('```GAME MODE DEACTIVATED, BYE!```')
            else:
                await ctx.send("Game is not running.")
        elif arg.lower() == "loadstate":
            if self.game_mode:
                await self.load_game_state()
                await ctx.send('Loaded game from previously saved state')
                take_screenshot("gb.png")
                await ctx.send(file=discord.File('gb.png'))
            else:
                await ctx.send('Game is not running. ')
        elif arg.lower() == "savestate":
            if self.game_mode:
                await self.save_game_state()
                await ctx.send('Game saved!')
                take_screenshot("gb.png")
                await ctx.send(file=discord.File('gb.png'))
            else:
                await ctx.send('Game is not running. ')
        else:
            await ctx.send('```Invalid entry```')
            await ctx.send('```Usage:\n'
                           '{}game on : to activate game mode\n'
                           '{}game off : to deactivate game mode\n'
                           '{}game savestate : to save game state\n'
                           '{}game loadstate : to load game state\n```'.format(
                               COMMAND_PREFIX, COMMAND_PREFIX, COMMAND_PREFIX,
                               COMMAND_PREFIX))
Ejemplo n.º 6
0
    login = passwords.logins[args.service]

except:
    if not (args.u and args.p):
        import sys
        sys.stderr.write('passwords.py or (-u and -p args) are required')
        sys.exit(1)

    login = Login(args.u, args.p)

lib = importlib.import_module(args.service)

out = {}

with lib.Site() as a:
    utils.take_screenshot('site-loaded')

    a.login(login)

    utils.take_screenshot('login-done')
    a.goto('statements')

    out['balance'] = a.balance

    out['pending'] = [
        dict(zip(Transaction._fields, tx))
        for tx in a.get_transactions(pending=True)
    ]

    out['posted'] = [
        dict(zip(Transaction._fields, tx))
Ejemplo n.º 7
0
def screenshot_windows(current_loop, screen_w_h, take_screenshot):
    """ take screenshot """

    if take_screenshot is True:
        utils.take_screenshot(current_loop, screen_w_h)
    return
Ejemplo n.º 8
0
  login = passwords.logins[args.service]

except:
  if not (args.u and args.p):
    import sys
    sys.stderr.write('passwords.py or (-u and -p args) are required')
    sys.exit(1)

  login = Login(args.u, args.p)

lib = importlib.import_module(args.service)

out = {}

with lib.Site() as a:
  utils.take_screenshot('site-loaded')

  a.login(login)

  utils.take_screenshot('login-done')
  a.goto('statements')

  out['balance'] = a.balance

  out['pending'] = [
    dict(zip(Transaction._fields, tx))
      for tx in a.get_transactions(pending=True)
  ]

  out['posted'] = [
    dict(zip(Transaction._fields, tx))