Ejemplo n.º 1
0
 def update_on_priv_msg(self, data):
     url = re.search("(?P<url>https?://[^\s]+)", 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")
             titleRE = re.compile("<title>(.+?)</title>")
             title = titleRE.search(content).group(1)
             title = html.unescape(title)
             title = title.replace("\n", " ").replace("\r", "")
             print(title)
             Connection.singleton().send_channel(title)
         except Exception as exc:
             print(exc)
             pass
Ejemplo n.º 2
0
 def update_on_priv_msg(self, data):
     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')
             titleRE = re.compile("<title>(.+?)</title>")
             title = titleRE.search(content).group(1)
             title = html.unescape(title)
             title = title.replace('\n', ' ').replace('\r', '')
             print(title)
             Connection.singleton().send_back(title, data)
         except Exception as exc:
             print(exc)
             pass
Ejemplo n.º 3
0
 def update_on_priv_msg(self, data):
     if data['message'].find('.modmail') == -1:
         return
     mods = Connection.singleton().details.get_mods()
     print(mods)
     message = data['message'].split('.modmail ')[1]
     for mod in mods:
         Connection.singleton().send_to_user(mod, data['nick'] + ' meldet: ' + message)
Ejemplo n.º 4
0
 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)
Ejemplo n.º 5
0
 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])
Ejemplo n.º 6
0
 def update_on_priv_msg(self, data):
     users = UserProvider()
     if data['channel'] == Connection.singleton().details.get_channel():
         users.set_active(data['nick'])
         users.add_characters(data['nick'],len(data['message']))
Ejemplo n.º 7
0
 def update_on_join(self, data):
     users = UserProvider()
     if data['channel'] == Connection.singleton().details.get_channel():
         users.set_active(data['nick'])
Ejemplo n.º 8
0
def run():
    running = True
    while running:
        if Connection.singleton().receive() == False:
            return
Ejemplo n.º 9
0
def setup():
    connection = Connection(ConnectionDateils(True))
    connection.establish()
    _thread.start_new_thread(connection.singleton().sender,())
    userList = UserList.UserList()
    Activity = ActivityObserver.AcitivityObserver()
    Connection.singleton().receive()
    data = Connection.singleton().last_data()
    while -1 == data.find('353'):
        Connection.singleton().receive()
        data = Connection.singleton().last_data()
    Connection.singleton().observeJoin(userList)
    Connection.singleton().observeJoin(Activity)
    Connection.singleton()._join.input_names(data)

    Connection.singleton().observeKick(userList)
    Connection.singleton().observeLeave(userList)
    Connection.singleton().observeNickChange(userList)
    Connection.singleton().observeNickChange(Activity)
    Connection.singleton().observePing(PingAnswerObserver.ModulePing())
    Connection.singleton().observePing(Kicker.Kicker())
    Connection.singleton().observePrivmsg(Activity )
    Connection.singleton().observePrivmsg(SeenObserver.SeenObserver())
    Connection.singleton().observePrivmsg(TitleObserver.TitleObserver())
    Connection.singleton().observePrivmsg(WikiObserver.WikiObserver())
    Connection.singleton().observePrivmsg(ModmailObserver.ModmailObserver())
    Connection.singleton().observePrivmsg(ICDObserver.ICDObserver())
Ejemplo n.º 10
0
 def update_on_ping(self, data):
     print('Module Ping')
     msg = 'PONG ' + data['server']
     Connection.singleton().raw_send(msg)