]> jfr.im git - irc/evilnet/x3.git/blob - src/modpython.py
more python work. Not safe to run yet
[irc/evilnet/x3.git] / src / modpython.py
1 #!/usr/bin/python
2
3
4 # TODO notes:
5 #
6 # - impliment handle_* functions for everything x3 has register fetaures for
7 # - impliment script load/unload for user scripts.
8 # - load a script via this script.
9 # - script calls functions from here to set its functions up for calling on various actions
10 # - provide helper functions for subscripts to save settings attached to users/chanels
11 # - provide helper functions for scripts to do common things like msg a person or a channel,
12 # reply, etc.
13
14 import svc
15
16 import math
17
18
19 class modules:
20 """Class to handle loading/unloading of modules"""
21 loaded_modules = []
22
23 def load(self, name):
24 mod_name = "plugins.%s"%name
25 if(sys.modules[mod_name]):
26 need_reload = true
27 #TODO: try to catch compile errors etc.
28 if(!need_reload):
29 __import__(mod_name)
30 module = sys.modules[mod_name]
31 if(need_reload):
32 reload(module) # to ensure its read fresh
33 self.loaded_modules[mod_name] = module
34
35 class irc:
36 """Used to interact with the world of IRC from module scripts"""
37
38 # some defaults to make shorthand easy
39 caller = ''
40 target = ''
41 service = ''
42
43 def __init__(self, service = None, caller = None, target = None):
44 """ Constructor """
45 self.caller = caller #the person who sent the command/message
46 self.service = service #the service who saw the message
47 self.target = target #the channel message was in (if public)
48
49 def send_target_privmsg(self, source, target, message):
50 svc.send_target_privmsg(source, target, "%s "%(message))
51
52 def reply(self, message):
53 """ Send a private reply to the user using convenience values"""
54 self.send_target_privmsg(self.service, self.caller, message)
55
56
57 def command_set(self, command_caller, command_target, command_service):
58 """ Setup defaults for convenience"""
59 global caller, target, service
60 caller = command_caller
61 target = command_target
62 service = command_service
63 return 0;
64
65 def command_clear(self):
66 """ Clear convenience defaults"""
67 global caller, target, service
68 caller = None
69 target = None
70 service = None
71 return 0;
72
73
74 class handler:
75 """ Handle callbacks """
76
77 def init(): # not to be confused with __init__!
78 print "DEBUG: This is x3init in python"
79 return 0
80
81 def join(self, channel, nick)
82 user = svc.get_user(nick)
83 irc.send_target_privmsg("x3", channel, "test %s "%(service))
84
85 #+print "This is mod-python.py"
86 #+
87 #+caller = ''
88 #+target = ''
89 #+service = ''
90 #+
91 #+def handle_init():
92 #+ print "This is x3init in python"
93 #+ return 0
94 #+
95 #+
96 #+def handle_join(channel, nick):
97 #+ global caller, target, service
98 #+ print "This is handle_join() in python"
99 #+ user = svc.get_user(nick)
100 #+ svc.send_target_privmsg("x3", channel, "test %s "%(service))
101 #+ svc.send_target_privmsg("x3", channel, " %s joined %s: %s"%(nick, channel, user))
102 #+ svc.send_target_privmsg("x3", channel, "Welcome to %s %s (*%s)! Your IP is %s. You are now in %d channels!"%(channel, user['nick'], user['account'], user['ip'], len(user['channels']) ))
103 #+ chan = svc.get_channel(channel)
104 #+ svc.send_target_privmsg("x3", channel, "Channel details: %s"%chan)
105 #+ return 0
106 #+
107 #+def run(command):
108 #+ eval(command)
109 #+ return 0
110 #+
111 #+def reply(message):
112 #+ global caller, target, service
113 #+ print "DEBUG: %s / %s / %s : %s" %(caller, target, service, message);
114 #+ if(len(target) > 0):
115 #+ svc.send_target_privmsg(service, target, "%s: %s"%(caller, message));
116 #+ else:
117 #+ svc.send_target_notice(service, caller, message);
118 #+ return 0