1 | #! perl |
1 | #! perl |
|
|
2 | |
|
|
3 | # implement a replacement for the built-in chat/shout/tell/reply commands |
|
|
4 | # adds ignore/unignore functionality |
2 | |
5 | |
3 | cf::register_command chat => 0, sub { |
6 | cf::register_command chat => 0, sub { |
4 | my ($who, $msg) = @_; |
7 | my ($who, $msg) = @_; |
5 | |
8 | |
6 | if ($msg) { |
9 | if ($msg) { |
7 | my $name = $who->name; |
10 | my $name = $who->name; |
8 | |
11 | |
9 | for my $player (cf::player::list) { |
|
|
10 | $player->ob->message ("$name chats: $msg", cf::NDI_BLUE) |
12 | $_->ob->message ("$name chats: $msg", cf::NDI_BLUE) |
11 | unless $player->ob->{ext_ignore_shout}; |
13 | for grep !$_->ob->{ext_ignore_shout}, cf::player::list; |
12 | } |
|
|
13 | |
14 | |
14 | } else { |
15 | } else { |
15 | $who->message ("Chat what?", cf::NDI_UNIQUE); |
16 | $who->message ("Chat what?", cf::NDI_UNIQUE); |
16 | } |
17 | } |
17 | }; |
18 | }; |
… | |
… | |
20 | my ($who, $msg) = @_; |
21 | my ($who, $msg) = @_; |
21 | |
22 | |
22 | if ($msg) { |
23 | if ($msg) { |
23 | my $name = $who->name; |
24 | my $name = $who->name; |
24 | |
25 | |
25 | for my $player (cf::player::list) { |
|
|
26 | $player->ob->message ("$name shouts: $msg", cf::NDI_RED) |
26 | $_->ob->message ("$name shouts: $msg", cf::NDI_RED) |
27 | unless $player->ob->{ext_ignore_shout}; |
27 | for grep !$_->ob->{ext_ignore_shout}, cf::player::list; |
28 | } |
28 | |
29 | } else { |
29 | } else { |
30 | $who->message ("Shout what?", cf::NDI_UNIQUE); |
30 | $who->message ("Shout what?", cf::NDI_UNIQUE); |
31 | } |
31 | } |
32 | |
32 | |
33 | }; |
33 | }; |
|
|
34 | |
|
|
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 | |