olijeffers0n / rustplus

Rust+ API Wrapper Written in Python for the Game: Rust
https://rplus.ollieee.xyz/
MIT License
102 stars 28 forks source link

Added optional args and kwargs arguments to on_success and on_failure #55

Closed ITz-Viks closed 1 year ago

ITz-Viks commented 1 year ago

I also added typehinting for both functions and the new kwargs and args arguments in RustSocket.connect()

My test code

import asyncio
from rustplus_.rustplus import RustSocket

async def on_success(*args, **kwargs):
    print(f"Success: Ip is {kwargs['ip']} and port is {kwargs['port']}")

def on_failure(*args, **kwargs):
    print(f"Error: Ip is {kwargs['ip']} and port is {kwargs['port']}")

async def main():
    socket = RustSocket("ip", "port", steamid, player_token)
    kwargs = {"ip": "ip", "port": port}
    await socket.connect(on_failure=on_failure, on_success=on_success, on_success_kwargs=kwargs, on_failure_kwargs=kwargs)
    print(f"It is {(await socket.get_time()).time}")

    await socket.disconnect()

asyncio.run(main())
ITz-Viks commented 1 year ago

Updated per request

ITz-Viks commented 1 year ago

I'm unsure whether to bundle the on_failure into the tuple as well... What do you think? as long as it is type hinted properly it should be fine

I don't think that should change. Keeping args and functions themselves separate makes it simple to understand and whoever needs args will find it anyway. I'm not home right now so ill make the changes later/tomorrow.