]> git.vpit.fr Git - perl/scripts/xchat.git/blobdiff - Xchat/XPI/Utils.pm
Make sure local_context() runs the code only when the context was found
[perl/scripts/xchat.git] / Xchat / XPI / Utils.pm
index 8fab3c469aae892395cf1ceec3f48bd49e1df141..c8994abd6b5e7ed616be2247390560e9c074a31f 100644 (file)
@@ -7,6 +7,14 @@ use Xchat qw<:all>;
 
 our $VERSION = '0.02';
 
+sub irc_lc {
+ my ($bytes) = @_;
+
+ $bytes =~ y/A-Z[\\]^/a-z{|}~/;
+
+ return $bytes;
+}
+
 my @rcolors;
 BEGIN {
  if (nickcmp(get_info('version'), '2.4.0') < 0) {
@@ -23,6 +31,17 @@ sub dye_nick {
  return sprintf "\003%d%s", $rcolors[$col % @rcolors], $nick;
 }
 
+my %gui_commands = (
+ 'clear'     => [ 'COLOR 0' ],
+ 'highlight' => [ 'FLASH' => 'COLOR 3' ],
+);
+
+sub gui {
+ my $commands = $gui_commands{$_[0] || 'nope'};
+ die 'Invalid command' unless defined $commands;
+ command "GUI $_" for @$commands;
+}
+
 sub save_context {
  my $cur_cxt = get_context;
  bless \$cur_cxt, 'Xchat::XPI::Utils::ContextGuard';
@@ -32,9 +51,10 @@ sub local_context {
  return unless @_ >= 2;
  my $code    = pop;
  my $new_cxt = (@_ == 1) ? $_[0] : find_context(@_);
+ return undef unless defined $new_cxt;
  my $cur_cxt = get_context;
+ my $guard   = bless \$cur_cxt, 'Xchat::XPI::Utils::ContextGuard';
  if (set_context $new_cxt) {
-  my $guard = bless \$cur_cxt, 'Xchat::XPI::Utils::ContextGuard';
   return $code->();
  } else {
   return undef;
@@ -72,7 +92,9 @@ use base qw<Exporter>;
 
 our @EXPORT         = ();
 our %EXPORT_TAGS    = ('funcs' => [ qw<
+ irc_lc
  dye_nick
+ gui
  save_context local_context
  called_from_script
 > ]);