Skip to content

Instantly share code, notes, and snippets.

@brwyatt
Last active December 29, 2015 21:19
Show Gist options
  • Save brwyatt/7729368 to your computer and use it in GitHub Desktop.
Save brwyatt/7729368 to your computer and use it in GitHub Desktop.
An irssi script to shorten long links using brwyatt.net (my personal site)
#!/usr/bin/perl -w
use strict;
use Irssi;
require LWP::UserAgent;
use vars qw($VERSION %IRSSI);
$VERSION = "0.1";
%IRSSI = (
authors => 'Bryan Wyatt',
contact => 'brwyatt@brwyatt.net',
name => 'linkshortener.pl',
description => 'This script will shorten your link using brwyatt.net and post it to the channel.',
license => 'GNU General Public License',
url => 'https://gist.github.com/brwyatt/7729368',
changed => '2013-12-01 0055 GMT-6',
);
sub shortenlink {
my ($data, $server, $witem) = @_;
my $ua = LWP::UserAgent->new;
$ua->timeout(10);
$ua->agent("FetchTitleLinkPreview/".$VERSION);
$ua->env_proxy;
my $response = $ua->get($data);
if (!$response->is_error) {
my $title = $response->title();
my $ua2 = LWP::UserAgent->new;
$ua2->timeout(10);
$ua2->env_proxy;
$data =~ s/&/%26/g;
$data =~ s/\+/%2B/g;
my $response2 = $ua2->get("https://brwyatt.net/linkshortener/create?u=".$data."");
if($response2 ne "ERROR"){
$witem->command("MSG ".$witem->{name}." https://brwyatt.net/l/".$response2->content." -- ".$title."");
}else{
Irssi::print("Error in Returned Data! (server reported an error)");
}
}
else {
Irssi::print("Error in URL: \"".$data."\"");
}
}
Irssi::command_bind('link', 'shortenlink');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment