Example #1
0
def _check_feed(bot: DeltaBot, f: sqlite3.Row) -> None:
    fchats = db.get_fchats(f['url'])

    if not fchats:
        db.remove_feed(f['url'])
        return

    bot.logger.debug('Checking feed: %s', f['url'])
    d = feedparser.parse(f['url'], etag=f['etag'], modified=f['modified'])

    bozo_exception = d.get('bozo_exception', '')
    if d.get('bozo') == 1 and not isinstance(bozo_exception,
                                             CharacterEncodingOverride):
        bot.logger.exception(bozo_exception)
        return

    if d.entries and f['latest']:
        d.entries = get_new_entries(d.entries,
                                    tuple(map(int, f['latest'].split())))
    if not d.entries:
        return

    html = format_entries(d.entries[:50])
    replies = Replies(bot, logger=bot.logger)
    for gid in fchats:
        try:
            replies.add(html=html, chat=bot.get_chat(gid))
        except (ValueError, AttributeError):
            db.remove_fchat(gid)
    replies.send_reply_messages()

    latest = get_latest_date(d.entries) or f['latest']
    modified = d.get('modified') or d.get('updated')
    db.update_feed(f['url'], d.get('etag'), modified, latest)
Example #2
0
 def _irc2dc(self, e) -> None:
     nick = e.source.split('!')[0]
     for cnn in self.preactor.puppets.values():
         if cnn.get_nickname() == nick:
             return
     sender = '{}[irc]'.format(nick)
     gid = self.db.get_chat(e.target)
     if not gid:
         self.dbot.logger.warning('Chat not found for room: %s', e.target)
         return
     replies = Replies(self.dbot, logger=self.dbot.logger)
     replies.add(text=' '.join(e.arguments), sender=sender,
                 chat=self.dbot.get_chat(gid))
     replies.send_reply_messages()
Example #3
0
def _send_diffusion(bot: DeltaBot, message: Message, chats: list) -> None:
    log = "diffusion: id={} chat={} sent with text: {!r}"
    text = message.text
    if lib.dc_msg_has_html(message._dc_msg):
        html = from_dc_charpointer(
            lib.dc_get_msg_html(bot.account._dc_context, message.id))
    else:
        html = None
    filename = message.filename
    quote = message.quote
    sender = _get_name(message.get_sender_contact())
    replies = Replies(message, logger=bot.logger)
    for chat in chats:
        replies.add(text=text,
                    html=html,
                    sender=sender,
                    quote=quote,
                    filename=filename,
                    viewtype=message._view_type,
                    chat=chat)
    try:
        replies.send_reply_messages()
    except ValueError as err:
        bot.logger.exception(err)