Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Way too cool! I'm going to borrow some expressions from your queries.

I do almost the same for our local irc channel, but connections are based only on number of directly addressed (=~ /^$nick/) messages. And GraphViz helps to avoid writing .DOT files.

#!/usr/bin/perl -w use strict; use Net::IRC; use Storable; use Data::Dumper; use GraphViz; use vars qw/$myself $version $channel $network_file $format_version $admin_nick $output_file $output_url %users $network $aliases @topic_log/; do 'octopus.config.pl' or die "Cannot read config: err= $!, evalerr= $@\n"; $network_file = "chan.$channel.8pus.$format_version"; my $nick_re = qr/[A-Za-z](?:[A-Za-z0-9_`\\\]\[^}{-])+/; sub save { store [$network, $aliases], $network_file; print "Saved network\n"; my $nnetwork; # normalized as per $aliases foreach my $from (keys %$network) { my $real_from = $aliases->{$from} || $from; foreach my $to (keys %{$network->{$from}}) { my $real_to = $aliases->{$to} || $to; $nnetwork->{$real_from}->{$real_to} += $network->{$from}-> +{$to}; } } my $g = new GraphViz layout => 'dot', concentrate => 1, directed => 0; foreach my $from (keys %$nnetwork) { $g->add_node($from); foreach my $to (keys %{$nnetwork->{$from}}) { $g->add_node($to); $g->add_edge($from, $to, weight => $nnetwork->{$from}->{$t +o}); } } open CHART, ">$output_file"; binmode CHART; print CHART $g->as_png; close CHART; } sub on_connect { my $self = shift; print "Joining $channel...\n"; $self->join($channel); $self->privmsg($channel, "Hi from the Deep."); eval { ($network, $aliases) = @{retrieve($network_file)} }; $network ||= {}; $aliases ||= {}; } sub on_public_msg { my $self = shift; my $event = shift; my $message = ($event->args)[0]; print $event->nick . " says: '" . $message . "'\n"; if ($message =~ /^$myself/o) { # to me if ($message =~ /\bhi\b/i) { $self->privmsg($channel, "Hi, (?:wo)?man. I\'m an 8pus v.$ +version reading $channel"); } elsif ($message =~ /\bwhere\b/) { $self->privmsg($channel, "Look at $output_url"); } elsif ($message =~ /help/) { $self->privmsg($channel, "Available commands: hi, where, h +elp, topiclog"); } } for my $user (keys %users) { if ($message =~ /^$user\b/) { $network->{$event->nick}->{$user}++; } } } sub on_msg { my $self = shift; my $event = shift; my $message = ($event->args)[0]; print $event->nick . " privately says: '" . $message . "'\n"; if ($message =~ /save/) { save; $self->privmsg($event->nick, 'Ok, saved'); } elsif ($message =~ /dump/) { for my $line (split "\n", Dumper($network)) { $self->privmsg($event->nick, $line); } } elsif ($event->nick eq $admin_nick && $message =~ /($nick_re)\s+ +aka\s+($nick_re)/o) { $aliases->{$2} = $1; $self->privmsg($event->nick, "'$2' is now an alias for '$1', a +h ok..."); } } sub on_names { my ($self, $event) = @_; my @args = $event->args; %users = map { $_ => 1 } map { s/^[@+]//; $_ } split ' ', $args[3] +; print "Users online: " . join (', ', keys %users) . "\n"; } sub on_part { my ($self, $event) = @_; delete $users{$event->nick}; } sub on_join { my ($self, $event) = @_; $users{$event->nick} = 1; } my $irc = new Net::IRC; my $conn = newconn $irc Nick => $myself, Server => 'irc.server', Port => 6667, Username=> '8pus', Ircname => 'Octopus Vulgaris'; $conn->add_handler(376 => \&on_connect); $conn->add_handler(public => \&on_public_msg); $conn->add_handler(msg => \&on_msg); $conn->add_handler(353 => \&on_names); $conn->add_handler('join' => \&on_join); $conn->add_handler(part => \&on_part); $irc->start; save;
Config file looks like this:
$myself = 'Octopus'; $version = '0.5'; $channel = '#free_tibet'; $format_version = 'III'; $admin_nick = 'kappa'; $channel =~ /^#(.+)$/ and do { $output_file = "charts/chan.$1.net.png"; $output_url = "http://my.web.site/octopus/chan.$1.net.png"; }

In reply to Re: Chatterbox conversational clusters by kappa
in thread Chatterbox conversational clusters by diotalevi

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and cookies bake in the oven...

    How do I use this? | Other CB clients
    Other Users?
    Others exploiting the Monastery: (9)
    As of 2017-10-21 09:46 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      My fridge is mostly full of:

















      Results (269 votes). Check out past polls.

      Notices?