Skip to content

Instantly share code, notes, and snippets.

@LifeIsPain
Last active December 17, 2015 10:39
Show Gist options
  • Save LifeIsPain/5596311 to your computer and use it in GitHub Desktop.
Save LifeIsPain/5596311 to your computer and use it in GitHub Desktop.
XChat script to make the location for nick change errors more prominent
# Name: nickerrorlocation.pl
# Version: 002
# Author: LifeIsPain < idontlikespam (at) orvp [dot] net >
# Date: 2013-05-17
# Description: Make the location for nick change errors more prominent than just where
# the error actually was (shows in server tab, current tab, and channel)
# Version History
# 001 2013-05-16 Initial Code
# 002 2013-05-17 Issue if there is no numeric passed fixed
# No changes needed within this file
use strict;
use warnings;
use Xchat qw(:all);
register('Nick Error Location', '002', 'Make errors when changing nick prominent');
# remember the hook, as we have to unhook so as to not get duplicates
my $hook = hook_print("Server Text", \&check_nick_error);
# 432 : desirednick :Erroneous Nickname
# 433 : desirednick :Nickname is already in use.
# 435 : desirednick #problemchannel :Cannot change nickname while banned on channel
# 437 : #problemchannel :Cannot change nickname while banned or moderated on channel
sub check_nick_error {
my ($tabinfo, $front_context, $problem_chan);
# 4 potential events to deal with
if (defined ($_[0][2]) && $_[0][2] == 432 || $_[0][2] == 433 || $_[0][2] == 435 || $_[0][2] == 437) {
# we are going to have the event printed multiple times, so temporarily unhook self
unhook($hook);
# only do if not in query context
$tabinfo = context_info;
# problem chan is the 2nd word
if ($_[0][2] == 435) {
$_[0][0] =~ /^\S+ (\S+)/;
$problem_chan = $1;
}
# problem chan is the 1st word
elsif ($_[0][2] == 437) {
$_[0][0] =~ /^(\S+)/;
$problem_chan = $1;
}
# Store what the overall front context is, as need to spit there if it doesn't get spit already
$front_context = find_context;
# if already on front context or the front context is on another server, we don't care about front context anymore
undef $front_context if ($front_context == $tabinfo->{context} || context_info($front_context)->{id} != $tabinfo->{id});
# If this isn't a server tab, need to emit in server tab
if ($tabinfo->{type} != 1) {
my $check_context = find_context($tabinfo->{network}, $tabinfo->{server});
# found a tab, need to make sure it is the right one
if ( $check_context ) {
my $checktab = context_info($check_context);
# the strange case of if the found context is actually a query or something, or a different server id
undef $check_context if ($checktab->{type} != 1 || $checktab->{id} != $tabinfo->{id});
}
# didn't find the correct one? LOOP!
if ( !$check_context ) {
my @channels = get_list('channels');
for (@channels) {
if ($_->{id} == $tabinfo->{id} && $_->{type} == 1) {
$check_context = $_->{context};
last;
}
}
}
# it still may not be found, in which case nothing will be done, but otherwise, copy event
if ( $check_context ) {
undef $front_context if (defined $front_context && $check_context == $front_context);
set_context($check_context);
emit_print('Server Text', @{$_[0]});
}
}
# If there is a problem channel, emit there as well
if (defined $problem_chan) {
# we may already be in that channel
if (nickcmp($problem_chan, $tabinfo->{channel}) != 0) {
my $check_context = find_context($problem_chan, $tabinfo->{server});
# found a tab, need to make sure it is the right one
if ( $check_context ) {
my $checktab = context_info($check_context);
# the case if a renamed query, or on a different server id
undef $check_context if ($checktab->{type} != 2 || $checktab->{id} != $tabinfo->{id});
}
# didn't find the correct one? LOOP!
if ( !$check_context ) {
my @channels = get_list('channels');
for (@channels) {
if ($_->{id} == $tabinfo->{id} && $_->{type} == 2) {
$check_context = $_->{context};
last;
}
}
}
# it still may not be found, in which case nothing will be done, but otherwise, copy event
if ( $check_context ) {
undef $front_context if (defined $front_context && $check_context == $front_context);
set_context($check_context);
emit_print('Server Text', @{$_[0]});
}
}
}
if (defined ($front_context)) {
set_context($front_context);
emit_print('Server Text', @{$_[0]});
}
# all done, re-hook for the next time through
$hook = hook_print("Server Text", \&check_nick_error);
}
return EAT_NONE;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment