25 lines
783 B
Python
25 lines
783 B
Python
import plugin, subprocess, requests, collections
|
|
|
|
def register_command_call(command,cli,use_args=False,verify_args=lambda args: args):
|
|
@plugin.command(command)
|
|
def on_call(self,channel,nick,*args):
|
|
output = subprocess.check_output([cli]+list(verify_args(args) if use_args else [])).decode("utf-8").split("\n")
|
|
output = filter(None,output)
|
|
for line in output:
|
|
self.say(channel,"{}".format(line))
|
|
|
|
def get(*args,**kwargs):
|
|
r = requests.get(*args,**kwargs)
|
|
r.raise_for_status()
|
|
return r.json()
|
|
|
|
class LazyLoadedDict(collections.UserDict):
|
|
def __init__(self,func,initialdata=dict()):
|
|
super().__init__(initialdata)
|
|
self.func = func
|
|
def __getitem__(self,key):
|
|
if key not in self.data:
|
|
self.data[key]=self.func(key)
|
|
return self.data[key]
|
|
return self.data[key]
|