-
Notifications
You must be signed in to change notification settings - Fork 0
/
account_info.pl
59 lines (53 loc) · 1.6 KB
/
account_info.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# Rewrite nicknames to indicate services account information if available
# Nicks will be shown with a ~ if not identified
# if identified to an account other than the current nickname account name in brackets will be appended
sub weechat_print_cb {
my $message= $_[3];
my ($plugin, $buffer, $args)=split /;/,$_[2];
my ($server, $channel) = split /\./,$buffer,2;
my $nick='none';
my $dnick;
if ($args=~/^irc_(notice|privmsg)/) {
foreach $arg (split /,/, $args) {
if ($arg=~/^nick_(\S+)/) {
$nick=$1;
$dnick=$nick;
last;
}
}
if ($channel && $channel=~/^\#/) {
my $infolist = weechat::infolist_get( "irc_nick", '', "$server,$channel,$nick");
weechat::infolist_next($infolist);
my $account=weechat::infolist_string( $infolist, "account");
if (!$account) {
$dnick = "~$nick";
} elsif ($account && irclc($account) ne irclc($nick)) {
$dnick="$nick($account)";
}
weechat::infolist_free($infolist);
my $qnick=quotemeta($nick);
$message=~s{$qnick}{$dnick};
}
}
return $message;
}
sub account_info_hook {
weechat::hook_modifier("weechat_print", "weechat_print_cb", "");
}
sub irclc {
# converts a string to lower case, using rfc1459 casemapping
my $s=shift;
$s=~tr/A-Z[]\\^/a-z{}|~/;
return $s;
}
if (!weechat::register("account_info", "mquin", "0.1", "GPL2", "Rewrite irc nicknames to indicate services identification", "", ""))
{
# Double load
weechat::print ("", "\taccount_info is already loaded");
return weechat::WEECHAT_RC_OK;
}
else
{
# Start everything
account_info_hook();
}