[Add] irssi desktop and voice notifications.

This commit is contained in:
Ritchie Cunningham 2025-06-07 13:40:10 +01:00
parent 1316343a97
commit a25b527804
2 changed files with 171 additions and 1 deletions

View File

@ -1,3 +1,100 @@
# irssi-scripts # irssi-scripts
## FNotify - Desktop and Voice Notifications for Irssi
Scripts of irssi. I have left out some of the things I have until I clean them up. But my latest one is included here. FNotify is a Perl script for the [Irssi](https://irssi.org/) IRC client that provides real-time desktop notifications for private messages and channel highlights. It helps you stay aware of important IRC activity even when your terminal is not in focus.
The script is designed to be robust and "theme-proof," meaning it works reliably even if you use a custom Irssi theme that modifies the appearance of messages. It also includes an optional, configurable voice alert feature using the Festival Speech Synthesis System.
### Features
* **Desktop Notifications:** Get instant pop-up notifications via `notify-send` when you receive a private message or when your nick is mentioned in a channel.
* **Voice Alerts (Optional):** Enable spoken notifications through Festival for.. hands-free awareness?
* **Theme-Proof:** Uses a two-signal method to reliably detect highlights, making it compatible with custom Irssi themes.
* **Configurable:** Easily enable or disable voice alerts on-the-fly from within Irssi without needing to edit the script.
* **Lightweight:** The script is simple and efficient, with no external Perl library dependencies.
### Prerequisites
Before using `fnotify.pl`, you must have the following software installed on your system:
1. **`notify-send`**: A command-line tool for sending desktop notifications.
* On Debian, install with:
```bash
sudo apt-get install libnotify-bin
```
2. **Festival (Optional)**: Required only if you want to use the voice alert feature.
* On Debian, install with:
```bash
sudo apt-get install festival
```
* You may also want a higher-quality voice pack, such as `festvox-us-slt-hts`.
### Installation
1. **Place the Script:**
Download or save the `fnotify.pl` script into your Irssi scripts directory.
```bash
mkdir -p ~/.irssi/scripts/
# Now, place fnotify.pl inside ~/.irssi/scripts/
```
2. **Load the Script:**
Inside Irssi, load the script with the following command:
```
/script load fnotify.pl
```
3. **Automatic Loading (Recommended):**
To ensure the script loads every time you start Irssi, create a symbolic link to it in your `autorun` directory.
```bash
cd ~/.irssi/scripts/autorun/
ln -s ../fnotify.pl .
```
If the `autorun` directory does not exist, create it first: `mkdir -p ~/.irssi/scripts/autorun`.
### Configuration
You can control the script's features directly from the Irssi command prompt.
#### Enabling/Disabling Voice Alerts
* **To enable voice alerts:**
```
/set festival_enabled ON
```
* **To disable voice alerts (default):**
```
/set festival_enabled OFF
```
* **To check the current setting:**
```
/set festival_enabled
```
### Customizing the Festival Voice
If you have multiple Festival voices installed, you can choose which one the script uses by editing the `fnotify.pl` file directly.
1. Open `~/.irssi/scripts/fnotify.pl` in a text editor.
2. Find the following line near the top of the script:
```perl
my $festival_voice = '(voice_us1_mbrola)';
```
3. Change the value to the name of your preferred voice. You can find available voices by running `festival` and entering the command `(voice.list)`.
### How It Works (Technical Detail)
We use a two-signal approach to maintain compatibility with custom themes:
1. The `message public` signal is used first to capture the raw, unformatted message content and the sender's nickname *before* any theme can audaciously modify them.
2. The `print text` signal, which fires immediately after, is then used *only* to check if Irssi has flagged the message as a highlight.
3. If it is a highlight, the script uses the clean, raw data captured in the first step to build the notification, completely ignoring the themed text.
This decoupling ensures that notifications are always reliable, regardless of your visual setup in Irssi.
## License
This script is released into the **Public Domain**. You are free to use, modify, and distribute it as you see fit.

73
fnotify.pl Normal file
View File

@ -0,0 +1,73 @@
use strict;
use Irssi;
use vars qw($VERSION %IRSSI);
$VERSION = "3.0-themeproof";
%IRSSI = (
authors => 'Ritchie Cunningham',
contact => 'ritchie@ritchiecunningham.co.uk',
name => 'fnotify',
description => 'Sends notify-send notifications for private messages and highlights. Optionally uses festival for voice.',
license => 'Public Domain',
);
# --- Global variables to hold raw message data between signals. ---
my ($last_public_msg, $last_public_nick, $last_public_target);
# --- Configuration. ---
my $festival_voice = '(voice_us1_mbrola)';
# --- Core Functions. ---
sub notify {
my ($title, $message) = @_;
system("notify-send", "-i", "irssi", $title, $message);
if (Irssi::settings_get_bool('festival_enabled')) {
my $text = "$title. $message";
$text =~ s/[^A-Za-z0-9\s,.]//g; # Sanitize for festival.
system("echo '$text' | festival --tts --language english --pipe &");
}
}
# --- Signal Handlers. ---
# Private messages are simple and clean. No theme conflicts.
sub private_message_handler {
my ($server, $msg, $nick, $address) = @_;
return if ($nick =~ /^(NickServ|ChanServ|MemoServ)$/i);
notify("Private Message from $nick", $msg);
}
# FFS! THEME! Stop f.cking with my data please..
sub public_message_handler {
my ($server, $msg, $nick, $address, $target) = @_;
$last_public_msg = $msg;
$last_public_nick = $nick;
$last_public_target = $target;
}
sub print_text_handler {
my ($dest, $text, $stripped) = @_;
# Check if the level is a highlight and the target matches the one we just saved.
# The target check prevents us from misfiring on other window text.
if (($dest->{level} & Irssi::MSGLEVEL_HILIGHT) && ($dest->{target} eq $last_public_target)) {
# Make sure the data from the first signal is actually there.
return unless defined $last_public_nick;
# Use the CLEAN data we saved to build the notification!
notify("Mentioned by $last_public_nick in $last_public_target", $last_public_msg);
# Clear the variables so we don't accidentally re-use them.
undef $last_public_nick;
}
}
# --- Settings and Signal Registration. ---
Irssi::settings_add_bool('lookandfeel', 'festival_enabled', 0);
# Register all three handlers.
Irssi::signal_add('message private', 'private_message_handler');
Irssi::signal_add('message public', 'public_message_handler');
Irssi::signal_add('print text', 'print_text_handler');