Пример #1
0
    def add(self, message):
        """add lat,lon - adds a nick to the chat map, or updates if already added"""

        coords = ''.join(message.ParameterList[1:])
        if not ',' in coords:
            return 'lat,lon coords must be comma separated'
        (lat, lon) = coords.split(',')
        if not StringUtils.isNumber(lat) or not StringUtils.isNumber(lon):
            return 'latitude or longitude are not numeric'

        (lat, lon) = float(lat), float(lon)

        if not -90.0 < lat < 90.0:
            return 'latitude is outside valid range (-90 -> 90)'
        if not -180.0 < lon < 180.0:
            return 'longitude is outside valid range (-180 -> 180)'

        db = create_database("mysql://{0}:{1}@{2}:{3}/{4}".format(
            self.chatMapDB['User'], self.chatMapDB['Password'],
            self.chatMapDB['Host'], 3306, self.chatMapDB['DB']))
        store = Store(db)

        result = store.execute(
            "SELECT nick, latitude, longitude FROM " +
            self.chatMapDB['Table'] + " WHERE nick=%s", [message.User.Name])

        response = 'There has been a fatal error updating your GPS coordinates. Please contact Emily to let her know.'

        if result.rowcount == 1:
            result = store.execute(
                "UPDATE " + self.chatMapDB['Table'] +
                " SET latitude=%s, longitude=%s WHERE nick=%s",
                [lat, lon, message.User.Name])
            if result:
                response = 'Your chatmap position has been updated with the new GPS coordinates!'

        elif result.rowcount == 0:
            result = store.execute(
                "INSERT INTO " + self.chatMapDB['Table'] +
                " (nick, latitude, longitude) VALUES(%s, %s, %s)",
                [message.User.Name, lat, lon])
            if result:
                response = 'You are now on the chatmap at the specified GPS coordinates! ' \
                           'Be sure to do an addYear to add the year you first started as a Survivor!'

        store.close()

        return response
Пример #2
0
    def execute(self, message):
        """
        @type message: IRCMessage
        """

        date = datetime.datetime.utcnow()
        if len(message.ParameterList) == 1:
            if StringUtils.isNumber(message.ParameterList[0]):
                date += datetime.timedelta(days=int(message.ParameterList[0]))
            else:
                try:
                    date = dparser.parse(message.ParameterList[0], fuzzy=True, dayfirst=True)
                except ValueError:
                    pass

        proc = subprocess.Popen(['/usr/bin/php',
                                 '/home/ubuntu/moronbot/getloghash.php',
                                 message.ReplyTo + "-" + date.strftime('%Y%m%d')],
                                stdout=subprocess.PIPE)
        logHash = proc.stdout.read()
        if logHash == "Not found":
            output = "I don't have that log."
        else:
            output = "Log for " + date.strftime('%Y/%m/%d') + ": http://www.moronic-works.co.uk/logs/?l=" + logHash

        return IRCResponse(ResponseType.Say, output, message.ReplyTo)
Пример #3
0
    def execute(self, message):
        """
        @type message: IRCMessage
        """

        date = datetime.datetime.utcnow()
        if len(message.ParameterList) == 1:
            if StringUtils.isNumber(message.ParameterList[0]):
                date += datetime.timedelta(days=int(message.ParameterList[0]))
            else:
                try:
                    date = dparser.parse(message.ParameterList[0],
                                         fuzzy=True,
                                         dayfirst=True)
                except ValueError:
                    pass

        proc = subprocess.Popen([
            '/usr/bin/php', '/home/ubuntu/moronbot/getloghash.php',
            message.ReplyTo + "-" + date.strftime('%Y%m%d')
        ],
                                stdout=subprocess.PIPE)
        logHash = proc.stdout.read()
        if logHash == "Not found":
            output = "I don't have that log."
        else:
            output = "Log for " + date.strftime(
                '%Y/%m/%d'
            ) + ": http://www.moronic-works.co.uk/logs/?l=" + logHash

        return IRCResponse(ResponseType.Say, output, message.ReplyTo)
