Code Monkey home page Code Monkey logo

pybot's Introduction

PyBot

logo-128x128

What is PyBot

PyBot is a Python scripting engine that provides a framework for building component based tasks with the following features: task dispatcher, component system, input controls, easy script configuration (via json), extendable script configuration, multithreading, and more!

Purpose

The purpose of this project is to provide an easy to use task-based scripting engine that can be used as a foundation for simple or advanced tasks.

Running the application

Install python 3.10.1+ from python.org

Install requirements:

pip install .

Run with:

pybot-cli

Building the application

Run build.bat the binary, scripts and settings are found in /dist directory

dist

How it works

PyBot loads using the settings.json configurations. It will first attempt to "attach" to a given program if the bot tasks are dictatorial (configured from settings.json) programs can be added to /scripts/programs. Once attached it will then load any tasks specific to the program, which is also configurable. Next PyBot will load the components from /scripts/components, once loaded it will load all scripts provided in /scripts.

Components

Components are isolated segments of logic that can be plugged into tasks using TaskComponent. The components are loaded from /scripts/components at startup. Here is an example of a component:

class MouseMoveTaskComponent(TaskComponent):
  def __init__(self, config):
    super().__init__(config)
    self.position   = self.config.get("position")   or None
    self.speed      = self.config.get("speed")      or [25, 55]
    self.delay      = self.config.get("delay")      or None
    self.post_delay = self.config.get("post_delay") or [0, 0]

  def update(self, task):
    super().update(task)

    if self.position:
      self.program.mouse.navigate(xy=(self.position[0], self.position[1]), speed=self.speed, delay=self.delay)

    time.sleep(random.uniform(self.post_delay[0], self.post_delay[1]))

  def post_update(self, task):
    super().post_update(task)

This component will move the mouse based on the configuration it's provided.

Tasks

Tasks are a multithreaded code execution that run on a delay.

@task(delay=[1,4], silent=True)
def my_task(self, *args):
  return TaskHandler()

The above task will execute every rand(1, 4) seconds. We have marked it as silent so it doesn't print every execution to the console. The returned TaskHandler is what allows us to fine-grain our task control. If None or False is returned the task will simply not execute.

def can_start(task):
  return True
def started(task):
  print("task started")
def completed(task):
  print("task completed")
def failed(task, err):
  print("task failed")
return TaskHandler(can_start=can_start, started=started, completed=completed, failed=failed)

Configuring a task in our script configuration looks something like this:

"tasks": {

  "my_task": {
    "enabled": true,
    "delay": [3, 6],
    "components": [{
      "name": "MouseMoveTaskComponent",
      "config": {
        "enabled": true,
        "position": [2300, 1140, 2320, 1164],
        "speed": [35, 65],
        "delay": [0.000001, 0.00002],
        "post_delay": [0.3, 0.5]
      }
    }]
  }
  
}

We can turn off our tasks by setting "enabled": false and you can see we have even overriden the "delay". This task also has a component that will execute (in given order). There can be as many components as you like.

Scripts

A script is a module that orcastrates tasks and components to accomplish a specific goal. The script must come with a json file of the same name (i.e. my_script.py must have my_script.json) which contains its default configurations, these configurations can be overriden inside the settings.json "scripts":{}. They are comprised of "tasks" which are configured scripts json configuration file. Tasks can then be comprised of components. The standard structure of a Script is like so:

class MyScript(Script):
  def __init__(self, parent, config):
    super().__init__(parent, config, __name__)
    
   def load(self, conf):
    super().load(conf)

  def unload(self):
    super().unload()

  def start(self):
    super().start()
  • load is called when the script is loaded at startup
  • unload is called when the script is unloaded
  • start is called when the program starts the script (generally at startup)

Scripts will often contain @tasks (see Tasks section above)

Configuration

TODO

License

MIT License

Disclaimer

The sample scripts provided are made as test cases for automating some game tasks. This is strictly done as a way to improve PyBot. I am not responsible if this results in bans.

pybot's People

Contributors

bendol avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

wdavidsideon

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.