irc3.dec
decorators¶
bot event¶
-
class
irc3.dec.
event
(regexp, callback=None, iotype='in', venusian_category='irc3.rfc1459')[source]¶ register a method or function an irc event callback:
>>> @event('^:\S+ 353 [^&#]+(?P<channel>\S+) :(?P<nicknames>.*)') ... def on_names(bot, channel=None, nicknames=None): ... '''this will catch nickname when you enter a channel''' ... print(channel, nicknames.split(':'))
The callback can be either a function or a plugin method
If you specify the iotype parameter to “out” then the event will be triggered when the regexp match something sent by the bot.
For example this event will repeat private messages sent by the bot to the #irc3 channel:
>>> @event(r'PRIVMSG (?P<target>[^#]+) :(?P<data>.*)', iotype='out') ... def msg3(bot, target=None, data=None): ... bot.privmsg('#irc3', ... '<{0}> {1}: {2}'.format(bot.nick, target, data))
bot extend¶
-
irc3.dec.
extend
(func)[source]¶ Allow to extend a bot:
Create a module with some useful routine:
# -*- coding: utf-8 -*- import irc3 @irc3.extend def my_usefull_function(bot, *args): return 'my_usefull_function(*%s)' % (args,) @irc3.plugin class MyPlugin(object): def __init__(self, bot): self.bot = bot @irc3.extend def my_usefull_method(self, *args): return 'my_usefull_method(*%s)' % (args,)
Now you can use those routine in your bot:
>>> bot = IrcBot() >>> bot.include('myextends') >>> print(bot.my_usefull_function(1)) my_usefull_function(*(1,)) >>> print(bot.my_usefull_method(2)) my_usefull_method(*(2,))