diff options
| author | tomaw | 2014-08-19 21:21:35 +0100 |
|---|---|---|
| committer | tomaw | 2014-08-19 21:21:35 +0100 |
| commit | 01de4a72e9103e8087bd5fdf7bb42ce4b7f8f9ab (patch) | |
| tree | 1645b616de2e605c9ba2c7cd8895adfe0da543ef | |
| parent | 0ee155adf31ecd046ba1b895a777d358a1171df3 (diff) | |
| parent | bc91800f2a296b0dffbb65153f99bc08cd8e743f (diff) | |
| download | scripts.irssi.org-01de4a72e9103e8087bd5fdf7bb42ce4b7f8f9ab.tar.bz2 | |
Merge pull request #33 from dgl/oopsie
Add oopsie.pl
| -rw-r--r-- | _data/scripts.yaml | 9 | ||||
| -rw-r--r-- | scripts/oopsie.pl | 44 |
2 files changed, 53 insertions, 0 deletions
diff --git a/_data/scripts.yaml b/_data/scripts.yaml index 30c8808..3303db7 100644 --- a/_data/scripts.yaml +++ b/_data/scripts.yaml @@ -4229,3 +4229,12 @@ license: "WTFPL" name: "urlinfo" version: "1.2" + +- authors: "David Leadbeater" + contact: "dgl@dgl.cx" + description: "Stops those silly mistakes being sent (spaces at start of line, /1/1 for window changes, etc)." + filename: "urlinfo.pl" + modified: "2014-08-13" + license: "WTFPL" + name: "oopsie" + version: "1.0" diff --git a/scripts/oopsie.pl b/scripts/oopsie.pl new file mode 100644 index 0000000..8cb5992 --- /dev/null +++ b/scripts/oopsie.pl @@ -0,0 +1,44 @@ +use strict; +use warnings; + +our $VERSION = "1.0"; +our %IRSSI = ( + authors => 'David Leadbeater', + contact => 'dgl@dgl.cx', + name => 'oopsie', + description => 'Stops those silly mistakes being sent (spaces at start of ' . + 'line, /1/1 for window changes, etc).', + license => 'WTFPL <http://dgl.cx/licence>', + url => 'http://dgl.cx/irssi', +); + +# /SET oopsie_chars_regexp [0-9] +# This can have nearly anything in it, but you may block some commands if +# you're not careful. \w may be useful (e.g. blocks "/ m foo bar") but \w+ is +# problematic (it would block /exec /some/file among other useful things, +# although if you're a bad typist maybe that is a reasonable trade-off). +Irssi::settings_add_str("misc", "oopsie_chars_regexp", "[0-9]"); + +my @words = qw(stopped prevented avoided inhibited forestalled averted deflected + repelled); + +Irssi::signal_add("send command" => sub { + my ($command, $server, $rec) = @_; + + my $chars = Irssi::settings_get_str("cmdchars"); + my $cmdchars_re = qr/[$chars]/; + my $oopsie_re = Irssi::settings_get_str("oopsie_chars_regexp"); + + if ($command =~ /^\s+$cmdchars_re/ || + $command =~ /^$cmdchars_re(?:\s+$oopsie_re|$oopsie_re\s*$cmdchars_re)/) { + Irssi::signal_stop(); + $rec->print("oopsie " . $words[rand @words] . ": $command", MSGLEVEL_CRAP); + } +}); + +Irssi::signal_add("setup changed" => sub { + if (" " =~ Irssi::settings_get_str("oopsie_chars_regexp")) { + Irssi::active_win->print( + "Your oopsie_chars_regexp matches a space. This is a very bad idea."); + } +}); |
