################################################################ # ignore.irc # Description: Extended ignore functions for jIRCii # Version : 1.0 # Author : blue-elf (j3pr0x@gmail.com) # * updated for jIRCii b41 by `butane * ################################################################ # # /ignore [-pcnt[N]] [M] # Ignores with [pcnt] flags for [N] seconds with hostmask type [M] # # Examples: # # /ignore -t10 *!*@*.tm.net.my # Ignores CTCPs from all *!*@*.tm.net.my users for 10 seconds # # /ignore -pn30 *!*@*.aol.com # Ignores private messages and notices from *!*@*.aol.com users for 30 seconds # # /ignore -pc *!*@*.hick.org # Ignores all private messages and channel messages from *!*@*.hick.org users. # This is will not expire. # # /ignore butane 2 # Looks up butane's hostmask and ignores *!*@address type. # # /ignore -p [Serge] 3 # Looks up [Serge]'s hostmask type 3 and ignores private messages. # # /unignore # Removes from the ignore list # # /ignorelist # Shows the ignore list # ################################################################ alias ignorelist { # This isn't really complicated. It's just extremely wordy/verbose. import java.awt.*; import javax.swing.*; import javax.swing.table.*; $ignore_window = [new JFrame:"Ignore List"]; [$ignore_window setDefaultCloseOperation: [JFrame DISPOSE_ON_CLOSE]]; [$ignore_window setLayout: [new BorderLayout]]; [$ignore_window setSize: 600, 300]; [$ignore_window setLocationRelativeTo: $null]; $ignore_frame = [$ignore_window getContentPane]; $ignore_model = [new DefaultTableModel]; $ignore_table = [new JTable: $ignore_model]; [$ignore_table setModel: $ignore_model]; $ignore_scroll = [new JScrollPane: $ignore_table]; [$ignore_frame add: $ignore_scroll, [BorderLayout CENTER]]; [$ignore_model addColumn: "Hostmask"]; [$ignore_model addColumn: "Flags"]; local('@l'); @l = keys(%IGNORE_LIST); if (size(@l)) { map({ [$ignore_model addRow: array($1, %IGNORE_LIST[$1])]; }, @l); } for ($i = 0; $i < 300; $i++) { [$ignore_model addRow: array('','')]; } # Filler [Serge] :P $ignore_sidepanel = [new JPanel]; [$ignore_frame add: $ignore_sidepanel, [BorderLayout EAST]]; $ignore_status = [new JTextField]; [$ignore_status setEditable: false]; [$ignore_status setText:"Flags available\: pcnti \(private, channel, notice, ctcp, invite\)"]; [$ignore_frame add: $ignore_status, [BorderLayout SOUTH]]; [$ignore_sidepanel setLayout: [new BorderLayout]]; $ignore_upper = [new JPanel]; [$ignore_upper setLayout: [new FlowLayout:[FlowLayout CENTER]]]; $ignore_lower = [new JPanel]; [$ignore_lower setLayout: [new BoxLayout: $ignore_lower, [BoxLayout Y_AXIS]]]; [$ignore_lower setBorder: [BorderFactory createEmptyBorder: 2, 5, 2, 2]]; [$ignore_sidepanel add: [new JLabel:" "], [BorderLayout NORTH]]; # Filler [$ignore_sidepanel add: $ignore_upper, [BorderLayout CENTER]]; [$ignore_sidepanel add: $ignore_lower, [BorderLayout SOUTH]]; local('$dim $b'); $dim = [new Dimension: 75, 25]; $ignore_del = [new JButton:"Delete"]; [$ignore_del addActionListener: lambda({ this('$sel'); $sel = [$ignore_table getSelectedRow]; if ($sel ne "-1") { [$ignore_model removeRow: $sel]; } })]; [$ignore_del setPreferredSize: $dim]; [$ignore_del setMaximumSize: $dim]; [$ignore_del setMinimumSize: $dim]; [$ignore_upper add: $ignore_del]; $ignore_buttonOK = [new JButton:"Ok"]; [$ignore_buttonOK addActionListener: &ignoreOK]; $ignore_buttonCancel = [new JButton:"Cancel"]; [$ignore_buttonCancel addActionListener: lambda({ [$ignore_window dispose]; })]; $temp = [new JLabel: " "]; [$temp setFont:[new Font: "Arial", [Font PLAIN], 2]]; foreach $b (array($ignore_buttonOK, $ignore_buttonCancel)) { [$b setPreferredSize: $dim]; [$b setMaximumSize: $dim]; [$b setMinimumSize: $dim]; [$ignore_lower add: $temp]; # Filler [$ignore_lower add: $b]; } [$ignore_window show]; } sub ignoreOK { clear(%IGNORE_LIST); local('$total_ignores $row $entry $flags'); $total_ignores = [$ignore_model getRowCount]; # Total rows/lines if ($total_ignores == 0) { [$ignore_window dispose]; return; } for ($row = 0; $row < $total_ignores; $row++) { $entry = [$ignore_table getValueAt: $row, 0]; # table.getValueAt(int row, int col); $flags = [$ignore_table getValueAt: $row, 1]; if ($entry && $flags) { %IGNORE_LIST[$entry] = $flags; } } [$ignore_window dispose]; } menu nicklist { menu "&Ignore" { addItem("&Messages", "/ignore -p $1 2"); addItem("&Channel" , "/ignore -c $1 2"); addItem("C&TCP" , "/ignore -t $1 2"); addItem("&Notices" , "/ignore -n $1 2"); addItem("&Invites" , "/ignore -i $1 2"); addSeparator(); addItem("&All", "/ignore -pcnti $1 2"); } } # /ignore [-pcntiN] [type] alias ignore { # Catch errors. if (!$1 || ('-*' iswm $1 && !$2)) { ignore_error("Insufficient"); return; } if (-isnumber $1) { ignore_error("Invalid"); return; } # Ignore proper. if ($1 && !$2) { ignore_add($1, 'pcnti', 0); } else if ($1- ismatch '^\-([pcnti\d]+)\s(\S+)\s*(\d*)$') { # /ignore <-flags> [N] local('$flags $entry $mtype $type $time'); ($flags, $entry, $mtype) = matched(); $type = replace($flags, '[^a-z]', ''); $time = replace($flags, '[^\d]', ''); if ('*!*@*' iswm $entry) { ignore_add($entry, $type, $time); } else if (-isnumber $mtype) { %IGNORE_TEMPMASK[$entry] = $mtype; %IGNORE_TEMPTYPE[$entry] = $type; %IGNORE_TEMPTIME[$entry] = $time; sendRaw("USERHOST $entry"); wait ($event == 302) { local('$addr $user'); $addr = replace(replace(replace($parms, '\=(\+|\-)', '!'), '\*', ''), '\s', ''); $user = split('!', $addr)[0]; $addr = mask($addr, %IGNORE_TEMPMASK[$user]); ignore_add($addr, %IGNORE_TEMPTYPE[$user], %IGNORE_TEMPTIME[$user]); remove(%IGNORE_TEMPTIME, $user); remove(%IGNORE_TEMPTYPE, $user); halt; } } } else if (-isnumber $2) { call("/ignore -pcnti $1-"); } # /ignore else { call("/ignore $1"); } } sub ignore_error { echoStatus("*** /ignore: $1 parameters"); } # ignore_add(entry, flags or type, duration); # 0 duration means permanent. sub ignore_add { local('$entry $undo $str $s'); $entry = $1; if ('*!*@*' !iswm $1) { $entry = $1 . "!*@*"; } $str = "Added $entry to ignore list"; %IGNORE_LIST["$entry"] = $2; if ($3) { $s = iff($3 <= 1, 2, $3); $undo = addTimer(&ignore_rem, $s * 1000, 1, $entry); $str = $str . " for $s seconds"; } echoStatus("*** $str"); } # /unignore alias unignore { if ($1) { ignore_rem($1); } } sub ignore_rem { if (%IGNORE_LIST[$1] ne '') { remove(%IGNORE_LIST, $1); echoStatus("*** Removed $1 from ignore list"); } } on raw { local('$regex'); $regex = '^\:(\S+)\s(PRIVMSG|NOTICE|INVITE)+\s(\S+)\s\:(.*)$'; if ($parms ismatch $regex) { local('@list $addr $type $targ $text $flags'); ($addr, $type, $targ, $text) = matched(); if (substr($text, 0, 1) eq chr(01) && substr($text, 1) ne 'ACTION') { $flags = 't'; } else { if ($type eq 'PRIVMSG') { $flags = iff($targ eq $me, 'p', 'c'); } else if ($type eq 'INVITE') { $flags = 'i'; } else if ($type eq 'NOTICE') { $flags = 'n'; } } if (is_ignore($addr, $flags)) { halt; } } } # is_ignore(fulladdress, pcnti) sub is_ignore { local('$key $v'); foreach $key (keys(%IGNORE_LIST)) { $v = %IGNORE_LIST[$key]; if (($key iswm $1 || $1 eq $key) && ($2 isin $v || $v eq 'a')) { return 1; } } return 0; } on exit { $ifile = openf("> ignore.dat"); map({ println($ifile, "$1 " . %IGNORE_LIST[$1]); }, keys(%IGNORE_LIST)); closef($ifile); } sub ignore_load { local('$f $f $file @data $line'); $f = "ignore.dat"; if (!-isFile $f || !-canread $f) { return; } $file = openf($f); @data = readAll($file); closef($file); if (size(@data) == 0) { return; } foreach $line (@data) { @temp = split(' ', $line); %IGNORE_LIST[@temp[0]] = @temp[1]; } } ignore_load(); # EOF