% Allows channel flipping. % We like channel flipping. typedef struct{nick,server} FlipT_Type; private variable flip_targets = make_list(); private define flip_display() { variable i, p0, p; variable display = NullString; p0 = flip_targets.f; p = p0; for(i = 0; i < 12; i++) { if (p == NULL) break; if(strlen(display)) display = strcat(display, " | "); display = strcat(display, sprintf("F%d - %s", i + 1, p.v.nick)); p = p.n; if (p == p0) break; } irc_set_top(display); irc_update_display(); } define f_keypress(which) { variable p; p = s_nth(flip_targets, which - 0x201); if (p != NULL) { irc_set_target(p.v.nick); % sjb: 6/99 commented next line out for now, because it messes /server change % p.v.server is still at the old disconnected value, needs work % irc_set_servername(p.v.server); irc_change_window(irc_which_window(irc_target, "", p.v.server)); } } % Global, called from dcc.sl define flip_put(targ) { variable p,ft; (targ, ) = v_split(targ, " "); if (targ == NullString) return; % also, don't want ourself as a target: if(streq_i(irc_nickname,targ)) return; p = s_find_n1(flip_targets.f, &NC0_cmp, targ); if (p != NULL) return; % If we're adding a channel, add a window. if(is_channel(targ)) { irc_create_window(targ, targ, "", irc_servername); irc_change_window(targ); } else { % Otherwise, we'll add messages to this nick to our Messages window. irc_create_window("Messages", targ, "", ""); if("Messages" != irc_which_window(irc_nickname, "", "")) irc_create_window("Messages", irc_nickname, "", ""); } % irc_Logf(" FP3 %s",targ); irc_update_display(); ft = @FlipT_Type; ft.nick = targ; ft.server = irc_servername; %irc_Inff("$ flip_put added %s", ft.nick); () = s_putlast(flip_targets, ft); flip_display(); } % PART,QUIT,NICK trigger this: % Note, we don't destroy the window, yet... define flip_remove(s) { variable p,x; s = strcompress(s," ,"); %irc_Inff("$ flip_remove %s", s); foreach (strchop(s,' ',0)) { x = (); p = s_find_n1(flip_targets.f, &NC0_cmp, x); if (p != NULL) { %irc_Inff("$ flip_removed %s", p.v.nick); s_del(p); flip_display(); } } } private define setup_flip() { variable which; irc_log("[Flip] Version 0.11.0 ALPHA loading."); for(which = 1; which < 13; which++) { () = irc_set_keysym(0x200 + which, "f_keypress", 1); } flip_display(); % irc_create_window("Messages", irc_nickname, "", ""); % irc_Inff("A message from THP to %s on server %s should go to %s.", % irc_nickname, % irc_servername, % irc_which_window(irc_nickname, "THP", irc_servername) % ); } define cmnd_flip_LIST(dummy) { variable i, p0, p, which; p0 = flip_targets.f; p = p0; for(i = 0; i < 12; i++) { if(p == NULL) break; irc_Inff("F%d - %s", i + 1, p.v.nick); p = p.n; if(p == p0) break; } } define cmnd_flip_ADD(targ) { flip_put(targ); if (strspn(targ,"#&")) !if (is_list_element(on_chans,strlow(targ),' ')) irc_info("Warning: you have not /JOIN'd this channel!",targ); } define cmnd_flip_DEL(targ) { variable i,p; if (targ == NullString) { targ = irc_target; if (strspn(targ,"#&")) return; } if (is_digits(targ)) { i = integer(targ) - 1; if ((i >= 0) and (i < 12)) { p = s_nth(flip_targets,i); if (p != NULL) { s_del(p); flip_display(); return; } } } flip_remove(targ); } add_cmnd("query"); define command_QUERY(text) { variable targ; (targ,) = v_split(strtrim(text)," "); !if(strspn(targ,"#&")) flip_put(targ); } add_cmnd("flip"); define command_FLIP(text) { variable function, command, rest; (command,rest) = v_split(text," "); if (command == NullString) command = "LIST"; command = strup(command); rest = strtrim(rest); function = "cmnd_flip_" + command; if(is_defined(function)) { rest; eval(function); } else { irc_Inff("[DCC] Unknown /FLIP subcommand %s", command); } } define PUwin_list(key, n, s) { variable win; if(key == 0x0d) { % Switch to window. (, win) = v_split(s, " "); irc_change_window(win); } else if(key == 'd') { (, win) = v_split(s, " "); irc_destroy_window(win); } else if(key == 'm') { (, win) = v_split(s, " "); irc_change_mini(win); } irc_destroy_popup(); } % % This could be done better. % define cmnd_win_LIST(text) { variable puff = ""; variable noogie; variable winlist; variable mywinlist = ""; winlist = irc_get_winlist(); while(int(winlist)) { (noogie, winlist) = v_split(winlist, " "); !if(is_list_element(mywinlist, substr(noogie, 2, strlen(noogie)), ' ')) { puff += sprintf("%s %s\n", substr(noogie, 1, 1), substr(noogie, 2, strlen(noogie))); if(int(mywinlist)) mywinlist += " "; mywinlist += substr(noogie, 2, strlen(noogie)); } } if(int(puff)) irc_create_popup("Window-List", puff, "PUwin_list"); } add_cmnd("win"); define command_WIN(text) { variable function, command, rest; (command,rest) = v_split(text," "); if (command == NullString) command = "LIST"; command = strup(command); rest = strtrim(rest); function = "cmnd_win_" + command; if(is_defined(function)) { rest; eval(function); } else { irc_Inff("[FLIP] Unknown /WIN subcommand %s", command); } } private define flip_response_msg() { variable target; (target, ) = v_split(action_param, " "); if(strspn(target,"#&")) flip_put(action_param); else flip_put(extract_nick(action_param)); return 0; } register_cmd_action("MSG", &flip_response_msg); private define flip_response_privmsg() { variable target = Rpms[2]; if(strspn(target,"#&")) flip_put(Rpms[2]); else flip_put(extract_nick(Rpms[0])); return 0; } register_action("PRIVMSG", &flip_response_privmsg); private define flip_response_join() { variable nick; (nick, ) = v_split(Rpms[0], "!"); if(streq_i(nick,irc_nickname)) { %irc_Logf("-JOIN %s",Rpms[2]); irc_update_display(); flip_put(Rpms[2]); %irc_Logf("+JOIN %s",Rpms[2]); irc_update_display(); } return 0; } register_action("JOIN", &flip_response_join); private define flip_response_part() { flip_remove(action_param); return 0; } register_cmd_action("PART", &flip_response_part); private define flip_response_quit() { flip_remove(extract_nick(Rpms[0])); return 0; } register_action("QUIT", &flip_response_quit); register_action("NICK", &flip_response_quit); % Question: should KICK's also remove a flip-target? setup_flip();