def _join(frame, cmd, args, args_eol): """/join CHANNEL Join channel CHANNEL. """ if len(args) == 1: frame.client.join(args[0]) else: kaechatlib.usage(frame, cmd, "Missing channel.")
def _nick(frame, cmd, args, args_eol): """/nick NICKNAME Change your nickname to NICKNAME. """ if len(args) == 1: frame.client.nick(args[0]) else: kaechatlib.usage(frame, cmd, "Missing nickname.")
def _recv(frame, cmd, args, args_eol): """/recv TEXT Make the client handle TEXT as if it was received from the server. """ if len(args) < 1: kaechatlib.usage(frame, cmd, "Missing parameter.") return frame.client.on_received(unicode(args_eol[0]))
def _quote(frame, cmd, args, args_eol): """/quote TEXT Send raw protocol text to the server. """ if len(args) < 1: kaechatlib.usage(frame, cmd, "Missing parameter.") else: frame.client.send(args_eol[0])
def _say(frame, cmd, args, args_eol): """/say TEXT Send TEXT to the current channel. Useful for macros. """ if len(args) < 1: kaechatlib.usage(frame, cmd, "Missing parameter.") return frame.echo(args_eol[0], who=frame.client.nickname) frame.client.privmsg(frame.cur_channel, args_eol[0])
def _msg(frame, cmd, args, args_eol): """/msg (NICKNAME|CHANNEL) MESSAGE Send a message to a channel or an user. """ if len(args) >= 2: frame.client.privmsg(args[0], args_eol[1]) frame.echo(args_eol[1], who=frame.client.nickname, channel=args[0], event=kaechatlib.MESSAGE_EV) else: kaechatlib.usage(frame, cmd, "Missing parameter.")
def _whois(frame, cmd, args, args_eol): """/whois NICKNAME... Get information about NICKNAME(s). """ if len(args) < 1: kaechatlib.usage(frame, cmd, "Missing nickname.") else: for name in args: frame.client.whois(name)
def _help(frame, cmd, args, args_eol): """/help [COMMAND] Get help on COMMAND, or a short description of all commands if none is specified. """ if len(args) == 1: kaechatlib.usage(frame, args[0], full=True) else: for name in sorted(kaechatlib.chat_commands.keys()): kaechatlib.usage(frame, name, prefix="")
def _server(frame, cmd, args, args_eol): """/server NET_ID Connect to the network whose ID is NET_ID. """ if len(args) < 1: kaechatlib.usage(frame, cmd, "Missing parameter.") return if args[0] in kaechatlib.networks: kaechatlib.mainframe.connect(args[0]) else: frame.echo("Unknown network `%s'." % args[0])
def _nctcp(frame, cmd, args, args_eol): """/nctcp NICKNAME MESSAGE Send a CTCP notice. This is usually used to reply to a previous CTCP query. """ if len(args) < 2: kaechatlib.usage(frame, cmd, "Missing parameter.") return elif args[0][0] in kaeirc.CHANNEL_PREFIXES: kaechatlib.usage(frame, cmd, "/NCTCP may not be used on channels.") return frame.client.notice(args[0], "\1%s\1" % args_eol[1])
def _me(frame, cmd, args, args_eol): """/me ACTION Send a message as if performing an action. """ if len(args) < 1: kaechatlib.usage(frame, cmd, "Missing parameter.") else: frame.client.privmsg_ctcp(frame.cur_channel, "ACTION %s" % args_eol[0]) frame.echo( args_eol[0], who=frame.client.nickname, channel=frame.cur_channel, prefix="* ", event=kaechatlib.MESSAGE_EV )
def _set_user_mode(frame, cmd, args, args_eol, mode): if len(args) < 1: kaechatlib.usage(frame, cmd, "Missing parameter.") return if args[0][0] in kaeirc.CHANNEL_PREFIXES: channel = args[0] nicks = args[1:] if len(nicks) < 1: usage(frame, cmd, "Missing parameter.") return else: channel = frame.cur_channel nicks = args for nick in nicks: frame.client.mode(channel, mode, nick)
def _set_ban(frame, cmd, args, args_eol, do_set): if len(args) < 1: kaechatlib.usage(frame, cmd, "Missing parameter.") return False if args[0][0] in kaeirc.CHANNEL_PREFIXES: if len(args) < 2: kaechatlib.usage(frame, cmd, "Missing parameter.") return False channel, mask = args[0:2] else: channel = frame.cur_channel mask = args[0] if not (('!' in mask) or ('@' in mask)): mask += "!*@*" frame.client.mode(channel, "+b" if do_set else "-b", mask) return True
def _ping(frame, cmd, args, args_eol): """/ping NICKNAME Measure the time it takes for NICKNAME's client to respond back. """ if len(args) < 1: kaechatlib.usage(frame, cmd, "Missing parameter.") return elif args[0][0] in kaeirc.CHANNEL_PREFIXES: kaechatlib.usage(frame, cmd, "/ping cannot be used on channels.") return global ping_handler if ping_handler is None: ping_handler = PingHandler(frame) frame.client.add_listener(ping_handler) ping_handler.sent[args[0]] = time.clock() # TODO: Use some other number. frame.client.privmsg(args[0], "\1PING 12345678\1")
def _sh(frame, cmd, args, args_eol): """/sh [(-t TIMEOUT|-c CHANNEL|-s)] COMMAND Run COMMAND in the system shell and print it's output to a channel. If `-t TIMEOUT' is specified, it's the number of seconds to wait for the \ process. If the process takes more than TIMEOUT, it's killed. If not \ specified, defaults to 10 seconds, to avoid accidental runs of long running \ programs. If `-c CHANNEL' is specified, output goes to CHANNEL (note that the output is \ only "echoed" to the textbox; it's not actually sent to the server, unless \ `-s' is specified. If not specified, sends to '(shell)' channel. If `-s' is specified, and a (non-special) CHANNEL was specified, the output \ of the COMMAND is sent as messages to the channel. WARNING: BE CAREFUL WITH \ THIS OPTION! YOU CAN EASILY GET YOU BANNED FROM CHANNELS, AND EVEN NETWORKS \ IF THE COMMAND YOU RUN FLOODS WITH OUTPUT! Only use for commands with short \ output like `uname', `uptime', etc. In particular, DON'T EVEN THINK ABOUT \ RUNNING PROGRAMS LIKE `yes'! """ timeout = 10 channel = "(shell)" send = False i = 0 while i < len(args): a = args[i] if a == "-t": i += 1 if i >= len(args): kaechatlib.usage(frame, cmd, "Missing parameter to `-t'.") return try: timeout = int(args[i]) except ValueError: kaechatlib.usage(frame, cmd, "Timeout must be an integer.") return elif a == "-c": i += 1 if i >= len(args): kaechatlib.usage(frame, cmd, "Missing parameter to `-c'.") return channel = args[i] elif a == "-s": send = True else: break i += 1 if i >= len(args): kaechatlib.usage(frame, cmd, "Missing command.") return command = args_eol[i] t = ShellThread(frame, timeout, channel, send, command) t.start()
def _kick(frame, cmd, args, args_eol): """/kick [CHANNEL] NICKNAME [REASON] Kick users from the channel. """ if len(args) < 1: usage(frame, cmd, "Missing parameter.") return if args[0][0] in kaeirc.CHANNEL_PREFIXES: channel = args[0] args = args[1:] if len(args) < 1: kaechatlib.usage(frame, cmd, "Missing parameter.") return else: channel = frame.cur_channel if len(args) >= 2: nickname, reason = args[0], args_eol[1] else: nickname, reason = args[0], args[0] frame.client.kick(channel, nickname, reason)
def _ctcp(frame, cmd, args, args_eol): """/ctcp NICKNAME QUERY Send a CTCP query. QUERY may be an arbitrary string, but some strings are handled specially: /ctcp ... ACTION <message> This is the same as using `/me <message>'. Use `/help me' for details. /ctcp ... VERSION Query NICKNAME's client version. /ctcp ... TIME Query NICKNAME's current time. """ if len(args) < 2: kaechatlib.usage(frame, cmd, "Missing parameter.") return elif args[0][0] in kaeirc.CHANNEL_PREFIXES: kaechatlib.usage(frame, cmd, "/CTCP may not be used on channels.") return frame.client.privmsg(args[0], "\1%s\1" % args_eol[1])