from plugin import Plugin
import re

class istheinternetonfire(Plugin):

    def help_text(self):
        return ("!security - Aktuelle Sicherheitsprobleme im Internetz anzeigen")

    def on_msg(self, bot, user_nick, host, channel, message):
        url = "https://istheinternetonfire.com/status.txt"
        msg = bot.sanitize(bot.getpage(url))
        msg = re.sub('<[^<]+?>', '', msg)
        #msg = re.sub('https?://[^\s]+', '', msg)
        if self.is_message_new(msg):
            self.save_message(msg)
            bot.send_message(channel, "Brennt das Internet? {msg}".format(msg=msg))

    def save_message(self, msg):
        f = open('/tmp/.internetbrenntcache','w')
        f.write(msg)
        f.close()

    def is_message_new(self, msg):
        try:
            f = open('/tmp/.internetbrenntcache')
            c = f.read()
        except IOError:
            c = "THISWILLNEVERHAPPEN"

        if c != msg:
            return True
        else:
            return False


from plugin import Plugin
import re

class istheinternetonfire(Plugin):

    def help_text(self):
        return ("!security - Aktuelle Sicherheitsprobleme im Internetz anzeigen")

    def on_msg(self, bot, user_nick, host, channel, message):
        url = "https://istheinternetonfire.com/status.txt"
        msg = bot.sanitize(bot.getpage(url))
        msg = re.sub('<[^<]+?>', '', msg)
        #msg = re.sub('https?://[^\s]+', '', msg)
        if self.is_message_new(msg):
            self.save_message(msg)
            bot.send_message(channel, "Brennt das Internet? {msg}".format(msg=msg))
        if message.startswith("!security"):
            bot.send_message(channel, "Brennt das Internet? {msg}".format(msg=msg))

    def save_message(self, msg):
        f = open('/tmp/.internetbrenntcache','w')
        f.write(msg)
        f.close()

    def is_message_new(self, msg):
        try:
            f = open('/tmp/.internetbrenntcache')
            c = f.read()
        except IOError:
            c = "THISWILLNEVERHAPPEN"

        if c != msg:
            return True
        else:
            return False


fix security when asked for specifically