All pastes #372427 Raw Edit

Miscellany

public text v1 · immutable
#372427 ·published 2007-02-26 01:15 UTC
rendered paste body
use strict;
use vars qw($VERSION %IRSSI);

use Irssi;
$VERSION = '1.00';
%IRSSI = (
    authors     => 'Peter Greenwood',
    contact     => 'pjgat09@gmail.com',
    name        => '#rubik stats engine and scramble generators',
    license     => 'Public Domain',
);
my (@totals, @scrambles, $time,$flag);

# Load counts
  open COUNT, "/home/pjgat09/.irssi/scripts/counts.txt";
  my $line = <COUNT>;
  @totals = split /\*/, $line;
  close COUNT;
  
# This sub will handle ALL incoming private messages
sub event_privmsg {
  my ($server, $data, $nick, $address) = @_;
  my ($target, $text) = split(/ :/, $data, 2);
  # $server  -- Name of the server on which which privmsg was received
  # $nick    -- Nickname who sent the message
  # $address -- Address of $nick
  # $target  -- Location where the text was directed to
  # $text    -- Text which was sent
  
  if ($nick =~ /^pjgat09$/ && $text =~ /^\.test/ && $target =~ /^#testing123$/) {
    $server->command("msg #testing123 $flag");
  }

# -1x-1x-1 Scramble Generator    
  if ((time()-$time) >= 20 && $target =~ /^#testing123$/ && $text =~ /^[.!]-1(\s\d+)?/) {
    $totals[8]++;
    my $result = "-1x-1x-1 scramble #$totals[8]: ";
    for (my $i; $i < 15; $i++) {
      $result .= chr(int(rand(129))+1);
    }
    $server->command("msg #testing123 " . $result . "Error: Subscript out of range.");
    $time = time() - 18;
    save_counts();
  }  
  
# 0x0x0 Scramble Generator    
  if ((time()-$time) >= 20 && $target =~ /^#testing123$/ && $text =~ /^[.!]0(\s\d+)?/) {
    $totals[0]++;
    $server->command("msg #testing123 0x0x0 scramble #$totals[0]:");
    $time = time() - 18;
    save_counts();
  }  

# 1x1x1 Scramble Generator  
  if ((time()-$time) >= 20 && $target =~ /^#testing123$/ && $text =~ /^[.!]1(\s(\d+))?/) {
    my $len = $2;
    if ($len > 50) { $len = 50; }
    if ($len <= 0) { $len = 10; }
    Irssi::signal_stop();
    my $chars = "xyz2'";
    my ($result,$rand,$a);
    for (my $i; $i < $len; $i++) {
      $rand = int(rand(3));
      while ($rand == $a) { $rand = int(rand(3)); }
      $a = $rand;
      $result .= substr($chars,$rand,1);
      $rand = int(rand(3));
      if ($rand) { $result .= substr($chars,$rand+2,1); }
      $result .= " ";
    }
    $totals[1]++;
    $time = time() - 15;
    $server->command("msg #testing123 1x1x1 scramble #$totals[1]: $result");
    save_counts();
  }

    
# 3x3x3 Scramble Generator  
  if ((time()-$time) >= 20 && $target =~ /^#testing123$/ && $text =~ /^[.!]3(\s(\d+))?/) {
    my $len = $2;
    if ($len > 100) { $len = 100; }
    if ($len <= 0) { $len = 25; }
    Irssi::signal_stop();
    my $chars = "UDFBLR2'";
    my ($result, $a, $b,$rand);
    my @check = (1,0,3,2,5,4);
    for (my $i; $i < $len; $i++) {
      $rand = int(rand(6));
      while ($rand == $a || ($rand == $b && $check[$rand] == $a)) { $rand = int(rand(6));  }
      $b = $a;
      $a = $rand;
      $result .= substr($chars,$rand,1);
      $rand = int(rand(3));
      if ($rand) { $result .= substr($chars,$rand+5,1); }
      $result .= " ";
    }
    $totals[3]++;
    $time = time();
    $server->command("msg #testing123 3x3x3 scramble #$totals[3]: $result");
    save_counts();
  }

# Roux/2gen Scramble Generator
  if (((time()-$time) >= 20 || $nick =~ /^pjgat09$/) && $target =~ /^#testing123$/ && $text =~ /^[.!](roux|2g(en)?)(\s(\d+))?/) {
    my $type = $1;
    my $len = $4;
    if ($len > 100) { $len = 100; }
    if ($len <= 0) { $len = 16; }
    my $start = int(rand(2));
    $flag = $start;
    my ($result,$rand);
    my $chars; 
    $chars = "UM2'" if ($type =~ /roux/);
    $chars = "UR2'" if ($type =~ /2/);
    for (my $i; $i < $len; $i++) {
      $result .= substr($chars,$start,1);
      $rand = int(rand(3));
      if ($rand) {
        $result .= substr($chars,$rand+1,1);
      }
      $result .= " ";
      $start = $start ^ 1;
      $flag .= $start;
    }
    $totals[6]++ if ($type =~ /roux/);
    $totals[9]++ if ($type =~ /2/);
    $server->command("msg #testing123 roux scramble #$totals[6]: $result") if ($type =~ /roux/); 
    $server->command("msg #testing123 2gen scramble #$totals[9]: $result") if ($type =~ /2/); 
    $time = time();
    save_counts();
  }
}

# This signal_add tells where to to direct incoming private message: event_privmsg
Irssi::signal_add("event privmsg", "event_privmsg");

# Subs

sub save_counts {
  open COUNT, ">/home/pjgat09/.irssi/scripts/counts.txt";
  print COUNT join ('*', @totals[0 .. 9]);
  close COUNT;
}