-
Notifications
You must be signed in to change notification settings - Fork 1
/
exec.py
56 lines (43 loc) · 1.36 KB
/
exec.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import sys, urllib2
#Update schema
__url__ = "https://raw.githubusercontent.com/KittyHawkIrc/modules/production/" + __name__ + ".py"
__version__ = 1.0
try:
from cStringIO import StringIO
except:
from StringIO import StringIO
def declare():
return {"exec": "privmsg", "exec_url": "privmsg"}
def callback(self):
backup = sys.stdout
if self.channel.startswith('#') and self.isowner:
if self.command == 'exec':
text = self.message.split('^exec ')[1]
else:
req = urllib2.Request(self.message.split('^exec_url ')[1])
fd = urllib2.urlopen(req)
text = fd.read()
fd.close()
log = StringIO()
sys.stdout = log
try:
exec(text)
return self.msg(self.channel, log.getvalue())
except Exception, e:
return self.msg(self.channel, str(e))
log.close()
sys.stdout = backup
class api:
def msg(self, channel, text):
return "[%s] %s" % (channel, text)
if __name__ == "__main__":
api = api()
setattr(api, 'isop', True)
setattr(api, 'isowner', True)
setattr(api, 'type', 'privmsg')
setattr(api, 'command', 'exec')
setattr(api, 'message', '^exec print "test"')
setattr(api, 'user', 'joe!username@hostmask')
setattr(api, 'channel', '#test')
if not callback(api):
exit(1)