|
|
#!/usr/local/bin/expect
# Usage: screen myparty chanName
# If chanName is omitted then default's to party.
# :help or :h for help.
# Create a .ignore file.
# To be done:
# 1. Has to be started via screen else robocop kills it! Prevent this but how?
# ---- CHANGE THIS ----
set ignoreFile "~/.ignore";
set insultFile "~/.insult";
set user "snarf";
# END
set awayOnMsg "-- You are AWAY! --\n";
set awayOffMsg "-- Welcome back! --\n";
set filterOnMsg "-- Filtering is now ON --\n";
set filterOffMsg "-- Filtering is now OFF --\n";
set jlOnMsg "-- Filtering join/leave Messages --\n";
set jlOffMsg "-- Filtering join/leave Messages turned Off --\n";
set bell "\007";
set ignoreList "";
set filter 0; #If 1 Filtering.
set away 0; #If 1 AWAY.
set jlmesgs 0; #If 1 discard join/leave messages.
set chanName [lindex $argv 0];
proc ClearScreen {} {
for {set count 45} {$count > 0} {incr count -1} {
send_user "\n";
}
}
proc SendBell {} {
global bell;
send -- " $bell\r";
}
proc SetVar {varname varstate varmesg} {
global $varmesg;
global $varname;
eval set varmesg $$varmesg;
if { $varstate == "off" } { set $varname 0; send_user -- "$varmesg";
return; } set $varname 1; send_user -- "$varmesg";
}
proc IsVar {varname} {
global $varname;
eval set varname $$varname;
if { $varname == 1 } { return 1; }
return 0;
}
proc AwayStatus {} {
global away;
send_user -- "Away is $away\n";
}
proc FilterStatus {} {
global filter;
send_user -- "Filter is $filter\n";
}
proc ignoreUser {name mesg filterLevel attackLevel line} {
global user;
switch -- "$filterLevel" \
"0" {
send_user -- "$name: --Filtered lvl 0-- $mesg\n";
} "1" {
regsub -all "\[a-zA-Z]" $mesg "-" mesgSend;
send_user -- "$name: --Filtered lvl 1-- $mesgSend\n";
} "2" {
#Dont send anything for this lvl.
} "default" {
send_user "Filtered lvl default. Bug! Please report it: $line";
}
switch -- "$attackLevel" \
"0" {
#Dont send anything
} "1" {
if [regexp -nocase "$user" "$mesg"] {
send "The user $name is on my IGNORE list. I don't know what is being
said, and therefore can't refute any allegations being made.\n"; }
}
}
proc ProcessALinefromParty {line} {
global ignoreList;
global user;
set mesgname "";
set mesg "";
if { [IsVar jlmesgs] && [regexp "^(---)(.*)$" $line ignore ignore ignore]
} { return; }
regexp "^(\[^ ]+)(:.*)$" $line ignore mesgname mesg;
if { [IsVar away] } {
if [regexp -nocase "$user" $mesg] { send -- " -- $user is AWAY. The
mice will play --\n"; }
}
if { [IsVar filter] } {
foreach element $ignoreList {
if { [string compare $mesgname [lindex $element 0]] == "0" } {
ignoreUser [lindex $element 0] $mesg [lindex $element 1] [lindex
$element 2] $line; return; }
}
}
send_user -- "$line";
}
proc ListIgnore {} {
global ignoreList;
send_user -- "$ignoreList\n";
}
proc Help {} {
send_user --
"\n\n--------------------------------------------------------\n";
send_user -- "Expect script for the party program.\n\n";
send_user -- ":cls Clear Screen\n";
send_user -- ":aoff or :aon toggles Away message On and Off.\n";
send_user -- ":foff or :fon toggles Filtering On and Off.\n\n";
send_user -- ":ignore userName:FilterLevel:AttackLevel.\n";
send_user -- "FilterLevel 0,1,3(FilterOff,Filter--,Nothing\n";
send_user -- "AttackLevel 0,1 (AttackOff,NukeDisclaimer\n";
send_user --
"\n--------------------------------------------------------\n\n";
send -- ":h\n";
}
proc SetIgnore {firstChar firstWord restOfLine line} {
global ignoreList;
set count 0;
set ignoreArgs "";
set restOfLine [string trim $restOfLine " "];
regsub -all ":" $restOfLine " " restOfLine;
foreach element $ignoreList {
if { [string compare [lindex $restOfLine 0] [lindex $element 0]] == "0"
} { send_user -- "Changed $ignoreList to $restOfLine\n"; set ignoreList
[lreplace $ignoreList $count $count $restOfLine]; }
incr count 1;
}
}
proc ProcessColonCmd {firstChar firstWord restOfLine line} {
switch -- "$firstWord" \
"foff" {
SetVar filter off filterOffMsg;
} "fon" {
SetVar filter on filterOnMsg;
} "cls" {
ClearScreen;
} "ignore" {
SetIgnore $firstChar $firstWord $restOfLine $line;
} "lignore" {
ListIgnore;
} "aon" {
SetVar away on awayOnMsg;
} "aoff" {
SetVar away off awayOffMsg;
} "astat" {
AwayStatus;
} "fstat" {
FilterStatus;
} "jlon" {
SetVar jlmesgs on jlOnMsg;
} "jloff" {
SetVar jlmesgs off jlOffMsg;
} "bl" {
SendBell;
} "help" {
Help;
} "h" {
Help;
} default {
send -- "$line\r";
}
}
proc ProcessTailbackCmd {firstChar firstWord restOfLine line} {
SetVar filter off filterOffMsg;
SetVar away off awayOffMsg;
send -- "$line\r";
}
proc ProcessBang {firstChar firstWord restOfLine line} {
SetVar filter off filterOffMsg;
send -- "$line\r";
}
proc ProcessALinefromKybrd {line} {
set firstChar "";
set firstWord "";
set restOfLine "";
regexp "^(.)(\[^ ]+)(.*)$" $line ignore firstChar firstWord restOfLine;
# send_user -- "$firstChar $firstWord $restOfLine\r\r\n";
switch -- "$firstChar" \
":" {
ProcessColonCmd $firstChar $firstWord $restOfLine $line;
} "-" {
ProcessTailbackCmd $firstChar $firstWord $restOfLine $line;
} "!" {
ProcessBang $firstChar $firstWord $restOfLine $line;
} default {
send -- "$line\r";
}
}
proc Close {} { exit; }
proc Interact {} {
interact {
-echo -re "(\[^\r]+)\r" { ProcessALinefromKybrd $interact_out(1,string); }
-o
-re "(\[^\r]*)\r\n" { ProcessALinefromParty $interact_out(0,string); }
}
}
proc InitPartyScreen {} {
global spawn_id;
set InitScreen ":back 50\n:w\n";
SetVar filter off filterOffMsg;
send $InitScreen;
}
proc SpawnParty {chanName} {
global spawn_id;
if { $chanName == "" } {
spawn party_ #test;
} else {
spawn party_ #$chanName;
}
}
proc InitIgnoreList {} {
global ignoreList, ignoreFile;
set ignoreFileH [open $ignoreFile r];
#Ignore File format
#Name:FilterLevel:AttackLevel
#FilterLevel: 0-NoFilter, 1-Dashed, 3-Nothing
#AttackLevel: 0-Peace, 1-Disclaimer on Assault, 3-Disc+Insult,4-Nuke
while 1 {
if { [gets $ignoreFileH line] == -1 } break;
set line [split $line ":"];
set name [lindex $line 0];
set filterLevel [lindex $line 1];
set attackLevel [lindex $line 2];
#Link local ignoreList to global ignoreList
upvar ignoreList ignoreList;
lappend ignoreList [list $name $filterLevel $attackLevel];
}
}
InitIgnoreList;
SpawnParty $chanName;
InitPartyScreen;
Interact;
Close;
0 responses total.
Response not possible - You must register and login before posting.
|
|
- Backtalk version 1.3.30 - Copyright 1996-2006, Jan Wolter and Steve Weiss