Exemplo n.º 1
0
def init(conf):
    setcache('__all__', 'echo', utils.as_list(conf['echo_channels']))
    setcache('__all__', 'msg', conf['echo_msg'])
    r = praw.Reddit(conf["praw_bot"], user_agent=conf['ua'])
    for subname in utils.as_list(conf['subs']):
        sub = r.subreddit(subname)
        setcache(subname, 'sub', sub)
        try:
            setcache(subname, 'latest', get_new(sub, limit=1).next())
        except StopIteration:
            setcache(subname, 'latest', None)
Exemplo n.º 2
0
	def connect_twitter(self):
		for config_key, config_value in self.config.items():
			if config_value and str(config_key).endswith('.account'):
				screen_name = config_value
				details = self.twitter_api.users.show(screen_name=screen_name)
				self.twitter_ids[details["id_str"]] = screen_name

				self.twitter_channels[screen_name.lower()] = self.tweet_channels
				config_id = config_key[:-8]
				if self.config.get(config_id + '.channels'):
					self.twitter_channels[screen_name.lower()] = as_list(self.config.get(config_id+'.channels'))
				self.twitter_webhooks[screen_name.lower()] = self.config.get(config_id+'.webhook')
				self.twitter_filters[screen_name.lower()] = as_list(self.config.get(config_id+'.filters'))

		threading.Thread(target=self.receive_stream).start()
Exemplo n.º 3
0
 def __init__(self, bot):
     self.bot = bot
     self._r = praw.Reddit(bot.config['reddit']['praw_bot'],
                           user_agent=bot.config['reddit']['ua'])
     self.default_sub = self._r.subreddit(utils.as_list(
         bot.config['reddit']['subs'])[0])
     init(bot.config['reddit'])
Exemplo n.º 4
0
Arquivo: core.py Projeto: Mika64/irc3
 def autojoin(self, **kw):
     """autojoin at the end of MOTD"""
     self.bot.config['nick'] = kw['me']
     self.bot.recompile()
     channels = utils.as_list(self.bot.config.get('autojoins', []))
     for channel in channels:
         channel = utils.as_channel(channel)
         self.bot.log.info('Trying to join %s', channel)
         self.bot.join(channel)
Exemplo n.º 5
0
Arquivo: core.py Projeto: jpcw/irc3
 def autojoin(self, **kw):
     """autojoin at the end of MOTD"""
     self.bot.config['nick'] = kw['me']
     self.bot.recompile()
     channels = utils.as_list(self.bot.config.get('autojoins', []))
     for channel in channels:
         channel = utils.as_channel(channel)
         self.bot.log.info('Trying to join %s', channel)
         self.bot.join(channel)
Exemplo n.º 6
0
 def __init__(self, bot):
     self.bot = bot
     self.channels = utils.as_list(self.bot.config.get('autojoins', []))
     self.delay = self.bot.config.get('autojoin_delay', 0)
     self.handles = {}
     self.timeout = 240
     self.joined = set()
     self.delayed_join = None
     if not isinstance(self.delay, (int, float)):  # pragma: no cover
         self.bot.log.error('Wrong autojoin_delay value: %r', self.delay)
         self.delay = 0
Exemplo n.º 7
0
    def __init__(self, bot):
        self.bot = bot
        self.config = bot.config.get(__name__, {})

        handler = irc3.utils.maybedotted(
            self.config.get('handler', file_handler))
        self.bot.log.debug('%s Handler: %s %s', self.__module__,
                           handler.__module__, handler.__name__)
        self.handler = handler(bot)

        self.message_filters = []
        #self.bot.log.info('Filters:')
        for message_filter in as_list(self.config.get('filters')):
            self.message_filters.append(message_filter)
Exemplo n.º 8
0
	def __init__(self, bot):
		self.bot = bot
		self.twitter_stream = self.bot.get_social_connection(id='twitter_stream')
		self.twitter_api = self.bot.get_social_connection(id='twitter')

		self.twitter_channels = {}
		self.twitter_ids = {}
		self.twitter_webhooks = {}
		self.twitter_filters = {}
		self.twitter_connected = False

		self.config = self.bot.config.get(__name__, {})
		self.tweet_channels = as_list(self.config.get('tweet_channels'))
		self.tweet_format = self.config.get('tweet_format', '@{screen_name}: {text}')
		self.webhook_username = self.config.get('webhook_username')
		self.webhook_avatar = self.config.get('webhook_avatar')
Exemplo n.º 9
0
    def format_action(self, act_type, action, **kwargs):
        config = self.actions[act_type]
        actions = set(as_list(config['actions']))

        if not {action, 'all'} & actions:
            return

        values = {k[8:]: v
                  for k, v in config.items()
                  if k.startswith('default_')}

        values.update({k: v
                       for k, v in kwargs.items()
                       if k not in values or v})

        fmt = config.get(action, config.get('default', ''))
        if not fmt:
            raise ValueError('Undefined action: %s' % action)
        if config.get('prefix'):
            fmt = config['prefix'] + ' ' + fmt

        return fmt.format(**values)
Exemplo n.º 10
0
    def __init__(self, bot):
        self.bot = bot
        self.reader = None

        self.log = logging.getLogger('irc3.%s' % __name__)
        self.log_parser = LogParser(self.log)

        self.config = dict(DEFAULT_CONFIG)
        self.config.update(bot.config.get(self.__class__.__module__, {}))
        self.log.debug('config: %r', self.config)

        autojoins = self.bot.config.get('autojoins')
        self.channels = [
            as_channel(c)
            for c in as_list(
                self.config.get('channels', autojoins)
            )
        ]

        self.actions = {}

        for act_type in DEFAULT_FORWARDING:
            config = dict(DEFAULT_FORWARDING[act_type])
            config.update(self.bot.config.get(
                '%s.%s-forwarding' % (self.__class__.__module__, act_type)))
            self.actions[act_type] = config

        self.log.debug('actions: %r', self.actions)

        # on_quit needs to be executed before the userlist plugin sees
        # the QUIT event so that we can check which channels the user
        # was in
        self.bot.attach_events(
            irc3.event(irc3.rfc.QUIT, self.on_quit),
            insert=True
        )
        self.log.info('FactoIRC %s loaded.' % __version__)
Exemplo n.º 11
0
 def __init__(self, bot):
     self.bot = bot
     cmds = utils.as_list(self.bot.config.get('autocommands', []))
     self.commands = [self.parse_command(cmd) for cmd in cmds]
Exemplo n.º 12
0
 def __init__(self, bot):
     self.bot = bot
     self.channels = utils.as_list(self.bot.config.get('autojoins', []))
     self.handles = {}
     self.timeout = 240
Exemplo n.º 13
0
 def __init__(self, bot):
     self.bot = bot
     cmds = utils.as_list(self.bot.config.get('autocommands', []))
     self.commands = [self.parse_command(cmd) for cmd in cmds]
Exemplo n.º 14
0
 def __init__(self, bot):
     self.bot = bot
     self.channels = utils.as_list(self.bot.config.get('autojoins', []))
     self.handles = {}
     self.timeout = 240