# 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/*
```
Raw data
{
"_id": null,
"home_page": "https://github.com/mnemonicmane/irc_bot",
"name": "lotek-rpc",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": null,
"keywords": null,
"author": "anonymous",
"author_email": "internetrelaychatter@proton.me",
"download_url": "https://files.pythonhosted.org/packages/b0/27/933bd5ed1b2ccf175022424942ac595b72b6b4dbf7c6cc56fc323c579733/lotek_rpc-1.0.11.tar.gz",
"platform": null,
"description": "# RPC Module\n\n## Installing from PyPi\n\n`pip3 install lotek-rpc`\n\n\nExample implementation\n\n```python\nimport asyncio\nimport lotek_rpc.api as api\n\n\nclass Impl(api.IrcImpl):\n async def on_message(self, target, by, message):\n print(target, by, message)\n # do some shit like\n if message == 'hack_a_gibson':\n await self.rpc.send_message(target, 'hacking gibson from RPC')\n elif message.startswith('dieplz'):\n await self.rpc.disconnect()\n exit(1)\n\n\nasync def main():\n # endless loop to always try and connect\n while True:\n try:\n tcp = api.TcpClient(\n '127.0.0.1', # use your bots host ip\n 12345,\n Impl(),\n cafile='path/to/yourcafile.cert' # optional. remove this line if using hosted bot\n )\n await tcp.connect()\n await tcp.read()\n except (asyncio.TimeoutError, ConnectionError) as e:\n print(f\"Connection error occurred: {e}\")\n await asyncio.sleep(5)\n except Exception as e:\n print(f\"Unexpected error: {e}\")\n await asyncio.sleep(5)\n\n\nloop = asyncio.get_event_loop()\n\ntry:\n loop.run_until_complete(main())\nexcept KeyboardInterrupt:\n print(\"Bot terminated by user.\")\n```\n\n<br/>\n<br/>\n\n#### \ud83d\udea8Important info before starting to implement your own client not using this library\ud83d\udea8\n*Messages are terminated by a nullbyte 0x00. \nThis means at the end of any message you send, add 0x00 byte. Any message you \nreceive from the server will be ended with 0x00*\n\n## Info for those who want to implement their own client\n\n### Supported Messages you can send from the client\n1. Sending a message to a channel or user\n - `CLIENT_CMD:SEND_MESSAGE:{\"target\": \"#channel/user\", \"message\": \"hello world:\"}`\n2. Telling the server you are disconnecting\n - `CLIENT_END:`\n\n### Supported Message you can receive from the server\n1. On message in a channel or from user\n - `SERVER_EVENT:ON_MESSAGE:{\"target\": \"#channel/user\", \"by\": \"user_who_sent_msg\", \"message\": \"hello world\"}`\n2. On RPC Server restarting\n - `SERVER_EVENT:RESTARTING`\n\n\n<br/>\n<br/>\n\n## Building wheel + src\n```bash\n# https://packaging.python.org/tutorials/packaging-projects/\npython3.9 -m pip install --upgrade build\npython3.9 -m build\npython3.9 -m twine upload --repository testpypi dist/*\n```\n\n\n",
"bugtrack_url": null,
"license": "WTFPL-2.0",
"summary": "Simple TCP client impl to interact with the irc bot and build remote plugins.",
"version": "1.0.11",
"project_urls": {
"Bug Tracker": "https://github.com/mnemonicmane/irc_bot/issues",
"Homepage": "https://github.com/mnemonicmane/irc_bot"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "05188317e4692530d84961a51bb42ab7584939324be64dc844eb57e20017edb6",
"md5": "6f23710e3af562ba743495c999789864",
"sha256": "a740ebe647cefee070ee3449b552862dd1134e3a51a9aa6389a62857584fdda4"
},
"downloads": -1,
"filename": "lotek_rpc-1.0.11-py3-none-any.whl",
"has_sig": false,
"md5_digest": "6f23710e3af562ba743495c999789864",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 6178,
"upload_time": "2025-02-20T12:47:23",
"upload_time_iso_8601": "2025-02-20T12:47:23.000298Z",
"url": "https://files.pythonhosted.org/packages/05/18/8317e4692530d84961a51bb42ab7584939324be64dc844eb57e20017edb6/lotek_rpc-1.0.11-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "b027933bd5ed1b2ccf175022424942ac595b72b6b4dbf7c6cc56fc323c579733",
"md5": "8f6b8f04a0a7ee9e728b6b217e3f851e",
"sha256": "33d297f5d49905257e5991fd5f43ab52b049ad9b99656749f655b8e9bd27fb3d"
},
"downloads": -1,
"filename": "lotek_rpc-1.0.11.tar.gz",
"has_sig": false,
"md5_digest": "8f6b8f04a0a7ee9e728b6b217e3f851e",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 6455,
"upload_time": "2025-02-20T12:47:24",
"upload_time_iso_8601": "2025-02-20T12:47:24.081761Z",
"url": "https://files.pythonhosted.org/packages/b0/27/933bd5ed1b2ccf175022424942ac595b72b6b4dbf7c6cc56fc323c579733/lotek_rpc-1.0.11.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-02-20 12:47:24",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "mnemonicmane",
"github_project": "irc_bot",
"github_not_found": true,
"lcname": "lotek-rpc"
}