Last active
October 30, 2017 23:48
-
-
Save mwgamera/4b17029b3b974c90dc9e00d12324dd77 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Bet in Rizon lottery | |
# <https://wiki.rizon.net/index.php?title=Vizon> | |
# klg, May 2017 | |
use strict; | |
use Irssi; | |
use List::Util 'shuffle'; | |
my $server_tag = 'Rizon'; | |
my $vizon_nick = 'VIzon'; | |
schedule_next(3600, \&place_bet); | |
# Find next drawing time using GNU date(1) | |
# Drawing every Tuesday, Thursday, and Saturday at 00:00 CET/CEST | |
sub next_drawing { | |
my $off = shift // 0; | |
my @d = map int `date +%s -d 'TZ="CET-1CEST,M3.5.0,M10.5.0/3" $_ + $off sec'`, qw/Tuesday Thursday Saturday/; | |
(sort {$a <=> $b} grep $_ > time + $off, @d)[0]; | |
} | |
sub schedule_next { | |
my ($offset, $fun) = @_; | |
my $sleep = next_drawing(-$offset) - time; | |
$sleep = 1 if $sleep < 1; | |
Irssi::print "VIzon: Scheduling bet in $sleep sec", MSGLEVEL_CRAP; | |
Irssi::timeout_add_once 1000*$sleep, sub { | |
Irssi::timeout_add_once 1000*($offset+1), sub { | |
schedule_next($offset, $fun); }, 0; | |
$fun->(); | |
}, 0; | |
} | |
sub place_bet { | |
return unless my $s = Irssi::server_find_tag $server_tag; | |
my @bet = sort {$a <=> $b} (shuffle 1..29)[0..5]; | |
Irssi::print "VIzon: Attempting to place a bet: @bet", MSGLEVEL_CRAP; | |
$s->send_message($vizon_nick, "bet @bet", 1); | |
} | |
1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment