-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathqwizmail.pm
162 lines (135 loc) · 3.13 KB
/
qwizmail.pm
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#!/usr/local/bin/perl5
#=--------------------------------------=
# Quizbot - qwizmail.pm
# Copyright (C) Ed Halley and other authors.
#
# This program is free software. You may use, modify, and distribute it
# under the terms of the Perl Artistic license, avialible on the world
# wide web at:
# http://www.perl.com/pub/a/language/misc/Artistic.html
# and included in the file LICENSE.
#
# $Id: $
#
#=--------------------------------------=
@gmails = ();
#----------------------------------------------------------------------------
sub readmail
{
local($filename) = @_;
if (!open(INFO, $filename))
{
print "Cannot read $filename.\n";
return 0;
}
my @gmaillist = <INFO>;
close(INFO);
my $newg = 0;
foreach $gmailline (@gmaillist)
{
$gmailline =~ s/\n//;
$gmailline =~ s/\r//;
if ($gmailline eq '') { next; }
if ($gmailline =~ /^\s*#/) { next; }
my($to,$from,$when,$message) = split(/\º/, $gmailline);
$gmails[++$#gmail] = $gmailline;
$newg++;
}
return $newg;
}
sub writemail
{
local($filename) = @_;
if (!open(INFO, ">$filename"))
{
print "Cannot write $filename.\n";
return 0;
}
my $wrote = 0;
my $now = time();
foreach $gmail (@gmails)
{
my($to,$from,$when,$message) = split(/\º/, $gmail);
if (!isplayer($to)) { next; }
if (($when + (60*60*24*14)) < $now) { next; }
print INFO $gmail . "\n";
$wrote++;
}
close(INFO);
return $wrote;
}
#----------------------------------------------------------------------------
sub isgmailwaiting
{
local($nick) = @_;
foreach $gmail (@gmails)
{
my($to,$from,$when,$message) = split(/\º/, $gmail);
if (lc($to) eq lc($nick))
{ return 1; }
}
return 0;
}
sub delivergmail
{
local($nick,$limit) = @_;
$limit = 5 if !defined($limit);
my $now = time();
my $read = 0;
foreach $imail (0 .. $#gmails)
{
my $gmail = $gmails[$imail];
my($to,$from,$when,$message) = split(/\º/, $gmail);
if (lc($to) eq lc($nick))
{
my $ago = describetimespan($now - $when);
my $age = "${__kolor}3";
if (($now - $when) >= (60*60)) { $age = "${__kolor}7"; }
if (($now - $when) >= (60*60*24)) { $age = "${__kolor}4"; }
$age .= $__bold . $__bold;
&NOTICE($to, "from ${__kolor}3$from$__kolor/$age$ago ago$__kolor/$message");
$read++;
splice(@gmails, $imail, 1);
$limit--;
if ($limit <= 0)
{
&NOTICE($to, "(more messages; wait a few moments and !gmail again to read more)");
last;
}
if ($#gmails >= $imail) { redo; }
}
}
}
sub postgmail
{
local($to,$from,$message) = @_;
my $when = time();
if ($to eq '*')
{
$message = '4Mass Gmail: '.$message;
foreach $nick (keys %players)
{
postgmail($nick,$from,$message);
}
}
if ($to eq '@')
{
$message = '4Mass Op Message: '.$message;
foreach $nick (keys %players)
{
my @player = getplayer($nick);
if ($player[$sFlags] !~ /o/) { next; }
postgmail($nick,$from,$message);
}
}
elsif (isplayer($to))
{
$gmails[++$#gmail] = join("\º", $to, $from, $when, $message);
if (ircispresent($to))
{
&NOTICE($to, "New gmail from $from. Use !gmail to read your waiting gmail.");
}
}
}
#----------------------------------------------------------------------------
1;