]>
jfr.im git - irc/evilnet/x3.git/blob - src/modpython.py
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,
20 """Class to handle loading/unloading of modules"""
24 mod_name
= "plugins. %s " % name
25 if ( sys
. modules
[ mod_name
]):
27 #TODO: try to catch compile errors etc.
30 module
= sys
. modules
[ mod_name
]
32 reload ( module
) # to ensure its read fresh
33 self
. loaded_modules
[ mod_name
] = module
36 """Used to interact with the world of IRC from module scripts"""
38 # some defaults to make shorthand easy
43 def __init__ ( self
, service
= None , caller
= None , target
= None ):
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)
49 def send_target_privmsg ( self
, source
, target
, message
):
50 svc
. send_target_privmsg ( source
, target
, " %s " %(message))
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
)
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
65 def command_clear ( self
):
66 """ Clear convenience defaults"""
67 global caller
, target
, service
75 """ Handle callbacks """
77 def init (): # not to be confused with __init__!
78 print "DEBUG: This is x3init in python"
81 def join ( self
, channel
, nick
)
82 user
= svc
. get_user ( nick
)
83 irc
. send_target_privmsg ( "x3" , channel
, "test %s " %(service))
85 #+print "This is mod-python.py"
92 #+ print "This is x3init in python"
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)
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));
117 #+ svc.send_target_notice(service, caller, message);