36 lines
1.0 KiB
Python
36 lines
1.0 KiB
Python
from subapi import SubAPI
|
|
|
|
class LuaPlugin:
|
|
"""Handles lua execution"""
|
|
def __init__(self,bot):
|
|
self.bot = bot
|
|
self.channels = dict()
|
|
|
|
def addChannel(self,chan):
|
|
self.channels[chan]=SubAPI()
|
|
self.channels[chan].addListener(self.outWithIt(chan))
|
|
self.channels[chan].start(["/usr/bin/lua"])
|
|
|
|
def outWithIt(self,chan):
|
|
def handler(msg):
|
|
if msg.strip()=="Lua 5.2.4 Copyright (C) 1994-2015 Lua.org, PUC-Rio":
|
|
return
|
|
self.bot.say(chan,msg)
|
|
return handler
|
|
|
|
def handleCommand(self,chan,sender,cmd):
|
|
if cmd.strip()=="!lua":
|
|
self.bot.mention(chan,sender,"Use !lua <lua command> to execute lua.")
|
|
elif not cmd.startswith("!lua "):
|
|
return
|
|
elif cmd.strip()=="!lua start" and not self.channels[chan]:
|
|
self.addChannel(chan)
|
|
self.bot.say(chan,"Lua session started")
|
|
elif cmd.strip()=="!lua reset" and self.channels[chan]:
|
|
self.channels[chan].stop()
|
|
del self.channels[chan]
|
|
self.addChannel(chan)
|
|
self.bot.say(chan,"Lua session reset")
|
|
else:
|
|
self.channels[chan].sendInput(cmd.strip.split(" ",2)[1])
|