Add send and close built-ins
This commit is contained in:
parent
d7b4e198a5
commit
6607646c49
1 changed files with 78 additions and 8 deletions
86
prompt.py
86
prompt.py
|
|
@ -47,6 +47,9 @@ def launch(servers):
|
||||||
cmds = parsecmd(sys.stdin.readline().strip())
|
cmds = parsecmd(sys.stdin.readline().strip())
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
cmds = parsecmd("quit")
|
cmds = parsecmd("quit")
|
||||||
|
except:
|
||||||
|
exc_type, exc_value, exc_traceback = sys.exc_info()
|
||||||
|
sys.stdout.write (traceback.format_exception_only(exc_type, exc_value)[0])
|
||||||
if cmds is not None and len(cmds) > 0:
|
if cmds is not None and len(cmds) > 0:
|
||||||
try:
|
try:
|
||||||
ret = run(cmds, servers)
|
ret = run(cmds, servers)
|
||||||
|
|
@ -78,6 +81,20 @@ def load(cmds, servers):
|
||||||
print ("Not enough arguments. `load' takes an filename.")
|
print ("Not enough arguments. `load' takes an filename.")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def close(cmds, servers):
|
||||||
|
if len(cmds) > 1:
|
||||||
|
for s in cmds[1:]:
|
||||||
|
if s in servers:
|
||||||
|
servers[s].disconnect()
|
||||||
|
del servers[s]
|
||||||
|
else:
|
||||||
|
print ("close: server `%s' not found." % s)
|
||||||
|
elif selectedServer is not None:
|
||||||
|
selectedServer.disconnect()
|
||||||
|
del servers[selectedServer.id]
|
||||||
|
selectedServer = None
|
||||||
|
return
|
||||||
|
|
||||||
def select(cmds, servers):
|
def select(cmds, servers):
|
||||||
global selectedServer
|
global selectedServer
|
||||||
if len(cmds) == 2 and cmds[1] != "None" and cmds[1] != "nemubot" and cmds[1] != "none":
|
if len(cmds) == 2 and cmds[1] != "None" and cmds[1] != "nemubot" and cmds[1] != "none":
|
||||||
|
|
@ -114,6 +131,44 @@ def connect(cmds, servers):
|
||||||
else:
|
else:
|
||||||
print (" Please SELECT a server or give its name in argument.")
|
print (" Please SELECT a server or give its name in argument.")
|
||||||
|
|
||||||
|
def send(cmds, servers):
|
||||||
|
rd = 1
|
||||||
|
if len(cmds) <= rd:
|
||||||
|
print ("send: not enough arguments.")
|
||||||
|
return
|
||||||
|
|
||||||
|
if cmds[rd] in servers:
|
||||||
|
srv = servers[cmds[rd]]
|
||||||
|
rd += 1
|
||||||
|
elif selectedServer is not None:
|
||||||
|
srv = selectedServer
|
||||||
|
else:
|
||||||
|
print (" Please SELECT a server or give its name in argument.")
|
||||||
|
return
|
||||||
|
|
||||||
|
if len(cmds) <= rd:
|
||||||
|
print ("send: not enough arguments.")
|
||||||
|
return
|
||||||
|
|
||||||
|
#Check the server is connected
|
||||||
|
if not srv.connected:
|
||||||
|
print ("send: server `%s' not connected." % srv.id)
|
||||||
|
return
|
||||||
|
|
||||||
|
if cmds[rd] in srv.channels:
|
||||||
|
chan = cmds[rd]
|
||||||
|
rd += 1
|
||||||
|
else:
|
||||||
|
print ("send: channel `%s' not authorized in server `%s'." % (cmds[rd], srv.id))
|
||||||
|
return
|
||||||
|
|
||||||
|
if len(cmds) <= rd:
|
||||||
|
print ("send: not enough arguments.")
|
||||||
|
return
|
||||||
|
|
||||||
|
srv.send_msg_final(chan, cmds[rd])
|
||||||
|
return "done"
|
||||||
|
|
||||||
def disconnect(cmds, servers):
|
def disconnect(cmds, servers):
|
||||||
if len(cmds) > 1:
|
if len(cmds) > 1:
|
||||||
for s in cmds[1:]:
|
for s in cmds[1:]:
|
||||||
|
|
@ -128,6 +183,18 @@ def disconnect(cmds, servers):
|
||||||
else:
|
else:
|
||||||
print (" Please SELECT a server or give its name in argument.")
|
print (" Please SELECT a server or give its name in argument.")
|
||||||
|
|
||||||
|
def zap(cmds, servers):
|
||||||
|
if len(cmds) > 1:
|
||||||
|
for s in cmds[1:]:
|
||||||
|
if s in servers:
|
||||||
|
servers[s].connected = not servers[s].connected
|
||||||
|
else:
|
||||||
|
print ("disconnect: server `%s' not found." % s)
|
||||||
|
elif selectedServer is not None:
|
||||||
|
selectedServer.connected = not selectedServer.connected
|
||||||
|
else:
|
||||||
|
print (" Please SELECT a server or give its name in argument.")
|
||||||
|
|
||||||
def end(cmds, servers):
|
def end(cmds, servers):
|
||||||
if cmds[0] == "reset":
|
if cmds[0] == "reset":
|
||||||
return "reset"
|
return "reset"
|
||||||
|
|
@ -138,12 +205,15 @@ def end(cmds, servers):
|
||||||
|
|
||||||
#Register build-ins
|
#Register build-ins
|
||||||
CAPS = {
|
CAPS = {
|
||||||
'quit': end,
|
'quit': end, #Disconnect all server and quit
|
||||||
'exit': end,
|
'exit': end, #Alias for quit
|
||||||
'reset': end,
|
'reset': end, #Reload the prompt
|
||||||
'load': load,
|
'load': load, #Load a servers configuration file
|
||||||
'select': select,
|
'close': load, #Disconnect and remove a server from the list
|
||||||
'list': liste,
|
'select': select, #Select a server
|
||||||
'connect': connect,
|
'list': liste, #Show lists
|
||||||
'disconnect': disconnect,
|
'connect': connect, #Connect to a server
|
||||||
|
'send': send, #Send a message on a channel
|
||||||
|
'disconnect': disconnect, #Disconnect from a server
|
||||||
|
'zap': zap, #Reverse internal connection state without check
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue