Menu

Ircutils

nanotube

The ircutils.py file in supybot src dir contains a number of convenience functions useful in your plugin development.

Most plugins access it with the following import:

import supybot.ircutils as ircutils

ircutils.isChannel()

isChannel(s, chantypes='#&+!', channellen=50)

Checks if s is a valid channel. chantypes specifies valid channel first characters, and channellen specifies the maximum allowed length of channel name.

There's a higher-level function irc.isChannel(), which calls ircutils.isChannel() and passes it appropriate values for chantypes and channellen, based on network properties. That one is probably better to use in your plugin code, unless you have a good reason to do otherwise.

Example:

ircutils.isChannel('#somechannel') # returns true
ircutils.isChannel('somechannel') # returns false

See also: irc.isChannel().

ircutils.isNick()

isNick(s, strictRfc=True, nicklen=None)

Checks if s is a valid irc nick. If strictRfc is true, it checks according to the rules set out in the IRC RFC 2812. Otherwise, just makes sure it contains no spaces and exclamation points, and is not a channel name (see ircutils.isChannel()). nicklen is maximum allowed nick length.

There's a higher-level function irc.isNick(), which calls ircutils.isNick() and passes it appropriate values for strictRfc and nicklen, based on bot configuration and network properties. That one is probably better to use in your plugin code, unless you have a good reason to do otherwise.

Example:

ircutils.isNick('someguy') # returns true
ircutils.isNick('bla$foo') # returns false, $ is not a valid char for nicks

See also: ircutils.isChannel(), irc.isNick().


Related

Wiki: Supybot_Resources