1 |
#! perl |
2 |
|
3 |
# implement a replacement for the built-in chat/shout/tell/reply commands |
4 |
# adds ignore/unignore functionality |
5 |
|
6 |
cf::register_command chat => 0, sub |
7 |
{ |
8 |
my ($who, $msg) = @_; |
9 |
|
10 |
if ($msg) { |
11 |
my $name = $who->name; |
12 |
|
13 |
$_->ob->message ("$name chats: $msg", cf::NDI_BLUE) |
14 |
for grep !$player->ob->{ext_ignore_shout}, cf::player::list; |
15 |
|
16 |
} else { |
17 |
$who->message ("Chat what?", cf::NDI_UNIQUE); |
18 |
} |
19 |
}; |
20 |
|
21 |
cf::register_command shout => 0, sub |
22 |
{ |
23 |
my ($who, $msg) = @_; |
24 |
|
25 |
if ($msg) { |
26 |
my $name = $who->name; |
27 |
|
28 |
$_->ob->message ("$name shouts: $msg", cf::NDI_RED) |
29 |
for grep !$player->ob->{ext_ignore_shout}, cf::player::list; |
30 |
|
31 |
} else { |
32 |
$who->message ("Shout what?", cf::NDI_UNIQUE); |
33 |
} |
34 |
|
35 |
}; |
36 |
|
37 |
cf::register_command tell => 0, sub { |
38 |
my ($who, $args) = @_; |
39 |
my ($target, $msg) = split /\s+/, $args, 2; |
40 |
|
41 |
my $name = $who->name; |
42 |
|
43 |
if (my $other = cf::player::find $target) { |
44 |
|
45 |
$other->ob->{ext_ignore_tell}{$name} >= time |
46 |
or delete $other->ob->{ext_ignore_tell}{$name}; |
47 |
|
48 |
if ($target ne $name and !$other->ob->{ext_ignore_tell}{$name}) { |
49 |
$who->message ("You tell $target: $msg"); |
50 |
$other->ob->message ("$name tells you: $msg"); |
51 |
$other->ob->{ext_last_tell} = $name; |
52 |
} elsif ($target eq $name) { |
53 |
$who->message ("You are talking to yourself, you freak!", cf::NDI_UNIQUE); |
54 |
} else { |
55 |
$who->message ($other->ob->name . " ignores what you say. Give up on it.", cf::NDI_UNIQUE); |
56 |
} |
57 |
|
58 |
} else { |
59 |
$who->message ("No such player or ambiguous name. Your message: $msg", cf::NDI_UNIQUE); |
60 |
} |
61 |
}; |
62 |
|
63 |
cf::register_command reply => 0, sub { |
64 |
my ($who, $args) = @_; |
65 |
my $name = $who->name; |
66 |
|
67 |
if (my $other = cf::player::find $who->{ext_last_tell}) { |
68 |
|
69 |
$other->ob->{ext_ignore_tell}{$name} >= time |
70 |
or delete $other->ob->{ext_ignore_tell}{$name}; |
71 |
|
72 |
if (!$other->ob->{ext_ignore_tell}{$name}) { |
73 |
$who->message ("You tell " . $other->ob->name . ": $args"); |
74 |
$other->ob->message ("$name tells you: $args"); |
75 |
$who->{ext_last_tell} = $other->ob->name; |
76 |
} else { |
77 |
$who->message ($other->ob->name . " ignores what you say. Give up on it.", cf::NDI_UNIQUE); |
78 |
} |
79 |
|
80 |
} else { |
81 |
$who->message ("Can't reply, player left. Your message: $args", cf::NDI_UNIQUE); |
82 |
} |
83 |
}; |
84 |
|
85 |
cf::register_command ignore => 0, sub { |
86 |
my ($who, $args) = @_; |
87 |
my ($target, $type, $timeout) = split /\s+/, $args; |
88 |
|
89 |
if ($args eq "list") { |
90 |
if ((my @ignored_tell = sort keys %{$who->{ext_ignore_tell}}) |
91 |
+ (my @ignored_shout = sort keys %{$who->{ext_ignore_shout}})) { |
92 |
$who->message ("Currently ignoring private messages from: ", cf::NDI_UNIQUE); |
93 |
$who->message ((join ", ", @ignored_tell), cf::NDI_UNIQUE); |
94 |
$who->message ("Currently ignoring shouts from: ", cf::NDI_UNIQUE); |
95 |
$who->message ((join ", ", @ignored_shout), cf::NDI_UNIQUE); |
96 |
$who->message ("To stop ignoring one, use unignore.", cf::NDI_UNIQUE); |
97 |
} else { |
98 |
$who->message ("Not ignoring anyone", cf::NDI_UNIQUE); |
99 |
} |
100 |
|
101 |
} elsif ($target && $type) { |
102 |
|
103 |
$timeout ne "" or $timeout = 24; |
104 |
|
105 |
my $absolute_timeout = time + $timeout * 3600; |
106 |
|
107 |
if (my $other = cf::player::find $target) { |
108 |
if ($type eq "tell") { |
109 |
$who->message ("Now ignoring private messages from " . $other->ob->name . " for $timeout hours.", cf::NDI_UNIQUE); |
110 |
$who->{ext_ignore_tell}{$other->ob->name} = $absolute_timeout; |
111 |
} elsif ($type eq "shout") { |
112 |
$who->message ("Now ignoring shouts from " . $other->ob->name . " for $timeout hours.", cf::NDI_UNIQUE); |
113 |
$who->{ext_ignore_shout}{$other->ob->name} = $absolute_timeout; |
114 |
} elsif ($type eq "all") { |
115 |
$who->message ("Now ignoring everything from " . $other->ob->name . " for $timeout hours.", cf::NDI_UNIQUE); |
116 |
$who->{ext_ignore_tell}{$other->ob->name} = $absolute_timeout; |
117 |
$who->{ext_ignore_shout}{$other->ob->name} = $absolute_timeout; |
118 |
} else { |
119 |
$who->message ("You need to specify tell, shout or all.", cf::NDI_UNIQUE); |
120 |
} |
121 |
} else { |
122 |
$who->message ("No such player or ambiguous name: $target", cf::NDI_UNIQUE); |
123 |
} |
124 |
|
125 |
} else { |
126 |
$who->message ("Usage:", cf::NDI_UNIQUE); |
127 |
$who->message ("ignore <player> <tell | shout | all> <timeout>", cf::NDI_UNIQUE); |
128 |
$who->message ("will ignore a player for <timeout> hours.", cf::NDI_UNIQUE); |
129 |
$who->message ("ignore list", cf::NDI_UNIQUE); |
130 |
$who->message ("will show you a list of players currently ignored.", cf::NDI_UNIQUE); |
131 |
} |
132 |
}; |
133 |
|
134 |
cf::register_command unignore => 0, sub { |
135 |
my ($who, $args) = @_; |
136 |
my ($target, $type) = split /\s+/, $args; |
137 |
|
138 |
if ($args eq "") { |
139 |
if ($who->{ ext_ignore_tell }) { |
140 |
$who->message ("Currently ignoring private messages from: ", cf::NDI_UNIQUE); |
141 |
$who->message ((join ", ", sort keys %{ $who->{ext_ignore_tell} }), cf::NDI_UNIQUE); |
142 |
$who->message ("Currently ignoring shouts from: ", cf::NDI_UNIQUE); |
143 |
$who->message ((join ", ", sort keys %{ $who->{ext_ignore_shout} }), cf::NDI_UNIQUE); |
144 |
} else { |
145 |
$who->message ("Not ignoring anyone", cf::NDI_UNIQUE); |
146 |
} |
147 |
} else { |
148 |
|
149 |
if (my $other = cf::player::find $target) { |
150 |
if ($type eq "tell") { |
151 |
$who->message ("Not ignoring private messages from " . $other->ob->name . " anymore.", cf::NDI_UNIQUE); |
152 |
delete $who->{ext_ignore_tell}{$other->ob->name}; |
153 |
} elsif ($type eq "shout") { |
154 |
$who->message ("Not ignoring shouts from " . $other->ob->name." anymore . ", cf::NDI_UNIQUE); |
155 |
delete $who->{ext_ignore_shout}{$other->ob->name}; |
156 |
} elsif ($type eq "all") { |
157 |
$who->message ("Not ignoring anything from " . $other->ob->name." anymore . ", cf::NDI_UNIQUE); |
158 |
delete $who->{ext_ignore_tell} {$other->ob->name}; |
159 |
delete $who->{ext_ignore_shout}{$other->ob->name}; |
160 |
} else { |
161 |
$who->message ("You need to specify tell, shout or all.", cf::NDI_UNIQUE); |
162 |
} |
163 |
} else { |
164 |
$who->message ("No such player or ambiguous name: $target", cf::NDI_UNIQUE); |
165 |
} |
166 |
|
167 |
} |
168 |
}; |
169 |
|