def _answer_query(self, data, connection: Connection):
     """
     :param data: 
     :param connection: 
     :return: 
     """
     glossary_provider = GlossaryProvider()
     split = data['message'].split(GlossaryModule._QUERY_EXPLANATION)
     if not len(split) == 2:
         return
     answer = glossary_provider.get_explanation(split[1].strip())
     if answer is None or answer[1] is None or answer[1].strip() == '':
         if split[1].strip() == '':
             return
         connection.send_back(
             "Tut mir leid, " + data['nick'] + ". Für " + split[1].strip() +
             " habe ich noch keinen Eintrag. Aber Wikipedia sagt dazu:",
             data)
         wikiObserver = WikiObserver()
         wikiObserver.config = self.config
         data2 = data
         data2['message'] = '.w ' + split[1] + " \r\n"
         wikiObserver.update_on_priv_msg(data2, connection)
     else:
         connection.send_back(
             data['nick'] + ": " + split[1] + " - " + answer[1], data)
 def update_on_priv_msg(self, data, connection: Connection):
     regex = "(?P<url>https?://[^\s]+)"
     url = re.search(regex, data['message'])
     if url is not None:
         url = url.group()
         print(url)
         try:
             headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64)'}
             url = url
             req = urllib.request.Request(url, None, headers)
             resource = urllib.request.urlopen(req)
             encoding = resource.headers.get_content_charset()
             # der erste Fall kann raus, wenn ein anderer Channel benutzt wird
             if url.find('rehakids.de') != -1:
                 encoding = 'windows-1252'
             if not encoding:
                 encoding = 'utf-8'
             content = resource.read().decode(encoding, errors='replace')
             title_re = re.compile("<title>(.+?)</title>")
             title = title_re.search(content).group(1)
             title = html.unescape(title)
             title = title.replace('\n', ' ').replace('\r', '')
             print(title)
             connection.send_back(title, data)
         except Exception as exc:
             print(exc)
             pass
 def update_on_priv_msg(self, data, connection: Connection):
     if data['message'].find('.allseen') == -1:
         return
     if not self._is_idented_mod(data, connection):
         return
     User_afk = defaultdict(int)
     for who in self.user_list.userList.keys():
         user_provider = UserProvider()
         activity = user_provider.get_activity(who)
         delta = time.time() - activity
         User_afk[who] = delta
         print(who)
         print(delta)
     for w in sorted(User_afk, key=User_afk.get):
         output = (w + ":\t" + str(datetime.timedelta(seconds=User_afk[w])))
         connection.send_back(output, data)
Exemple #4
0
 def _add_query(self, data, connection: Connection):
     """
     
     :param data: 
     :param connection: 
     :return: 
     """
     if not self._is_idented_mod(data, connection):
         connection.send_back("Dir fehlen leider die Rechte zum Hinzufügen von Einträgen, " + data['nick'] + ".",
                              data)
         return
     msg = data['message'].split(GlossaryModule._ADD_EXPLANATION)[1].strip()
     split = msg.split(' ', 1)
     glossary_provider = GlossaryProvider()
     glossary_provider.save_or_replace(split[0], split[1])
     connection.send_back(data['nick'] + ": der Eintrag zu " + split[0] + " wurde gespeichert.", data)
Exemple #5
0
    def _remove_query(self, data, connection: Connection):
        """

        :param data: 
        :param connection: 
        :return: 
        """
        if not self._is_idented_mod(data, connection):
            connection.send_back("Dir fehlen die Berechtigungen zum Löschen von Einträgen, " + data['nick'] + ".", data)
            return
        glossary_provider = GlossaryProvider()
        split = data['message'].split(GlossaryModule._REMOVE_EXPLANATION)
        if not len(split) == 2:
            return
        glossary_provider.delete_explanation(split[1])
        connection.send_back("Der Eintrag zu " + split[1] + " wurde gelöscht, " + data['nick'] + ".", data)
Exemple #6
0
 def update_on_priv_msg(self, data, connection: Connection):
     regex = "(?P<url>https?://[^\s]+)"
     message = re.sub(regex, ' ', data['message'])
     if data['channel'] != connection.details.get_channel():
         return
     regex = r'\b(\w\d{2}\.?\d?)\b'
     codes = re.findall(regex, message)
     for code in codes:
         code = code.capitalize()
         text = self.get_icd(code)
         if text == 0:
             if code.find('.') != -1:
                 code += '-'
             else:
                 code += '.-'
         text = self.get_icd(code)
         if text != 0:
             connection.send_back(text, data)
