preliminary work for class based plugins #27
This commit is contained in:
		
							parent
							
								
									fdb16287ce
								
							
						
					
					
						commit
						4ae8753095
					
				@ -1,3 +1,4 @@
 | 
			
		||||
from abc import ABC, abstractmethod
 | 
			
		||||
from enum import Enum
 | 
			
		||||
from functools import wraps
 | 
			
		||||
 | 
			
		||||
@ -23,6 +24,35 @@ class Output:
 | 
			
		||||
            return msg
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Command(ABC):
 | 
			
		||||
    def __init__(self, **kwargs):
 | 
			
		||||
        self.cmd = kwargs.get('cmd')
 | 
			
		||||
        self.help = kwargs.get('help', '')
 | 
			
		||||
        self.ops = kwargs.get('ops', False)
 | 
			
		||||
        self.ops_msg = kwargs.get('ops_msg', '')
 | 
			
		||||
        self.enabled = True
 | 
			
		||||
        self.add_command()
 | 
			
		||||
    
 | 
			
		||||
    @abstractmethod
 | 
			
		||||
    def run(self, msg):
 | 
			
		||||
        pass
 | 
			
		||||
 | 
			
		||||
    def add_command(self):
 | 
			
		||||
        cmds[self.cmd] = {
 | 
			
		||||
            'run': self.run,
 | 
			
		||||
            'help': self.help,
 | 
			
		||||
            'enabled': self.enabled,
 | 
			
		||||
        }
 | 
			
		||||
        if self.ops:
 | 
			
		||||
            cmds[self.cmd].update({
 | 
			
		||||
                'ops': self.ops,
 | 
			
		||||
                'ops_msg': self.ops_msg,
 | 
			
		||||
            })
 | 
			
		||||
 | 
			
		||||
    def __str__(self):
 | 
			
		||||
        return self.cmd
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def action(msg):
 | 
			
		||||
    return Output(OutputType.Action, msg)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user