Beispiel #1
0
def test_group_alert(import_groups, import_counts):
    expected = ['Test Text 2', 'Test Text 3']
    assert alerts.group_alert('last_two', hit_socket=False) in expected

    expected = ['Test Text 1', 'Test Text 2']
    assert alerts.group_alert('first_two', hit_socket=False) in expected

    expected = ['Test Text 1', 'Test Text 2']
    assert alerts.group_alert('first_two', hit_socket=False) in expected

    count = counts.get_count('count1')
    assert count == 39

    count = counts.get_count('count2')
    assert count == 4
Beispiel #2
0
    def _substitute_vars(self, message):
        # edit message to replace {count_name} with count number
        for variable in re.findall('{(.*?)}', message):
            variable = variable.strip()

            # if it's a count name, return the count
            found_count = counts.get_count(variable)
            if found_count is not None:
                message = message.replace('{{{}}}'.format(variable), str(found_count))
                continue

            # if it's a list, return a random one or use the index
            list_params = variable.split()
            list_name = list_params[0]
            if list_name not in [list_dict['name'] for list_dict in lists.list_lists()]:
                continue

            index = None
            try:
                # accounting for negative indexes
                pulled_index = int(list_params[1])-1
                if pulled_index < lists.get_list_size(name=list_name):
                    index = pulled_index
            except (ValueError, IndexError):
                pass

            found_item, index = lists.get_list_item(name=list_name, index=index)
            if found_item is not None:
                message = message.replace('{{{}}}'.format(variable), found_item)
                continue

        return message
Beispiel #3
0
 def set_count_commands(self):
     self.count_commands = {
         'list_counts': {
             'badge': Badges.CHAT,
             'callback': lambda text, user, badges: self.list_counts(),
             'format': '^!list_counts$',
             'help': '!list_counts'
         },
         'get_count': {
             'badge': Badges.CHAT,
             'callback': lambda text, user, badges: self.chat_count_output(text, counts.get_count(text)),
             'format': '^!get_count\s+\S+$',
             'help': '!get_count count_name'
         },
         'set_count': {
             'badge': Badges.VIP,
             'callback': lambda text, user, badges: self.chat_count_output(text.split()[0],
                                                                           counts.set_count(text.split()[0],
                                                                                            text.split()[1])),
             'format': '^!set_count\s+\S+\s+\d+$',
             'help': '!set_count count_name number'
         },
         'copy_count': {
             'badge': Badges.VIP,
             'callback': lambda text, user, badges: self.copy_count(text),
             'format': '^!copy_count\s+\S+\s+\S+$',
             'help': '!copy_count count_from count_to'
         },
         'reset_count': {
             'badge': Badges.VIP,
             'callback': lambda text, user, badges: self.reset_count(text),
             'format': '^!reset_count(\s+\S+)+$',
             'help': '!reset_count count_name1 count_name2 ...'
         },
         'remove_count': {
             'badge': Badges.VIP,
             'callback': lambda text, user, badges: self.remove_count_output(text),
             'format': '^!remove_count\s+\S+$',
             'help': '!remove_count count_name'
         },
         'add_count': {
             'badge': Badges.VIP,
             'callback': lambda text, user, badges: self.chat_count_output(text, counts.add_to_count(text)),
             'format': '^!add_count\s+\S+$',
             'help': '!add_count count_name'
         },
         'subtract_count': {
             'badge': Badges.VIP,
             'callback': lambda text, user, badges: self.chat_count_output(text, counts.subtract_from_count(text)),
             'format': '^!subtract_count\s+\S+$',
             'help': '!subtract_count count_name'
         }
     }
Beispiel #4
0
def test_copy_count(import_counts):
    assert counts.copy_count('count3', 'count2') == 90
    assert counts.get_count('count2') == 90
Beispiel #5
0
def test_get_count(import_counts):
    assert counts.get_count('count2') == 20