Пример #4
0
    def add(self, message):
        """add lat,lon - adds a nick to the chat map, or updates if already added"""

        coords = ''.join(message.ParameterList[1:])
        if not ',' in coords:
            return 'lat,lon coords must be comma separated'
        (lat, lon) = coords.split(',')
        if not StringUtils.isNumber(lat) or not StringUtils.isNumber(lon):
            return 'latitude or longitude are not numeric'

        (lat, lon) = float(lat), float(lon)

        if not -90.0 < lat < 90.0:
            return 'latitude is outside valid range (-90 -> 90)'
        if not -180.0 < lon < 180.0:
            return 'longitude is outside valid range (-180 -> 180)'

        db = create_database("mysql://{0}:{1}@{2}:{3}/{4}".format(self.chatMapDB['User'],
                                                                  self.chatMapDB['Password'],
                                                                  self.chatMapDB['Host'],
                                                                  3306,
                                                                  self.chatMapDB['DB']))
        store = Store(db)

        result = store.execute("SELECT nick, latitude, longitude FROM " + self.chatMapDB['Table'] + " WHERE nick=%s",
                               [message.User.Name])

        response = 'There has been a fatal error updating your GPS coordinates. Please contact Emily to let her know.'

        if result.rowcount == 1:
            result = store.execute("UPDATE " + self.chatMapDB['Table'] + " SET latitude=%s, longitude=%s WHERE nick=%s",
                                   [lat, lon, message.User.Name])
            if result:
                response = 'Your chatmap position has been updated with the new GPS coordinates!'

        elif result.rowcount == 0:
            result = store.execute(
                "INSERT INTO " + self.chatMapDB['Table'] + " (nick, latitude, longitude) VALUES(%s, %s, %s)",
                [message.User.Name, lat, lon])
            if result:
                response = 'You are now on the chatmap at the specified GPS coordinates! ' \
                           'Be sure to do an addYear to add the year you first started as a Survivor!'

        store.close()

        return response
Пример #5
0
    def addYear(self, message):
        """addYear - updates desert bus year for the user, (first surviving year)"""

        year = ''.join(message.ParameterList[1:])
        if not StringUtils.isNumber(year):
            return 'the desert bus year should only be numeric (1-8)'

        year = int(year)

        if year >= 2010:
            year -= 2006
        if not 4 <= year <= 8:
            return 'the desert bus year should only be for valid years (4 -> 8)'

        db = create_database("mysql://{0}:{1}@{2}:{3}/{4}".format(self.chatMapDB['User'],
                                                                  self.chatMapDB['Password'],
                                                                  self.chatMapDB['Host'],
                                                                  3306,
                                                                  self.chatMapDB['DB']))
        store = Store(db)

        result = store.execute("SELECT nick, dbyear FROM " + self.chatMapDB['Table'] + " WHERE nick=%s",
                               [message.User.Name])

        response = 'There has been a fatal error updating your Desert Bus Year. Please contact Emily to let her know.'

        if result.rowcount == 1:
            result = store.execute("UPDATE " + self.chatMapDB['Table'] + " SET dbyear=%s WHERE nick=%s",
                                   [year, message.User.Name])
            if result:
                response = 'Your desert bus year has been updated with your information!'

        elif result.rowcount == 0:
            response = 'You do not currently have a chatmap record, please use add lat,lon first.'

        store.close()

        return response
Пример #6
0
    def addYear(self, message):
        """addYear - updates desert bus year for the user, (first surviving year)"""

        year = ''.join(message.ParameterList[1:])
        if not StringUtils.isNumber(year):
            return 'the desert bus year should only be numeric (1-8)'

        year = int(year)

        if year >= 2010:
            year -= 2006
        if not 4 <= year <= 8:
            return 'the desert bus year should only be for valid years (4 -> 8)'

        db = create_database("mysql://{0}:{1}@{2}:{3}/{4}".format(
            self.chatMapDB['User'], self.chatMapDB['Password'],
            self.chatMapDB['Host'], 3306, self.chatMapDB['DB']))
        store = Store(db)

        result = store.execute(
            "SELECT nick, dbyear FROM " + self.chatMapDB['Table'] +
            " WHERE nick=%s", [message.User.Name])

        response = 'There has been a fatal error updating your Desert Bus Year. Please contact Emily to let her know.'

        if result.rowcount == 1:
            result = store.execute(
                "UPDATE " + self.chatMapDB['Table'] +
                " SET dbyear=%s WHERE nick=%s", [year, message.User.Name])
            if result:
                response = 'Your desert bus year has been updated with your information!'

        elif result.rowcount == 0:
            response = 'You do not currently have a chatmap record, please use add lat,lon first.'

        store.close()

        return response