No project description provided
Project description
ircevents
usage
example code
import ircstates, irctokens, ircevents, socket
# Connection settings
NICK = "nickname"
HOST = "127.0.0.1"
POST = 6667
server = ircstates.Server("freenode")
sock = socket.socket()
events = ircevents.Engine(sock)
sock.connect((HOST, POST))
def _send(text):
line = irctokens.tokenise(text)
server.send(line)
def _sent(source, state):
if not state.get("init"):
state.set("init", True)
_send(f"USER {NICK} 0 * :{NICK}")
_send(f"NICK {NICK}")
while server.pending():
send_lines = server.sent(source.send(server.pending()))
for line in send_lines:
print(f"< {line.format()}")
@events.when(always_run=True)
def _display(line, state):
print(f"> {line.format()}")
@events.when(command="PING")
def _ping(line, state)
_send(f"PONG {line.params[0]}")
@events.when(command="001")
def _join(line, state):
channels = state.get("channels", list())
for channel in channels:
if channel not in server.channels:
_send(f"JOIN {channel}")
state.set("joined_channels", True)
# Load ircstates as a state mutation
events.use("ircstates", lambda raw: server.recv(raw))
# Events will be received using 1024 bytes from socket
events.recv_with(lambda source, state: source.recv(1024))
# Before processing new data, send queued data to server
events.pre_process(_sent)
# Define what channels to join
events.ns_set("ircstates", "channels", ["#bots", "#test"])
# Run event loop
events.run()
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
ircevents-0.3.0.tar.gz
(5.8 kB
view details)
Built Distribution
File details
Details for the file ircevents-0.3.0.tar.gz
.
File metadata
- Download URL: ircevents-0.3.0.tar.gz
- Upload date:
- Size: 5.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 50e2a9c1209f4a9f2007e99f3b20870ca64409e863e3056abe18162a6777e611 |
|
MD5 | b078d12cd1c582329bbc6e7789c3b34c |
|
BLAKE2b-256 | 1ec4e943c1e660d07d3adcbf20159590f41af9e68446bcd4fb14e7f0f472183b |
File details
Details for the file ircevents-0.3.0-py3-none-any.whl
.
File metadata
- Download URL: ircevents-0.3.0-py3-none-any.whl
- Upload date:
- Size: 7.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 26a8088e1fc2ab87e939db5893d8c0a0a02a8b18a4716aef71b3552da773ce75 |
|
MD5 | 1fa643e7adab00e08c4bd6fb3d97a565 |
|
BLAKE2b-256 | 877f8d993fa2183edf1de43a5cb6a23cfefa81ce3ba1af519a5084ad5efd4631 |