<commit_before># Copyright (C) 2007-2009 <NAME>
# Modificiations (C) 2011 - 2012 <NAME>
# Released under the GNU Affero General Public License v3
package Util::BaseNick;
use LocalNetwork;
use Persist 'LocalNetwork';
use Scalar::Util qw(isweak weaken);
use strict;
use warnings;

our @nicks;
Persist::register_vars('nicks');

sub _init {
	my $net = shift;
	$nicks[$$net] = {};
}

sub mynick {
	my($net, $name) = @_;
	$name = $net->lc($name);
	my $nick = $nicks[$$net]{$name};
	unless ($nick) {
		Log::debug_in($net, "Nick '$name' does not exist; ignoring");
		return undef;
	}
	if ($nick->homenet() ne $net) {
	#	Log::err_in($net, "Nick '$name' is from network '".$nick->homenet()->name().
	#		"' but was sourced locally");
		return undef;
	}
	return $nick;
}

sub nick {
	my($net, $name) = @_;
	$name = $net->lc($name);
	return $nicks[$$net]{$name} if $nicks[$$net]{$name};
	Log::debug_in($net, "Nick '$name' does not exist; ignoring") unless $_[2];
	undef;
}

# Request a nick on a remote network (CONNECT/JOIN must be sent AFTER this)
sub request_nick {
	my($net, $nick, $reqnick, $tagged) = @_;
	my ($given,$given_lc);
	# The shit I do to deal with multiple Januses:
	$reqnick =~ s/(\/[a-zA-Z0-9]+){2,}// if $reqnick =~ /(\/[a-zA-Z0-9]+){2,}/;

	if ($nick->homenet() eq $net) {
		$given = $reqnick;
		$given_lc = $net->lc($given);
	} else {
		my $maxlen = $net->nicklen();
		$given = substr $reqnick, 0, $maxlen;
		$given_lc = $net->lc($given);
		
		$tagged = 1 if exists $nicks[$$net]->{$given_lc};

		my $tagre = Setting::get(force_tag => $net);
		$tagged = 1 if $tagre && $$nick != 1 && $given =~ /^$tagre$/i;

		# Let's be less destructive than ircreview...
		$tagged = 1 if $Janus::tagall;

		# Let's NOT tag the Janus bot ;)
		$tagged = 0 if $nick->homenet()->name() eq 'janus';

		# Let's reverse forcetag's function when tagall is enabled
		$tagged = 0 if $tagre && $Janus::tagall && $$nick != 1 && $given =~ /^$tagre$/i;

		if ($tagged) {
			my $tagsep = $Janus::septag;
			my $tag = $tagsep . $nick->homenet()->name();
			my $i = 0;
			$given = substr($reqnick, 0, $maxlen - length $tag) . $tag;
			$given_lc = $net->lc($given);
			while (exists $nicks[$$net]->{$given_lc}) {
				my $itag = $tagsep.(++$i).$tag;
				$given = substr($reqnick, 0, $maxlen - length $itag) . $itag;
				$given_lc = $net->lc($given);
			}
		}
	}
	$nicks[$$net]->{$given_lc} = $nick;
	return $given;
}

sub request_newnick {
	my $n = shift;
	$n->request_nick(@_);
}

sub request_cnick {
	my($net, $nick, $reqnick, $tagged) = @_;
	$tagged ||= 0;
	my $b4 = $net->lc($nick->str($net));
	if ($tagged != 2 && $nicks[$$net]{$b4} == $nick) {
		delete $nicks[$$net]{$b4};
	}
	my $gv = $net->request_nick($nick, $reqnick, $tagged);
	if ($tagged == 2 && $nicks[$$net]{$b4} == $nick) {
		delete $nicks[$$net]{$b4};
	}
	return $gv;
}

# Release a nick on a remote network (PART/QUIT must be sent BEFORE this)
sub release_nick {
	my($net, $req, $nick) = @_;
	delete $nicks[$$net]->{$net->lc($req)};
}

sub all_nicks {
	my $net = shift;
	values %{$nicks[$$net]};
}

sub item {
	my($net, $item) = @_;
	return undef unless defined $item;
	$item = $net->lc($item);
	return $net->chan($item) if $item =~ /^#/;
	return $nicks[$$net]{$item} if exists $nicks[$$net]{$item};
	return $net if $item =~ /\./;
	return undef;
}

