Exemplo n.º 1
0
    def __init__(self, handler: Callable, about: str, allow_selfact=False):
        self.about = about
        self.handler = handler

        self.usraccess = AccessList(allow_others=False,
                                    allow_selfact=allow_selfact)
        self.chataccess = AccessList(allow_others=True,
                                     allow_selfact=allow_selfact)
Exemplo n.º 2
0
 def test_me(self):
     al = AccessList()
     me = IahrConfig.ME
     assert al.is_allowed(me)
     al.ban(me)
     assert al.is_allowed(me)
     al = AccessList(allow_others=True)
     assert al.is_allowed(me)
Exemplo n.º 3
0
    def test_operation_when_already_done_for_all(self, allow_others):
        operation = 'allow' if allow_others else 'ban'
        al = AccessList(allow_others)
        lst = al.whitelist if allow_others else al.blacklist

        getattr(al, operation)(self.ENT)
        assert (len(lst) == 0)
Exemplo n.º 4
0
    def test_others(self, operation):
        should_be = operation == 'allow'
        opposite = 'allow' if operation == 'ban' else 'ban'
        al = AccessList()
        others = IahrConfig.OTHERS

        assert not al.is_allowed(self.ENT)
        getattr(al, operation)(others)
        assert al.is_allowed(self.ENT) == should_be

        getattr(al, opposite)(self.ENT)
        assert not (al.is_allowed(self.ENT) == should_be)
        getattr(al, operation)(others)
        assert al.is_allowed(self.ENT) == should_be
Exemplo n.º 5
0
    def __init__(self):
        """
            Load state from file and register dumping to file
            atexit
        """
        # for new message events only(commands)
        self.commands = {}
        # for all other types of events, plain handlers, can't be combined
        self.handlers = {
            prefix: {}
            for prefix in IahrConfig.REVERSE_PREFIXES.keys()
        }
        # tags for quick search
        self.tags = {}
        # for errignore on chat level
        self.chatlist = AccessList(allow_others=False)
        # state for dumping and loading from file
        self.commands_state, self.handlers_state = self.load()

        atexit.register(self.dump)
Exemplo n.º 6
0
 def test_simple_operation(self, operation, should_be):
     for allow_others in (True, False):
         al = AccessList(allow_others)
         getattr(al, operation)(self.ENT)
         assert al.is_allowed(self.ENT) == should_be