Skip to content

Commit ce39528

Browse files
committed
Vesta: improve errors on bogus text
1 parent 6b167f4 commit ce39528

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

lib/Synergy/VestaUtil.pm

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package Synergy::VestaUtil;
66
use experimental qw(signatures);
77
use utf8;
88

9+
use List::Util qw(uniq);
910
use MIME::Base64 ();
1011

1112
my %CHAR_FOR = (
@@ -182,8 +183,8 @@ sub _text_to_board ($self, $text) {
182183
sub text_to_board ($self, $text) {
183184
$text = uc $text;
184185

185-
unless ($self->_text_is_valid($text)) {
186-
return (undef, "Sorry, I can't post that to the board.");
186+
if (my $text_problem = $self->_problem_with_text($text)) {
187+
return (undef, $text_problem);
187188
}
188189

189190
my $post = $self->_text_to_board($text);
@@ -195,11 +196,19 @@ sub text_to_board ($self, $text) {
195196
return $post;
196197
}
197198

198-
sub _text_is_valid ($self, $text) {
199+
sub _problem_with_text ($self, $text) {
200+
if (length $text > 6 * 22) {
201+
return "That text is too long. The limit is 132 characters (six rows of 22)."
202+
}
203+
199204
# This feels pretty thing. -- rjbs, 2021-05-31
200-
return if $text =~ m{[^ 0-9A-Z!@#\$\(\)\-\+&=;:'"%,./?°🟥🟧🟨🟩🟦🟪⬜️]};
201-
return if length $text > 6 * 22;
202-
return 1;
205+
my $unwanted = $text =~ s{[ 0-9A-Z!@#\$\(\)\-\+&=;:'"%,./?°🟥🟧🟨🟩🟦🟪⬜️]}{}gr;
206+
207+
return unless $unwanted;
208+
209+
$unwanted = join q{}, sort(uniq(split //, $unwanted));
210+
211+
return "That text contains characters you can't use. Here they are: $unwanted";
203212
}
204213

205214
1;

0 commit comments

Comments
 (0)