Ejemplo n.º 1
0
nicks = make_storage('nicks.json', 'nickmark')
# Initializes a list.
if not nicks.known:
    nicks.known = []

from easyirc.const import JOIN # You can use 'JOIN' in simple way.
from easyirc import util


# Message hook of JOIN message
# We will say 'hello' to new nick for this bot.
# About number of params of each message, refer to RFC.
@client.events.hookmsg(JOIN)
def on_join(connection, sender, channel):
    ident = util.parseid(sender) # 'util' has parsers of irc text.
    nick = ident.nick # Got a nick now!
    if not nick in nicks.known:
        # You can use irc protocols-wrapper for connection.
        # See easyirc.command.protocol
        connection.privmsg(channel, u'Hello, new user! ' + nick)
        nicks.known.append(nick)
        nicks._commit() # save to storage


# Client starts connection.
client.start()

# Enable interactive command mode (optional)
client.interactive()
client.quit(u'Keyboard Interuppt')
Ejemplo n.º 2
0
    context.reply('host:' + context.ident.host)


@pevent.hook('msgtype')
def on_msgtype(context, message=None):
    # 'msgtype' is type of sent message. Usually 'PRIVMSG' or 'NOTICE'
    context.reply('msgtype:' + context.msgtype)


@pevent.hook('target')
def on_target(context, message=None):
    # 'target' is the target to expected to reply. Channel or user.
    context.reply('target:' + context.target)


@pevent.hook('reply2')
def on_reply2(context, message=None):
    # Actually, reply is a shortcut of components of context.
    context.connection.sendl(context.msgtype, context.target,
                             'Reply by msgtype')
    context.connection.privmsg(context.target, 'Reply by privmsg')
    context.connection.notice(context.target, 'Reply by notice')


# Client starts connection.
client.start()

# Enable interactive command mode (optional)
client.interactive()
client.quit(u'Keyboard Interuppt')