Metadata-Version: 2.1
Name: lotek-rpc
Version: 1.0.10
Summary: Simple TCP client impl to interact with the irc bot and build remote plugins.
Home-page: https://github.com/mnemonicmane/irc_bot
Author: anonymous
Author-email: internetrelaychatter@proton.me
License: WTFPL-2.0
Project-URL: Bug Tracker, https://github.com/mnemonicmane/irc_bot/issues
Platform: UNKNOWN
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.7
Description-Content-Type: text/markdown

# RPC Module

## Installing from PyPi

`pip3 install lotek_rpc`


Example implementation

```python
import asyncio
import lotek_rpc.api as api


class Impl(api.IrcImpl):
    async def on_message(self, target, by, message):
        print(target, by, message)
        # do some shit like
        if message == 'hack_a_gibson':
            await self.rpc.send_message(target, 'hacking gibson from RPC')
        elif message.startswith('dieplz'):
            await self.rpc.disconnect()
            exit(1)


async def main():
    # endless loop to always try and connect
    while True:
        try:
            tcp = api.TcpClient(
                '127.0.0.1',  # use your bots host ip
                12345,
                Impl(),
                cafile='path/to/yourcafile.cert' # optional. remove this line if using hosted bot
            )
            await tcp.connect()
            await tcp.read()
        except (asyncio.TimeoutError, ConnectionError) as e:
            print(f"Connection error occurred: {e}")
            await asyncio.sleep(5)
        except Exception as e:
            print(f"Unexpected error: {e}")
            await asyncio.sleep(5)


loop = asyncio.get_event_loop()

try:
    loop.run_until_complete(main())
except KeyboardInterrupt:
    print("Bot terminated by user.")
```

<br/>
<br/>

#### 🚨Important info before starting to implement your own client not using this library🚨
*Messages are terminated by a nullbyte 0x00. 
This means at the end of any message you send, add 0x00 byte. Any message you 
receive from the server will be ended with 0x00*

## Info for those who want to implement their own client

### Supported Messages you can send from the client
1. Sending a message to a channel or user
   - `CLIENT_CMD:SEND_MESSAGE:{"target": "#channel/user", "message": "hello world:"}`
2. Telling the server you are disconnecting
   - `CLIENT_END:`

### Supported Message you can receive from the server
1. On message in a channel or from user
   - `SERVER_EVENT:ON_MESSAGE:{"target": "#channel/user", "by": "user_who_sent_msg", "message": "hello world"}`
2. On RPC Server restarting
   - `SERVER_EVENT:RESTARTING`


<br/>
<br/>

## Building wheel + src
```bash
# https://packaging.python.org/tutorials/packaging-projects/
python3.9 -m pip install --upgrade build
python3.9 -m build
python3.9 -m twine upload --repository testpypi dist/*
```


