### Typical IRC Client Usage Source: https://github.com/luk3yx/miniirc/blob/master/README.md Example of how to initialize and configure an IRC client with common parameters. This snippet demonstrates setting the server, port, nickname, and channels to join. ```python irc = miniirc.IRC('irc.example.com', 6697, 'my-bot', ['#my-channel'], ns_identity=('my-bot', 'hunter2'), executor=concurrent.futures.ThreadPoolExecutor()) ``` -------------------------------- ### notice(target, *msg, tags=None) Source: https://github.com/luk3yx/miniirc/blob/master/README.md Sends a NOTICE to a target. The target should not contain spaces or start with a colon. ```APIDOC ## notice(target, *msg, tags=None) ### Description Sends a `NOTICE` to `target`. `target` should not contain spaces or start with a colon. The `tags` parameter optionally allows you to add a `dict` with IRCv3 client tags. ### Method (Implicitly called by the IRC client instance) ### Parameters - **target** (string) - The recipient of the notice. - **msg** (string) - The notice content. Can be multiple arguments which will be joined by spaces. - **tags** (dict) - Optional - IRCv3 client tags. ``` -------------------------------- ### Basic MiniIRC Handler Example Source: https://github.com/luk3yx/miniirc/blob/master/README.md This snippet shows the fundamental structure of a MiniIRC handler using the @miniirc.Handler decorator. It's recommended to set 'colon=False' for modern parsing. ```python import miniirc @miniirc.Handler(*events, colon=False) def handler(irc, hostmask, args): # irc: An 'IRC' object. # hostmask: A 'hostmask' object. # args: A list containing the arguments sent to the command. Everything # following the first `:` in the command is put into one item # (args[-1]). If "colon" is "False", the leading ":" (if any) # is automatically removed. To prevent your code from horribly # breaking, always set it to False unless you know what you are # doing. pass ``` -------------------------------- ### Handling Multiple Events with CmdHandler Source: https://github.com/luk3yx/miniirc/blob/master/README.md Use `@miniirc.CmdHandler` to process events and receive the command name. The `colon=False` argument means the message content does not start after a colon. ```python import miniirc # Not required, however this makes sure miniirc isn't outdated. assert miniirc.ver >= (1,8,2) @miniirc.CmdHandler('PRIVMSG', 'NOTICE', colon=False) def cmdhandler(irc, command, hostmask, args): print(hostmask[0], 'sent a', command, 'to', args[0], 'with content', args[1]) # nickname sent a PRIVMSG to #channel with content Hello, world! ``` -------------------------------- ### MiniIRC Handler with IRCv3 Tags Source: https://github.com/luk3yx/miniirc/blob/master/README.md Example of a handler configured to support IRCv3 message tags. The 'ircv3=True' argument adds a 'tags' dictionary parameter to the handler function. ```python import miniirc @miniirc.Handler(*events, colon=False, ircv3=True) def handler(irc, hostmask, tags, args): pass ``` -------------------------------- ### msg(target, *msg, tags=None) Source: https://github.com/luk3yx/miniirc/blob/master/README.md Sends a PRIVMSG to a target. The target should not contain spaces or start with a colon. ```APIDOC ## msg(target, *msg, tags=None) ### Description Sends a `PRIVMSG` to `target`. `target` should not contain spaces or start with a colon. The `tags` parameter optionally allows you to add a `dict` with IRCv3 client tags. ### Method (Implicitly called by the IRC client instance) ### Parameters - **target** (string) - The recipient of the message. - **msg** (string) - The message content. Can be multiple arguments which will be joined by spaces. - **tags** (dict) - Optional - IRCv3 client tags. ``` -------------------------------- ### Handling Multiple Events with Handler Source: https://github.com/luk3yx/miniirc/blob/master/README.md Use `@miniirc.Handler` to process specific events like PRIVMSG or NOTICE. The `colon=True` argument indicates that the message content starts after the colon. ```python import miniirc # Not required, however this makes sure miniirc isn't outdated. assert miniirc.ver >= (1,8,2) @miniirc.Handler('PRIVMSG', 'NOTICE', colon=True) def handler(irc, hostmask, args): print(hostmask[0], 'sent a message to', args[0], 'with content', args[1]) # nickname sent a message to #channel with content :Hello, world! ``` -------------------------------- ### Handling IRCv3 message tags Source: https://github.com/luk3yx/miniirc/blob/master/CHANGELOG.md Details the addition of support for sending and processing IRCv3 message tags, including handling tags that do not start with '+'. ```python # Example usage for message tags would go here, but is not provided in the source. ``` -------------------------------- ### Handling IRCv3 Capabilities Before Connection Source: https://github.com/luk3yx/miniirc/blob/master/README.md Shows how to set up a handler for IRCv3 capabilities negotiation before the main connection is established. Use 'force=True' for 'irc.quote()' calls and do not use the 'colon' argument. ```python import miniirc @miniirc.Handler('IRCv3 my-cap-name') def handler(irc, hostmask, args): # Process the capability here # IRCv3.2 capabilities: # args = ['my-cap-name', 'IRCv3.2-parameters'] # IRCv3.1 capabilities: # args = ['my-cap-name'] # Remove the capability from the processing list. irc.finish_negotiation(args[0]) # This can also be 'my-cap-name'. ``` -------------------------------- ### connect() Source: https://github.com/luk3yx/miniirc/blob/master/README.md Connects to the IRC server if not already connected. ```APIDOC ## connect() ### Description Connects to the IRC server if not already connected. ### Method (Implicitly called by the IRC client instance) ### Parameters None ``` -------------------------------- ### IRC Client Initialization Parameters Source: https://github.com/luk3yx/miniirc/blob/master/README.md Defines the parameters available for initializing an IRC client instance. Note that ip, port, and nick are positional arguments. ```python irc = miniirc.IRC(ip, port, nick, channels=None, *, ssl=None, ident=None, realname=None, persist=True, debug=False, ns_identity=None, auto_connect=True, ircv3_caps=set(), quit_message='I grew sick and died.', ping_interval=60, ping_timeout=None, verify_ssl=True, server_password=None, executor=None) ``` -------------------------------- ### send(*msg, force=False, tags=None) Source: https://github.com/luk3yx/miniirc/blob/master/README.md Sends a command to the IRC server, treating each argument as a parameter. Recommended over quote() for most cases. ```APIDOC ## send(*msg, force=False, tags=None) ### Description Sends a command to the IRC server, treating every positional argument as a parameter. The usage of this is recommended over `irc.quote()` unless you know what you are doing. If arguments passed to `irc.send()` contain spaces, they are replaced with U+00A0 (a non-breaking space). ### Method (Implicitly called by the IRC client instance) ### Parameters - **msg** (string) - The command and its parameters. - **force** (boolean) - Optional - If True, sends the message even if disconnected. Throws an error if miniirc is completely disconnected and force is False. - **tags** (dict) - Optional - IRCv3 client tags. ``` -------------------------------- ### Passing ns_identity as a tuple or list Source: https://github.com/luk3yx/miniirc/blob/master/CHANGELOG.md Shows how the `ns_identity` keyword argument can accept a tuple or list for username and password, accommodating spaces. ```python ('username', 'password with spaces') ``` -------------------------------- ### me(target, *msg, tags=None) Source: https://github.com/luk3yx/miniirc/blob/master/README.md Sends a /me (CTCP ACTION) to a target. ```APIDOC ## me(target, *msg, tags=None) ### Description Sends a `/me` (`CTCP ACTION`) to `target`. ### Method (Implicitly called by the IRC client instance) ### Parameters - **target** (string) - The recipient of the action. - **msg** (string) - The action message. - **tags** (dict) - Optional - IRCv3 client tags. ``` -------------------------------- ### Send PRIVMSG with spaces in channel name Source: https://github.com/luk3yx/miniirc/blob/master/CHANGELOG.md Demonstrates how to send a PRIVMSG to a channel that contains spaces in its name. The library handles the necessary quoting. ```python irc.send('PRIVMSG', '#channel with spaces', 'Test message') ``` ```python irc.quote('PRIVMSG', '#channel\xa0with\xa0spaces', ':Test message') ``` -------------------------------- ### Using irc.current_nick Source: https://github.com/luk3yx/miniirc/blob/master/CHANGELOG.md Introduces `irc.current_nick` as an alternative to `irc.nick` for retrieving the current nickname. Note: it's currently an alias for `irc.nick`. ```python # Example usage for irc.current_nick would go here, but is not provided in the source. ``` -------------------------------- ### Send a message with send Source: https://github.com/luk3yx/miniirc/blob/master/README.md Use `irc.send()` to send a command to the IRC server, treating each argument as a parameter. Arguments with spaces are replaced with non-breaking spaces. ```python irc.send('PRIVMSG', '#channel', 'Hello, world!') ``` ```python irc.send('PRIVMSG', '#channel :Hello,', 'world!') ``` -------------------------------- ### Adding Handlers to a Specific IRC Object Source: https://github.com/luk3yx/miniirc/blob/master/README.md Demonstrates how to create a handler decorator for a specific IRC object instance, useful for class-based bots. Multiple handlers can be added sequentially. ```python add_handler = irc.Handler('PRIVMSG', colon=False) add_handler(handler_1) add_handler(self.instance_handler) ``` -------------------------------- ### Handling multiple events with CmdHandlers Source: https://github.com/luk3yx/miniirc/blob/master/CHANGELOG.md Introduces CmdHandlers for managing multiple events, allowing retrieval of the command associated with an event. ```python # Example usage for CmdHandlers would go here, but is not provided in the source. ``` -------------------------------- ### Allowing channels as a single string Source: https://github.com/luk3yx/miniirc/blob/master/CHANGELOG.md Introduces the ability to pass a single channel name as a string to the `channels` argument, in addition to a comma-delimited string. ```python # Example usage for single channel string would go here, but is not provided in the source. ``` -------------------------------- ### Changing Message Parsers Source: https://github.com/luk3yx/miniirc/blob/master/README.md Demonstrates how to change the message parser of an IRC connection dynamically. Use `auto_connect=False` to change parsers before connecting. ```python irc = miniirc.IRC(..., auto_connect=False) irc.change_parser(my_message_parser) irc.connect() ``` -------------------------------- ### quote(*msg, force=False, tags=None) Source: https://github.com/luk3yx/miniirc/blob/master/README.md Sends a raw message to IRC. Use force=True to send while disconnected. Newlines in messages will be stripped. ```APIDOC ## quote(*msg, force=False, tags=None) ### Description Sends a raw message to IRC, use `force=True` to send while disconnected. Do not send multiple commands in one `irc.quote()`, as the newlines will be stripped and it will be sent as one command. The `tags` parameter optionally allows you to add a `dict` with IRCv3 client tags (all starting in `+`), and will not be sent to IRC servers that do not support client tags. ### Method (Implicitly called by the IRC client instance) ### Parameters - **msg** (string) - The raw message to send. All arguments will be joined by spaces. - **force** (boolean) - Optional - If True, sends the message even if disconnected. Throws an error if miniirc is completely disconnected and force is False. - **tags** (dict) - Optional - IRCv3 client tags. ``` -------------------------------- ### Configuring ping interval Source: https://github.com/luk3yx/miniirc/blob/master/CHANGELOG.md Allows modification of the server ping interval using the `ping_interval` keyword argument during connection. ```python # Example usage for ping_interval would go here, but is not provided in the source. ``` -------------------------------- ### Send a raw message with quote Source: https://github.com/luk3yx/miniirc/blob/master/README.md Use `irc.quote()` to send a raw message to IRC. All arguments are joined with spaces. Use `force=True` to send while disconnected. Do not send multiple commands in one call. ```python irc.quote('PRIVMSG', '#channel :Hello,', 'world!') ``` -------------------------------- ### ctcp(target, *msg, reply=False, tags=None) Source: https://github.com/luk3yx/miniirc/blob/master/README.md Sends a CTCP request or reply to a target. ```APIDOC ## ctcp(target, *msg, reply=False, tags=None) ### Description Sends a `CTCP` request or reply to `target`. ### Method (Implicitly called by the IRC client instance) ### Parameters - **target** (string) - The recipient of the CTCP message. - **msg** (string) - The CTCP message content. - **reply** (boolean) - Optional - If True, sends as a CTCP reply. - **tags** (dict) - Optional - IRCv3 client tags. ``` -------------------------------- ### Automatic TLS/SSL for port 6697 Source: https://github.com/luk3yx/miniirc/blob/master/CHANGELOG.md Automatically enables TLS/SSL when the specified port is the string '6697'. ```python # Example usage for automatic TLS/SSL would go here, but is not provided in the source. ``` -------------------------------- ### Custom Message Parser Source: https://github.com/luk3yx/miniirc/blob/master/README.md Allows '~' as an IRCv3 tag prefix character by modifying the message before parsing. This is useful for custom tag handling. ```python import miniirc def my_message_parser(msg): if msg.startswith('~'): msg = '@' + msg[1:] return miniirc.ircv3_message_parser(msg) ``` -------------------------------- ### Handler(...) Source: https://github.com/luk3yx/miniirc/blob/master/README.md Represents an event handler. See Handlers section for more information. ```APIDOC ## Handler(...) ### Description An event handler, see [Handlers](#handlers) for more info. ### Method (Constructor for Handler class) ### Parameters (Details depend on the Handlers section.) ``` -------------------------------- ### Handler and CmdHandler 'colon' argument Source: https://github.com/luk3yx/miniirc/blob/master/CHANGELOG.md Explains the `colon` keyword argument for `Handler` and `CmdHandler`. When `False`, the leading colon is removed from `args[-1]`. This argument will default to `False` in v2.0.0. ```python # Example usage for the 'colon' argument would go here, but is not provided in the source. ``` -------------------------------- ### wait_until_disconnected() Source: https://github.com/luk3yx/miniirc/blob/master/README.md Waits until the IRC server is disconnected and automatic reconnecting is turned off. ```APIDOC ## wait_until_disconnected() ### Description Waits until the IRC server is disconnected and automatic reconnecting is turned off. ### Method (Implicitly called by the IRC client instance) ### Parameters None ``` -------------------------------- ### debug(...) Source: https://github.com/luk3yx/miniirc/blob/master/README.md Debug function that calls print(...) if debug mode is on. ```APIDOC ## debug(...) ### Description Debug, calls `print(...)` if debug mode is on. ### Method (Implicitly called by the IRC client instance) ### Parameters - **...** - Arguments to be printed if debug mode is enabled. ``` -------------------------------- ### Custom debug logging function Source: https://github.com/luk3yx/miniirc/blob/master/CHANGELOG.md Enables custom debug logging by passing a function to the `debug` keyword argument, which will be called for each `irc.debug()` line. ```python # Example usage for custom debug function would go here, but is not provided in the source. ``` -------------------------------- ### disconnect(msg=..., *, auto_reconnect=False) Source: https://github.com/luk3yx/miniirc/blob/master/README.md Disconnects from the IRC server. The auto_reconnect parameter can be set to True to attempt reconnection. ```APIDOC ## disconnect(msg=..., *, auto_reconnect=False) ### Description Disconnects from the IRC server. The `auto_reconnect` parameter will be overridden by `self.persist` if set to `True`. ### Method (Implicitly called by the IRC client instance) ### Parameters - **msg** (string) - Optional - The message to send upon disconnection. - **auto_reconnect** (boolean) - Optional - If True, attempts to reconnect automatically. This is overridden by `self.persist` if it's True. ``` -------------------------------- ### change_parser(parser=...) Source: https://github.com/luk3yx/miniirc/blob/master/README.md Changes the message parser. See the message parser section for documentation. ```APIDOC ## change_parser(parser=...) ### Description Changes the message parser. See the message parser section for documentation. ### Method (Implicitly called by the IRC client instance) ### Parameters - **parser** - The new parser to use. (Type and details depend on the message parser section.) ``` -------------------------------- ### Preventing premature shutdown Source: https://github.com/luk3yx/miniirc/blob/master/README.md Ensures the Python script does not exit while the IRC client is still connected, which is important for maintaining thread pool integrity in Python 3.9+. ```python irc.wait_until_disconnected() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.