<commit_before>#!/usr/bin/env python

from circuits import Component, Debugger
from circuits.net.sockets import TCPClient, Connect
from circuits.net.protocols.irc import IRC, PRIVMSG, USER, NICK, JOIN

from circuits.net.protocols.irc import ERR_NICKNAMEINUSE
from circuits.net.protocols.irc import RPL_ENDOFMOTD, ERR_NOMOTD

class Bot(Component):

    def __init__(self, host, port=6667):
        super(Bot, self).__init__()
        self += TCPClient() + IRC()
        self.push(Connect(host, port))

    def connected(self, host, port):
        self.push(USER("circuits", host, host, "Test circuits IRC Bot"))
        self.push(NICK("circuits"))

    def numeric(self, source, target, numeric, args, message):
        if numeric == ERR_NICKNAMEINUSE:
            self.push(NICK("%s_" % args))
        if numeric in (RPL_ENDOFMOTD, ERR_NOMOTD):
            self.push(JOIN("#circuits"))

    def message(self, source, target, message):
        self.push(PRIVMSG(source[0], message))

bot = Bot("irc.freenode.net") + Debugger()
bot.run()<commit_msg>examples/ircbot.py: Make this IRC Bot example respect circuits' channel settings (not related to IRC channels)<commit_after>#!/usr/bin/env python

from circuits import Component, Debugger
from circuits.net.sockets import TCPClient, Connect
from circuits.net.protocols.irc import IRC, PRIVMSG, USER, NICK, JOIN

from circuits.net.protocols.irc import ERR_NICKNAMEINUSE
from circuits.net.protocols.irc import RPL_ENDOFMOTD, ERR_NOMOTD

class Bot(Component):

    channel = "ircbot"

    def __init__(self, host, port=6667, channel=channel):
        super(Bot, self).__init__()
        self += TCPClient(channel=self.channel) + IRC(channel=self.channel)
        self.push(Connect(host, port))

    def connected(self, host, port):
        self.push(USER("circuits", host, host, "Test circuits IRC Bot"))
        self.push(NICK("circuits"))

    def numeric(self, source, target, numeric, args, message):
        if numeric == ERR_NICKNAMEINUSE:
            self.push(NICK("%s_" % args))
        if numeric in (RPL_ENDOFMOTD, ERR_NOMOTD):
            self.push(JOIN("#circuits"))

    def message(self, source, target, message):
        self.push(PRIVMSG(source[0], message))

bot = Bot("irc.freenode.net") + Debugger()
bot.run()
{'fraction_non_alphanumeric': 0.12720070422535212, 'fraction_numerical': 0.0044014084507042256, 'mean_word_length': 3.7752100840336134, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5959460', 'n_tokens_mistral': 785, 'n_tokens_neox': 720, 'n_words': 182}