|
5 | 5 | 
|
6 | 6 |
|
7 | 7 |
|
8 |
| -#### If you are using Python3, this package can help you to parse all json responses it does all the work for you. |
9 |
| - |
10 |
| -## How to use this package |
| 8 | +## Introduction |
| 9 | +If you are using Python3, this package can help you to parse all json responses it does all the work for you. |
| 10 | + |
| 11 | +## How to install this package |
| 12 | +```bash |
| 13 | + pip3 install unrealircd_rpc_py |
| 14 | +``` |
| 15 | +> [!NOTE] |
| 16 | +> I recommend installing a virtual environment and then installing the package within it. |
| 17 | +
|
| 18 | +## How to establish the link |
| 19 | +```python |
| 20 | + # Using requests method |
| 21 | + rpc = Loader( |
| 22 | + req_method='requests', |
| 23 | + url='https://your.irc.domaine.org:8600/api', |
| 24 | + username='apiname', |
| 25 | + password='apiPASSWORD' |
| 26 | + ) |
11 | 27 |
|
12 |
| - $ pip3 install unrealircd_rpc_py |
| 28 | + # Using socket method |
| 29 | + rpc = Loader( |
| 30 | + req_method='socket', |
| 31 | + url='https://your.irc.domaine.org:8600/api', |
| 32 | + username='apiname', |
| 33 | + password='apiPASSWORD' |
| 34 | + ) |
13 | 35 |
|
14 |
| -## How to work with (remotly) |
| 36 | + # Using unixsocket method (Local only) |
| 37 | + rpc = Loader( |
| 38 | + req_method='unixsocket', |
| 39 | + path_to_socket_file='/path/to/unrealircd/data/rpc.socket' |
| 40 | + ) |
15 | 41 |
|
16 |
| -This package allows easy interfacing with UnrealIRCd through regular Python3 code, such as: |
| 42 | + # Live Connection (Local only) |
| 43 | + LiveRpc = Live( |
| 44 | + path_to_socket_file='/path/to/unrealircd/data/rpc.socket', |
| 45 | + callback_object_instance=Callback_class_instance, |
| 46 | + callback_method_name='your_method_name' |
| 47 | + ) |
17 | 48 |
|
18 |
| - from unrealircd_rpc_py.Loader import Loader |
| 49 | +``` |
19 | 50 |
|
20 |
| - # Initialize your connexion to unrealircd |
21 |
| - rpc = Loader( |
22 |
| - req_method='requests', # you can also use 'socket' |
23 |
| - url='https://your.irc.domaine.org:8600/api', |
24 |
| - username='apiname', |
25 |
| - password='apiPASSWORD' |
26 |
| - ) |
| 51 | +## How to work with (remotly) |
27 | 52 |
|
28 |
| - # Enjoy the power of JSON-RPC |
| 53 | +This package allows easy interfacing with UnrealIRCd through regular Python3 code, such as: |
| 54 | +```python |
| 55 | + from unrealircd_rpc_py.Loader import Loader |
| 56 | + |
| 57 | + # Initialize your connexion to unrealircd |
| 58 | + rpc = Loader( |
| 59 | + req_method='requests', # you can also use 'socket' |
| 60 | + url='https://your.irc.domaine.org:8600/api', |
| 61 | + username='apiname', |
| 62 | + password='apiPASSWORD' |
| 63 | + ) |
29 | 64 |
|
30 |
| - User = rpc.User |
31 |
| - response = User.get('adator') |
| 65 | + # Enjoy the power of JSON-RPC |
32 | 66 |
|
33 |
| - print(f'Nickname: {response.name}') |
34 |
| - print(f'Ip: {response.ip}') |
| 67 | + User = rpc.User |
| 68 | + response = User.get('adator') |
35 | 69 |
|
36 |
| - Channels = rpc.Channel |
37 |
| - response = Channels.list_(_object_detail_level=3) |
| 70 | + print(f'Nickname: {response.name}') |
| 71 | + print(f'Ip: {response.ip}') |
38 | 72 |
|
39 |
| - for chan in Channels.DB_CHANNELS: |
40 |
| - print(f'-' * 16) |
41 |
| - print(f'Channel: {chan.name}') |
42 |
| - print(f'Created on: {chan.creation_time}') |
43 |
| - print(f'Bans: {chan.bans}') |
44 |
| - print(f'Members: {chan.members}') |
45 |
| - print(f'-' * 16) |
| 73 | + Channels = rpc.Channel |
| 74 | + response = Channels.list_(_object_detail_level=3) |
46 | 75 |
|
| 76 | + for chan in Channels: |
| 77 | + print(f'-' * 16) |
| 78 | + print(f'Channel: {chan.name}') |
| 79 | + print(f'Created on: {chan.creation_time}') |
| 80 | + print(f'Bans: {chan.bans}') |
| 81 | + print(f'Members: {chan.members}') |
| 82 | + print(f'-' * 16) |
| 83 | +``` |
47 | 84 | ## How to work with (using unix socket locally)
|
48 | 85 |
|
49 | 86 | This package allows easy interfacing with UnrealIRCd through regular Python3 code, such as:
|
| 87 | +```python |
| 88 | + from unrealircd_rpc_py.Loader import Loader |
50 | 89 |
|
51 |
| - from unrealircd_rpc_py.Loader import Loader |
52 |
| - |
53 |
| - # Initialize your connexion to unrealircd |
54 |
| - rpc = Loader( |
55 |
| - req_method='unixsocket', |
56 |
| - path_to_socket_file='/path/to/unrealircd/data/rpc.socket' |
57 |
| - ) |
58 |
| - |
59 |
| - # Enjoy the power of JSON-RPC |
| 90 | + # Initialize your connexion to unrealircd |
| 91 | + rpc = Loader( |
| 92 | + req_method='unixsocket', |
| 93 | + path_to_socket_file='/path/to/unrealircd/data/rpc.socket' |
| 94 | + ) |
60 | 95 |
|
61 |
| - User = rpc.User |
62 |
| - response = User.get('adator') |
| 96 | + # Enjoy the power of JSON-RPC |
63 | 97 |
|
64 |
| - print(f'Nickname: {response.name}') |
65 |
| - print(f'Ip: {response.ip}') |
| 98 | + User = rpc.User |
| 99 | + response = User.get('adator') |
66 | 100 |
|
67 |
| - Channels = rpc.Channel |
68 |
| - response = Channels.list_(_object_detail_level=3) |
| 101 | + print(f'Nickname: {response.name}') |
| 102 | + print(f'Ip: {response.ip}') |
69 | 103 |
|
70 |
| - for chan in Channels.DB_CHANNELS: |
71 |
| - print(f'-' * 16) |
72 |
| - print(f'Channel: {chan.name}') |
73 |
| - print(f'Created on: {chan.creation_time}') |
74 |
| - print(f'Bans: {chan.bans}') |
75 |
| - print(f'Members: {chan.members}') |
76 |
| - print(f'-' * 16) |
| 104 | + Channels = rpc.Channel |
| 105 | + response = Channels.list_(_object_detail_level=3) |
77 | 106 |
|
| 107 | + # The auto completion should help you to find all available attributes |
| 108 | + for chan in Channels: |
| 109 | + print(f'-' * 16) |
| 110 | + print(f'Channel: {chan.name}') |
| 111 | + print(f'Created on: {chan.creation_time}') |
| 112 | + print(f'Bans: {chan.bans}') |
| 113 | + print(f'Members: {chan.members}') |
| 114 | + print(f'-' * 16) |
| 115 | +``` |
78 | 116 | ## How to work with (using Live unix socket)
|
| 117 | +```python |
| 118 | + from unrealircd_rpc_py.Live import Live |
79 | 119 |
|
80 |
| - from unrealircd_rpc_py.Live import Live |
| 120 | + # This is un callback class that will recieve the response |
| 121 | + from TestObject import TestObject |
81 | 122 |
|
82 |
| - # This is un callback class that will recieve the response |
83 |
| - from TestObject import TestObject |
| 123 | + InitCallbackClass = TestObject() |
84 | 124 |
|
85 |
| - InitCallbackClass = TestObject() |
| 125 | + # The Callback method must always have 1 parameter as string |
| 126 | + liveRpc = Live( |
| 127 | + path_to_socket_file='/path/to/unrealircd/data/rpc.socket', |
| 128 | + callback_object_instance=InitCallbackClass, |
| 129 | + callback_method_name='your_method_name' |
| 130 | + ) |
86 | 131 |
|
87 |
| - # The Callback method must always have 1 parameter as string |
88 |
| - liveRpc = Live( |
89 |
| - path_to_socket_file='/path/to/unrealircd/data/rpc.socket', |
90 |
| - callback_object_instance=InitCallbackClass, |
91 |
| - callback_method_name='your_method_name' |
92 |
| - ) |
93 |
| - |
94 |
| - # This method will run forever and will send to your callback method the response |
95 |
| - # in SimpleNameSpace type that you can parse |
96 |
| - liveRpc.execute_async_method() |
| 132 | + # This method will run forever and will send to your callback method the response |
| 133 | + # in SimpleNameSpace type that you can parse |
| 134 | + liveRpc.subscribe() |
| 135 | +``` |
97 | 136 |
|
98 | 137 | ## Exemple of a Callback Class
|
| 138 | +```python |
| 139 | + class CallbackObject: |
99 | 140 |
|
100 |
| - class CallbackObject: |
| 141 | + def __init__(self) -> None: |
| 142 | + pass |
101 | 143 |
|
102 |
| - def __init__(self) -> None: |
103 |
| - pass |
| 144 | + def run(self, json_response) -> bool: |
104 | 145 |
|
105 |
| - def run(self, json_response) -> bool: |
| 146 | + print(json_response) |
106 | 147 |
|
107 |
| - print(json_response) |
| 148 | + if type(json_response.result) != bool: |
| 149 | + print(json_response.result.channel) |
| 150 | +``` |
108 | 151 |
|
109 |
| - if type(json_response.result) != bool: |
110 |
| - print(json_response.result.channel) |
| 152 | +## Object that you can use in a synchrone mode |
| 153 | +```python |
| 154 | + from unrealircd_rpc_py.Loader import Loader |
| 155 | + |
| 156 | + # Initialize your connexion to unrealircd using the unixsocket |
| 157 | + rpc = Loader( |
| 158 | + req_method='unixsocket', |
| 159 | + path_to_socket_file='/path/to/unrealircd/data/rpc.socket' |
| 160 | + ) |
111 | 161 |
|
| 162 | + Channel = rpc.Channel |
| 163 | + Name_ban = rpc.Name_ban |
| 164 | + Server_ban_exception = rpc.Server_ban_exception |
| 165 | + Server_ban = rpc.Server_ban |
| 166 | + Spamfilter = rpc.Spamfilter |
| 167 | + Stats = rpc.Stats |
| 168 | + User = rpc.User |
| 169 | + Whowas = rpc.Whowas |
112 | 170 |
|
| 171 | +``` |
0 commit comments