summaryrefslogtreecommitdiffstats
path: root/scripts/munge_own_nickname_to_username.pl
diff options
context:
space:
mode:
authorÆvar Arnfjörð Bjarmason2016-03-15 17:52:13 +0000
committerÆvar Arnfjörð Bjarmason2016-03-16 11:07:11 +0000
commita098b519551471f4ef84f4c942b57fe9e640ab5d (patch)
treebbf9abca036bdd37664b67284c8a7b40628034b2 /scripts/munge_own_nickname_to_username.pl
parent5dbfd9f54b6dbc114458ea02bbb1a75e1f447302 (diff)
downloadscripts.irssi.org-a098b519551471f4ef84f4c942b57fe9e640ab5d.tar.bz2
Submit my collection of scripts from my dotfiles.git
These are all irssi scripts that I maintain & use myself that I think are useful for general use, none of this has anything hardcoded related to me and when applicable has a configurable interface.
Diffstat (limited to 'scripts/munge_own_nickname_to_username.pl')
-rw-r--r--scripts/munge_own_nickname_to_username.pl79
1 files changed, 79 insertions, 0 deletions
diff --git a/scripts/munge_own_nickname_to_username.pl b/scripts/munge_own_nickname_to_username.pl
new file mode 100644
index 0000000..85e9328
--- /dev/null
+++ b/scripts/munge_own_nickname_to_username.pl
@@ -0,0 +1,79 @@
+use strict;
+use warnings;
+use Irssi;
+
+our $VERSION = '1.0';
+our %IRSSI = (
+ authors => 'Ævar Arnfjörð Bjarmason',
+ contact => 'avarab@gmail.com',
+ name => 'munge_own_nickname_to_username.pl',
+ description => 'Changes messages from myself to appear to come from my username, not my nickname',
+ license => 'Public Domain',
+ url => 'http://scripts.irssi.org & https://github.com/avar/dotfiles/blob/master/.irssi/scripts/munge_own_nickname_to_username.pl',
+);
+
+# HOWTO:
+#
+# /load munge_own_nickname_to_username.pl
+#
+# This is for use on servers where your NICK is forced upon you,
+# e.g. when connecting to some corporate maintained Bitlbee server
+# that has LDAP-connected accounts.
+#
+# In that case your NICK may not be what you're used to. This
+# intercepts "print text" events from irssi and rewrites them so that
+# they appear to come from the "nick" configured in
+# settings.core.user_name instead of whatever your nickname is on the
+# server.
+#
+# The result is that you'll appear to yourself to have your "correct"
+# nickname. The illusion goes pretty far, even down to your IRC logs,
+# but of course everyone else will see you as your real nickname, or
+# maybe your username (I use this for a IRC->Slack/Bitlee gateway).
+#
+# This should just automatically work, it'll detect what your nick is,
+# what you're username is, and automatically substitute
+# s/nick/username/ if applicable.
+#
+# Note that if your theme adjusts the msgnick rendering this may not
+# work, because we try to match "< yournick>" in the line. We could
+# potentially do better, please contact the author if you run into
+# issues with this.
+
+sub msg_rename_myself_in_printed_text {
+ my ($tdest, $data, $stripped) = @_;
+
+ # The $tdest object has various other things, like ->{target},
+ # ->{window} (object) etc.
+ my $server = $tdest->{server};
+
+ # Some events just have ->{window} and no ->{server}, we can
+ # ignore those
+ return unless $server;
+
+ # Unpack our configuration from $server.
+ my $server_username = $server->{username};
+ my $server_nick = $server->{nick};
+
+ # We have nothing to do here, our nick is already the same as our
+ # username.
+ return if $server_username eq $server_nick;
+
+ # We're matching against $stripped but replacing both because the
+ # $data thing is escaped and much harder to match against.
+ #
+ # We're just replacing nick mentions, so e.g. if you say "Hi I'm
+ # bob here but my username is bobby" it won't turn into "Hi I'm
+ # bobby here but my username is bobby".
+ #
+ # The illusion here isn't complete, e.g. if you do /NAMES your
+ # nick will show up and not your username, but I consider that a
+ # feature.
+ if ($stripped =~ /^<.?\Q$server_nick\E> /s) {
+ s/\Q$server_nick\E/$server_username/ for $data, $stripped;
+
+ Irssi::signal_continue($tdest, $data, $stripped);
+ }
+}
+
+Irssi::signal_add_first('print text', 'msg_rename_myself_in_printed_text');