Python library for unrealIRCD json-rpc
Project description
UNREALIRCD-RPC-PY
Introduction
If you are using Python3, this package can help you to parse all json responses it does all the work for you.
How to install this package
pip3 install unrealircd_rpc_py
[!NOTE] I recommend installing a virtual environment and then installing the package within it.
How to establish the link
from unrealircd_rpc_py.Loader import Loader
# Using requests method
rpc = Loader(
req_method='requests',
url='https://your.irc.domaine.org:8600/api',
username='apiname',
password='apiPASSWORD'
)
# Using socket method
rpc = Loader(
req_method='socket',
url='https://your.irc.domaine.org:8600/api',
username='apiname',
password='apiPASSWORD'
)
# Using unixsocket method (Local only)
rpc = Loader(
req_method='unixsocket',
path_to_socket_file='/path/to/unrealircd/data/rpc.socket'
)
from unrealircd_rpc_py.Live import Live
# Live Connection (Local only)
LiveRpc = Live(
req_method='unixsocket',
path_to_socket_file='/path/to/unrealircd/data/rpc.socket',
callback_object_instance=Callback_class_instance,
callback_method_name='your_method_name'
)
# Live Connection (Local Or Remote)
liveRpc = Live(
req_method='websocket',
url='https://your.irc.domaine.org:8600/api',
username='apiname',
password='apiPASSWORD',
callback_object_instance=InitCallbackClass,
callback_method_name='your_method_name'
)
How to work with (remotly)
This package allows easy interfacing with UnrealIRCd through regular Python3 code, such as:
from unrealircd_rpc_py.Loader import Loader
# Initialize your connexion to unrealircd
rpc = Loader(
req_method='requests', # you can also use 'socket'
url='https://your.irc.domaine.org:8600/api',
username='apiname',
password='apiPASSWORD'
)
# Enjoy the power of JSON-RPC
User = rpc.User
response = User.get('adator')
print(f'Nickname: {response.name}')
print(f'Ip: {response.ip}')
Channels = rpc.Channel
response = Channels.list_(_object_detail_level=3)
for chan in Channels:
print(f'-' * 16)
print(f'Channel: {chan.name}')
print(f'Created on: {chan.creation_time}')
print(f'Bans: {chan.bans}')
print(f'Members: {chan.members}')
print(f'-' * 16)
How to work with (using unix socket locally)
This package allows easy interfacing with UnrealIRCd through regular Python3 code, such as:
from unrealircd_rpc_py.Loader import Loader
# Initialize your connexion to unrealircd
rpc = Loader(
req_method='unixsocket',
path_to_socket_file='/path/to/unrealircd/data/rpc.socket'
)
# Enjoy the power of JSON-RPC
User = rpc.User
response = User.get('adator')
print(f'Nickname: {response.name}')
print(f'Ip: {response.ip}')
Channels = rpc.Channel
response = Channels.list_(_object_detail_level=3)
# The auto completion should help you to find all available attributes
for chan in Channels:
print(f'-' * 16)
print(f'Channel: {chan.name}')
print(f'Created on: {chan.creation_time}')
print(f'Bans: {chan.bans}')
print(f'Members: {chan.members}')
print(f'-' * 16)
Object that you can use in a synchrone mode
from unrealircd_rpc_py.Loader import Loader
# Initialize your connexion to unrealircd using one of the three method
rpc = Loader(
req_method='unixsocket',
path_to_socket_file='/path/to/unrealircd/data/rpc.socket'
)
Channel = rpc.Channel
Name_ban = rpc.Name_ban
Server_ban_exception = rpc.Server_ban_exception
Server_ban = rpc.Server_ban
Spamfilter = rpc.Spamfilter
Stats = rpc.Stats
User = rpc.User
Whowas = rpc.Whowas
Log = rpc.Log # This feature requires unrealIRCd 6.1.8 or higher
Live Connection via unixsocket or websocket
How to work with (using Live unixsocket)
from unrealircd_rpc_py.Live import Live
# This is un callback class that will recieve the response
from TestObject import TestObject
InitCallbackClass = TestObject()
# The Callback method must always have 1 parameter as string
liveRpc = Live(req_method='unixsocket',
path_to_socket_file='/path/to/unrealircd/data/rpc.socket',
callback_object_instance=InitCallbackClass,
callback_method_name='your_method_name'
)
# This method will run forever and will send to your callback method the response
# in SimpleNameSpace type that you can parse
if liveRpc.Error.code == 0:
# Subscribe to live events
liveRpc.subscribe()
else:
# If error show the error message
print(liveRpc.Error.message)
How to work with (using Live websocket)
from unrealircd_rpc_py.Live import Live
# This is un callback class that will recieve the response
from TestObject import TestObject
InitCallbackClass = TestObject()
# The Callback method must always have 1 parameter as string
liveRpc = Live(req_method='websocket',
url='https://your.irc.domaine.org:8600/api',
username='apiname',
password='apiPASSWORD',
callback_object_instance=InitCallbackClass,
callback_method_name='your_method_name'
)
# This method will run forever and will send to your callback method the response
# in SimpleNameSpace type that you can parse
if liveRpc.Error.code == 0:
# Subscribe to live events
liveRpc.subscribe()
else:
# If error show the error message
print(liveRpc.Error.message)
Exemple of a Callback Class
class CallbackObject:
def __init__(self) -> None:
pass
def run(self, json_response) -> bool:
print(json_response)
if type(json_response.result) != bool:
print(json_response.result.channel)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
unrealircd_rpc_py-1.0.7.tar.gz
(25.2 kB
view details)
Built Distribution
File details
Details for the file unrealircd_rpc_py-1.0.7.tar.gz
.
File metadata
- Download URL: unrealircd_rpc_py-1.0.7.tar.gz
- Upload date:
- Size: 25.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2bf87b22b9137f5b7b199f5799c43ba2ae53b7bddbc1bd9de6be4d47ee9ac75b |
|
MD5 | 83d52c0d96ddb1a57b0379dfb941784c |
|
BLAKE2b-256 | f89073915d4666b7a4709bcf62a855374b7140ce277f880a9cd3a119c715a219 |
File details
Details for the file unrealircd_rpc_py-1.0.7-py3-none-any.whl
.
File metadata
- Download URL: unrealircd_rpc_py-1.0.7-py3-none-any.whl
- Upload date:
- Size: 35.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 97f9b56fc4ec686d9be5c07f0b2f88b76968e692be1bc80afa4f0670f51edd91 |
|
MD5 | 741f7bae22c2bcc79de57d782714fbb6 |
|
BLAKE2b-256 | 00a7a38f3c2399ae8f9dd9a6e7f431600a5fe054577367f297e3424dfec2891b |