Attachment 'ddtopic.pl'

Download

   1 # This script was written by Ari Pollak <ari at debian.org>.
   2 # I hereby place it into the public domain.
   3 #
   4 # This script sucks, it currently freezes irssi while it does the
   5 # web page processing.
   6 #
   7 # The cookie file at ~/.irssi/lwp_cookies.txt should look like this (obviously
   8 # replace it with your own login cookie), and removing the leading #s:
   9 #
  10 # #LWP-Cookies-1.0
  11 # Set-Cookie3: MOIN_SESSION=00000000000; path="/"; domain=wiki.debian.org; path_spec; expires="2018-12-26 00:01:51Z"; version=0
  12 
  13 use strict;
  14 use vars qw($VERSION %IRSSI);
  15 
  16 use Irssi;
  17 use WWW::Mechanize;
  18 
  19 $VERSION = '1.30';
  20 %IRSSI = (
  21     authors     => 'Ari Pollak',
  22     name        => 'ddtopic',
  23     description => "Changes the appropriate wiki.debian.org page when a channel's topic changes",
  24     license     => 'Public Domain'
  25 );
  26 
  27 my $monitor_channel = "#debian-devel";
  28 my $monitor_network = "oftc";
  29 my $wikipage = "http://wiki.debian.org/TopicDebianDevel";
  30 my $cookiefile = "$ENV{'HOME'}/.irssi/lwp_cookies.txt";
  31 
  32 my $agent = WWW::Mechanize->new;
  33 $agent->cookie_jar({file => $cookiefile});
  34 $agent->timeout(5);
  35 
  36 sub update_wiki {
  37 	my ($channame, $chantopic, $topicby) = @_;
  38 
  39 	$topicby = (split /!/, $topicby)[0]; # don't include user's hostname
  40 	return unless $topicby;
  41 
  42 	$chantopic =~ s/^/ * /;
  43 	$chantopic =~ s/\s+\|\s+/\n * /g; # Separate |s into bullets
  44 	$chantopic =~ s!#(\d+)![[DebianBug:$1|#$1]]!g; # Link bug numbers
  45 	$chantopic =~ s/FUCKED/BROKEN/g; # Censoring
  46 	$chantopic =~ s/Fucked/Broken/g; # Censoring
  47 	$chantopic =~ s/fucked/broken/g; # Censoring
  48 	$chantopic =~ s/FUCK/BROK/g; # Censoring
  49 	$chantopic =~ s/fuck/brok/g; # Censoring
  50 	
  51 	$chantopic .= "\n(Topic set by $topicby)";
  52 	$chantopic .= "\n----\nThis page contains an automatically-updated representation of the topic on the $monitor_channel [[IRC]] channel on $monitor_network. Please don't edit this page, as it has no effect on the IRC topic. Also, there are no guarantees that this page is accurate. If there are any questions/concerns, please contact AriPollak.\n\nThe source to the irssi script used to update this page is here: [[attachment:ddtopic.pl]]";
  53 
  54 	$agent->get("$wikipage?action=edit");
  55 	$agent->field("savetext", $chantopic);
  56 	$agent->field("comment", "Automatically updated by ddtopic.pl");
  57 	$agent->click("button_save");
  58 
  59 	$agent->cookie_jar->save();
  60 }
  61 
  62 sub new_topic {
  63 	my ($channel) = @_;
  64 	return unless $channel->{name} eq $monitor_channel;
  65 	return unless $channel->{server}->{tag} eq $monitor_network;
  66 
  67 	eval {
  68 	    update_wiki($channel->{name}, $channel->{topic},
  69 			$channel->{topic_by});
  70 	};
  71 	print "ddtopic.pl: " . $@ if $@;
  72 }
  73 
  74 foreach my $channel (Irssi::channels()) {
  75 	if($channel->{name} eq $monitor_channel) {
  76 		new_topic($channel);
  77 	}
  78 }
  79 
  80 # Topic has changed
  81 Irssi::signal_add 'channel topic changed' => \&new_topic;
  82 
  83 # We've joined a new channel
  84 Irssi::signal_add 'channel joined' => \&new_topic;

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.

You are not allowed to attach a file to this page.