コード例 #1
0
ファイル: example.py プロジェクト: SMFOSS/irc
from irc import Dispatcher, IRCBot


class GreetingDispatcher(Dispatcher):
    def greet(self, sender, message, channel, is_ping, reply):
        if is_ping or channel is None:
            reply('Hi, %s' % sender)
    
    def get_patterns(self):
        return (
            ('^hello', self.greet),
        )


host = 'irc.freenode.net'
port = 6667
nick = 'greeterbot'

greeter = IRCBot(host, port, nick, ['#lawrence-botwars'], [GreetingDispatcher])
greeter.run_forever()
コード例 #2
0
ファイル: ascii.py プロジェクト: SMFOSS/irc
    
    def display(self, sender, message, channel, is_ping, reply):
        if is_ping:
            result = self.fetch_result(message)
            if result:
                self.display_incrementally(reply, result)
    
    def display_incrementally(self, reply, result):
        i = 0
        for line in result.splitlines():
            if line.strip():
                i += 1
                reply(line)
                if i % 3 == 0:
                    time.sleep(.75)
                if i > 15:
                    return
    
    def get_patterns(self):
        return (
            ('^\S+', self.display),
        )


host = 'irc.freenode.net'
port = 6667
nick = 'picasso_bot'

ascii = IRCBot(host, port, nick, ['#lawrence-botwars'], [AsciiArtDispatcher])
ascii.run_forever()
コード例 #3
0
 def __init__(self, connexion, dispatcher):
     self.dispatcher = dispatcher;
     IRCBot.__init__(self,connexion)
コード例 #4
0
ファイル: quote.py プロジェクト: SMFOSS/irc
        no_html = re.sub('<[^\>]+>', '', ghetto_parsed)
        no_charrefs = re.sub('&[^\;]+;', '', no_html)
        return chap, no_charrefs
    
    def display(self, sender, message, channel, is_ping, reply):
        if is_ping:
            result = self.fetch_result(message)
            if result:
                reply('%s: %s' % (result[0], result[1]))
        else:
            self.last_message = message
    
    def contextualize(self, sender, message, channel, is_ping, reply):
        result = self.fetch_result(self.last_message)
        if result:
            reply('%s: %s' % (result[0], result[1]))
    
    def get_patterns(self):
        return (
            ('^contextualize', self.contextualize),
            ('', self.display),
        )


host = 'irc.freenode.net'
port = 6667
nick = 'quote_bot'

quote = IRCBot(host, port, nick, ['#lawrence-botwars'], [QuoteDispatcher])
quote.run_forever()