def update_on_priv_msg(self, data): if data['message'].find('.w ') == -1: return i18n_server = i18n() w = wikipedia.set_lang(i18n_server.get_text('wiki_lang')) q = data['message'].split(' ') query = '' for word in q: if word.strip() != '.w': query += word + ' ' w = wikipedia.search(query) if w.__len__() == 0: Connection.singleton().send_back(data['nick'] + ', ' + i18n_server.get_text('wiki_fail'), data) return try: page = wikipedia.WikipediaPage(w.pop(0)) except wikipedia.DisambiguationError as error: print('disambiguation page') page = wikipedia.WikipediaPage(error.args[1][0]) Connection.singleton().send_back(data['nick'] + ' ' + page.url, data) index = 51 + page.summary[50:230].find('. ') if index == -1 or index > 230: Connection.singleton().send_back(page.summary[0:230], data) else: Connection.singleton().send_back(page.summary[0:index], data)
def update_on_priv_msg(self, data): if data['message'].find('.seen') == -1: return who = data['message'].split(' ')[1] userProvider = UserProvider() activity = userProvider.get_activity(who) delta = time.time()-activity i18n_server = i18n() replacements = {} replacements['user'] = who replacements['time'] = str(datetime.timedelta(seconds=delta)) output = i18n_server.get_text('seen', replacements) Connection.instance.send_channel(output)
def update_on_priv_msg(self, data): if data['message'].find('.w ') == -1: return i18n_server = i18n() w = wikipedia.set_lang(i18n_server.get_text('wiki_lang')) q = data['message'].split(' ') query = '' for word in q: if word.strip() != '.w': query += word + ' ' w = wikipedia.search(query) if w.__len__() == 0: Connection.singleton().send_channel(data['nick'] + ', ' + i18n_server.get_text('wiki_fail')) return page = wikipedia.WikipediaPage(w.pop(0)) Connection.singleton().send_channel(data['nick'] + ' ' + page.url) Connection.singleton().send_channel(page.summary[0:230])
def update_on_priv_msg(self, data): if data['message'].find('.g') == -1: return i18n_server = i18n() lang = i18n_server.get_text('google_lang') t = i18n_server.get_text('google_tld') q = data['message'].split(' ') query = '' for word in q: if word.strip() != '.g': query += word + ' ' # g = google.search(query, tld=t, lang=lang, num=1, start=0, stop=0, pause=2.0) # s = next(g) # print(s) # Connection.singleton().send_channel(g) # if g has nonzero results: # Connection.singleton().send_channel(data['nick'] + ', ' + i18n_server.get_text('google_fail')) # return #Connection.singleton().send_channel(data['nick'] + ' ' + gefundenes erstes result) #Connection.singleton().send_channel(title von dem link) pass