First commit, irssi-autospeak is here!
This commit is contained in:
commit
12e2cf3187
38
README.md
Normal file
38
README.md
Normal file
@ -0,0 +1,38 @@
|
||||
# Irssi Autospeak
|
||||
Written ByJeremiah Ticket and contributers!
|
||||
|
||||
Adds speech to some events.
|
||||
|
||||
This script requires you have espeak-ng installed and in your path.
|
||||
|
||||
## Usage
|
||||
Place autospeak.pl in .irssi/scripts/
|
||||
Then in irssi do:
|
||||
/script load autospeak
|
||||
If you want to autorun the script, place the script in or simlink to ~/.irssi/scripts/autorun/
|
||||
|
||||
## Automated Install
|
||||
There is a basic install script, just run:
|
||||
|
||||
./install
|
||||
|
||||
This install script creates the folder ~/.irssi/scripts/autorun if it doesn't exist and simlinks the script to start automatically.
|
||||
|
||||
## Configuration
|
||||
This script has some settings. Use the /set command to set them.
|
||||
- speech_voice <voice> - espeak-ng voice to use (default is en-us)
|
||||
- speech_rate <digits> - speech rate in words per minute (default is 175)
|
||||
- speak_public_messages <on/off> - Speak public messages; This does not speak all messages. This only speaks when you are directly spoken to. (Default is on)
|
||||
- speak_indirect_messages - Speaks indirect messages in public channels, reguardless of where your nick sits in the message; If this if off, public messages will only pseak if directly addressed to you. (Default is off)
|
||||
- speak_private_messages <on/off> - Speaks incoming private messages. (Default is on)
|
||||
- speak_active_window <on/off> - Speaks the currently focused window (Default is off)
|
||||
- speak_dcc_messages <on/off> - Speaks DCC messages; Notifys if a file transfer or dcc chat request.
|
||||
|
||||
### Explanation of Public Message Speaking
|
||||
This script is designed not to be very spammy. Public messages only speak when you are directly addressed, unless you have the speak_indirect_message setting on, then it speaks also when you are mensioned.
|
||||
|
||||
#### Examples
|
||||
When only speak_public_messages is on,
|
||||
"<someone> jticket: Hi there!" Will be spoken.
|
||||
"<someone> Hi there jticket!" will not automatically be spoken.
|
||||
When speak_public_messages and speak_indirect_messages is on, both will be spoken.
|
192
autospeak.pl
Normal file
192
autospeak.pl
Normal file
@ -0,0 +1,192 @@
|
||||
#autospeak, autospeak incoming events through speech-dispatcher
|
||||
|
||||
# This program is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License as published by the
|
||||
# Free Software Foundation; version 3 of the License.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but
|
||||
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABI-
|
||||
# LITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
||||
# License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along
|
||||
# with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Encode;
|
||||
use Irssi;
|
||||
|
||||
# The character encoding of the Irssi client:
|
||||
use constant ENCODING => "UTF-8";
|
||||
|
||||
# General script information:
|
||||
our $VERSION = '1.0';
|
||||
our %IRSSI = (
|
||||
name => 'autospeak',
|
||||
description => 'Autospeak incoming messages.',
|
||||
authors => 'Jeremiah Ticket',
|
||||
contact => 'seashellpromises@gmail.com',
|
||||
url => 'https://git.stormux.org/jticket/autospeak',
|
||||
license => 'GNU General Public License, version 3',
|
||||
changed => '2023/10/05',
|
||||
);
|
||||
|
||||
|
||||
|
||||
|
||||
# Speak Some Text
|
||||
sub speak_message {
|
||||
my ($summary, $body) = @_;
|
||||
|
||||
# Convert the strings to Perl's internal representation:
|
||||
$summary = decode(ENCODING, $summary);
|
||||
$body = decode(ENCODING, $body);
|
||||
my $SpeechRate = Irssi::settings_get_int("speech_rate");
|
||||
my $SpeechVoice = Irssi::settings_get_str("speech_voice");
|
||||
# Speak The Message
|
||||
system("espeak-ng -v $SpeechVoice -s $SpeechRate \"$summary $body\"");
|
||||
}
|
||||
|
||||
# Handle incoming public messages:
|
||||
sub message_public {
|
||||
my ($server, $message, $nick, $address, $target) = @_;
|
||||
|
||||
# Check whether to notify the user about public messages:
|
||||
return unless (Irssi::settings_get_bool('speak_public_messages'));
|
||||
|
||||
# Check whether to notify the user about messages in the active window:
|
||||
unless (Irssi::settings_get_bool('speak_active_window')) {
|
||||
# Get the name of the active window:
|
||||
my $window = Irssi::active_win()->{active}->{name} || '';
|
||||
|
||||
# Ignore messages in the active window:
|
||||
return if ($window eq $target);
|
||||
}
|
||||
|
||||
# Get the user's nick name:
|
||||
my $user = $server->{nick};
|
||||
|
||||
# Check whether to notify the user about indirect messages:
|
||||
unless (Irssi::settings_get_bool('speak_indirect_messages')) {
|
||||
# Ignore messages that are not explicitly addressed to the user:
|
||||
return if ($message !~ /^$user[\s:,]/);
|
||||
}
|
||||
else {
|
||||
# Ignore messages that do not mention the user:
|
||||
return if ($message !~ /\b$user\b/);
|
||||
}
|
||||
|
||||
# Get the server's tag:
|
||||
my $tag = $server->{tag};
|
||||
|
||||
# Prepare the message body:
|
||||
(my $body = $message) =~ s/^$user[\s:,]\s*//;
|
||||
|
||||
# Notify the user about the incoming public message:
|
||||
speak_message("Message from $nick/$tag on $target:", $body);
|
||||
}
|
||||
|
||||
# Handle incoming private messages:
|
||||
sub message_private {
|
||||
my ($server, $message, $nick, $address) = @_;
|
||||
|
||||
# Check whether to notify the user about private messages:
|
||||
return unless (Irssi::settings_get_bool('speak_private_messages'));
|
||||
|
||||
# Check whether to notify the user about messages in the active window:
|
||||
unless (Irssi::settings_get_bool('speak_active_window')) {
|
||||
# Get the name of the active window:
|
||||
my $window = Irssi::active_win()->{active}->{name} || '';
|
||||
|
||||
# Ignore messages in the active window:
|
||||
return if ($window eq $nick);
|
||||
}
|
||||
|
||||
# Get the server's tag:
|
||||
my $tag = $server->{tag};
|
||||
|
||||
# Notify the user about the incoming private message:
|
||||
speak_message("Message from $nick/$tag:", $message);
|
||||
}
|
||||
|
||||
# Handle incoming DCC requests:
|
||||
sub dcc_request {
|
||||
my ($dcc, $sendaddr) = @_;
|
||||
|
||||
# Check whether to notify the user about DCC requests:
|
||||
return unless (Irssi::settings_get_bool('speak_dcc_messages'));
|
||||
|
||||
# Check whether to notify the user about messages in the active window:
|
||||
unless (Irssi::settings_get_bool('speak_active_window')) {
|
||||
# Get the name of the active window:
|
||||
my $window = Irssi::active_win()->{active}->{name} || '';
|
||||
|
||||
# Ignore messages in the active window:
|
||||
return unless ($window);
|
||||
}
|
||||
|
||||
# Get the request type:
|
||||
my $type = $dcc->{type};
|
||||
|
||||
# Get the sender's nick:
|
||||
my $nick = $dcc->{nick};
|
||||
|
||||
# Get the server's tag:
|
||||
my $tag = $dcc->{server}->{tag};
|
||||
|
||||
# Check the request type:
|
||||
if ($type eq 'GET') {
|
||||
# Get the file name and size:
|
||||
my $name = $dcc->{arg};
|
||||
my $size = $dcc->{size};
|
||||
|
||||
# Notify the user about the incoming SEND request:
|
||||
speak_message("$nick/$tag offers a file:", "$name ($size B)");
|
||||
}
|
||||
elsif ($type eq 'CHAT') {
|
||||
# Notify the user about the incoming CHAT request:
|
||||
speak_message("$nick/$tag offers a DCC chat.", "");
|
||||
}
|
||||
}
|
||||
|
||||
# Handle incoming DCC CHAT messages:
|
||||
sub dcc_chat_message {
|
||||
my ($dcc, $message) = @_;
|
||||
|
||||
# Check whether to notify the user about DCC requests:
|
||||
return unless (Irssi::settings_get_bool('speak_dcc_messages'));
|
||||
|
||||
# Get the sender's nick:
|
||||
my $nick = $dcc->{id};
|
||||
|
||||
# Check whether to notify the user about messages in the active window:
|
||||
unless (Irssi::settings_get_bool('speak_active_window')) {
|
||||
# Get the name of the active window:
|
||||
my $window = Irssi::active_win()->{active}->{name} || '';
|
||||
|
||||
# Ignore messages in the active window:
|
||||
return if ($window eq "=$nick");
|
||||
}
|
||||
|
||||
# Get the server's tag:
|
||||
my $tag = $dcc->{server}->{tag};
|
||||
|
||||
# Notify the user about the incoming CHAT message:
|
||||
speak_message("DCC chat message from $nick/$tag:", $message);
|
||||
}
|
||||
|
||||
# Register configuration options:
|
||||
Irssi::settings_add_int("autospeak", "speech_rate", 175);
|
||||
Irssi::settings_add_str("autospeak", "speech_voice", "en-us");
|
||||
Irssi::settings_add_bool('autospeak', 'speak_private_messages', 1);
|
||||
Irssi::settings_add_bool('autospeak', 'speak_public_messages', 1);
|
||||
Irssi::settings_add_bool('autospeak', 'speak_indirect_messages',0);
|
||||
Irssi::settings_add_bool('autospeak', 'speak_active_window', 0);
|
||||
Irssi::settings_add_bool('autospeak', 'speak_dcc_messages', 1);
|
||||
|
||||
# Register signals:
|
||||
Irssi::signal_add('message public', 'message_public');
|
||||
Irssi::signal_add('message private', 'message_private');
|
||||
Irssi::signal_add('dcc request', 'dcc_request');
|
||||
Irssi::signal_add('dcc chat message', 'dcc_chat_message');
|
7
install
Executable file
7
install
Executable file
@ -0,0 +1,7 @@
|
||||
#!/bin/bash
|
||||
#Basic Install Script
|
||||
read -p "This will install to~/.irssi/scripts and create a simlink to autostart the script. Press enter to continue or control+c to exit." continue
|
||||
mkdir -p ~/.irssi/scripts/autorun/
|
||||
cp -v autospeak.pl ~/.irssi/scripts/
|
||||
[ -L $HOME/.irssi/scripts/autorun/autospeak.pl ] || ln -s $HOME/.irssi/scripts/autospeak.pl $HOME/.irssi/scripts/autorun/autospeak.pl
|
||||
echo "Done!"
|
Loading…
Reference in New Issue
Block a user