File: seen.pl

package info (click to toggle)
rccp 0.5-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 164 kB
  • ctags: 40
  • sloc: ansic: 827; sh: 127; perl: 112; makefile: 66
file content (89 lines) | stat: -rwxr-xr-x 2,304 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/perl -w
#its ugly but it works 
#seen script for CCCP by hampa@chello.se
#usage ./seen.pl [dctc client]
#basic example, just connect to running hub and start serving !seen nickname:
#./seen.pl 
#if you have severad hubs specify them like this
#./seen.pl <dctc client>
#<hubname> should be a substring of one of your running dctc clients

#dc clients can send bot private and public chat mesages
#if private the response from seen bot will be in private

#open a stream to catch !seen nickname
print "--=CCCP v0.1 seen script by hampa=--\n";

my $dctcname = "";
if($ARGV[0]){
	$dctcname = "-H $ARGV[0]";
	print "$dctcname\n";
}

open CCCP, "cccp -o -S $dctcname | tee -a dctc.log |" or die "cant start cccp or open dctc.log";


my $cccp_cmd = "";
while(<CCCP>){
	# catch querys 
	# CHAT ] "" <asker> !seen elvis
	if(/(PRIV|CHAT)\s\]\s\"\".*\|?<(.*)\>\s\!seen\s(.*)\|/){
		#print "priv output 1=$2  2 =$3\n";
		$priv = $1;
		$asker = $2;	
		$elvis = $3;
		if($t = seen_query($elvis)){
			$difftime = time - $t;
			$hours = int($difftime/3600);
			$minutes = int(($difftime%3600)/60);
			$seconds = $difftime%60;

			if($priv eq "PRIV"){
				$cccp_cmd = "-p \"*$asker*$elvis was last seen $hours hours $minutes minutes  and $seconds seconds ago\"\n";	
			}
			elsif($priv eq "CHAT"){
				$cccp_cmd = "-c \"$elvis was last seen $hours hours $minutes minutes  and $seconds seconds ago\"\n";	
			}
			else {
				print "wtf not PRIV not CHAT:$priv:\n";
				exit 1;
			}
			print $cccp_cmd;
			system("cccp -N -O $cccp_cmd");
		}
		else {
			if($priv eq "PRIV"){
				$cccp_cmd = "-p \"*$asker*havent seen $elvis\"\n";	
			}
			elsif($priv eq "CHAT"){
				$cccp_cmd = "-c \"*havent seen $elvis\"\n";	
			}
			else {
				print "wtf not PRIV not CHAT :$priv:\n";
				exit 1;
			}
			print "$cccp_cmd\n";
			system("cccp -N -O $cccp_cmd");
		}
	}
}

sub seen_query {
	my $time = 0;
	my $nick = $_[0];
	print $nick;

	open LOGFILE, "dctc.log" or die "Can't find logfile\n";
	while(<LOGFILE>){
		#if ((/^(\d{10})\|USER[\+\-]\]\s\"\"(.*)\|/) | (/^(\d{10})\|CHAT\s\]\s\"\"\<(.*)\>\s/) ) {
		if (
			(/^(\d{10})\|UINFO\]\s\"\"$nick\s/i) |
			(/^(\d{10})\|USER[\+\-]\]\s\"\"$nick\|/i) | 
			(/^(\d{10})\|CHAT\s\]\s\"\"\<$nick\>\s/i) ) {
			$time = $1;
			#print "time $1 nick $nick\n";
		}

	}
	return $time;
}