Code Monkey home page Code Monkey logo

moonblade's Introduction

moonblade

A Python 3 asynchronous library committed to communicating with LOL server through the LCU API in a simple and flexible way.

Setup

pip install moonblade

Usage

moonblade consists of MoonBlade, Router, and Node.

MoonBlade

MoonBlade is a connector to connect to LOL server. At the beginning, it is necessary to import the class.

from moonblade import MoonBlade

To communicating with LOL server, you need to start MoonBlade first.

mb = MoonBlade()
mb.start()

Similarly, when stopping the use of MoonBlade, it is necessary to stop MoonBlade.

mb.stop()

MoonBlade is alse support context managers.

async with MoonBlade() as mb:
    ...
    while True:
        await asyncio.sleep(1)

Router

Router is used to distribute events received from the LOL server. Before use, it is also necessary to import the class.

from moonblade import Router

register

To receive events, we need to register asynchronous handlers. The handler should be able to accept a dict param.

async def example(data: dict):
    pass

router = Router()
router.register(route = "/moonblade/start", event_type = "All", handler = example)

Note that Router is a singleton class that points to the same Router no matter how many times it is instantiated.

Router can also be used without instantiation.

Router.register(route = "/moonblade/start", event_type = "All", handler = example)

Router can also be use as a decorator to register route.

@Router.register(route = "/moonblade/start", event_type = "All")
async def example(data: dict):
    pass

In fact, I recommend using this way. It should be noted that when registering route with a decorator, the handler param should be None.

We can also register asynchronous methods, which will be introduced later.

event_type

Including Create, Update, Delete and All. Default to All and case-insensitive.

fake

An asynchronous method to fake an event from the server.

await Router.fake(None, 'Update', '/moonblade/start')

Node

Router can register asynchronous methods. In this situation, the class witch the method in should be a subclass of Node.

class C(Node):

    def __init__(self) -> None:
        ...
        super().__init__()

    @Router.register('/moonblade/start')
    async def example(self, data: dict):
        pass

Also, we can add for key in self.__dir__(): getattr(self, key) to the end of the __init__ method to achieve the same effect.

class C:
    def __init__(self) -> None:
        for key in self.__dir__():
            getattr(self, key)

    @Router.register('/moonblade/start')
    async def example(self, data: dict):
        pass

Application

For more detailed usage instructions, reference the library Diana witch is based on moonblade.

moonblade's People

Contributors

gfk-sveyigey avatar

Stargazers

 avatar

Watchers

 avatar

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.