1;
<commit_msg>Should handle multiple janus linked channels better now<commit_after># Copyright (C) 2007-2009 <NAME>
# Modificiations (C) 2011 - 2012 <NAME>
# Released under the GNU Affero General Public License v3
package Util::BaseNick;
use LocalNetwork;
use Persist 'LocalNetwork';
use Scalar::Util qw(isweak weaken);
use strict;
use warnings;

our @nicks;
Persist::register_vars('nicks');

sub _init {
	my $net = shift;
	$nicks[$$net] = {};
}

sub mynick {
	my($net, $name) = @_;
	$name = $net->lc($name);
	my $nick = $nicks[$$net]{$name};
	unless ($nick) {
		Log::debug_in($net, "Nick '$name' does not exist; ignoring");
		return undef;
	}
	if ($nick->homenet() ne $net) {
	#	Log::err_in($net, "Nick '$name' is from network '".$nick->homenet()->name().
	#		"' but was sourced locally");
		return undef;
	}
	return $nick;
}

sub nick {
	my($net, $name) = @_;
	$name = $net->lc($name);
	return $nicks[$$net]{$name} if $nicks[$$net]{$name};
	Log::debug_in($net, "Nick '$name' does not exist; ignoring") unless $_[2];
	undef;
}

# Request a nick on a remote network (CONNECT/JOIN must be sent AFTER this)
sub request_nick {
	my($net, $nick, $reqnick, $tagged) = @_;
	my ($given,$given_lc);
	# The shit I do to deal with multiple Januses:
	$reqnick =~ s/(\/[a-zA-Z0-9]+){2,}/-ln/ if $reqnick =~ /(\/[a-zA-Z0-9]+){2,}/;

	if ($nick->homenet() eq $net) {
		$given = $reqnick;
		$given_lc = $net->lc($given);
	} else {
		my $maxlen = $net->nicklen();
		$given = substr $reqnick, 0, $maxlen;
		$given_lc = $net->lc($given);
		
		$tagged = 1 if exists $nicks[$$net]->{$given_lc};

		my $tagre = Setting::get(force_tag => $net);
		$tagged = 1 if $tagre && $$nick != 1 && $given =~ /^$tagre$/i;

		# Let's be less destructive than ircreview...
		$tagged = 1 if $Janus::tagall;

		# Let's NOT tag the Janus bot ;)
		$tagged = 0 if $nick->homenet()->name() eq 'janus';

		# Let's reverse forcetag's function when tagall is enabled
		$tagged = 0 if $tagre && $Janus::tagall && $$nick != 1 && $given =~ /^$tagre$/i;

		if ($tagged) {
			my $tagsep = $Janus::septag;
			my $tag = $tagsep . $nick->homenet()->name();
			my $i = 0;
			$given = substr($reqnick, 0, $maxlen - length $tag) . $tag;
			$given_lc = $net->lc($given);
			while (exists $nicks[$$net]->{$given_lc}) {
				my $itag = $tagsep.(++$i).$tag;
				$given = substr($reqnick, 0, $maxlen - length $itag) . $itag;
				$given_lc = $net->lc($given);
			}
		}
	}
	$nicks[$$net]->{$given_lc} = $nick;
	return $given;
}

sub request_newnick {
	my $n = shift;
	$n->request_nick(@_);
}

sub request_cnick {
	my($net, $nick, $reqnick, $tagged) = @_;
	$tagged ||= 0;
	my $b4 = $net->lc($nick->str($net));
	if ($tagged != 2 && $nicks[$$net]{$b4} == $nick) {
		delete $nicks[$$net]{$b4};
	}
	my $gv = $net->request_nick($nick, $reqnick, $tagged);
	if ($tagged == 2 && $nicks[$$net]{$b4} == $nick) {
		delete $nicks[$$net]{$b4};
	}
	return $gv;
}

# Release a nick on a remote network (PART/QUIT must be sent BEFORE this)
sub release_nick {
	my($net, $req, $nick) = @_;
	delete $nicks[$$net]->{$net->lc($req)};
}

sub all_nicks {
	my $net = shift;
	values %{$nicks[$$net]};
}

sub item {
	my($net, $item) = @_;
	return undef unless defined $item;
	$item = $net->lc($item);
	return $net->chan($item) if $item =~ /^#/;
	return $nicks[$$net]{$item} if exists $nicks[$$net]{$item};
	return $net if $item =~ /\./;
	return undef;
}

1;

{'fraction_non_alphanumeric': 0.22540922060369425, 'fraction_numerical': 0.013215197477098664, 'mean_word_length': 3.915129151291513, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 61, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 2, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5750170', 'n_tokens_mistral': 2993, 'n_tokens_neox': 2708, 'n_words': 695}