class Default(EventPlugin): """Fetch the titles of URLs mentioned in normal messages or actions. Requires `Little Brother`__. __ https://github.com/kxz/littlebrother :charlie: http://www.example.com/ is an example site :bot: [www.example.com] Example Domain :alice: http://www.example.org/ and http://www.example.net/ too :bot: [www.example.org] Example Domain :bot: [www.example.net] Example Domain """ def __init__(self): self.fetcher = TitleFetcher() self.fetcher.agent = IdentifyingAgent(self.fetcher.agent) def on_privmsg(self, msg): fetches = [] for iri in extract_iris(msg.content.decode(msg.encoding, 'replace')): self.log.debug( 'Saw URL {iri} from {msg.actor} in venue {msg.venue}', iri=iri.encode('utf-8'), msg=msg) fetches.append(self.fetcher.fetch_title( iri, hostname_tag=True, friendly_errors=True)) finished = DeferredList(fetches) finished.addCallback(self.send_replies, msg) return finished on_action = on_privmsg def send_replies(self, results, msg): for success, value in results: if success: msg.connection.reply(value, msg) else: self.log.failure( 'Unhandled error during URL title extraction', failure=value)
def __init__(self): self.fetcher = TitleFetcher() self.fetcher.agent = IdentifyingAgent(self.fetcher.agent)