summaryrefslogtreecommitdiffstats
path: root/scripts/topicsed.pl
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 20:19:02 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 20:19:02 +0000
commit03929dac2a29664878d2c971648a4fe1fb698462 (patch)
tree02c5e2b3e006234aa29545f7a93a1ce01b291a8b /scripts/topicsed.pl
parentInitial commit. (diff)
downloadirssi-scripts-upstream/20231031.tar.xz
irssi-scripts-upstream/20231031.zip
Adding upstream version 20231031.upstream/20231031upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--scripts/topicsed.pl61
1 files changed, 61 insertions, 0 deletions
diff --git a/scripts/topicsed.pl b/scripts/topicsed.pl
new file mode 100644
index 0000000..58d0143
--- /dev/null
+++ b/scripts/topicsed.pl
@@ -0,0 +1,61 @@
+#
+# Topicsed edits channel topics by perl regexps via the command /topicsed.
+#
+# Thanks to Mikael Magnusson for the idea and patch to implement a
+# preview functionality. ;]
+#
+use strict;
+use Irssi;
+
+use vars qw/%IRSSI $VERSION/;
+$VERSION="0.1";
+%IRSSI = (
+ authors => "Gabor Nyeki",
+ contact => "bigmac\@vim.hu",
+ name => "topicsed",
+ description => "editing channel topics by regexps",
+ license => "public domain",
+ changed => "2017-03-18"
+);
+
+
+sub topicsed {
+ my ($regexp, $server, $winit) = @_;
+
+ my $preview = 0;
+ if ($regexp =~ m/^-p(review|) ?/) {
+ $preview = 1;
+ $regexp =~ s/^-p\w* ?//;
+ }
+
+ unless ($regexp) {
+ Irssi::print("Usage: /topicsed [-p[review]] <regexp>");
+ return;
+ }
+ return if (!$server || !$server->{connected} ||
+ !$winit || $winit->{type} ne 'CHANNEL');
+
+ my $topic = $winit->{topic};
+ my $x = $topic;
+
+ unless (eval "\$x =~ $regexp") {
+ Irssi::print("topicsed:error: An error occured with your regexp.");
+ return;
+ }
+
+ if ($x eq $topic) {
+ Irssi::print("topicsed:error: The topic wouldn't be changed.");
+ return;
+ } elsif ($x eq "") {
+ Irssi::print("topicsed:error: Edited topic is empty; try '/topic -delete' instead.");
+ return;
+ }
+
+ if ($preview) {
+ Irssi::print("topicsed: Edited topic for $winit->{name}: $x");
+ } else {
+ $server->send_raw("TOPIC $winit->{name} :$x");
+ }
+}
+
+Irssi::command_bind('topicsed', 'topicsed');