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