Exemple #7
0
 def _answer_query(self, data, connection: Connection):
     """
     :param data: 
     :param connection: 
     :return: 
     """
     glossary_provider = GlossaryProvider()
     split = data['message'].split(GlossaryModule._QUERY_EXPLANATION)
     if not len(split) == 2:
         return
     answer = glossary_provider.get_explanation(split[1].strip())
     if answer is None or answer[1] is None or answer[1].strip() == '':
         if split[1].strip() == '':
             return
         connection.send_back("Tut mir leid, " + data['nick'] + ". Für " + split[1].strip() +
                              " habe ich noch keinen Eintrag.", data)
     else:
         connection.send_back(data['nick'] + ": " + split[1] + " - " + answer[1], data)
 def update_on_priv_msg(self, data, connection: Connection):
     regex = "(?P<url>https?://[^\s]+)"
     url = re.search(regex, data['message'])
     if url is not None:
         url = url.group()
         print(url)
         try:
             headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64)'}
             url = url
             req = urllib.request.Request(url, None, headers)
             resource = urllib.request.urlopen(req)
             title = self.getTitle(resource)
             print(title)
             title = title[:250]
             connection.send_back(title, data)
         except Exception as exc:
             print(exc)
             pass
Exemple #9
0
 def update_on_priv_msg(self, data, connection: Connection):
     regex = "(?P<url>https?://[^\s]+)"
     message = re.sub(regex, ' ', data['message'])
     if data['channel'] != connection.details.get_channel():
         return
     regex = r'\b(\w\d{2}\.?\d?)\b'
     codes = re.findall(regex, message)
     for code in codes:
         code = code.capitalize()
         text = self.get_icd(code)
         if text == 0:
             if code.find('.') != -1:
                 code += '-'
             else:
                  code += '.-'
         text = self.get_icd(code)
         if text != 0:
             connection.send_back(text, data)
Exemple #10
0
 def update_on_priv_msg(self, data: dict, connection: Connection):
     if data['message'].find('.comic') == -1:
         return
         
     #Join list of comics that have a web based random functionality and those that need a scraper
     all_comics=comics+scraper_comics
     
     #Choose from the joined list
     comic = random.choice(all_comics)
     
     #Check which type of comic it is: If it's one that doesn't need a scaper, get the url and return it.
     #If it needs a scraper, use ComicScraper to scrape the comic.
     #If you want to add custom comic scrapers: Look at ComicScraper.py and insert your functionality.
     if not comic in scraper_comics:
         headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64)'}
         req = urllib.request.Request(comic, None, headers)
         resource = urllib.request.urlopen(req)
         title = TitleObserver.getTitle(TitleObserver(), resource)
         connection.send_back(resource.geturl() + " " + title, data)
     else:
         connection.send_back(ComicScraper.getRandomComic(comic),data);
Exemple #11
0
 def update_on_priv_msg(self, data, connection: Connection):
     if data['message'].find('.seen ') == -1:
         return
     if not self._is_idented_mod(data, connection):
         return
     who = data['message'].split(' ')[1]
     user_provider = UserProvider()
     activity = user_provider.get_activity(who)
     delta = time.time() - activity
     i18n_server = i18n()
     replacements = {
         'user': who,
         'time': str(datetime.timedelta(seconds=delta)),
         'asker': data['nick']
     }
     output = i18n_server.get_text('seen',
                                   replacements=replacements,
                                   lang=self.config.lang)
     if not self._is_idented_mod(data, connection):
         connection.send_channel(output)
         return
     connection.send_back(output, data)
 def update_on_priv_msg(self, data, connection: Connection):
     if data['message'].find('.starthunt') != -1:
         if not self._is_idented_mod(data, connection):
             connection.send_back(
                 "Dir fehlen leider die Rechte zum Starten der Jagd, " +
                 data['nick'] + ".", data)
             return
         self.active = 1
         connection.send_channel("Jagd eröffnet")
         return
     if data['message'].find('.stophunt') != -1:
         if not self._is_idented_mod(data, connection):
             connection.send_back(
                 "Dir fehlen leider die Rechte zum Stoppen der Jagd, " +
                 data['nick'] + ".", data)
             return
         self.active = 0
         self.duck_alive = 0
         connection.send_channel("Jagd beended")
         return
     if data['message'].find('.freunde') != -1:
         self.befriend(data, connection)
     if data['message'].find('.schiessen') != -1:
         self.shoot(data, connection)
Exemple #13
0
 def update_on_priv_msg(self, data: dict, connection: Connection):
     if data['message'].find('.drink') == -1:
         return
     connection.send_back(
         '\001ACTION schenkt ' + data['nick'] + ' ' +
         random.choice(getraenke) + ' ein.\001', data)
Exemple #14
0
 def update_on_priv_msg(self, data: dict, connection: Connection):
     if data['message'].find('.food') == -1:
         return
     connection.send_back(
         '\001ACTION tischt ' + data['nick'] + ' ' + random.choice(essen) +
         ' auf.\001', data)
 def update_on_priv_msg(self, data: dict, connection: Connection):
     if data['message'].find('.drink') == -1:
         return
     connection.send_back('\001ACTION schenkt ' + data['nick'] + ' ' + random.choice(getraenke) + ' ein.\001', data)