aboutsummaryrefslogtreecommitdiffstats
path: root/hipchat-stfu.pl
blob: 1695ca037ea77e919684a308b8633c9447df7bc1 (plain)
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
60
61
62
use strict;
use vars qw($VERSION %IRSSI);

use Irssi qw(signal_add signal_stop signal_continue);

$VERSION = '1.00';
%IRSSI = (
	authors     => 'Teddy Wing',
	contact     => 'irssi@teddywing.com',
	name        => 'HipChat STFU',
	description => 'Silences annoying messages originating from HipChat.',
	license     => 'MIT',
);

sub prettify_hipchat {
	my ($input) = @_;
	
	# Grab browse link
	my ($link) = $input =~ /"([^"]+\/browse\/[^"]+)"/;
	
	# Remove HTML tags
	$input =~ s/<.+?>//g;
	
	# Trim whitespace
	$input =~ s/^(\s| )+|(\s| )+$//g;
	
	# Trim whitespace between words
	$input =~ s/(\s| ){2,}/ /g;
	
	# Remove Priority
	$input =~ s/Priority://g;
	
	# Remove Status
	$input =~ s/Status://g;
	
	# Construct start message
	if ($link) {
		$input =~ s/Created by (.+)$/($1) ($link)/g;
	}
	
	return $input;
};

sub hipchat_stfu {
	my ($server, $text, $nick, $address, $target) = @_;
	
	if ($server->{'chatnet'} eq 'Bitlbee' &&
		$nick eq 'root') {
		my $msg = prettify_hipchat($text);
		
		if ($msg eq '') {
			signal_stop();
		}
		else {
			signal_continue($server, $msg, $nick, $address, $target);
		}
	}
};

signal_add {
	'message public' => \&hipchat_stfu,
};