예제 #1
0
    def __init__(self, config):
        self.config = config

        self.bitstamp = BitstampWatcher(
            triggervolume=self.config['volume_alert_threshold'])
        self.channels = list()
        self.broadcast_to_channels = list()
        #self.broadcast_to_users = list()
        self.responder = botresponder.BotResponder(self.config, self.bitstamp)
예제 #2
0
파일: bot.py 프로젝트: m4q4/twobitbot
    def __init__(self, config):
        self.config = config

        self.bitstamp = BitstampWatcher(triggervolume=self.config['volume_alert_threshold'])
        self.channels = list()
        self.broadcast_to_channels = list()
        #self.broadcast_to_users = list()
        self.responder = botresponder.BotResponder(self.config, self.bitstamp)
예제 #3
0
class TerminalBot(basic.LineReceiver):
    delimiter = '\n'

    def __init__(self, config):
        self.config = config
        self.watcher = BitstampWatcher()
        self.watcher.add_alert_callback(self.out)
        self.responder = BotResponder(self.config, self.watcher)

    def connectionMade(self):
        print("Welcome! This should work if you aren't using Windows.")

    def lineReceived(self, line):
        response = self.responder.dispatch(line)
        if response:
            self.out(response)

    def out(self, line):
        self.sendLine(line)
예제 #4
0
파일: bot.py 프로젝트: m4q4/twobitbot
class TwoBitBotIRC(irc.IRCClient):
    def __init__(self, config):
        self.config = config

        self.bitstamp = BitstampWatcher(triggervolume=self.config['volume_alert_threshold'])
        self.channels = list()
        self.broadcast_to_channels = list()
        #self.broadcast_to_users = list()
        self.responder = botresponder.BotResponder(self.config, self.bitstamp)

    # todo this overwrites ircclient var
    @property
    def nickname(self):
        return self.config['botname']
    #nickname = property(_get_nickname)

    def signedOn(self):
        """Called upon connecting to the server successfully."""
        if 'freenode' in self.config['server'] and len(self.config['password']) > 0:
            self.msg('nickserv', 'identify %s' % (self.config['password']))
        try:
            for chan in self.config['channels']:
                self.join(chan)
        except TypeError:
            log.critical("Problem joining channels sepecified in config file", exc_info=True)

        log.info("Signed on as %s." % (self.nickname))
        self.bitstamp.add_alert_callback(self.broadcast_msg)
        # not really necessary
        self.responder.set_name(self.nickname)

    def joined(self, channel):
        """Called when we finish joining a channel."""
        log.info("Joined %s." % (channel))
        self.channels.append(channel)
        self.broadcast_to_channels.append(channel)

    @defer.inlineCallbacks
    def privmsg(self, user, channel, msg):
        """Called when a message is seen in PM or a channel."""
        userhost = user.rsplit('@', 1)[1]
        user = user.split('!', 1)[0]

        if channel == self.nickname:
            # message directed just to us
            respond_to = user
            in_str = 'privmsg'
        else:
            # message was sent to a channel
            respond_to = channel
            in_str = respond_to

        if self.can_reply(userhost):
            response = yield self.responder.dispatch(msg, user)
            if response:
                log.debug("RESPOND to %s@%s in %s with '%s'" % (user, userhost, in_str, response.encode("utf8")))
                self.msg(respond_to, response.encode("utf8"))
                self.responded_to_user(userhost)

    def broadcast_msg(self, msg):
        """Send msg to all interested parties (per config)."""
        log.debug("BROADCAST to %s: '%s'" % (', '.join(self.broadcast_to_channels), msg.encode("utf8")))
        for ch in self.broadcast_to_channels:
            self.msg(ch, msg.encode("utf8"))
        # send msg to all interested channels/users

    def can_reply(self, userhost):
        """Check if the user has been responded to recently.
        Parameter: userhost
        Return:
            True if user should not be responded to, otherwise False."""

        if userhost in self.config['privileged_users']:
            return True
        elif userhost in self.config['banned_users']:
            return False
        elif self.factory.ratelimiter.is_limited(userhost):
            return False
        else:
            return True

    def responded_to_user(self, userhost):
        """ Track when a user was replied to for ratelimiting.
        Parameter: userhost"""
        self.factory.ratelimiter.user_event_now(userhost)
예제 #5
0
class TwoBitBotIRC(irc.IRCClient):
    def __init__(self, config):
        self.config = config

        self.bitstamp = BitstampWatcher(
            triggervolume=self.config['volume_alert_threshold'])
        self.channels = list()
        self.broadcast_to_channels = list()
        #self.broadcast_to_users = list()
        self.responder = botresponder.BotResponder(self.config, self.bitstamp)

    # todo this overwrites ircclient var
    @property
    def nickname(self):
        return self.config['botname']

    #nickname = property(_get_nickname)

    def signedOn(self):
        """Called upon connecting to the server successfully."""
        if 'freenode' in self.config['server'] and len(
                self.config['password']) > 0:
            self.msg('nickserv', 'identify %s' % (self.config['password']))
        try:
            for chan in self.config['channels']:
                self.join(chan)
        except TypeError:
            log.critical("Problem joining channels sepecified in config file",
                         exc_info=True)

        log.info("Signed on as %s." % (self.nickname))
        self.bitstamp.add_alert_callback(self.broadcast_msg)
        # not really necessary
        self.responder.set_name(self.nickname)

    def joined(self, channel):
        """Called when we finish joining a channel."""
        log.info("Joined %s." % (channel))
        self.channels.append(channel)
        self.broadcast_to_channels.append(channel)

    @defer.inlineCallbacks
    def privmsg(self, user, channel, msg):
        """Called when a message is seen in PM or a channel."""
        userhost = user.rsplit('@', 1)[1]
        user = user.split('!', 1)[0]

        if channel == self.nickname:
            # message directed just to us
            respond_to = user
            in_str = 'privmsg'
        else:
            # message was sent to a channel
            respond_to = channel
            in_str = respond_to

        if self.can_reply(userhost):
            response = yield self.responder.dispatch(msg, user)
            if response:
                log.debug("RESPOND to %s@%s in %s with '%s'" %
                          (user, userhost, in_str, response.encode("utf8")))
                self.msg(respond_to, response.encode("utf8"))
                self.responded_to_user(userhost)

    def broadcast_msg(self, msg):
        """Send msg to all interested parties (per config)."""
        log.debug("BROADCAST to %s: '%s'" %
                  (', '.join(self.broadcast_to_channels), msg.encode("utf8")))
        for ch in self.broadcast_to_channels:
            self.msg(ch, msg.encode("utf8"))
        # send msg to all interested channels/users

    def can_reply(self, userhost):
        """Check if the user has been responded to recently.
        Parameter: userhost
        Return:
            True if user should not be responded to, otherwise False."""

        if userhost in self.config['privileged_users']:
            return True
        elif userhost in self.config['banned_users']:
            return False
        elif self.factory.ratelimiter.is_limited(userhost):
            return False
        else:
            return True

    def responded_to_user(self, userhost):
        """ Track when a user was replied to for ratelimiting.
        Parameter: userhost"""
        self.factory.ratelimiter.user_event_now(userhost)
예제 #6
0
 def __init__(self, config):
     self.config = config
     self.watcher = BitstampWatcher()
     self.watcher.add_alert_callback(self.out)
     self.responder = BotResponder(self.config, self.watcher)