Example #1
0
 def system_message(self, message, category='system'):
     system_message(message,
                    self.queue,
                    source=SOURCE,
                    icon=SOURCE_ICON,
                    from_user=SYSTEM_USER,
                    category=category)
Example #2
0
    def set_level(self, user, queue):
        if user == 'System':
            return []
        db = sqlite3.connect(self.db_location)

        cursor = db.cursor()
        user_select = cursor.execute(
            'SELECT User, Experience FROM UserLevels WHERE User = ?', [user])
        user_select = user_select.fetchall()

        experience = self.exp_for_message
        exp_to_add = self.calculate_experience(user)
        if len(user_select) == 1:
            row = user_select[0]
            experience = int(row[1]) + exp_to_add
            cursor.execute(
                'UPDATE UserLevels SET Experience = ? WHERE User = ? ',
                [experience, user])
        elif len(user_select) > 1:
            log.error("Select yielded more than one User")
        else:
            cursor.execute('INSERT INTO UserLevels VALUES (?, ?)',
                           [user, experience])
        db.commit()

        max_level = 0
        for level in self.levels:
            if level['exp'] < experience:
                max_level += 1
        if max_level >= len(self.levels):
            max_level -= 1

        if experience >= self.levels[max_level]['exp']:
            if self.experience == 'random':
                max_level = random.randint(0, len(self.levels) - 1)
                experience = self.levels[max_level]['exp'] - self.exp_for_level
                cursor.execute(
                    'UPDATE UserLevels SET Experience = ? WHERE User = ? ',
                    [experience, user])
                db.commit()
            else:
                max_level += 1
            system_message(self._conf_params['config']['config']
                           ['message'].decode('utf-8').format(
                               user, self.levels[max_level]['name']),
                           queue,
                           category='module')
        cursor.close()
        return self.levels[max_level].copy()
Example #3
0
    def set_level(self, user, queue):
        if user == 'System':
            return []
        db = sqlite3.connect(self.db_location)

        cursor = db.cursor()
        user_select = cursor.execute('SELECT User, Experience FROM UserLevels WHERE User = ?', [user])
        user_select = user_select.fetchall()

        experience = self.exp_for_message
        exp_to_add = self.calculate_experience(user)
        if len(user_select) == 1:
            row = user_select[0]
            experience = int(row[1]) + exp_to_add
            cursor.execute('UPDATE UserLevels SET Experience = ? WHERE User = ? ', [experience, user])
        elif len(user_select) > 1:
            log.error("Select yielded more than one User")
        else:
            cursor.execute('INSERT INTO UserLevels VALUES (?, ?)', [user, experience])
        db.commit()

        max_level = 0
        for level in self.levels:
            if level['exp'] < experience:
                max_level += 1
        if max_level >= len(self.levels):
            max_level -= 1

        if experience >= self.levels[max_level]['exp']:
            if self.experience == 'random':
                max_level = random.randint(0, len(self.levels) - 1)
                experience = self.levels[max_level]['exp'] - self.exp_for_level
                cursor.execute('UPDATE UserLevels SET Experience = ? WHERE User = ? ', [experience, user])
                db.commit()
            else:
                max_level += 1
            system_message(self.message.format(user, self.levels[max_level]['name']), queue)
        cursor.close()
        return self.levels[max_level]
Example #4
0
 def system_message(self, msg):
     system_message(msg,
                    self.queue,
                    SOURCE,
                    icon=SOURCE_ICON,
                    from_user=SYSTEM_USER)
Example #5
0
 def fs_system_message(self, message):
     system_message(message,
                    self.queue,
                    source=SOURCE,
                    icon=SOURCE_ICON,
                    from_user=SYSTEM_USER)
Example #6
0
 def system_message(self, msg):
     system_message(msg, self.queue, SOURCE,
                    icon=SOURCE_ICON, from_user=SYSTEM_USER)
Example #7
0
 def system_message(self, message):
     system_message(message, self.queue,
                    source=SOURCE, icon=SOURCE_ICON, from_user=SYSTEM_USER)