2018-01-29 06:53:40 +01:00
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
2019-09-01 20:01:18 +02:00
package Plugins::Spinach ;
2018-01-29 06:53:40 +01:00
use warnings ;
use strict ;
2019-04-24 12:55:48 +02:00
use FindBin ;
use lib "$FindBin::RealBin/../.." ;
2018-01-29 06:53:40 +01:00
use feature 'switch' ;
no if $] >= 5.018 , warnings = > "experimental::smartmatch" ;
2019-07-11 03:40:53 +02:00
use feature 'unicode_strings' ;
2018-01-29 06:53:40 +01:00
use Carp ( ) ;
use JSON ;
2018-02-04 05:42:27 +01:00
use Lingua::EN::Fractions qw/fraction2words/ ;
use Lingua::EN::Numbers qw/num2en num2en_ordinal/ ;
use Lingua::EN::Numbers::Years qw/year2en/ ;
use Lingua::Stem qw/stem/ ;
2018-02-09 21:47:06 +01:00
use Lingua::EN::ABC qw/b2a/ ;
2018-02-04 05:42:27 +01:00
2018-02-25 03:17:55 +01:00
use Time::Duration qw/concise duration/ ;
2019-05-07 11:19:03 +02:00
use Text::Unidecode ;
use Encode ;
2018-01-30 06:54:52 +01:00
use Data::Dumper ;
2018-03-02 20:02:34 +01:00
$ Data:: Dumper:: Sortkeys = sub { my ( $ h ) = @ _ ; my @ a = sort grep { not /^(?:seen_questions|alternativeSpellings)$/ } keys %$ h ; \ @ a } ;
2018-02-25 03:17:55 +01:00
$ Data:: Dumper:: Useqq = 1 ;
2018-01-29 06:53:40 +01:00
2019-04-24 02:59:39 +02:00
use PBot::HashObject ;
2019-09-01 20:01:18 +02:00
use Plugins::Spinach::Stats ;
use Plugins::Spinach::Rank ;
2019-04-24 12:55:48 +02:00
2018-01-29 06:53:40 +01:00
sub new {
Carp:: croak ( "Options to " . __FILE__ . " should be key/value pairs, not hash reference" ) if ref $ _ [ 1 ] eq 'HASH' ;
my ( $ class , % conf ) = @ _ ;
my $ self = bless { } , $ class ;
$ self - > initialize ( % conf ) ;
return $ self ;
}
sub initialize {
my ( $ self , % conf ) = @ _ ;
$ self - > { pbot } = delete $ conf { pbot } // Carp:: croak ( "Missing pbot reference to " . __FILE__ ) ;
$ self - > { pbot } - > { commands } - > register ( sub { $ self - > spinach_cmd ( @ _ ) } , 'spinach' , 0 ) ;
$ self - > { pbot } - > { timer } - > register ( sub { $ self - > spinach_timer } , 1 , 'spinach timer' ) ;
2018-01-30 07:15:08 +01:00
$ self - > { pbot } - > { event_dispatcher } - > register_handler ( 'irc.part' , sub { $ self - > on_departure ( @ _ ) } ) ;
$ self - > { pbot } - > { event_dispatcher } - > register_handler ( 'irc.quit' , sub { $ self - > on_departure ( @ _ ) } ) ;
$ self - > { pbot } - > { event_dispatcher } - > register_handler ( 'irc.kick' , sub { $ self - > on_kick ( @ _ ) } ) ;
2018-02-11 00:57:58 +01:00
2020-01-22 05:15:14 +01:00
$ self - > { channel } = $ self - > { pbot } - > { registry } - > get_value ( 'spinach' , 'channel' ) // '##spinach' ;
2019-04-24 12:55:48 +02:00
2019-05-06 08:11:45 +02:00
my $ default_file = $ self - > { pbot } - > { registry } - > get_value ( 'spinach' , 'file' ) // 'trivia.json' ;
$ self - > { questions_filename } = $ self - > { pbot } - > { registry } - > get_value ( 'general' , 'data_dir' ) . "/spinach/$default_file" ;
2019-04-23 00:51:09 +02:00
$ self - > { stopwords_filename } = $ self - > { pbot } - > { registry } - > get_value ( 'general' , 'data_dir' ) . '/spinach/stopwords' ;
2019-04-24 02:59:39 +02:00
$ self - > { metadata_filename } = $ self - > { pbot } - > { registry } - > get_value ( 'general' , 'data_dir' ) . '/spinach/metadata' ;
2019-04-24 12:55:48 +02:00
$ self - > { stats_filename } = $ self - > { pbot } - > { registry } - > get_value ( 'general' , 'data_dir' ) . '/spinach/stats.sqlite' ;
2019-04-24 02:59:39 +02:00
$ self - > { metadata } = PBot::HashObject - > new ( pbot = > $ self - > { pbot } , name = > 'Spinach Metadata' , filename = > $ self - > { metadata_filename } ) ;
2020-01-24 07:46:41 +01:00
$ self - > load_metadata ( ) ;
2018-01-29 06:53:40 +01:00
2019-09-01 20:01:18 +02:00
$ self - > { stats } = Plugins::Spinach::Stats - > new ( pbot = > $ self - > { pbot } , filename = > $ self - > { stats_filename } ) ;
$ self - > { rankcmd } = Plugins::Spinach::Rank - > new ( pbot = > $ self - > { pbot } , channel = > $ self - > { channel } , filename = > $ self - > { stats_filename } ) ;
2019-04-24 12:55:48 +02:00
2020-01-24 07:46:41 +01:00
$ self - > create_states ( ) ;
$ self - > load_questions ( ) ;
$ self - > load_stopwords ( ) ;
2018-01-29 06:53:40 +01:00
2018-03-23 20:33:07 +01:00
$ self - > { choosecategory_max_count } = 4 ;
2018-02-01 07:11:26 +01:00
$ self - > { picktruth_max_count } = 4 ;
2020-01-19 11:35:33 +01:00
$ self - > { tock_duration } = 30 ;
2018-01-29 06:53:40 +01:00
}
sub unload {
my $ self = shift ;
$ self - > { pbot } - > { commands } - > unregister ( 'spinach' ) ;
$ self - > { pbot } - > { timer } - > unregister ( 'spinach timer' ) ;
2019-04-24 12:55:48 +02:00
$ self - > { stats } - > end if $ self - > { stats_running } ;
2018-01-29 06:53:40 +01:00
}
2018-01-30 07:15:08 +01:00
sub on_kick {
my ( $ self , $ event_type , $ event ) = @ _ ;
my ( $ nick , $ user , $ host ) = ( $ event - > { event } - > nick , $ event - > { event } - > user , $ event - > { event } - > host ) ;
my ( $ victim , $ reason ) = ( $ event - > { event } - > to , $ event - > { event } - > { args } [ 1 ] ) ;
my $ channel = $ event - > { event } - > { args } [ 0 ] ;
return 0 if lc $ channel ne $ self - > { channel } ;
$ self - > player_left ( $ nick , $ user , $ host ) ;
return 0 ;
}
sub on_departure {
my ( $ self , $ event_type , $ event ) = @ _ ;
2018-02-02 05:15:54 +01:00
my ( $ nick , $ user , $ host , $ channel ) = ( $ event - > { event } - > nick , $ event - > { event } - > user , $ event - > { event } - > host , $ event - > { event } - > to ) ;
my $ type = uc $ event - > { event } - > type ;
return 0 if $ type ne 'QUIT' and lc $ channel ne $ self - > { channel } ;
2018-01-30 07:15:08 +01:00
$ self - > player_left ( $ nick , $ user , $ host ) ;
return 0 ;
}
2018-01-29 06:53:40 +01:00
sub load_questions {
2018-02-27 01:54:34 +01:00
my ( $ self , $ filename ) = @ _ ;
if ( not defined $ filename ) {
$ filename = exists $ self - > { loaded_filename } ? $ self - > { loaded_filename } : $ self - > { questions_filename } ;
} else {
$ filename = $ self - > { pbot } - > { registry } - > get_value ( 'general' , 'data_dir' ) . "/spinach/$filename" ;
}
2018-01-29 06:53:40 +01:00
2019-05-08 10:37:00 +02:00
$ self - > { pbot } - > { logger } - > log ( "Spinach: Loading questions from $filename...\n" ) ;
2018-01-29 06:53:40 +01:00
my $ contents = do {
2018-02-27 01:54:34 +01:00
open my $ fh , '<' , $ filename or do {
$ self - > { pbot } - > { logger } - > log ( "Spinach: Failed to open $filename: $!\n" ) ;
return "Failed to load $filename" ;
2018-01-29 06:53:40 +01:00
} ;
local $/ ;
2019-07-01 00:08:18 +02:00
my $ text = <$fh> ;
2019-06-28 09:22:57 +02:00
close $ fh ;
2019-07-01 00:08:18 +02:00
$ text ;
2018-01-29 06:53:40 +01:00
} ;
2018-02-27 01:54:34 +01:00
$ self - > { loaded_filename } = $ filename ;
2018-01-29 06:53:40 +01:00
$ self - > { questions } = decode_json $ contents ;
$ self - > { categories } = ( ) ;
my $ questions ;
foreach my $ key ( keys % { $ self - > { questions } } ) {
foreach my $ question ( @ { $ self - > { questions } - > { $ key } } ) {
2018-02-15 18:21:41 +01:00
$ question - > { category } = uc $ question - > { category } ;
2018-02-15 04:09:57 +01:00
$ self - > { categories } { $ question - > { category } } { $ question - > { id } } = $ question ;
2019-05-03 08:13:27 +02:00
if ( not exists $ question - > { seen_timestamp } ) {
$ question - > { seen_timestamp } = 0 ;
}
2019-05-06 08:11:45 +02:00
if ( not exists $ question - > { value } ) {
$ question - > { value } = 0 ;
}
2018-01-29 06:53:40 +01:00
$ questions + + ;
}
}
my $ categories ;
2018-02-15 18:21:41 +01:00
foreach my $ category ( sort { keys % { $ self - > { categories } { $ b } } <=> keys % { $ self - > { categories } { $ a } } } keys % { $ self - > { categories } } ) {
2018-02-15 04:09:57 +01:00
my $ count = keys % { $ self - > { categories } { $ category } } ;
2019-05-08 10:37:00 +02:00
# $self->{pbot}->{logger}->log("Category [$category]: $count\n");
2018-01-29 06:53:40 +01:00
$ categories + + ;
}
$ self - > { pbot } - > { logger } - > log ( "Spinach: Loaded $questions questions in $categories categories.\n" ) ;
2018-02-27 01:54:34 +01:00
return "Loaded $questions questions in $categories categories." ;
2018-01-29 06:53:40 +01:00
}
2019-05-03 08:13:27 +02:00
sub save_questions {
my $ self = shift ;
2019-07-01 02:00:03 +02:00
my $ json = JSON - > new ;
my $ json_text = $ json - > pretty - > canonical - > utf8 - > encode ( $ self - > { questions } ) ;
2019-05-03 08:13:27 +02:00
my $ filename = exists $ self - > { loaded_filename } ? $ self - > { loaded_filename } : $ self - > { questions_filename } ;
open my $ fh , '>' , $ filename or do {
$ self - > { pbot } - > { logger } - > log ( "Failed to open Spinach file $filename: $!\n" ) ;
return ;
} ;
2019-07-01 02:00:03 +02:00
print $ fh "$json_text\n" ;
2019-05-03 08:13:27 +02:00
close $ fh ;
}
2018-02-11 02:13:26 +01:00
sub load_stopwords {
my $ self = shift ;
open my $ fh , '<' , $ self - > { stopwords_filename } or do {
$ self - > { pbot } - > { logger } - > log ( "Spinach: Failed to open $self->{stopwords_filename}: $!\n" ) ;
return ;
} ;
foreach my $ word ( <$fh> ) {
chomp $ word ;
$ self - > { stopwords } { $ word } = 1 ;
}
close $ fh ;
}
2019-04-24 02:59:39 +02:00
sub load_metadata {
2019-04-23 00:51:09 +02:00
my $ self = shift ;
2019-04-24 02:59:39 +02:00
$ self - > { metadata } - > load ;
2019-04-24 03:41:57 +02:00
2019-05-14 02:59:15 +02:00
my $ defaults = {
category_choices = > 7 ,
category_autopick = > 0 ,
min_players = > 2 ,
stats = > 1 ,
seen_expiry = > 432000 ,
min_difficulty = > 0 ,
max_difficulty = > 25000 ,
2019-05-17 17:46:20 +02:00
max_missed_inputs = > 3 ,
2019-05-15 19:58:32 +02:00
debug_state = > 0 ,
2019-05-14 02:59:15 +02:00
} ;
2020-01-15 03:10:53 +01:00
if ( not exists $ self - > { metadata } - > { hash } - > { settings } ) {
$ self - > { metadata } - > { hash } - > { settings } = $ defaults ;
2019-05-14 02:59:15 +02:00
} else {
foreach my $ key ( keys %$ defaults ) {
2020-01-15 03:10:53 +01:00
if ( not exists $ self - > { metadata } - > { hash } - > { settings } - > { $ key } ) {
$ self - > { metadata } - > { hash } - > { settings } - > { $ key } = $ defaults - > { $ key } ;
2019-05-14 02:59:15 +02:00
}
}
2019-04-24 03:41:57 +02:00
}
2019-04-23 00:51:09 +02:00
}
2019-04-24 02:59:39 +02:00
sub save_metadata {
2019-04-23 00:51:09 +02:00
my $ self = shift ;
2019-04-24 02:59:39 +02:00
$ self - > { metadata } - > save ;
2019-04-23 00:51:09 +02:00
}
2018-02-01 07:11:26 +01:00
my % color = (
white = > "\x0300" ,
black = > "\x0301" ,
blue = > "\x0302" ,
green = > "\x0303" ,
red = > "\x0304" ,
maroon = > "\x0305" ,
purple = > "\x0306" ,
orange = > "\x0307" ,
yellow = > "\x0308" ,
lightgreen = > "\x0309" ,
teal = > "\x0310" ,
cyan = > "\x0311" ,
lightblue = > "\x0312" ,
magneta = > "\x0313" ,
gray = > "\x0314" ,
lightgray = > "\x0315" ,
bold = > "\x02" ,
italics = > "\x1D" ,
underline = > "\x1F" ,
reverse = > "\x16" ,
reset = > "\x0F" ,
) ;
2018-01-29 06:53:40 +01:00
sub spinach_cmd {
my ( $ self , $ from , $ nick , $ user , $ host , $ arguments ) = @ _ ;
2018-02-04 05:42:27 +01:00
$ arguments =~ s/^\s+|\s+$//g ;
2018-01-29 06:53:40 +01:00
2019-05-05 04:28:34 +02:00
my $ usage = "Usage: spinach join|exit|ready|unready|choose|lie|reroll|skip|keep|score|show|rank|categories|filter|set|unset|kick|abort; for more information about a command: spinach help <command>" ;
2018-01-29 06:53:40 +01:00
my $ command ;
( $ command , $ arguments ) = split / / , $ arguments , 2 ;
2020-01-22 05:15:14 +01:00
$ command = defined $ command ? lc $ command : '' ;
2018-01-29 06:53:40 +01:00
my ( $ channel , $ result ) ;
given ( $ command ) {
when ( 'help' ) {
given ( $ arguments ) {
2018-02-04 05:42:27 +01:00
when ( 'help' ) {
return "Seriously?" ;
}
2018-01-29 06:53:40 +01:00
when ( 'join' ) {
return "Help is coming soon." ;
}
when ( 'ready' ) {
return "Help is coming soon." ;
}
when ( 'exit' ) {
return "Help is coming soon." ;
}
2018-02-15 07:13:54 +01:00
when ( 'skip' ) {
2018-02-15 18:21:41 +01:00
return "Use `skip` to skip a question and return to the \"choose category\" stage. A majority of the players must agree to skip." ;
2018-02-15 07:13:54 +01:00
}
2019-05-05 04:28:34 +02:00
when ( 'keep' ) {
return "Use `keep` to vote to prevent the current question from being rerolled or skipped." ;
}
2018-01-29 06:53:40 +01:00
when ( 'abort' ) {
return "Help is coming soon." ;
}
2018-02-26 09:46:59 +01:00
when ( 'reroll' ) {
return "Use `reroll` to get a different question from the same category." ;
2018-01-29 06:53:40 +01:00
}
when ( 'kick' ) {
return "Help is coming soon." ;
}
2018-02-02 05:15:54 +01:00
when ( 'players' ) {
return "Help is coming soon." ;
}
2018-02-01 07:11:26 +01:00
when ( 'score' ) {
return "Help is coming soon." ;
}
2018-01-29 06:53:40 +01:00
when ( 'choose' ) {
return "Help is coming soon." ;
}
when ( 'lie' ) {
return "Help is coming soon." ;
}
when ( 'truth' ) {
return "Help is coming soon." ;
}
2018-01-30 06:54:52 +01:00
when ( 'show' ) {
2019-04-22 03:56:46 +02:00
return "Show the current question again." ;
}
when ( 'categories' ) {
return "Help is coming soon." ;
}
when ( 'filter' ) {
2018-01-30 06:54:52 +01:00
return "Help is coming soon." ;
}
2019-04-24 03:22:52 +02:00
when ( 'set' ) {
return "Help is coming soon." ;
}
when ( 'unset' ) {
return "Help is coming soon." ;
}
2019-04-24 12:55:48 +02:00
when ( 'rank' ) {
return "Help is coming soon." ;
}
2018-01-29 06:53:40 +01:00
default {
if ( length $ arguments ) {
return "Spinach has no such command '$arguments'. I can't help you with that." ;
} else {
return "Usage: spinach help <command>" ;
}
}
}
}
2018-02-15 04:09:57 +01:00
when ( 'edit' ) {
2020-01-25 21:31:08 +01:00
my $ admin = $ self - > { pbot } - > { users } - > loggedin_admin ( $ self - > { channel } , "$nick!$user\@$host" ) ;
2018-02-15 04:09:57 +01:00
if ( not $ admin ) {
return "$nick: Sorry, only admins may edit questions." ;
}
my ( $ id , $ key , $ value ) = split /\s+/ , $ arguments , 3 ;
if ( not defined $ id ) {
2020-01-29 22:35:56 +01:00
return "Usage: spinach edit <question id> [key [value]]" ;
2018-02-15 04:09:57 +01:00
}
2018-02-16 19:35:08 +01:00
$ id =~ s/,//g ;
2018-02-15 04:09:57 +01:00
my $ question ;
foreach my $ q ( @ { $ self - > { questions } - > { questions } } ) {
if ( $ q - > { id } == $ id ) {
$ question = $ q ;
last ;
}
}
if ( not defined $ question ) {
return "$nick: No such question." ;
}
if ( not defined $ key ) {
my $ dump = Dumper $ question ;
2018-02-19 05:24:51 +01:00
$ dump =~ s/\$VAR\d+ = \{\s*// ;
$ dump =~ s/ \};\s*$// ;
2018-02-15 04:09:57 +01:00
return "$nick: Question $id: $dump" ;
}
if ( not defined $ value ) {
my $ v = $ question - > { $ key } // 'unset' ;
return "$nick: Question $id: $key => $v" ;
}
2018-02-25 03:17:55 +01:00
if ( $ key !~ m/^(?:question|answer|category)$/i ) {
return "$nick: You may not edit that key." ;
}
2018-02-15 04:09:57 +01:00
$ question - > { $ key } = $ value ;
2019-07-01 02:00:03 +02:00
$ self - > save_questions ;
2018-02-15 07:13:54 +01:00
return "$nick: Question $id: $key set to $value" ;
2018-02-15 04:09:57 +01:00
}
2018-01-29 06:53:40 +01:00
when ( 'load' ) {
2020-01-25 21:31:08 +01:00
my $ admin = $ self - > { pbot } - > { users } - > loggedin_admin ( $ self - > { channel } , "$nick!$user\@$host" ) ;
2018-01-29 06:53:40 +01:00
if ( not $ admin or $ admin - > { level } < 90 ) {
return "$nick: Sorry, only very powerful admins may reload the questions." ;
}
2018-02-27 01:54:34 +01:00
$ arguments = undef if not length $ arguments ;
return $ self - > load_questions ( $ arguments ) ;
2018-01-29 06:53:40 +01:00
}
when ( 'join' ) {
if ( $ self - > { current_state } eq 'nogame' ) {
2018-02-19 01:40:17 +01:00
$ self - > { state_data } = { players = > [] , counter = > 0 } ;
2018-02-04 05:42:27 +01:00
$ self - > { current_state } = 'getplayers' ;
2018-01-29 06:53:40 +01:00
}
2019-05-08 10:39:52 +02:00
my $ id = $ self - > { pbot } - > { messagehistory } - > { database } - > get_message_account_ancestor ( $ nick , $ user , $ host ) ;
2018-01-29 06:53:40 +01:00
foreach my $ player ( @ { $ self - > { state_data } - > { players } } ) {
if ( $ player - > { id } == $ id ) {
return "$nick: You have already joined this game." ;
}
}
2018-02-11 00:57:58 +01:00
2018-02-04 05:42:27 +01:00
my $ player = { id = > $ id , name = > $ nick , score = > 0 , ready = > $ self - > { current_state } eq 'getplayers' ? 0 : 1 , missedinputs = > 0 } ;
2018-01-29 06:53:40 +01:00
push @ { $ self - > { state_data } - > { players } } , $ player ;
2018-02-02 05:15:54 +01:00
$ self - > { state_data } - > { counter } = 0 ;
2018-01-29 06:53:40 +01:00
return "/msg $self->{channel} $nick has joined the game!" ;
}
when ( 'ready' ) {
2019-05-08 10:39:52 +02:00
my $ id = $ self - > { pbot } - > { messagehistory } - > { database } - > get_message_account_ancestor ( $ nick , $ user , $ host ) ;
2018-01-29 06:53:40 +01:00
foreach my $ player ( @ { $ self - > { state_data } - > { players } } ) {
if ( $ player - > { id } == $ id ) {
2018-02-12 08:37:37 +01:00
if ( $ self - > { current_state } ne 'getplayers' ) {
return "/msg $nick This is not the time to use `ready`." ;
}
if ( $ player - > { ready } == 0 ) {
$ player - > { ready } = 1 ;
$ player - > { score } = 0 ;
return "/msg $self->{channel} $nick is ready!" ;
} else {
return "/msg $nick You are already ready." ;
}
2018-01-29 06:53:40 +01:00
}
}
2018-02-12 08:37:37 +01:00
return "$nick: You haven't joined this game yet. Use `j` to play now!" ;
2018-01-29 06:53:40 +01:00
}
2018-02-11 00:57:58 +01:00
when ( 'unready' ) {
2019-05-08 10:39:52 +02:00
my $ id = $ self - > { pbot } - > { messagehistory } - > { database } - > get_message_account_ancestor ( $ nick , $ user , $ host ) ;
2018-02-11 00:57:58 +01:00
foreach my $ player ( @ { $ self - > { state_data } - > { players } } ) {
if ( $ player - > { id } == $ id ) {
2018-02-12 08:37:37 +01:00
if ( $ self - > { current_state } ne 'getplayers' ) {
return "/msg $nick This is not the time to use `unready`." ;
}
if ( $ player - > { ready } != 0 ) {
$ player - > { ready } = 0 ;
return "/msg $self->{channel} $nick is no longer ready!" ;
} else {
return "/msg $nick You are already not ready." ;
}
2018-02-11 00:57:58 +01:00
}
}
2018-02-12 08:37:37 +01:00
return "$nick: You haven't joined this game yet. Use `j` to play now!" ;
2018-02-11 00:57:58 +01:00
}
2018-01-29 06:53:40 +01:00
when ( 'exit' ) {
2019-05-08 10:39:52 +02:00
my $ id = $ self - > { pbot } - > { messagehistory } - > { database } - > get_message_account_ancestor ( $ nick , $ user , $ host ) ;
2018-01-29 06:53:40 +01:00
my $ removed = 0 ;
for ( my $ i = 0 ; $ i < @ { $ self - > { state_data } - > { players } } ; $ i + + ) {
if ( $ self - > { state_data } - > { players } - > [ $ i ] - > { id } == $ id ) {
splice @ { $ self - > { state_data } - > { players } } , $ i - - , 1 ;
$ removed = 1 ;
}
}
if ( $ removed ) {
2018-02-02 05:15:54 +01:00
if ( $ self - > { state_data } - > { current_player } >= @ { $ self - > { state_data } - > { players } } ) {
$ self - > { state_data } - > { current_player } = @ { $ self - > { state_data } - > { players } } - 1
}
2019-05-07 12:26:40 +02:00
if ( not @ { $ self - > { state_data } - > { players } } ) {
$ self - > { current_state } = 'nogame' ;
return "/msg $self->{channel} $nick has left the game! All players have left. The game has been stopped." ;
} else {
return "/msg $self->{channel} $nick has left the game!" ;
}
2018-01-29 06:53:40 +01:00
} else {
return "$nick: But you are not even playing the game." ;
}
}
when ( 'abort' ) {
2020-01-25 21:31:08 +01:00
if ( not $ self - > { pbot } - > { users } - > loggedin_admin ( $ self - > { channel } , "$nick!$user\@$host" ) ) {
2018-01-29 06:53:40 +01:00
return "$nick: Sorry, only admins may abort the game." ;
}
$ self - > { current_state } = 'gameover' ;
return "/msg $self->{channel} $nick: The game has been aborted." ;
}
2018-02-12 08:37:37 +01:00
when ( $ _ eq 'score' or $ _ eq 'players' ) {
if ( $ self - > { current_state } eq 'getplayers' ) {
my @ names ;
foreach my $ player ( @ { $ self - > { state_data } - > { players } } ) {
if ( not $ player - > { ready } ) {
push @ names , "$player->{name} $color{red}(not ready)$color{reset}" ;
} else {
push @ names , $ player - > { name } ;
}
}
my $ players = join ', ' , @ names ;
$ players = 'none' if not @ names ;
return "Current players: $players" ;
2018-02-01 07:11:26 +01:00
}
2018-02-12 08:37:37 +01:00
# score
if ( not @ { $ self - > { state_data } - > { players } } ) {
return "There is nobody playing right now." ;
2018-02-01 07:11:26 +01:00
}
2018-02-12 08:37:37 +01:00
my $ text = '' ;
my $ comma = '' ;
foreach my $ player ( sort { $ b - > { score } <=> $ a - > { score } } @ { $ self - > { state_data } - > { players } } ) {
2018-02-15 07:13:54 +01:00
$ text . = "$comma$player->{name}: " . $ self - > commify ( $ player - > { score } ) ;
2018-02-12 08:37:37 +01:00
$ comma = '; ' ;
}
return $ text ;
2018-02-01 07:11:26 +01:00
}
2018-01-29 06:53:40 +01:00
when ( 'kick' ) {
2020-01-25 21:31:08 +01:00
if ( not $ self - > { pbot } - > { users } - > loggedin_admin ( $ self - > { channel } , "$nick!$user\@$host" ) ) {
2018-01-29 06:53:40 +01:00
return "$nick: Sorry, only admins may kick people from the game." ;
}
if ( not length $ arguments ) {
return "Usage: spinach kick <nick>" ;
}
my $ removed = 0 ;
for ( my $ i = 0 ; $ i < @ { $ self - > { state_data } - > { players } } ; $ i + + ) {
if ( lc $ self - > { state_data } - > { players } - > [ $ i ] - > { name } eq $ arguments ) {
splice @ { $ self - > { state_data } - > { players } } , $ i - - , 1 ;
$ removed = 1 ;
}
}
if ( $ removed ) {
2018-02-02 05:15:54 +01:00
if ( $ self - > { state_data } - > { current_player } >= @ { $ self - > { state_data } - > { players } } ) {
$ self - > { state_data } - > { current_player } = @ { $ self - > { state_data } - > { players } } - 1
}
2018-01-29 06:53:40 +01:00
return "/msg $self->{channel} $nick: $arguments has been kicked from the game." ;
} else {
return "$nick: $arguments isn't even in the game." ;
}
}
2018-02-11 02:13:26 +01:00
when ( 'n' ) {
return $ self - > normalize_text ( $ arguments ) ;
}
when ( 'v' ) {
my ( $ truth , $ lie ) = split /;/ , $ arguments ;
return $ self - > validate_lie ( $ self - > normalize_text ( $ truth ) , $ self - > normalize_text ( $ lie ) ) ;
}
2018-02-26 09:46:59 +01:00
when ( 'reroll' ) {
if ( $ self - > { current_state } =~ /getlies$/ ) {
2019-05-08 10:39:52 +02:00
my $ id = $ self - > { pbot } - > { messagehistory } - > { database } - > get_message_account_ancestor ( $ nick , $ user , $ host ) ;
2018-02-26 09:46:59 +01:00
my $ player ;
my $ rerolled = 0 ;
2019-05-05 04:28:34 +02:00
my $ keep ;
2018-02-26 09:46:59 +01:00
foreach my $ i ( @ { $ self - > { state_data } - > { players } } ) {
if ( $ i - > { id } == $ id ) {
$ i - > { reroll } = 1 ;
2019-05-05 04:28:34 +02:00
delete $ i - > { keep } ;
2018-02-26 09:46:59 +01:00
$ rerolled + + ;
$ player = $ i ;
} elsif ( $ i - > { reroll } ) {
$ rerolled + + ;
2019-05-05 04:28:34 +02:00
} elsif ( $ i - > { keep } ) {
$ keep + + ;
2018-02-26 09:46:59 +01:00
}
}
if ( not $ player ) {
return "$nick: You are not playing in this game. Use `j` to start playing now!" ;
}
my $ needed = int ( @ { $ self - > { state_data } - > { players } } / 2 ) + 1 ;
$ needed -= $ rerolled ;
2019-05-05 04:28:34 +02:00
$ needed += $ keep ;
2018-02-26 09:46:59 +01:00
my $ votes_needed ;
if ( $ needed == 1 ) {
$ votes_needed = "$needed more vote to reroll!" ;
} elsif ( $ needed > 1 ) {
$ votes_needed = "$needed more votes to reroll!" ;
} else {
$ votes_needed = "Rerolling..." ;
}
return "/msg $self->{channel} $color{red}$nick has voted to reroll for another question from the same category! $color{reset}$votes_needed" ;
} else {
return "$nick: This command can be used only during the \"submit lies\" stage." ;
}
}
2018-02-15 07:13:54 +01:00
when ( 'skip' ) {
if ( $ self - > { current_state } =~ /getlies$/ ) {
2019-05-08 10:39:52 +02:00
my $ id = $ self - > { pbot } - > { messagehistory } - > { database } - > get_message_account_ancestor ( $ nick , $ user , $ host ) ;
2018-02-15 07:13:54 +01:00
my $ player ;
my $ skipped = 0 ;
2019-05-05 04:28:34 +02:00
my $ keep = 0 ;
2018-02-15 07:13:54 +01:00
foreach my $ i ( @ { $ self - > { state_data } - > { players } } ) {
if ( $ i - > { id } == $ id ) {
$ i - > { skip } = 1 ;
2019-05-05 04:28:34 +02:00
delete $ i - > { keep } ;
2018-02-15 07:13:54 +01:00
$ skipped + + ;
$ player = $ i ;
} elsif ( $ i - > { skip } ) {
$ skipped + + ;
2019-05-05 04:28:34 +02:00
} elsif ( $ i - > { keep } ) {
$ keep + + ;
2018-02-15 07:13:54 +01:00
}
}
if ( not $ player ) {
return "$nick: You are not playing in this game. Use `j` to start playing now!" ;
}
2018-02-15 18:21:41 +01:00
my $ needed = int ( @ { $ self - > { state_data } - > { players } } / 2 ) + 1 ;
2018-02-15 07:13:54 +01:00
$ needed -= $ skipped ;
2019-05-05 04:28:34 +02:00
$ needed += $ keep ;
2018-02-15 07:13:54 +01:00
2018-02-15 07:17:58 +01:00
my $ votes_needed ;
2018-02-15 07:13:54 +01:00
if ( $ needed == 1 ) {
$ votes_needed = "$needed more vote to skip!" ;
} elsif ( $ needed > 1 ) {
$ votes_needed = "$needed more votes to skip!" ;
} else {
$ votes_needed = "Skipping..." ;
}
2019-05-02 21:06:45 +02:00
return "/msg $self->{channel} $color{red}$nick has voted to skip this category! $color{reset}$votes_needed" ;
2018-02-15 07:13:54 +01:00
} else {
return "$nick: This command can be used only during the \"submit lies\" stage." ;
}
}
2019-05-05 04:28:34 +02:00
when ( 'keep' ) {
if ( $ self - > { current_state } =~ /getlies$/ ) {
2019-05-08 10:39:52 +02:00
my $ id = $ self - > { pbot } - > { messagehistory } - > { database } - > get_message_account_ancestor ( $ nick , $ user , $ host ) ;
2019-05-05 04:28:34 +02:00
my $ player ;
foreach my $ i ( @ { $ self - > { state_data } - > { players } } ) {
if ( $ i - > { id } == $ id ) {
$ i - > { keep } = 1 ;
delete $ i - > { skip } ;
delete $ i - > { reroll } ;
$ player = $ i ;
last ;
}
}
if ( not $ player ) {
return "$nick: You are not playing in this game. Use `j` to start playing now!" ;
}
return "/msg $self->{channel} $color{green}$nick has voted to keep playing the current question!" ;
} else {
return "$nick: This command can be used only during the \"submit lies\" stage." ;
}
}
2018-02-12 08:37:37 +01:00
when ( $ _ eq 'lie' or $ _ eq 'truth' or $ _ eq 'choose' ) {
2018-02-15 07:13:54 +01:00
$ arguments = lc $ arguments ;
2018-02-12 08:37:37 +01:00
if ( $ self - > { current_state } =~ /choosecategory$/ ) {
if ( not length $ arguments ) {
return "Usage: spinach choose <integer>" ;
}
2018-01-29 06:53:40 +01:00
2019-05-08 10:39:52 +02:00
my $ id = $ self - > { pbot } - > { messagehistory } - > { database } - > get_message_account_ancestor ( $ nick , $ user , $ host ) ;
2018-01-29 06:53:40 +01:00
2018-02-12 08:37:37 +01:00
if ( not @ { $ self - > { state_data } - > { players } } or $ id != $ self - > { state_data } - > { players } - > [ $ self - > { state_data } - > { current_player } ] - > { id } ) {
return "$nick: It is not your turn to choose a category." ;
}
2018-01-29 06:53:40 +01:00
2018-02-12 08:37:37 +01:00
if ( $ arguments !~ /^[0-9]+$/ ) {
return "$nick: Please choose a category number. $self->{state_data}->{categories_text}" ;
2018-01-29 06:53:40 +01:00
}
2018-02-12 08:37:37 +01:00
$ arguments - - ;
if ( $ arguments < 0 or $ arguments >= @ { $ self - > { state_data } - > { category_options } } ) {
return "$nick: Choice out of range. Please choose a valid category. $self->{state_data}->{categories_text}" ;
}
2018-02-26 10:32:02 +01:00
if ( $ arguments == @ { $ self - > { state_data } - > { category_options } } - 2 ) {
$ arguments = ( @ { $ self - > { state_data } - > { category_options } } - 2 ) * rand ;
2018-02-20 09:16:22 +01:00
$ self - > { state_data } - > { current_category } = $ self - > { state_data } - > { category_options } - > [ $ arguments ] ;
2018-02-26 10:32:02 +01:00
return "/msg $self->{channel} $nick has chosen RANDOM CATEGORY! Randomly choosing category: $self->{state_data}->{current_category}!" ;
} elsif ( $ arguments == @ { $ self - > { state_data } - > { category_options } } - 1 ) {
2018-04-01 23:25:13 +02:00
$ self - > { state_data } - > { reroll_category } = 1 ;
return "/msg $self->{channel} $nick has chosen REROLL CATEGORIES! Rerolling categories..." ;
2018-02-20 09:16:22 +01:00
} else {
$ self - > { state_data } - > { current_category } = $ self - > { state_data } - > { category_options } - > [ $ arguments ] ;
return "/msg $self->{channel} $nick has chosen $self->{state_data}->{current_category}!" ;
}
2018-01-29 06:53:40 +01:00
}
2018-02-12 08:37:37 +01:00
if ( $ self - > { current_state } =~ /getlies$/ ) {
if ( not length $ arguments ) {
return "Usage: spinach lie <text>" ;
}
2018-02-04 05:42:27 +01:00
2019-05-08 10:39:52 +02:00
my $ id = $ self - > { pbot } - > { messagehistory } - > { database } - > get_message_account_ancestor ( $ nick , $ user , $ host ) ;
2018-01-29 06:53:40 +01:00
2018-02-12 08:37:37 +01:00
my $ player ;
foreach my $ i ( @ { $ self - > { state_data } - > { players } } ) {
if ( $ i - > { id } == $ id ) {
$ player = $ i ;
last ;
}
}
2018-01-29 06:53:40 +01:00
2018-02-12 08:37:37 +01:00
if ( not $ player ) {
2018-02-12 18:04:33 +01:00
return "$nick: You are not playing in this game. Use `j` to start playing now!" ;
2018-02-12 08:37:37 +01:00
}
$ arguments = $ self - > normalize_text ( $ arguments ) ;
2019-05-14 03:04:09 +02:00
my @ truth_count = split /\s/ , $ self - > { state_data } - > { current_question } - > { answer } ;
my @ lie_count = split /\s/ , $ arguments ;
2019-05-14 02:59:15 +02:00
2020-01-15 03:10:53 +01:00
= cut
2019-05-14 02:59:15 +02:00
if ( @ truth_count > 1 and @ lie_count == 1 ) {
return "/msg $nick Your lie cannot be one word for this question. Please try again." ;
}
2020-01-15 03:10:53 +01:00
= cut
2018-02-12 08:37:37 +01:00
my $ found_truth = 0 ;
if ( not $ self - > validate_lie ( $ self - > { state_data } - > { current_question } - > { answer } , $ arguments ) ) {
2018-01-29 06:53:40 +01:00
$ found_truth = 1 ;
}
2018-02-12 08:37:37 +01:00
foreach my $ alt ( @ { $ self - > { state_data } - > { current_question } - > { alternativeSpellings } } ) {
if ( not $ self - > validate_lie ( $ alt , $ arguments ) ) {
$ found_truth = 1 ;
last ;
}
}
2018-01-29 06:53:40 +01:00
2018-02-28 04:50:30 +01:00
if ( not $ found_truth and + + $ player - > { lie_count } > 2 ) {
return "/msg $nick You cannot change your lie again this round." ;
}
2018-02-12 08:37:37 +01:00
if ( $ found_truth ) {
2018-02-24 00:51:17 +01:00
$ self - > send_message ( $ self - > { channel } , "$color{yellow}$nick has found the truth!$color{reset}" ) ;
2018-02-12 08:37:37 +01:00
return "$nick: Your lie is too similar to the truth! Please submit a different lie." ;
}
2018-01-29 06:53:40 +01:00
2018-02-12 08:37:37 +01:00
my $ changed = exists $ player - > { lie } ;
$ player - > { lie } = $ arguments ;
2018-01-29 06:53:40 +01:00
2018-02-12 08:37:37 +01:00
if ( $ changed ) {
return "/msg $self->{channel} $nick has changed their lie!" ;
} else {
return "/msg $self->{channel} $nick has submitted a lie!" ;
}
2018-01-29 06:53:40 +01:00
}
2018-02-12 08:37:37 +01:00
if ( $ self - > { current_state } =~ /findtruth$/ ) {
if ( not length $ arguments ) {
return "Usage: spinach truth <integer>" ;
}
2018-01-29 06:53:40 +01:00
2019-05-08 10:39:52 +02:00
my $ id = $ self - > { pbot } - > { messagehistory } - > { database } - > get_message_account_ancestor ( $ nick , $ user , $ host ) ;
2018-01-29 06:53:40 +01:00
2018-02-12 08:37:37 +01:00
my $ player ;
foreach my $ i ( @ { $ self - > { state_data } - > { players } } ) {
if ( $ i - > { id } == $ id ) {
$ player = $ i ;
last ;
}
2018-01-29 06:53:40 +01:00
}
2018-02-12 08:37:37 +01:00
if ( not $ player ) {
2018-02-12 18:04:33 +01:00
return "$nick: You are not playing in this game. Use `j` to start playing now!" ;
2018-02-12 08:37:37 +01:00
}
2018-01-29 06:53:40 +01:00
2018-02-12 08:37:37 +01:00
if ( $ arguments !~ /^[0-9]+$/ ) {
return "$nick: Please select a truth number. $self->{state_data}->{current_choices_text}" ;
}
2018-01-29 06:53:40 +01:00
2018-02-12 08:37:37 +01:00
$ arguments - - ;
2018-01-29 06:53:40 +01:00
2018-02-12 08:37:37 +01:00
if ( $ arguments < 0 or $ arguments >= @ { $ self - > { state_data } - > { current_choices } } ) {
2018-02-20 09:16:22 +01:00
return "$nick: Selection out of range. Please select a valid truth. $self->{state_data}->{current_choices_text}" ;
2018-02-12 08:37:37 +01:00
}
2018-01-29 06:53:40 +01:00
2018-02-12 08:37:37 +01:00
my $ changed = exists $ player - > { truth } ;
$ player - > { truth } = uc $ self - > { state_data } - > { current_choices } - > [ $ arguments ] ;
2018-01-29 06:53:40 +01:00
2018-02-12 08:37:37 +01:00
if ( $ player - > { truth } eq $ player - > { lie } ) {
delete $ player - > { truth } ;
return "$nick: You cannot select your own lie!" ;
}
2018-01-29 06:53:40 +01:00
2018-02-12 08:37:37 +01:00
if ( $ changed ) {
return "/msg $self->{channel} $nick has selected a different truth!" ;
} else {
return "/msg $self->{channel} $nick has selected a truth!" ;
}
2018-02-01 07:11:26 +01:00
}
2018-02-12 08:37:37 +01:00
return "$nick: It is not time to use this command." ;
2018-01-29 06:53:40 +01:00
}
2018-01-30 06:54:52 +01:00
when ( 'show' ) {
2018-02-04 05:42:27 +01:00
if ( $ self - > { current_state } =~ /(?:getlies|findtruth|showlies)$/ ) {
2019-05-06 08:11:45 +02:00
$ self - > showquestion ( $ self - > { state_data } , 1 ) ;
2018-01-30 06:54:52 +01:00
return ;
}
return "$nick: There is nothing to show right now." ;
}
2019-04-22 03:56:46 +02:00
when ( 'categories' ) {
if ( not length $ arguments ) {
return "Usage: spinach categories <regex>" ;
}
my $ result = eval {
use re::engine::RE2 - strict = > 1 ;
my @ categories = grep { /$arguments/i } keys % { $ self - > { categories } } ;
if ( not @ categories ) {
return "No categories found." ;
}
my $ text = "" ;
my $ comma = "" ;
foreach my $ cat ( sort @ categories ) {
$ text . = "$comma$cat: " . keys % { $ self - > { categories } { $ cat } } ;
$ comma = ", " ;
}
return $ text ;
} ;
return "$arguments: $@" if $@ ;
return $ result ;
}
when ( 'filter' ) {
my ( $ cmd , $ args ) = split / / , $ arguments , 2 ;
$ cmd = lc $ cmd ;
if ( not length $ cmd ) {
2019-04-22 05:48:07 +02:00
return "Usage: spinach filter include <regex> | exclude <regex> | show | clear" ;
2019-04-22 03:56:46 +02:00
}
given ( $ cmd ) {
2019-04-22 05:48:07 +02:00
when ( $ _ eq 'include' or $ _ eq 'exclude' ) {
2019-04-22 03:56:46 +02:00
if ( not length $ args ) {
2019-04-22 05:48:07 +02:00
return "Usage: spinach filter $_ <regex>" ;
2019-04-22 03:56:46 +02:00
}
eval { "" =~ /$args/ } ;
return "Bad filter $args: $@" if $@ ;
my @ categories = grep { /$args/i } keys % { $ self - > { categories } } ;
if ( not @ categories ) {
return "Bad filter: No categories match. Try again." ;
}
2020-01-15 03:10:53 +01:00
$ self - > { metadata } - > { hash } - > { filter } - > { "category_" . $ _ . "_filter" } = $ args ;
2019-04-24 02:59:39 +02:00
$ self - > save_metadata ;
2019-04-22 05:48:07 +02:00
return "Spinach $_ filter set." ;
2019-04-22 03:56:46 +02:00
}
when ( 'clear' ) {
2020-01-15 03:10:53 +01:00
delete $ self - > { metadata } - > { hash } - > { filter } ;
2019-04-24 02:59:39 +02:00
$ self - > save_metadata ;
2019-04-22 03:56:46 +02:00
return "Spinach filter cleared." ;
}
when ( 'show' ) {
2020-01-15 03:10:53 +01:00
if ( not exists $ self - > { metadata } - > { hash } - > { filter } - > { category_include_filter }
and not exists $ self - > { metadata } - > { hash } - > { filter } - > { category_exclude_filter } ) {
2019-04-22 03:56:46 +02:00
return "There is no Spinach filter set." ;
}
2019-04-22 05:48:07 +02:00
my $ text = "Spinach " ;
my $ comma = "" ;
2020-01-15 03:10:53 +01:00
if ( exists $ self - > { metadata } - > { hash } - > { filter } - > { category_include_filter } ) {
$ text . = "include filter set to: " . $ self - > { metadata } - > { hash } - > { filter } - > { category_include_filter } ;
2019-04-22 05:48:07 +02:00
$ comma = "; " ;
}
2020-01-15 03:10:53 +01:00
if ( exists $ self - > { metadata } - > { hash } - > { filter } - > { category_exclude_filter } ) {
$ text . = $ comma . "exclude filter set to: " . $ self - > { metadata } - > { hash } - > { filter } - > { category_exclude_filter } ;
2019-04-22 05:48:07 +02:00
}
return $ text ;
2019-04-22 03:56:46 +02:00
}
default {
return "Unknown filter command '$cmd'." ;
}
}
}
2019-05-08 10:37:00 +02:00
when ( 'state' ) {
my ( $ command , $ args ) = split /\s+/ , $ arguments ;
if ( $ command eq 'show' ) {
return "Previous state: $self->{previous_state}; Current state: $self->{current_state}; previous result: $self->{state_data}->{previous_result}" ;
}
if ( $ command eq 'set' ) {
if ( not length $ args ) {
return "Usage: spinach state set <new state>" ;
}
2020-01-25 21:31:08 +01:00
my $ admin = $ self - > { pbot } - > { users } - > loggedin_admin ( $ self - > { channel } , "$nick!$user\@$host" ) ;
2019-05-08 10:37:00 +02:00
if ( not $ admin or $ admin - > { level } < 90 ) {
return "$nick: Sorry, only very powerful admins may set game state." ;
}
$ self - > { previous_state } = $ self - > { current_state } ;
$ self - > { current_state } = $ args ;
return "State set to $args" ;
}
if ( $ command eq 'result' ) {
if ( not length $ args ) {
return "Usage: spinach state result <current state result>" ;
}
2020-01-25 21:31:08 +01:00
my $ admin = $ self - > { pbot } - > { users } - > loggedin_admin ( $ self - > { channel } , "$nick!$user\@$host" ) ;
2019-05-08 10:37:00 +02:00
if ( not $ admin or $ admin - > { level } < 90 ) {
return "$nick: Sorry, only very powerful admins may set game state." ;
}
$ self - > { state_data } - > { previous_result } = $ self - > { state_data } - > { result } ;
$ self - > { state_data } - > { result } = $ args ;
return "State result set to $args" ;
}
return "Usage: spinach state show | set <new state> | result <current state result>" ;
}
2019-04-24 03:22:52 +02:00
when ( 'set' ) {
my ( $ index , $ key , $ value ) = split /\s+/ , $ arguments ;
if ( not defined $ index ) {
return "Usage: spinach set <metadata> [key [value]]" ;
}
2019-04-28 09:21:15 +02:00
if ( lc $ index eq 'settings' and $ key and lc $ key eq 'stats' and defined $ value and $ self - > { current_state } ne 'nogame' ) {
return "Spinach stats setting cannot be modified while a game is in progress." ;
}
2020-01-25 21:31:08 +01:00
my $ admin = $ self - > { pbot } - > { users } - > loggedin_admin ( $ self - > { channel } , "$nick!$user\@$host" ) ;
2019-05-08 21:48:10 +02:00
if ( defined $ value and ( not $ admin or $ admin - > { level } <= 0 ) ) {
2019-05-08 10:37:00 +02:00
return "$nick: Sorry, only Spinach admins may set game settings." ;
}
2019-04-24 03:22:52 +02:00
return $ self - > { metadata } - > set ( $ index , $ key , $ value ) ;
}
when ( 'unset' ) {
my ( $ index , $ key ) = split /\s+/ , $ arguments ;
if ( not defined $ index or not defined $ key ) {
return "Usage: spinach unset <metadata> <key>" ;
}
2019-04-28 09:21:15 +02:00
if ( lc $ index eq 'settings' and lc $ key eq 'stats' and $ self - > { current_state } ne 'nogame' ) {
return "Spinach stats setting cannot be modified while a game is in progress." ;
}
2020-01-25 21:31:08 +01:00
my $ admin = $ self - > { pbot } - > { users } - > loggedin_admin ( $ self - > { channel } , "$nick!$user\@$host" ) ;
2019-05-08 10:37:00 +02:00
if ( not $ admin or $ admin - > { level } <= 0 ) {
return "$nick: Sorry, only Spinach admins may set game settings." ;
}
2019-04-24 03:22:52 +02:00
return $ self - > { metadata } - > unset ( $ index , $ key ) ;
}
2019-04-24 12:55:48 +02:00
when ( 'rank' ) {
2019-04-25 08:04:09 +02:00
return $ self - > { rankcmd } - > rank ( $ arguments ) ;
2019-04-24 12:55:48 +02:00
}
2018-01-29 06:53:40 +01:00
default {
return $ usage ;
}
}
return $ result ;
}
sub spinach_timer {
my $ self = shift ;
2020-01-24 07:46:41 +01:00
$ self - > run_one_state ( ) ;
2018-01-29 06:53:40 +01:00
}
2018-01-30 07:15:08 +01:00
sub player_left {
my ( $ self , $ nick , $ user , $ host ) = @ _ ;
2019-05-08 10:39:52 +02:00
my $ id = $ self - > { pbot } - > { messagehistory } - > { database } - > get_message_account_ancestor ( $ nick , $ user , $ host ) ;
2018-02-02 05:15:54 +01:00
my $ removed = 0 ;
2018-01-30 07:15:08 +01:00
for ( my $ i = 0 ; $ i < @ { $ self - > { state_data } - > { players } } ; $ i + + ) {
if ( $ self - > { state_data } - > { players } - > [ $ i ] - > { id } == $ id ) {
splice @ { $ self - > { state_data } - > { players } } , $ i - - , 1 ;
2018-02-02 05:15:54 +01:00
$ removed = 1 ;
2018-01-30 07:15:08 +01:00
}
}
2018-02-02 05:15:54 +01:00
if ( $ removed ) {
if ( $ self - > { state_data } - > { current_player } >= @ { $ self - > { state_data } - > { players } } ) {
$ self - > { state_data } - > { current_player } = @ { $ self - > { state_data } - > { players } } - 1
}
2019-05-07 12:26:40 +02:00
$ self - > send_message ( $ self - > { channel } , "$nick has left the game!" ) ;
2018-02-02 05:15:54 +01:00
}
2018-01-30 07:15:08 +01:00
}
2018-02-16 19:57:22 +01:00
sub send_message {
my ( $ self , $ to , $ text , $ delay ) = @ _ ;
$ delay = 0 if not defined $ delay ;
my $ botnick = $ self - > { pbot } - > { registry } - > get_value ( 'irc' , 'botnick' ) ;
my $ message = {
nick = > $ botnick , user = > 'spinach' , host = > 'localhost' , command = > 'spinach text' , checkflood = > 1 ,
message = > $ text
} ;
$ self - > { pbot } - > { interpreter } - > add_message_to_output_queue ( $ to , $ message , $ delay ) ;
}
2018-02-01 07:11:26 +01:00
sub add_new_suggestions {
my ( $ self , $ state ) = @ _ ;
my $ question = undef ;
my $ modified = 0 ;
foreach my $ player ( @ { $ state - > { players } } ) {
if ( $ player - > { deceived } ) {
2018-03-02 20:02:34 +01:00
$ self - > { pbot } - > { logger } - > log ( "Adding new suggestion for $state->{current_question}->{id}: $state->{current_question}->{question}: $player->{deceived}\n" ) ;
2018-02-01 07:11:26 +01:00
if ( not grep { lc $ _ eq lc $ player - > { deceived } } @ { $ state - > { current_question } - > { suggestions } } ) {
if ( not defined $ question ) {
2018-02-02 05:15:54 +01:00
foreach my $ q ( @ { $ self - > { questions } - > { questions } } ) {
2018-02-01 07:11:26 +01:00
if ( $ q - > { id } == $ state - > { current_question } - > { id } ) {
$ question = $ q ;
last ;
}
}
}
push @ { $ question - > { suggestions } } , uc $ player - > { deceived } ;
$ modified = 1 ;
}
}
}
if ( $ modified ) {
2019-05-03 08:13:27 +02:00
$ self - > save_questions ;
2018-02-01 07:11:26 +01:00
}
}
2018-01-29 06:53:40 +01:00
sub run_one_state {
my $ self = shift ;
2018-03-02 20:02:34 +01:00
# check for naughty or missing players
2018-02-16 19:35:08 +01:00
if ( $ self - > { current_state } =~ /r\dq\d/ ) {
my $ removed = 0 ;
for ( my $ i = 0 ; $ i < @ { $ self - > { state_data } - > { players } } ; $ i + + ) {
2019-05-14 02:59:15 +02:00
if ( $ self - > { state_data } - > { players } - > [ $ i ] - > { missedinputs } >= $ self - > { metadata } - > { hash } - > { settings } - > { max_missed_inputs } ) {
2018-02-19 01:40:17 +01:00
$ self - > send_message ( $ self - > { channel } , "$color{red}$self->{state_data}->{players}->[$i]->{name} has missed too many prompts and has been ejected from the game!$color{reset}" ) ;
2018-02-16 19:35:08 +01:00
splice @ { $ self - > { state_data } - > { players } } , $ i - - , 1 ;
$ removed = 1 ;
}
}
if ( $ removed ) {
if ( $ self - > { state_data } - > { current_player } >= @ { $ self - > { state_data } - > { players } } ) {
$ self - > { state_data } - > { current_player } = @ { $ self - > { state_data } - > { players } } - 1
}
}
if ( not @ { $ self - > { state_data } - > { players } } ) {
2018-02-26 09:46:59 +01:00
$ self - > send_message ( $ self - > { channel } , "All players have left the game!" ) ;
2018-02-16 19:35:08 +01:00
$ self - > { current_state } = 'nogame' ;
}
2018-01-30 06:54:52 +01:00
}
2018-01-29 06:53:40 +01:00
my $ state_data = $ self - > { state_data } ;
2018-03-02 20:02:34 +01:00
# this shouldn't happen
2018-02-26 09:46:59 +01:00
if ( not defined $ self - > { current_state } ) {
2018-01-30 06:54:52 +01:00
$ self - > { pbot } - > { logger } - > log ( "Spinach state broke.\n" ) ;
2018-02-26 09:46:59 +01:00
$ self - > { current_state } = 'nogame' ;
2018-01-29 06:53:40 +01:00
return ;
}
2018-03-02 20:02:34 +01:00
# transistioned to a brand new state; prepare first tock
2018-01-30 06:54:52 +01:00
if ( $ self - > { previous_state } ne $ self - > { current_state } ) {
$ state_data - > { newstate } = 1 ;
$ state_data - > { ticks } = 1 ;
2018-02-24 00:51:17 +01:00
if ( exists $ state_data - > { tick_drift } ) {
$ state_data - > { ticks } += $ state_data - > { tick_drift } ;
delete $ state_data - > { tick_drift } ;
}
2018-01-30 06:54:52 +01:00
$ state_data - > { first_tock } = 1 ;
} else {
$ state_data - > { newstate } = 0 ;
}
2018-03-02 20:02:34 +01:00
# dump new state data for logging/debugging
2019-05-15 19:58:32 +02:00
if ( $ state_data - > { newstate } and $ self - > { metadata } - > { hash } - > { settings } - > { debug_state } ) {
2019-05-08 10:37:00 +02:00
$ self - > { pbot } - > { logger } - > log ( "Spinach: New state: $self->{previous_state} ($state_data->{previous_result}) --> $self->{current_state}\n" . Dumper $ state_data ) ;
2018-01-30 06:54:52 +01:00
}
2018-02-25 03:17:55 +01:00
# run one state/tick
2018-02-26 09:46:59 +01:00
$ state_data = $ self - > { states } { $ self - > { current_state } } { sub } ( $ state_data ) ;
2018-01-29 06:53:40 +01:00
2018-02-25 03:17:55 +01:00
if ( $ state_data - > { tocked } ) {
delete $ state_data - > { tocked } ;
delete $ state_data - > { first_tock } ;
$ state_data - > { ticks } = 0 ;
}
# transform to next state
$ state_data - > { previous_result } = $ state_data - > { result } ;
2018-01-30 06:54:52 +01:00
$ self - > { previous_state } = $ self - > { current_state } ;
2019-05-08 10:37:00 +02:00
if ( not exists $ self - > { states } { $ self - > { current_state } } { trans } { $ state_data - > { result } } ) {
$ self - > { pbot } - > { logger } - > log ( "Spinach: State broke: no such transistion to $state_data->{result} for state $self->{current_state}\n" ) ;
# XXX: do something here
}
2018-02-26 09:46:59 +01:00
$ self - > { current_state } = $ self - > { states } { $ self - > { current_state } } { trans } { $ state_data - > { result } } ;
2018-01-29 06:53:40 +01:00
$ self - > { state_data } = $ state_data ;
2018-01-30 06:54:52 +01:00
2018-02-25 03:17:55 +01:00
# next tick
2018-01-30 06:54:52 +01:00
$ self - > { state_data } - > { ticks } + + ;
2018-01-29 06:53:40 +01:00
}
sub create_states {
my $ self = shift ;
$ self - > { pbot } - > { logger } - > log ( "Spinach: Creating game state machine\n" ) ;
2018-01-30 06:54:52 +01:00
$ self - > { previous_state } = '' ;
2019-05-09 22:25:33 +02:00
$ self - > { previous_result } = '' ;
2018-01-29 06:53:40 +01:00
$ self - > { current_state } = 'nogame' ;
2018-01-30 06:54:52 +01:00
$ self - > { state_data } = { players = > [] , ticks = > 0 , newstate = > 1 } ;
2018-01-29 06:53:40 +01:00
$ self - > { states } { 'nogame' } { sub } = sub { $ self - > nogame ( @ _ ) } ;
$ self - > { states } { 'nogame' } { trans } { start } = 'getplayers' ;
$ self - > { states } { 'nogame' } { trans } { nogame } = 'nogame' ;
2018-01-30 06:54:52 +01:00
2018-01-29 06:53:40 +01:00
$ self - > { states } { 'getplayers' } { sub } = sub { $ self - > getplayers ( @ _ ) } ;
2018-02-02 05:15:54 +01:00
$ self - > { states } { 'getplayers' } { trans } { stop } = 'nogame' ;
2018-01-29 06:53:40 +01:00
$ self - > { states } { 'getplayers' } { trans } { wait } = 'getplayers' ;
$ self - > { states } { 'getplayers' } { trans } { allready } = 'round1' ;
2018-01-30 06:54:52 +01:00
2018-01-29 06:53:40 +01:00
$ self - > { states } { 'round1' } { sub } = sub { $ self - > round1 ( @ _ ) } ;
$ self - > { states } { 'round1' } { trans } { next } = 'round1q1' ;
$ self - > { states } { 'round1q1' } { sub } = sub { $ self - > round1q1 ( @ _ ) } ;
2018-02-24 00:51:17 +01:00
$ self - > { states } { 'round1q1' } { trans } { wait } = 'round1q1' ;
2018-01-29 06:53:40 +01:00
$ self - > { states } { 'round1q1' } { trans } { next } = 'r1q1choosecategory' ;
$ self - > { states } { 'r1q1choosecategory' } { sub } = sub { $ self - > r1q1choosecategory ( @ _ ) } ;
$ self - > { states } { 'r1q1choosecategory' } { trans } { wait } = 'r1q1choosecategory' ;
$ self - > { states } { 'r1q1choosecategory' } { trans } { next } = 'r1q1showquestion' ;
$ self - > { states } { 'r1q1showquestion' } { sub } = sub { $ self - > r1q1showquestion ( @ _ ) } ;
2018-01-30 06:54:52 +01:00
$ self - > { states } { 'r1q1showquestion' } { trans } { wait } = 'r1q1showquestion' ;
2018-01-29 06:53:40 +01:00
$ self - > { states } { 'r1q1showquestion' } { trans } { next } = 'r1q1getlies' ;
$ self - > { states } { 'r1q1getlies' } { sub } = sub { $ self - > r1q1getlies ( @ _ ) } ;
2018-02-26 09:46:59 +01:00
$ self - > { states } { 'r1q1getlies' } { trans } { reroll } = 'r1q1showquestion' ;
2018-02-15 07:13:54 +01:00
$ self - > { states } { 'r1q1getlies' } { trans } { skip } = 'round1q1' ;
2018-01-29 06:53:40 +01:00
$ self - > { states } { 'r1q1getlies' } { trans } { wait } = 'r1q1getlies' ;
$ self - > { states } { 'r1q1getlies' } { trans } { next } = 'r1q1findtruth' ;
$ self - > { states } { 'r1q1findtruth' } { sub } = sub { $ self - > r1q1findtruth ( @ _ ) } ;
$ self - > { states } { 'r1q1findtruth' } { trans } { wait } = 'r1q1findtruth' ;
$ self - > { states } { 'r1q1findtruth' } { trans } { next } = 'r1q1showlies' ;
$ self - > { states } { 'r1q1showlies' } { sub } = sub { $ self - > r1q1showlies ( @ _ ) } ;
$ self - > { states } { 'r1q1showlies' } { trans } { wait } = 'r1q1showlies' ;
$ self - > { states } { 'r1q1showlies' } { trans } { next } = 'r1q1showtruth' ;
$ self - > { states } { 'r1q1showtruth' } { sub } = sub { $ self - > r1q1showtruth ( @ _ ) } ;
2018-01-30 06:54:52 +01:00
$ self - > { states } { 'r1q1showtruth' } { trans } { wait } = 'r1q1showtruth' ;
$ self - > { states } { 'r1q1showtruth' } { trans } { next } = 'r1q1reveallies' ;
$ self - > { states } { 'r1q1reveallies' } { sub } = sub { $ self - > r1q1reveallies ( @ _ ) } ;
$ self - > { states } { 'r1q1reveallies' } { trans } { wait } = 'r1q1reveallies' ;
$ self - > { states } { 'r1q1reveallies' } { trans } { next } = 'r1q1showscore' ;
2018-01-29 06:53:40 +01:00
$ self - > { states } { 'r1q1showscore' } { sub } = sub { $ self - > r1q1showscore ( @ _ ) } ;
2018-01-30 06:54:52 +01:00
$ self - > { states } { 'r1q1showscore' } { trans } { wait } = 'r1q1showscore' ;
2018-01-29 06:53:40 +01:00
$ self - > { states } { 'r1q1showscore' } { trans } { next } = 'round1q2' ;
$ self - > { states } { 'round1q2' } { sub } = sub { $ self - > round1q2 ( @ _ ) } ;
2018-02-24 00:51:17 +01:00
$ self - > { states } { 'round1q2' } { trans } { wait } = 'round1q2' ;
2018-01-29 06:53:40 +01:00
$ self - > { states } { 'round1q2' } { trans } { next } = 'r1q2choosecategory' ;
$ self - > { states } { 'r1q2choosecategory' } { sub } = sub { $ self - > r1q2choosecategory ( @ _ ) } ;
$ self - > { states } { 'r1q2choosecategory' } { trans } { wait } = 'r1q2choosecategory' ;
$ self - > { states } { 'r1q2choosecategory' } { trans } { next } = 'r1q2showquestion' ;
$ self - > { states } { 'r1q2showquestion' } { sub } = sub { $ self - > r1q2showquestion ( @ _ ) } ;
2018-01-30 06:54:52 +01:00
$ self - > { states } { 'r1q2showquestion' } { trans } { wait } = 'r1q2showquestion' ;
2018-01-29 06:53:40 +01:00
$ self - > { states } { 'r1q2showquestion' } { trans } { next } = 'r1q2getlies' ;
$ self - > { states } { 'r1q2getlies' } { sub } = sub { $ self - > r1q2getlies ( @ _ ) } ;
2018-02-26 09:46:59 +01:00
$ self - > { states } { 'r1q2getlies' } { trans } { reroll } = 'r1q2showquestion' ;
2018-02-15 07:13:54 +01:00
$ self - > { states } { 'r1q2getlies' } { trans } { skip } = 'round1q2' ;
2018-01-29 06:53:40 +01:00
$ self - > { states } { 'r1q2getlies' } { trans } { wait } = 'r1q2getlies' ;
$ self - > { states } { 'r1q2getlies' } { trans } { next } = 'r1q2findtruth' ;
$ self - > { states } { 'r1q2findtruth' } { sub } = sub { $ self - > r1q2findtruth ( @ _ ) } ;
$ self - > { states } { 'r1q2findtruth' } { trans } { wait } = 'r1q2findtruth' ;
$ self - > { states } { 'r1q2findtruth' } { trans } { next } = 'r1q2showlies' ;
$ self - > { states } { 'r1q2showlies' } { sub } = sub { $ self - > r1q2showlies ( @ _ ) } ;
$ self - > { states } { 'r1q2showlies' } { trans } { wait } = 'r1q2showlies' ;
$ self - > { states } { 'r1q2showlies' } { trans } { next } = 'r1q2showtruth' ;
$ self - > { states } { 'r1q2showtruth' } { sub } = sub { $ self - > r1q2showtruth ( @ _ ) } ;
2018-01-30 06:54:52 +01:00
$ self - > { states } { 'r1q2showtruth' } { trans } { wait } = 'r1q2showtruth' ;
$ self - > { states } { 'r1q2showtruth' } { trans } { next } = 'r1q2reveallies' ;
$ self - > { states } { 'r1q2reveallies' } { sub } = sub { $ self - > r1q2reveallies ( @ _ ) } ;
$ self - > { states } { 'r1q2reveallies' } { trans } { wait } = 'r1q2reveallies' ;
$ self - > { states } { 'r1q2reveallies' } { trans } { next } = 'r1q2showscore' ;
2018-01-29 06:53:40 +01:00
$ self - > { states } { 'r1q2showscore' } { sub } = sub { $ self - > r1q2showscore ( @ _ ) } ;
2018-01-30 06:54:52 +01:00
$ self - > { states } { 'r1q2showscore' } { trans } { wait } = 'r1q2showscore' ;
2018-01-29 06:53:40 +01:00
$ self - > { states } { 'r1q2showscore' } { trans } { next } = 'round1q3' ;
$ self - > { states } { 'round1q3' } { sub } = sub { $ self - > round1q3 ( @ _ ) } ;
$ self - > { states } { 'round1q3' } { trans } { next } = 'r1q3choosecategory' ;
2018-02-24 00:51:17 +01:00
$ self - > { states } { 'round1q3' } { trans } { wait } = 'round1q3' ;
2018-01-29 06:53:40 +01:00
$ self - > { states } { 'r1q3choosecategory' } { sub } = sub { $ self - > r1q3choosecategory ( @ _ ) } ;
$ self - > { states } { 'r1q3choosecategory' } { trans } { wait } = 'r1q3choosecategory' ;
$ self - > { states } { 'r1q3choosecategory' } { trans } { next } = 'r1q3showquestion' ;
$ self - > { states } { 'r1q3showquestion' } { sub } = sub { $ self - > r1q3showquestion ( @ _ ) } ;
2018-01-30 06:54:52 +01:00
$ self - > { states } { 'r1q3showquestion' } { trans } { wait } = 'r1q3showquestion' ;
2018-01-29 06:53:40 +01:00
$ self - > { states } { 'r1q3showquestion' } { trans } { next } = 'r1q3getlies' ;
$ self - > { states } { 'r1q3getlies' } { sub } = sub { $ self - > r1q3getlies ( @ _ ) } ;
2018-02-26 09:46:59 +01:00
$ self - > { states } { 'r1q3getlies' } { trans } { reroll } = 'r1q3showquestion' ;
2018-02-15 07:13:54 +01:00
$ self - > { states } { 'r1q3getlies' } { trans } { skip } = 'round1q3' ;
2018-01-29 06:53:40 +01:00
$ self - > { states } { 'r1q3getlies' } { trans } { wait } = 'r1q3getlies' ;
$ self - > { states } { 'r1q3getlies' } { trans } { next } = 'r1q3findtruth' ;
$ self - > { states } { 'r1q3findtruth' } { sub } = sub { $ self - > r1q3findtruth ( @ _ ) } ;
$ self - > { states } { 'r1q3findtruth' } { trans } { wait } = 'r1q3findtruth' ;
$ self - > { states } { 'r1q3findtruth' } { trans } { next } = 'r1q3showlies' ;
$ self - > { states } { 'r1q3showlies' } { sub } = sub { $ self - > r1q3showlies ( @ _ ) } ;
$ self - > { states } { 'r1q3showlies' } { trans } { wait } = 'r1q3showlies' ;
$ self - > { states } { 'r1q3showlies' } { trans } { next } = 'r1q3showtruth' ;
$ self - > { states } { 'r1q3showtruth' } { sub } = sub { $ self - > r1q3showtruth ( @ _ ) } ;
2018-01-30 06:54:52 +01:00
$ self - > { states } { 'r1q3showtruth' } { trans } { wait } = 'r1q3showtruth' ;
$ self - > { states } { 'r1q3showtruth' } { trans } { next } = 'r1q3reveallies' ;
$ self - > { states } { 'r1q3reveallies' } { sub } = sub { $ self - > r1q3reveallies ( @ _ ) } ;
$ self - > { states } { 'r1q3reveallies' } { trans } { wait } = 'r1q3reveallies' ;
$ self - > { states } { 'r1q3reveallies' } { trans } { next } = 'r1q3showscore' ;
2018-01-29 06:53:40 +01:00
$ self - > { states } { 'r1q3showscore' } { sub } = sub { $ self - > r1q3showscore ( @ _ ) } ;
2018-01-30 06:54:52 +01:00
$ self - > { states } { 'r1q3showscore' } { trans } { wait } = 'r1q3showscore' ;
2018-01-29 06:53:40 +01:00
$ self - > { states } { 'r1q3showscore' } { trans } { next } = 'round2' ;
2018-01-30 06:54:52 +01:00
2018-01-29 06:53:40 +01:00
$ self - > { states } { 'round2' } { sub } = sub { $ self - > round2 ( @ _ ) } ;
$ self - > { states } { 'round2' } { trans } { next } = 'round2q1' ;
$ self - > { states } { 'round2q1' } { sub } = sub { $ self - > round2q1 ( @ _ ) } ;
2018-02-24 00:51:17 +01:00
$ self - > { states } { 'round2q1' } { trans } { wait } = 'round2q1' ;
2018-01-29 06:53:40 +01:00
$ self - > { states } { 'round2q1' } { trans } { next } = 'r2q1choosecategory' ;
$ self - > { states } { 'r2q1choosecategory' } { sub } = sub { $ self - > r2q1choosecategory ( @ _ ) } ;
$ self - > { states } { 'r2q1choosecategory' } { trans } { wait } = 'r2q1choosecategory' ;
$ self - > { states } { 'r2q1choosecategory' } { trans } { next } = 'r2q1showquestion' ;
$ self - > { states } { 'r2q1showquestion' } { sub } = sub { $ self - > r2q1showquestion ( @ _ ) } ;
2018-01-30 06:54:52 +01:00
$ self - > { states } { 'r2q1showquestion' } { trans } { wait } = 'r2q1showquestion' ;
2018-01-29 06:53:40 +01:00
$ self - > { states } { 'r2q1showquestion' } { trans } { next } = 'r2q1getlies' ;
$ self - > { states } { 'r2q1getlies' } { sub } = sub { $ self - > r2q1getlies ( @ _ ) } ;
2018-02-26 09:46:59 +01:00
$ self - > { states } { 'r2q1getlies' } { trans } { reroll } = 'r2q1showquestion' ;
2018-02-15 07:13:54 +01:00
$ self - > { states } { 'r2q1getlies' } { trans } { skip } = 'round2q1' ;
2018-01-29 06:53:40 +01:00
$ self - > { states } { 'r2q1getlies' } { trans } { wait } = 'r2q1getlies' ;
$ self - > { states } { 'r2q1getlies' } { trans } { next } = 'r2q1findtruth' ;
$ self - > { states } { 'r2q1findtruth' } { sub } = sub { $ self - > r2q1findtruth ( @ _ ) } ;
$ self - > { states } { 'r2q1findtruth' } { trans } { wait } = 'r2q1findtruth' ;
$ self - > { states } { 'r2q1findtruth' } { trans } { next } = 'r2q1showlies' ;
$ self - > { states } { 'r2q1showlies' } { sub } = sub { $ self - > r2q1showlies ( @ _ ) } ;
$ self - > { states } { 'r2q1showlies' } { trans } { wait } = 'r2q1showlies' ;
$ self - > { states } { 'r2q1showlies' } { trans } { next } = 'r2q1showtruth' ;
$ self - > { states } { 'r2q1showtruth' } { sub } = sub { $ self - > r2q1showtruth ( @ _ ) } ;
2018-01-30 06:54:52 +01:00
$ self - > { states } { 'r2q1showtruth' } { trans } { wait } = 'r2q1showtruth' ;
$ self - > { states } { 'r2q1showtruth' } { trans } { next } = 'r2q1reveallies' ;
$ self - > { states } { 'r2q1reveallies' } { sub } = sub { $ self - > r2q1reveallies ( @ _ ) } ;
$ self - > { states } { 'r2q1reveallies' } { trans } { wait } = 'r2q1reveallies' ;
$ self - > { states } { 'r2q1reveallies' } { trans } { next } = 'r2q1showscore' ;
2018-01-29 06:53:40 +01:00
$ self - > { states } { 'r2q1showscore' } { sub } = sub { $ self - > r2q1showscore ( @ _ ) } ;
2018-01-30 06:54:52 +01:00
$ self - > { states } { 'r2q1showscore' } { trans } { wait } = 'r2q1showscore' ;
2018-01-29 06:53:40 +01:00
$ self - > { states } { 'r2q1showscore' } { trans } { next } = 'round2q2' ;
$ self - > { states } { 'round2q2' } { sub } = sub { $ self - > round2q2 ( @ _ ) } ;
2018-02-24 00:51:17 +01:00
$ self - > { states } { 'round2q2' } { trans } { wait } = 'round2q2' ;
2018-01-29 06:53:40 +01:00
$ self - > { states } { 'round2q2' } { trans } { next } = 'r2q2choosecategory' ;
$ self - > { states } { 'r2q2choosecategory' } { sub } = sub { $ self - > r2q2choosecategory ( @ _ ) } ;
$ self - > { states } { 'r2q2choosecategory' } { trans } { wait } = 'r2q2choosecategory' ;
$ self - > { states } { 'r2q2choosecategory' } { trans } { next } = 'r2q2showquestion' ;
$ self - > { states } { 'r2q2showquestion' } { sub } = sub { $ self - > r2q2showquestion ( @ _ ) } ;
2018-01-30 06:54:52 +01:00
$ self - > { states } { 'r2q2showquestion' } { trans } { wait } = 'r2q2showquestion' ;
2018-01-29 06:53:40 +01:00
$ self - > { states } { 'r2q2showquestion' } { trans } { next } = 'r2q2getlies' ;
$ self - > { states } { 'r2q2getlies' } { sub } = sub { $ self - > r2q2getlies ( @ _ ) } ;
2018-02-26 09:46:59 +01:00
$ self - > { states } { 'r2q2getlies' } { trans } { reroll } = 'r2q2showquestion' ;
2018-02-15 07:13:54 +01:00
$ self - > { states } { 'r2q2getlies' } { trans } { skip } = 'round2q2' ;
2018-01-29 06:53:40 +01:00
$ self - > { states } { 'r2q2getlies' } { trans } { wait } = 'r2q2getlies' ;
$ self - > { states } { 'r2q2getlies' } { trans } { next } = 'r2q2findtruth' ;
$ self - > { states } { 'r2q2findtruth' } { sub } = sub { $ self - > r2q2findtruth ( @ _ ) } ;
$ self - > { states } { 'r2q2findtruth' } { trans } { wait } = 'r2q2findtruth' ;
$ self - > { states } { 'r2q2findtruth' } { trans } { next } = 'r2q2showlies' ;
$ self - > { states } { 'r2q2showlies' } { sub } = sub { $ self - > r2q2showlies ( @ _ ) } ;
$ self - > { states } { 'r2q2showlies' } { trans } { wait } = 'r2q2showlies' ;
$ self - > { states } { 'r2q2showlies' } { trans } { next } = 'r2q2showtruth' ;
$ self - > { states } { 'r2q2showtruth' } { sub } = sub { $ self - > r2q2showtruth ( @ _ ) } ;
2018-01-30 06:54:52 +01:00
$ self - > { states } { 'r2q2showtruth' } { trans } { wait } = 'r2q2showtruth' ;
$ self - > { states } { 'r2q2showtruth' } { trans } { next } = 'r2q2reveallies' ;
$ self - > { states } { 'r2q2reveallies' } { sub } = sub { $ self - > r2q2reveallies ( @ _ ) } ;
$ self - > { states } { 'r2q2reveallies' } { trans } { wait } = 'r2q2reveallies' ;
$ self - > { states } { 'r2q2reveallies' } { trans } { next } = 'r2q2showscore' ;
2018-01-29 06:53:40 +01:00
$ self - > { states } { 'r2q2showscore' } { sub } = sub { $ self - > r2q2showscore ( @ _ ) } ;
2018-01-30 06:54:52 +01:00
$ self - > { states } { 'r2q2showscore' } { trans } { wait } = 'r2q2showscore' ;
2018-01-29 06:53:40 +01:00
$ self - > { states } { 'r2q2showscore' } { trans } { next } = 'round2q3' ;
$ self - > { states } { 'round2q3' } { sub } = sub { $ self - > round2q3 ( @ _ ) } ;
2018-02-24 00:51:17 +01:00
$ self - > { states } { 'round2q3' } { trans } { wait } = 'round2q3' ;
2018-01-29 06:53:40 +01:00
$ self - > { states } { 'round2q3' } { trans } { next } = 'r2q3choosecategory' ;
$ self - > { states } { 'r2q3choosecategory' } { sub } = sub { $ self - > r2q3choosecategory ( @ _ ) } ;
$ self - > { states } { 'r2q3choosecategory' } { trans } { wait } = 'r2q3choosecategory' ;
$ self - > { states } { 'r2q3choosecategory' } { trans } { next } = 'r2q3showquestion' ;
$ self - > { states } { 'r2q3showquestion' } { sub } = sub { $ self - > r2q3showquestion ( @ _ ) } ;
2018-01-30 06:54:52 +01:00
$ self - > { states } { 'r2q3showquestion' } { trans } { wait } = 'r2q3showquestion' ;
2018-01-29 06:53:40 +01:00
$ self - > { states } { 'r2q3showquestion' } { trans } { next } = 'r2q3getlies' ;
$ self - > { states } { 'r2q3getlies' } { sub } = sub { $ self - > r2q3getlies ( @ _ ) } ;
2018-02-26 09:46:59 +01:00
$ self - > { states } { 'r2q3getlies' } { trans } { reroll } = 'r2q3showquestion' ;
2018-02-15 07:13:54 +01:00
$ self - > { states } { 'r2q3getlies' } { trans } { skip } = 'round2q3' ;
2018-01-29 06:53:40 +01:00
$ self - > { states } { 'r2q3getlies' } { trans } { wait } = 'r2q3getlies' ;
$ self - > { states } { 'r2q3getlies' } { trans } { next } = 'r2q3findtruth' ;
$ self - > { states } { 'r2q3findtruth' } { sub } = sub { $ self - > r2q3findtruth ( @ _ ) } ;
$ self - > { states } { 'r2q3findtruth' } { trans } { wait } = 'r2q3findtruth' ;
$ self - > { states } { 'r2q3findtruth' } { trans } { next } = 'r2q3showlies' ;
$ self - > { states } { 'r2q3showlies' } { sub } = sub { $ self - > r2q3showlies ( @ _ ) } ;
$ self - > { states } { 'r2q3showlies' } { trans } { wait } = 'r2q3showlies' ;
$ self - > { states } { 'r2q3showlies' } { trans } { next } = 'r2q3showtruth' ;
$ self - > { states } { 'r2q3showtruth' } { sub } = sub { $ self - > r2q3showtruth ( @ _ ) } ;
2018-01-30 06:54:52 +01:00
$ self - > { states } { 'r2q3showtruth' } { trans } { wait } = 'r2q3showtruth' ;
$ self - > { states } { 'r2q3showtruth' } { trans } { next } = 'r2q3reveallies' ;
$ self - > { states } { 'r2q3reveallies' } { sub } = sub { $ self - > r2q3reveallies ( @ _ ) } ;
$ self - > { states } { 'r2q3reveallies' } { trans } { wait } = 'r2q3reveallies' ;
$ self - > { states } { 'r2q3reveallies' } { trans } { next } = 'r2q3showscore' ;
2018-01-29 06:53:40 +01:00
$ self - > { states } { 'r2q3showscore' } { sub } = sub { $ self - > r2q3showscore ( @ _ ) } ;
2018-01-30 06:54:52 +01:00
$ self - > { states } { 'r2q3showscore' } { trans } { wait } = 'r2q3showscore' ;
2018-01-29 06:53:40 +01:00
$ self - > { states } { 'r2q3showscore' } { trans } { next } = 'round3' ;
2018-01-30 06:54:52 +01:00
2018-01-29 06:53:40 +01:00
$ self - > { states } { 'round3' } { sub } = sub { $ self - > round3 ( @ _ ) } ;
$ self - > { states } { 'round3' } { trans } { next } = 'round3q1' ;
$ self - > { states } { 'round3q1' } { sub } = sub { $ self - > round3q1 ( @ _ ) } ;
2018-02-24 00:51:17 +01:00
$ self - > { states } { 'round3q1' } { trans } { wait } = 'round3q1' ;
2018-01-29 06:53:40 +01:00
$ self - > { states } { 'round3q1' } { trans } { next } = 'r3q1choosecategory' ;
$ self - > { states } { 'r3q1choosecategory' } { sub } = sub { $ self - > r3q1choosecategory ( @ _ ) } ;
$ self - > { states } { 'r3q1choosecategory' } { trans } { wait } = 'r3q1choosecategory' ;
$ self - > { states } { 'r3q1choosecategory' } { trans } { next } = 'r3q1showquestion' ;
$ self - > { states } { 'r3q1showquestion' } { sub } = sub { $ self - > r3q1showquestion ( @ _ ) } ;
2018-01-30 06:54:52 +01:00
$ self - > { states } { 'r3q1showquestion' } { trans } { wait } = 'r3q1showquestion' ;
2018-01-29 06:53:40 +01:00
$ self - > { states } { 'r3q1showquestion' } { trans } { next } = 'r3q1getlies' ;
$ self - > { states } { 'r3q1getlies' } { sub } = sub { $ self - > r3q1getlies ( @ _ ) } ;
2018-02-26 09:46:59 +01:00
$ self - > { states } { 'r3q1getlies' } { trans } { reroll } = 'r3q1showquestion' ;
2018-02-15 07:13:54 +01:00
$ self - > { states } { 'r3q1getlies' } { trans } { skip } = 'round3q1' ;
2018-01-29 06:53:40 +01:00
$ self - > { states } { 'r3q1getlies' } { trans } { wait } = 'r3q1getlies' ;
$ self - > { states } { 'r3q1getlies' } { trans } { next } = 'r3q1findtruth' ;
$ self - > { states } { 'r3q1findtruth' } { sub } = sub { $ self - > r3q1findtruth ( @ _ ) } ;
$ self - > { states } { 'r3q1findtruth' } { trans } { wait } = 'r3q1findtruth' ;
$ self - > { states } { 'r3q1findtruth' } { trans } { next } = 'r3q1showlies' ;
$ self - > { states } { 'r3q1showlies' } { sub } = sub { $ self - > r3q1showlies ( @ _ ) } ;
$ self - > { states } { 'r3q1showlies' } { trans } { wait } = 'r3q1showlies' ;
$ self - > { states } { 'r3q1showlies' } { trans } { next } = 'r3q1showtruth' ;
$ self - > { states } { 'r3q1showtruth' } { sub } = sub { $ self - > r3q1showtruth ( @ _ ) } ;
2018-01-30 06:54:52 +01:00
$ self - > { states } { 'r3q1showtruth' } { trans } { wait } = 'r3q1showtruth' ;
$ self - > { states } { 'r3q1showtruth' } { trans } { next } = 'r3q1reveallies' ;
$ self - > { states } { 'r3q1reveallies' } { sub } = sub { $ self - > r3q1reveallies ( @ _ ) } ;
$ self - > { states } { 'r3q1reveallies' } { trans } { wait } = 'r3q1reveallies' ;
$ self - > { states } { 'r3q1reveallies' } { trans } { next } = 'r3q1showscore' ;
2018-01-29 06:53:40 +01:00
$ self - > { states } { 'r3q1showscore' } { sub } = sub { $ self - > r3q1showscore ( @ _ ) } ;
2018-01-30 06:54:52 +01:00
$ self - > { states } { 'r3q1showscore' } { trans } { wait } = 'r3q1showscore' ;
2018-01-29 06:53:40 +01:00
$ self - > { states } { 'r3q1showscore' } { trans } { next } = 'round3q2' ;
$ self - > { states } { 'round3q2' } { sub } = sub { $ self - > round3q2 ( @ _ ) } ;
2018-02-24 00:51:17 +01:00
$ self - > { states } { 'round3q2' } { trans } { wait } = 'round3q2' ;
2018-01-29 06:53:40 +01:00
$ self - > { states } { 'round3q2' } { trans } { next } = 'r3q2choosecategory' ;
$ self - > { states } { 'r3q2choosecategory' } { sub } = sub { $ self - > r3q2choosecategory ( @ _ ) } ;
$ self - > { states } { 'r3q2choosecategory' } { trans } { wait } = 'r3q2choosecategory' ;
$ self - > { states } { 'r3q2choosecategory' } { trans } { next } = 'r3q2showquestion' ;
$ self - > { states } { 'r3q2showquestion' } { sub } = sub { $ self - > r3q2showquestion ( @ _ ) } ;
2018-01-30 06:54:52 +01:00
$ self - > { states } { 'r3q2showquestion' } { trans } { wait } = 'r3q2showquestion' ;
2018-01-29 06:53:40 +01:00
$ self - > { states } { 'r3q2showquestion' } { trans } { next } = 'r3q2getlies' ;
$ self - > { states } { 'r3q2getlies' } { sub } = sub { $ self - > r3q2getlies ( @ _ ) } ;
2018-02-26 09:46:59 +01:00
$ self - > { states } { 'r3q2getlies' } { trans } { reroll } = 'r3q2showquestion' ;
2018-02-15 07:13:54 +01:00
$ self - > { states } { 'r3q2getlies' } { trans } { skip } = 'round3q2' ;
2018-01-29 06:53:40 +01:00
$ self - > { states } { 'r3q2getlies' } { trans } { wait } = 'r3q2getlies' ;
$ self - > { states } { 'r3q2getlies' } { trans } { next } = 'r3q2findtruth' ;
$ self - > { states } { 'r3q2findtruth' } { sub } = sub { $ self - > r3q2findtruth ( @ _ ) } ;
$ self - > { states } { 'r3q2findtruth' } { trans } { wait } = 'r3q2findtruth' ;
$ self - > { states } { 'r3q2findtruth' } { trans } { next } = 'r3q2showlies' ;
$ self - > { states } { 'r3q2showlies' } { sub } = sub { $ self - > r3q2showlies ( @ _ ) } ;
$ self - > { states } { 'r3q2showlies' } { trans } { wait } = 'r3q2showlies' ;
$ self - > { states } { 'r3q2showlies' } { trans } { next } = 'r3q2showtruth' ;
$ self - > { states } { 'r3q2showtruth' } { sub } = sub { $ self - > r3q2showtruth ( @ _ ) } ;
2018-01-30 06:54:52 +01:00
$ self - > { states } { 'r3q2showtruth' } { trans } { wait } = 'r3q2showtruth' ;
$ self - > { states } { 'r3q2showtruth' } { trans } { next } = 'r3q2reveallies' ;
$ self - > { states } { 'r3q2reveallies' } { sub } = sub { $ self - > r3q2reveallies ( @ _ ) } ;
$ self - > { states } { 'r3q2reveallies' } { trans } { wait } = 'r3q2reveallies' ;
$ self - > { states } { 'r3q2reveallies' } { trans } { next } = 'r3q2showscore' ;
2018-01-29 06:53:40 +01:00
$ self - > { states } { 'r3q2showscore' } { sub } = sub { $ self - > r3q2showscore ( @ _ ) } ;
2018-01-30 06:54:52 +01:00
$ self - > { states } { 'r3q2showscore' } { trans } { wait } = 'r3q2showscore' ;
2018-01-29 06:53:40 +01:00
$ self - > { states } { 'r3q2showscore' } { trans } { next } = 'round3q3' ;
$ self - > { states } { 'round3q3' } { sub } = sub { $ self - > round3q3 ( @ _ ) } ;
2018-02-24 00:51:17 +01:00
$ self - > { states } { 'round3q3' } { trans } { wait } = 'round3q3' ;
2018-01-29 06:53:40 +01:00
$ self - > { states } { 'round3q3' } { trans } { next } = 'r3q3choosecategory' ;
$ self - > { states } { 'r3q3choosecategory' } { sub } = sub { $ self - > r3q3choosecategory ( @ _ ) } ;
$ self - > { states } { 'r3q3choosecategory' } { trans } { wait } = 'r3q3choosecategory' ;
$ self - > { states } { 'r3q3choosecategory' } { trans } { next } = 'r3q3showquestion' ;
$ self - > { states } { 'r3q3showquestion' } { sub } = sub { $ self - > r3q3showquestion ( @ _ ) } ;
2018-01-30 06:54:52 +01:00
$ self - > { states } { 'r3q3showquestion' } { trans } { wait } = 'r3q3showquestion' ;
2018-01-29 06:53:40 +01:00
$ self - > { states } { 'r3q3showquestion' } { trans } { next } = 'r3q3getlies' ;
$ self - > { states } { 'r3q3getlies' } { sub } = sub { $ self - > r3q3getlies ( @ _ ) } ;
2018-02-26 09:46:59 +01:00
$ self - > { states } { 'r3q3getlies' } { trans } { reroll } = 'r3q3showquestion' ;
2018-02-15 07:13:54 +01:00
$ self - > { states } { 'r3q3getlies' } { trans } { skip } = 'round3q3' ;
2018-01-29 06:53:40 +01:00
$ self - > { states } { 'r3q3getlies' } { trans } { wait } = 'r3q3getlies' ;
$ self - > { states } { 'r3q3getlies' } { trans } { next } = 'r3q3findtruth' ;
$ self - > { states } { 'r3q3findtruth' } { sub } = sub { $ self - > r3q3findtruth ( @ _ ) } ;
$ self - > { states } { 'r3q3findtruth' } { trans } { wait } = 'r3q3findtruth' ;
$ self - > { states } { 'r3q3findtruth' } { trans } { next } = 'r3q3showlies' ;
$ self - > { states } { 'r3q3showlies' } { sub } = sub { $ self - > r3q3showlies ( @ _ ) } ;
$ self - > { states } { 'r3q3showlies' } { trans } { wait } = 'r3q3showlies' ;
$ self - > { states } { 'r3q3showlies' } { trans } { next } = 'r3q3showtruth' ;
$ self - > { states } { 'r3q3showtruth' } { sub } = sub { $ self - > r3q3showtruth ( @ _ ) } ;
2018-01-30 06:54:52 +01:00
$ self - > { states } { 'r3q3showtruth' } { trans } { wait } = 'r3q3showtruth' ;
$ self - > { states } { 'r3q3showtruth' } { trans } { next } = 'r3q3reveallies' ;
$ self - > { states } { 'r3q3reveallies' } { sub } = sub { $ self - > r3q3reveallies ( @ _ ) } ;
$ self - > { states } { 'r3q3reveallies' } { trans } { wait } = 'r3q3reveallies' ;
$ self - > { states } { 'r3q3reveallies' } { trans } { next } = 'r3q3showscore' ;
2018-01-29 06:53:40 +01:00
$ self - > { states } { 'r3q3showscore' } { sub } = sub { $ self - > r3q3showscore ( @ _ ) } ;
2018-01-30 06:54:52 +01:00
$ self - > { states } { 'r3q3showscore' } { trans } { wait } = 'r3q3showscore' ;
2018-01-29 06:53:40 +01:00
$ self - > { states } { 'r3q3showscore' } { trans } { next } = 'round4' ;
2018-01-30 06:54:52 +01:00
2018-01-29 06:53:40 +01:00
$ self - > { states } { 'round4' } { sub } = sub { $ self - > round4 ( @ _ ) } ;
$ self - > { states } { 'round4' } { trans } { next } = 'round4q1' ;
$ self - > { states } { 'round4q1' } { sub } = sub { $ self - > round4q1 ( @ _ ) } ;
2018-02-24 00:51:17 +01:00
$ self - > { states } { 'round4q1' } { trans } { wait } = 'round4q1' ;
2018-01-29 06:53:40 +01:00
$ self - > { states } { 'round4q1' } { trans } { next } = 'r4q1choosecategory' ;
$ self - > { states } { 'r4q1choosecategory' } { sub } = sub { $ self - > r4q1choosecategory ( @ _ ) } ;
$ self - > { states } { 'r4q1choosecategory' } { trans } { wait } = 'r4q1choosecategory' ;
$ self - > { states } { 'r4q1choosecategory' } { trans } { next } = 'r4q1showquestion' ;
$ self - > { states } { 'r4q1showquestion' } { sub } = sub { $ self - > r4q1showquestion ( @ _ ) } ;
2018-01-30 06:54:52 +01:00
$ self - > { states } { 'r4q1showquestion' } { trans } { wait } = 'r4q1showquestion' ;
2018-01-29 06:53:40 +01:00
$ self - > { states } { 'r4q1showquestion' } { trans } { next } = 'r4q1getlies' ;
$ self - > { states } { 'r4q1getlies' } { sub } = sub { $ self - > r4q1getlies ( @ _ ) } ;
2018-02-26 09:46:59 +01:00
$ self - > { states } { 'r4q1getlies' } { trans } { reroll } = 'r4q1showquestion' ;
2018-02-15 07:13:54 +01:00
$ self - > { states } { 'r4q1getlies' } { trans } { skip } = 'round4q1' ;
2018-01-29 06:53:40 +01:00
$ self - > { states } { 'r4q1getlies' } { trans } { wait } = 'r4q1getlies' ;
$ self - > { states } { 'r4q1getlies' } { trans } { next } = 'r4q1findtruth' ;
$ self - > { states } { 'r4q1findtruth' } { sub } = sub { $ self - > r4q1findtruth ( @ _ ) } ;
$ self - > { states } { 'r4q1findtruth' } { trans } { wait } = 'r4q1findtruth' ;
$ self - > { states } { 'r4q1findtruth' } { trans } { next } = 'r4q1showlies' ;
$ self - > { states } { 'r4q1showlies' } { sub } = sub { $ self - > r4q1showlies ( @ _ ) } ;
$ self - > { states } { 'r4q1showlies' } { trans } { wait } = 'r4q1showlies' ;
$ self - > { states } { 'r4q1showlies' } { trans } { next } = 'r4q1showtruth' ;
$ self - > { states } { 'r4q1showtruth' } { sub } = sub { $ self - > r4q1showtruth ( @ _ ) } ;
2018-01-30 06:54:52 +01:00
$ self - > { states } { 'r4q1showtruth' } { trans } { wait } = 'r4q1showtruth' ;
$ self - > { states } { 'r4q1showtruth' } { trans } { next } = 'r4q1reveallies' ;
$ self - > { states } { 'r4q1reveallies' } { sub } = sub { $ self - > r4q1reveallies ( @ _ ) } ;
$ self - > { states } { 'r4q1reveallies' } { trans } { wait } = 'r4q1reveallies' ;
$ self - > { states } { 'r4q1reveallies' } { trans } { next } = 'r4q1showscore' ;
2018-01-29 06:53:40 +01:00
$ self - > { states } { 'r4q1showscore' } { sub } = sub { $ self - > r4q1showscore ( @ _ ) } ;
2018-01-30 06:54:52 +01:00
$ self - > { states } { 'r4q1showscore' } { trans } { wait } = 'r4q1showscore' ;
2018-01-29 06:53:40 +01:00
$ self - > { states } { 'r4q1showscore' } { trans } { next } = 'gameover' ;
2018-01-30 06:54:52 +01:00
2018-01-29 06:53:40 +01:00
$ self - > { states } { 'gameover' } { sub } = sub { $ self - > gameover ( @ _ ) } ;
2018-02-24 00:51:17 +01:00
$ self - > { states } { 'gameover' } { trans } { wait } = 'gameover' ;
2018-01-29 06:53:40 +01:00
$ self - > { states } { 'gameover' } { trans } { next } = 'getplayers' ;
}
2018-02-15 04:09:57 +01:00
sub commify {
my $ self = shift ;
my $ text = reverse $ _ [ 0 ] ;
$ text =~ s/(\d\d\d)(?=\d)(?!\d*\.)/$1,/g ;
return scalar reverse $ text ;
}
2019-05-02 21:06:45 +02:00
sub normalize_question {
my ( $ self , $ text ) = @ _ ;
my @ words = split / / , $ text ;
my $ uc = 0 ;
foreach my $ word ( @ words ) {
if ( $ word =~ m/^[A-Z]/ ) {
$ uc + + ;
}
}
if ( $ uc >= @ words * .8 ) {
$ text = ucfirst lc $ text ;
}
return $ text ;
}
2018-02-04 05:42:27 +01:00
sub normalize_text {
my ( $ self , $ text ) = @ _ ;
2019-07-11 03:40:53 +02:00
$ text = unidecode $ text ;
2019-05-07 11:19:03 +02:00
2018-02-04 05:42:27 +01:00
$ text =~ s/^\s+|\s+$//g ;
$ text =~ s/\s+/ /g ;
2019-04-27 07:20:54 +02:00
$ text =~ s/^(the|a|an) //i ;
2019-05-02 21:06:45 +02:00
$ text =~ s/&/ AND /g ;
2018-02-04 05:42:27 +01:00
2018-02-09 21:47:06 +01:00
$ text = lc substr ( $ text , 0 , 80 ) ;
$ text =~ s/\$\s+(\d)/\$$1/g ;
2018-02-19 01:40:17 +01:00
$ text =~ s/\s*%$// ;
2018-02-25 03:17:55 +01:00
$ text =~ s/(\d),(\d\d\d)/$1$2/g ;
$ text =~ s/(\D,)(\D)/$1 $2/g ;
2018-02-04 05:42:27 +01:00
2018-02-09 21:47:06 +01:00
my @ words = split / / , $ text ;
2018-02-04 05:42:27 +01:00
my @ result ;
foreach my $ word ( @ words ) {
2018-02-09 21:47:06 +01:00
my $ punct = $ 1 if $ word =~ s/(\p{PosixPunct}+)$// ;
2018-02-04 05:42:27 +01:00
my $ newword = $ word ;
if ( $ word =~ m/^\d{4}$/ and $ word >= 1700 and $ word <= 2100 ) {
$ newword = year2en ( $ word ) ;
2018-02-12 05:44:14 +01:00
} elsif ( $ word =~ m/^-?\d+$/ ) {
2018-02-04 05:42:27 +01:00
$ newword = num2en ( $ word ) ;
2018-02-09 21:47:06 +01:00
if ( defined $ punct and $ punct eq '%' ) {
$ newword . = " percent" ;
$ punct = undef ;
}
2018-02-12 05:44:14 +01:00
} elsif ( $ word =~ m/^(-?\d+)(?:st|nd|rd|th)$/i ) {
2018-02-04 05:42:27 +01:00
$ newword = num2en_ordinal ( $ 1 ) ;
2018-02-12 05:44:14 +01:00
} elsif ( $ word =~ m/^(-)?\$(\d+)?(\.\d+)?$/i ) {
my ( $ neg , $ dollars , $ cents ) = ( $ 1 , $ 2 , $ 3 ) ;
$ newword = '' ;
$ dollars = "$neg$dollars" if defined $ neg and defined $ dollars ;
if ( defined $ dollars ) {
$ word = num2en ( $ dollars ) ;
$ newword = "$word " . ( abs $ dollars == 1 ? "dollar" : "dollars" ) ;
}
2018-02-09 21:47:06 +01:00
if ( defined $ cents ) {
$ cents =~ s/^\.0*// ;
2018-02-12 05:44:14 +01:00
$ cents = "$neg$cents" if defined $ neg and not defined $ dollars ;
2018-02-09 21:47:06 +01:00
$ word = num2en ( $ cents ) ;
2018-02-12 05:44:14 +01:00
$ newword . = " and " if defined $ dollars ;
$ newword . = ( abs $ cents == 1 ? "$word cent" : "$word cents" ) ;
2018-02-09 21:47:06 +01:00
}
2018-02-12 05:44:14 +01:00
} elsif ( $ word =~ m/^(-?\d*\.\d+)(?:st|nd|rd|th)?$/i ) {
2018-02-04 05:42:27 +01:00
$ newword = num2en ( $ 1 ) ;
2018-02-12 05:44:14 +01:00
} elsif ( $ word =~ m {^(-?\d+\s*/\s*-?\d+)(?:st|nd|rd|th)?$}i ) {
2018-02-04 05:42:27 +01:00
$ newword = fraction2words ( $ 1 ) ;
}
2018-02-09 21:47:06 +01:00
$ newword . = $ punct if defined $ punct ;
2018-02-04 05:42:27 +01:00
push @ result , $ newword ;
}
2019-05-07 11:19:03 +02:00
$ text = uc b2a ( "@result" , s = > 1 ) ;
2018-02-19 01:40:17 +01:00
$ text =~ s/([A-Z])\./$1/g ;
$ text =~ s/-/ /g ;
$ text =~ s/["'?!]//g ;
2019-05-06 08:11:45 +02:00
$ text =~ s/\s+/ /g ;
2019-05-14 02:59:15 +02:00
$ text =~ s/^\s+|\s+$//g ;
2018-02-19 01:40:17 +01:00
2018-02-09 21:47:06 +01:00
return substr $ text , 0 , 80 ;
2018-02-04 05:42:27 +01:00
}
sub validate_lie {
my ( $ self , $ truth , $ lie ) = @ _ ;
2018-02-11 02:13:26 +01:00
my % truth_words = @ { stem map { $ _ = > 1 } grep { /^\w+$/ and not exists $ self - > { stopwords } { lc $ _ } } split /\b/ , $ truth } ;
2018-02-04 05:42:27 +01:00
my $ truth_word_count = keys % truth_words ;
2018-02-11 02:13:26 +01:00
my % lie_words = @ { stem map { $ _ = > 1 } grep { /^\w+$/ and not exists $ self - > { stopwords } { lc $ _ } } split /\b/ , $ lie } ;
2018-02-04 05:42:27 +01:00
my $ lie_word_count = keys % lie_words ;
my $ count = 0 ;
foreach my $ word ( keys % lie_words ) {
if ( exists $ truth_words { $ word } ) {
$ count + + ;
}
}
2018-08-06 07:52:29 +02:00
if ( $ count == $ truth_word_count ) {
2018-02-04 05:42:27 +01:00
return 0 ;
}
my $ stripped_truth = $ truth ;
$ stripped_truth =~ s/(?:\s|\p{PosixPunct})+//g ;
my $ stripped_lie = $ lie ;
$ stripped_lie =~ s/(?:\s|\p{PosixPunct})+//g ;
if ( $ stripped_truth eq $ stripped_lie ) {
return 0 ;
}
return 1 ;
}
2018-01-29 06:53:40 +01:00
# generic state subroutines
sub choosecategory {
my ( $ self , $ state ) = @ _ ;
2018-02-26 10:32:02 +01:00
if ( $ state - > { init } or $ state - > { reroll_category } ) {
2018-01-29 06:53:40 +01:00
delete $ state - > { current_category } ;
2018-02-26 10:32:02 +01:00
$ state - > { current_player } + + unless $ state - > { reroll_category } ;
2018-01-29 06:53:40 +01:00
if ( $ state - > { current_player } >= @ { $ state - > { players } } ) {
$ state - > { current_player } = 0 ;
}
my @ choices ;
2019-04-22 03:56:46 +02:00
my @ categories ;
2020-01-22 05:22:12 +01:00
if ( exists $ self - > { metadata } - > { hash } - > { filter } - > { category_include_filter } and length $ self - > { metadata } - > { hash } - > { filter } - > { category_include_filter } ) {
2019-04-24 02:59:39 +02:00
@ categories = grep { /$self->{metadata}->{hash}->{filter}->{category_include_filter}/i } keys % { $ self - > { categories } } ;
2019-04-22 03:56:46 +02:00
} else {
@ categories = keys % { $ self - > { categories } } ;
}
2018-01-29 06:53:40 +01:00
2020-01-22 05:22:12 +01:00
if ( exists $ self - > { metadata } - > { hash } - > { filter } - > { category_exclude_filter } and length $ self - > { metadata } - > { hash } - > { filter } - > { category_exclude_filter } ) {
2019-04-24 02:59:39 +02:00
@ categories = grep { $ _ !~ /$self->{metadata}->{hash}->{filter}->{category_exclude_filter}/i } @ categories ;
2019-04-22 05:48:07 +02:00
}
2018-01-29 06:53:40 +01:00
my $ no_infinite_loops = 0 ;
while ( 1 ) {
2019-05-07 06:08:09 +02:00
last if + + $ no_infinite_loops > 10000 ;
2018-01-29 06:53:40 +01:00
my $ cat = $ categories [ rand @ categories ] ;
2019-05-07 06:08:09 +02:00
my @ questions = keys % { $ self - > { categories } { $ cat } } ;
2018-01-29 06:53:40 +01:00
2019-05-07 06:08:09 +02:00
if ( not @ questions ) {
$ self - > { pbot } - > { logger } - > log ( "No questions for category $cat\n" ) ;
2018-02-25 03:17:55 +01:00
next ;
}
2019-05-07 06:08:09 +02:00
if ( exists $ self - > { metadata } - > { hash } - > { settings } - > { min_difficulty } ) {
@ questions = grep { $ self - > { categories } { $ cat } { $ _ } - > { value } >= $ self - > { metadata } - > { hash } - > { settings } - > { min_difficulty } } @ questions ;
}
if ( exists $ self - > { metadata } - > { hash } - > { settings } - > { max_difficulty } ) {
@ questions = grep { $ self - > { categories } { $ cat } { $ _ } - > { value } <= $ self - > { metadata } - > { hash } - > { settings } - > { max_difficulty } } @ questions ;
}
if ( exists $ self - > { metadata } - > { hash } - > { settings } - > { seen_expiry } ) {
my $ now = time ;
@ questions = grep { $ now - $ self - > { categories } { $ cat } { $ _ } - > { seen_timestamp } >= $ self - > { metadata } - > { hash } - > { settings } - > { seen_expiry } } @ questions ;
}
next if not @ questions ;
2018-01-29 06:53:40 +01:00
if ( not grep { $ _ eq $ cat } @ choices ) {
push @ choices , $ cat ;
}
2019-05-03 08:13:27 +02:00
last if @ choices == $ self - > { metadata } - > { hash } - > { settings } - > { category_choices } or @ categories < $ self - > { metadata } - > { hash } - > { settings } - > { category_choices } ; ;
2018-01-29 06:53:40 +01:00
}
2019-05-07 06:08:09 +02:00
if ( not @ choices ) {
$ self - > { pbot } - > { logger } - > log ( "Out of questions with current settings!\n" ) ;
# XXX: do something useful here
}
2018-02-26 10:32:02 +01:00
push @ choices , 'RANDOM CATEGORY' ;
push @ choices , 'REROLL CATEGORIES' ;
2018-02-20 09:16:22 +01:00
2018-01-29 06:53:40 +01:00
$ state - > { categories_text } = '' ;
my $ i = 1 ;
my $ comma = '' ;
foreach my $ choice ( @ choices ) {
2018-02-26 09:46:59 +01:00
$ state - > { categories_text } . = "$comma$color{green}$i)$color{reset} " . $ choice ;
2018-01-29 06:53:40 +01:00
$ i + + ;
$ comma = "; " ;
}
2019-05-03 08:13:27 +02:00
if ( $ state - > { reroll_category } and not $ self - > { metadata } - > { hash } - > { settings } - > { category_autopick } ) {
2018-02-26 10:32:02 +01:00
$ self - > send_message ( $ self - > { channel } , "$state->{categories_text}" ) ;
}
2018-01-29 06:53:40 +01:00
$ state - > { category_options } = \ @ choices ;
2018-02-26 10:32:02 +01:00
$ state - > { category_rerolls } = 0 if $ state - > { init } ;
2018-01-29 06:53:40 +01:00
delete $ state - > { init } ;
2018-02-26 10:32:02 +01:00
delete $ state - > { reroll_category } ;
2018-01-29 06:53:40 +01:00
}
2018-02-02 05:15:54 +01:00
if ( exists $ state - > { current_category } or not @ { $ state - > { players } } ) {
return 'next' ;
}
2018-01-30 06:54:52 +01:00
my $ tock ;
if ( $ state - > { first_tock } ) {
$ tock = 3 ;
} else {
2020-01-19 11:35:33 +01:00
$ tock = $ self - > { tock_duration } ;
2018-01-30 06:54:52 +01:00
}
if ( $ state - > { ticks } % $ tock == 0 ) {
2018-02-25 03:17:55 +01:00
$ state - > { tocked } = 1 ;
2018-02-02 05:15:54 +01:00
2019-04-24 03:41:57 +02:00
if ( exists $ state - > { random_category } or $ self - > { metadata } - > { hash } - > { settings } - > { category_autopick } ) {
2018-02-02 05:15:54 +01:00
delete $ state - > { random_category } ;
2018-02-28 04:50:30 +01:00
my $ category = $ state - > { category_options } - > [ rand ( @ { $ state - > { category_options } } - 2 ) ] ;
2019-04-28 09:21:15 +02:00
my $ questions = scalar keys % { $ self - > { categories } { $ category } } ;
2019-05-06 08:11:45 +02:00
$ self - > send_message ( $ self - > { channel } , "$color{green}Category:$color{reset} $category! ($questions questions)" ) ;
2018-02-02 05:15:54 +01:00
$ state - > { current_category } = $ category ;
return 'next' ;
}
2018-02-01 07:11:26 +01:00
if ( + + $ state - > { counter } > $ state - > { max_count } ) {
2018-02-20 09:16:22 +01:00
# $state->{players}->[$state->{current_player}]->{missedinputs}++;
2018-01-29 06:53:40 +01:00
my $ name = $ state - > { players } - > [ $ state - > { current_player } ] - > { name } ;
2019-04-22 05:48:07 +02:00
my $ category = $ state - > { category_options } - > [ rand ( @ { $ state - > { category_options } } - 2 ) ] ;
2018-02-26 09:46:59 +01:00
$ self - > send_message ( $ self - > { channel } , "$name took too long to choose. Randomly choosing: $category!" ) ;
2018-01-29 06:53:40 +01:00
$ state - > { current_category } = $ category ;
return 'next' ;
}
my $ name = $ state - > { players } - > [ $ state - > { current_player } ] - > { name } ;
2019-04-28 09:21:15 +02:00
my $ warning ;
if ( $ state - > { counter } == $ state - > { max_count } ) {
$ warning = $ color { red } ;
} elsif ( $ state - > { counter } == $ state - > { max_count } - 1 ) {
$ warning = $ color { yellow } ;
} else {
$ warning = '' ;
}
2018-02-25 03:17:55 +01:00
2020-01-19 11:35:33 +01:00
my $ remaining = $ self - > { tock_duration } * $ state - > { max_count } ;
$ remaining -= $ self - > { tock_duration } * ( $ state - > { counter } - 1 ) ;
2018-02-25 03:17:55 +01:00
$ remaining = "(" . ( concise duration $ remaining ) . " remaining)" ;
2019-04-28 09:21:15 +02:00
$ self - > send_message ( $ self - > { channel } , "$name: $warning$remaining Choose a category via `/msg me c <number>`:$color{reset}" ) ;
2018-02-26 09:46:59 +01:00
$ self - > send_message ( $ self - > { channel } , "$state->{categories_text}" ) ;
2018-01-29 06:53:40 +01:00
return 'wait' ;
}
if ( exists $ state - > { current_category } ) {
return 'next' ;
} else {
return 'wait' ;
}
}
sub getnewquestion {
my ( $ self , $ state ) = @ _ ;
2018-01-30 06:54:52 +01:00
if ( $ state - > { ticks } % 3 == 0 ) {
2018-02-15 04:09:57 +01:00
my @ questions = keys % { $ self - > { categories } { $ state - > { current_category } } } ;
2018-02-25 03:17:55 +01:00
2018-02-26 09:46:59 +01:00
if ( exists $ state - > { seen_questions } - > { $ state - > { current_category } } ) {
my @ seen = keys % { $ state - > { seen_questions } - > { $ state - > { current_category } } } ;
my % seen = map { $ _ = > 1 } @ seen ;
@ questions = grep { ! defined $ seen { $ _ } } @ questions ;
}
2019-05-03 08:13:27 +02:00
@ questions = sort { $ self - > { categories } { $ state - > { current_category } } { $ a } - > { seen_timestamp } <=> $ self - > { categories } { $ state - > { current_category } } { $ b } - > { seen_timestamp } } @ questions ;
my $ now = time ;
@ questions = grep { $ now - $ self - > { categories } { $ state - > { current_category } } { $ _ } - > { seen_timestamp } >= $ self - > { metadata } - > { hash } - > { settings } - > { seen_expiry } } @ questions ;
2019-05-06 08:11:45 +02:00
if ( exists $ self - > { metadata } - > { hash } - > { settings } - > { min_difficulty } ) {
@ questions = grep { $ self - > { categories } { $ state - > { current_category } } { $ _ } - > { value } >= $ self - > { metadata } - > { hash } - > { settings } - > { min_difficulty } } @ questions ;
}
if ( exists $ self - > { metadata } - > { hash } - > { settings } - > { max_difficulty } ) {
@ questions = grep { $ self - > { categories } { $ state - > { current_category } } { $ _ } - > { value } <= $ self - > { metadata } - > { hash } - > { settings } - > { max_difficulty } } @ questions ;
}
2018-02-25 03:17:55 +01:00
if ( not @ questions ) {
2019-05-07 11:19:03 +02:00
$ self - > send_message ( $ self - > { channel } , "No more questions available in category $state->{current_category}! Picking new category..." ) ;
2018-02-26 09:46:59 +01:00
delete $ state - > { seen_questions } - > { $ state - > { current_category } } ;
@ questions = keys % { $ self - > { categories } { $ state - > { current_category } } } ;
2019-05-03 08:13:27 +02:00
$ state - > { reroll_category } = 1 ;
2018-02-25 03:17:55 +01:00
}
2018-02-26 09:46:59 +01:00
if ( $ state - > { reroll_question } ) {
delete $ state - > { reroll_question } ;
2019-05-07 11:19:03 +02:00
unless ( $ state - > { reroll_category } ) {
my $ count = @ questions ;
2019-05-09 09:16:37 +02:00
$ self - > send_message ( $ self - > { channel } , "Rerolling new question from $state->{current_category} (" . $ self - > commify ( $ count ) . " question" . ( $ count == 1 ? '' : 's' ) . " remaining)\n" ) ;
2019-05-07 11:19:03 +02:00
}
2018-02-26 09:46:59 +01:00
}
2019-05-03 08:13:27 +02:00
$ state - > { current_question } = $ self - > { categories } { $ state - > { current_category } } { $ questions [ 0 ] } ;
2019-05-02 21:06:45 +02:00
$ state - > { current_question } - > { question } = $ self - > normalize_question ( $ state - > { current_question } - > { question } ) ;
2018-02-04 05:42:27 +01:00
$ state - > { current_question } - > { answer } = $ self - > normalize_text ( $ state - > { current_question } - > { answer } ) ;
2019-05-06 08:11:45 +02:00
$ state - > { current_question } - > { seen_timestamp } = time unless $ state - > { reroll_category } ;
2019-05-03 08:13:27 +02:00
2018-02-04 05:42:27 +01:00
my @ alts = map { $ self - > normalize_text ( $ _ ) } @ { $ state - > { current_question } - > { alternativeSpellings } } ;
$ state - > { current_question } - > { alternativeSpellings } = \ @ alts ;
2018-02-26 09:46:59 +01:00
$ state - > { seen_questions } - > { $ state - > { current_category } } - > { $ state - > { current_question } - > { id } } = 1 ;
2018-01-30 06:54:52 +01:00
foreach my $ player ( @ { $ state - > { players } } ) {
delete $ player - > { lie } ;
2018-02-24 00:51:17 +01:00
delete $ player - > { lie_count } ;
2018-01-30 06:54:52 +01:00
delete $ player - > { truth } ;
2019-04-24 12:55:48 +02:00
delete $ player - > { good_lie } ;
2018-01-30 06:54:52 +01:00
delete $ player - > { deceived } ;
2018-02-15 07:13:54 +01:00
delete $ player - > { skip } ;
2018-02-26 09:46:59 +01:00
delete $ player - > { reroll } ;
2019-05-05 04:28:34 +02:00
delete $ player - > { keep } ;
2018-01-30 06:54:52 +01:00
}
2018-02-20 09:16:22 +01:00
$ state - > { current_choices_text } = "" ;
2018-01-30 06:54:52 +01:00
return 'next' ;
} else {
return 'wait' ;
2018-01-29 06:53:40 +01:00
}
}
sub showquestion {
2019-05-06 08:11:45 +02:00
my ( $ self , $ state , $ show_category ) = @ _ ;
2018-01-29 06:53:40 +01:00
2019-05-03 08:13:27 +02:00
return if $ state - > { reroll_category } ;
2018-01-29 06:53:40 +01:00
if ( exists $ state - > { current_question } ) {
2019-05-06 08:11:45 +02:00
my $ category = "" ;
my $ value = "" ;
if ( $ show_category ) {
$ category = "[$state->{current_category}] " ;
}
if ( $ state - > { current_question } - > { value } ) {
$ value = "[$state->{current_question}->{value}] " ;
}
$ self - > send_message ( $ self - > { channel } , "$color{green}Current question:$color{reset} " . $ self - > commify ( $ state - > { current_question } - > { id } ) . ") $category$value$state->{current_question}->{question}" ) ;
2018-01-29 06:53:40 +01:00
} else {
2018-02-26 09:46:59 +01:00
$ self - > send_message ( $ self - > { channel } , "There is no current question." ) ;
2018-01-29 06:53:40 +01:00
}
}
sub getlies {
my ( $ self , $ state ) = @ _ ;
2019-05-03 08:13:27 +02:00
return 'skip' if $ state - > { reroll_category } ;
2018-01-30 06:54:52 +01:00
my $ tock ;
if ( $ state - > { first_tock } ) {
$ tock = 3 ;
} else {
2020-01-19 11:35:33 +01:00
$ tock = $ self - > { tock_duration } ;
2018-01-30 06:54:52 +01:00
}
2018-02-01 07:11:26 +01:00
my @ nolies ;
2019-05-14 02:59:15 +02:00
my $ reveallies = ". Revealing lies! " ;
my $ lies = 0 ;
my $ comma = '' ;
my @ keeps ;
my @ rerolls ;
my @ skips ;
2018-02-01 07:11:26 +01:00
foreach my $ player ( @ { $ state - > { players } } ) {
if ( not exists $ player - > { lie } ) {
push @ nolies , $ player - > { name } ;
2019-05-14 02:59:15 +02:00
} else {
$ lies + + ;
$ reveallies . = "$comma$player->{name}: $player->{lie}" ;
$ comma = '; ' ;
2018-02-01 07:11:26 +01:00
}
2018-02-26 09:46:59 +01:00
if ( $ player - > { reroll } ) {
push @ rerolls , $ player - > { name } ;
}
2019-05-05 04:28:34 +02:00
if ( $ player - > { skip } ) {
push @ skips , $ player - > { name } ;
}
if ( $ player - > { keep } ) {
push @ keeps , $ player - > { name } ;
}
2018-02-26 09:46:59 +01:00
}
2019-05-14 02:59:15 +02:00
return 'next' if not @ nolies ;
$ reveallies = "" if not $ lies ;
2018-02-26 09:46:59 +01:00
if ( @ rerolls ) {
2019-05-05 04:32:28 +02:00
my $ needed = int ( @ { $ state - > { players } } / 2 ) + 1 ;
$ needed += @ keeps ;
2018-02-26 09:46:59 +01:00
$ needed -= @ rerolls ;
if ( $ needed <= 0 ) {
$ state - > { reroll_question } = 1 ;
2019-05-14 02:59:15 +02:00
$ self - > send_message ( $ self - > { channel } , "The answer was: " . uc ( $ state - > { current_question } - > { answer } ) . $ reveallies ) ;
2019-06-26 18:34:19 +02:00
return 'reroll' ;
2018-02-26 09:46:59 +01:00
}
}
2018-02-15 07:13:54 +01:00
if ( @ skips ) {
2018-02-15 18:21:41 +01:00
my $ needed = int ( @ { $ state - > { players } } / 2 ) + 1 ;
2019-05-05 04:32:28 +02:00
$ needed += @ keeps ;
2018-02-15 07:13:54 +01:00
$ needed -= @ skips ;
2019-05-09 09:16:37 +02:00
if ( $ needed <= 0 ) {
2019-05-14 02:59:15 +02:00
$ self - > send_message ( $ self - > { channel } , "The answer was: " . uc ( $ state - > { current_question } - > { answer } ) . $ reveallies ) ;
2019-05-09 09:16:37 +02:00
return 'skip' ;
}
2018-02-15 07:13:54 +01:00
}
2018-02-01 07:11:26 +01:00
if ( $ state - > { ticks } % $ tock == 0 ) {
2018-02-25 03:17:55 +01:00
$ state - > { tocked } = 1 ;
2018-02-01 07:11:26 +01:00
if ( + + $ state - > { counter } > $ state - > { max_count } ) {
2018-01-29 06:53:40 +01:00
my @ missedinputs ;
foreach my $ player ( @ { $ state - > { players } } ) {
if ( not exists $ player - > { lie } ) {
push @ missedinputs , $ player - > { name } ;
$ player - > { missedinputs } + + ;
}
}
if ( @ missedinputs ) {
my $ missed = join ', ' , @ missedinputs ;
2018-02-26 09:46:59 +01:00
$ self - > send_message ( $ self - > { channel } , "$missed failed to submit a lie in time!" ) ;
2018-01-29 06:53:40 +01:00
}
return 'next' ;
}
my $ players = join ', ' , @ nolies ;
2019-04-28 09:21:15 +02:00
my $ warning ;
if ( $ state - > { counter } == $ state - > { max_count } ) {
$ warning = $ color { red } ;
} elsif ( $ state - > { counter } == $ state - > { max_count } - 1 ) {
$ warning = $ color { yellow } ;
} else {
$ warning = '' ;
}
2018-02-25 03:17:55 +01:00
2020-01-19 11:35:33 +01:00
my $ remaining = $ self - > { tock_duration } * $ state - > { max_count } ;
$ remaining -= $ self - > { tock_duration } * ( $ state - > { counter } - 1 ) ;
2018-02-25 03:17:55 +01:00
$ remaining = "(" . ( concise duration $ remaining ) . " remaining)" ;
2019-04-28 09:21:15 +02:00
$ self - > send_message ( $ self - > { channel } , "$players: $warning$remaining Submit your lie now via `/msg me lie <your lie>`!" ) ;
2018-01-29 06:53:40 +01:00
}
return 'wait' ;
}
sub findtruth {
my ( $ self , $ state ) = @ _ ;
2018-01-30 06:54:52 +01:00
my $ tock ;
if ( $ state - > { first_tock } ) {
$ tock = 3 ;
} else {
2020-01-19 11:35:33 +01:00
$ tock = $ self - > { tock_duration } ;
2018-01-30 06:54:52 +01:00
}
2018-01-29 06:53:40 +01:00
my @ notruth ;
foreach my $ player ( @ { $ state - > { players } } ) {
if ( not exists $ player - > { truth } ) {
push @ notruth , $ player - > { name } ;
}
}
return 'next' if not @ notruth ;
2018-02-20 09:16:22 +01:00
if ( $ state - > { init } ) {
delete $ state - > { init } ;
2018-01-29 06:53:40 +01:00
2018-02-20 09:16:22 +01:00
my @ choices ;
my @ suggestions = @ { $ state - > { current_question } - > { suggestions } } ;
my @ lies ;
2018-01-29 06:53:40 +01:00
2018-02-20 09:16:22 +01:00
foreach my $ player ( @ { $ state - > { players } } ) {
if ( $ player - > { lie } ) {
if ( not grep { $ _ eq $ player - > { lie } } @ lies ) {
push @ lies , uc $ player - > { lie } ;
2018-01-29 06:53:40 +01:00
}
}
2018-02-20 09:16:22 +01:00
}
2018-01-29 06:53:40 +01:00
2018-02-20 09:16:22 +01:00
while ( 1 ) {
my $ limit = @ { $ state - > { players } } < 5 ? 5 : @ { $ state - > { players } } ;
last if @ choices >= $ limit ;
if ( @ lies ) {
my $ random = rand @ lies ;
push @ choices , $ lies [ $ random ] ;
splice @ lies , $ random , 1 ;
next ;
}
2018-01-29 06:53:40 +01:00
2018-02-20 09:16:22 +01:00
if ( @ suggestions ) {
my $ random = rand @ suggestions ;
my $ suggestion = uc $ suggestions [ $ random ] ;
push @ choices , $ suggestion if not grep { $ _ eq $ suggestion } @ choices ;
splice @ suggestions , $ random , 1 ;
next ;
2018-01-29 06:53:40 +01:00
}
2018-02-20 09:16:22 +01:00
last ;
}
2018-01-29 06:53:40 +01:00
2018-02-20 09:16:22 +01:00
splice @ choices , rand @ choices , 0 , uc $ state - > { current_question } - > { answer } ;
$ state - > { correct_answer } = uc $ state - > { current_question } - > { answer } ;
2018-01-29 06:53:40 +01:00
2018-02-20 09:16:22 +01:00
my $ i = 0 ;
my $ comma = '' ;
my $ text = '' ;
foreach my $ choice ( @ choices ) {
+ + $ i ;
2018-02-26 09:46:59 +01:00
$ text . = "$comma$color{green}$i) $color{reset}$choice" ;
2018-02-20 09:16:22 +01:00
$ comma = '; ' ;
2018-01-29 06:53:40 +01:00
}
2018-02-20 09:16:22 +01:00
$ state - > { current_choices_text } = $ text ;
$ state - > { current_choices } = \ @ choices ;
}
if ( $ state - > { ticks } % $ tock == 0 ) {
2018-02-25 03:17:55 +01:00
$ state - > { tocked } = 1 ;
2018-02-01 07:11:26 +01:00
if ( + + $ state - > { counter } > $ state - > { max_count } ) {
my @ missedinputs ;
foreach my $ player ( @ { $ state - > { players } } ) {
if ( not exists $ player - > { truth } ) {
push @ missedinputs , $ player - > { name } ;
$ player - > { missedinputs } + + ;
2018-02-04 05:42:27 +01:00
$ player - > { score } -= $ state - > { lie_points } ;
2018-02-01 07:11:26 +01:00
}
}
if ( @ missedinputs ) {
my $ missed = join ', ' , @ missedinputs ;
2018-02-26 09:46:59 +01:00
$ self - > send_message ( $ self - > { channel } , "$missed failed to find the truth in time! They lose $state->{lie_points} points!" ) ;
2018-02-01 07:11:26 +01:00
}
return 'next' ;
}
2018-01-29 06:53:40 +01:00
my $ players = join ', ' , @ notruth ;
2019-04-28 09:21:15 +02:00
my $ warning ;
if ( $ state - > { counter } == $ state - > { max_count } ) {
$ warning = $ color { red } ;
} elsif ( $ state - > { counter } == $ state - > { max_count } - 1 ) {
$ warning = $ color { yellow } ;
} else {
$ warning = '' ;
}
2018-02-25 03:17:55 +01:00
2020-01-19 11:35:33 +01:00
my $ remaining = $ self - > { tock_duration } * $ state - > { max_count } ;
$ remaining -= $ self - > { tock_duration } * ( $ state - > { counter } - 1 ) ;
2018-02-25 03:17:55 +01:00
$ remaining = "(" . ( concise duration $ remaining ) . " remaining)" ;
2019-04-28 09:21:15 +02:00
$ self - > send_message ( $ self - > { channel } , "$players: $warning$remaining Find the truth now via `/msg me c <number>`!$color{reset}" ) ;
2018-02-26 09:46:59 +01:00
$ self - > send_message ( $ self - > { channel } , "$state->{current_choices_text}" ) ;
2018-01-29 06:53:40 +01:00
}
return 'wait' ;
}
sub showlies {
my ( $ self , $ state ) = @ _ ;
my @ liars ;
my $ player ;
2018-01-30 06:54:52 +01:00
my $ tock ;
if ( $ state - > { first_tock } ) {
$ tock = 3 ;
} else {
2019-05-07 11:19:03 +02:00
$ tock = 3 ;
2018-01-30 06:54:52 +01:00
}
if ( $ state - > { ticks } % $ tock == 0 ) {
2018-02-25 03:17:55 +01:00
$ state - > { tocked } = 1 ;
2018-01-29 06:53:40 +01:00
while ( $ state - > { current_lie_player } < @ { $ state - > { players } } ) {
$ player = $ state - > { players } - > [ $ state - > { current_lie_player } ] ;
$ state - > { current_lie_player } + + ;
next if not exists $ player - > { truth } ;
foreach my $ liar ( @ { $ state - > { players } } ) {
next if $ liar - > { id } == $ player - > { id } ;
next if not exists $ liar - > { lie } ;
if ( $ liar - > { lie } eq $ player - > { truth } ) {
push @ liars , $ liar ;
}
}
last if @ liars ;
if ( $ player - > { truth } ne $ state - > { correct_answer } ) {
2019-04-28 09:21:15 +02:00
if ( $ self - > { metadata } - > { hash } - > { settings } - > { stats } ) {
my $ player_id = $ self - > { stats } - > get_player_id ( $ player - > { name } , $ self - > { channel } ) ;
my $ player_data = $ self - > { stats } - > get_player_data ( $ player_id ) ;
$ player_data - > { bad_guesses } + + ;
$ self - > { stats } - > update_player_data ( $ player_id , $ player_data ) ;
}
2019-04-24 12:55:48 +02:00
2018-02-01 07:11:26 +01:00
my $ points = $ state - > { lie_points } * 0.25 ;
$ player - > { score } -= $ points ;
2018-02-26 09:46:59 +01:00
$ self - > send_message ( $ self - > { channel } , "$player->{name} fell for my lie: \"$player->{truth}\". -$points points!" ) ;
2018-02-01 07:11:26 +01:00
$ player - > { deceived } = $ player - > { truth } ;
2018-02-02 05:15:54 +01:00
if ( $ state - > { current_lie_player } < @ { $ state - > { players } } ) {
return 'wait' ;
} else {
return 'next' ;
}
2018-01-29 06:53:40 +01:00
}
}
if ( @ liars ) {
my $ liars_text = '' ;
my $ liars_no_apostrophe = '' ;
my $ lie = $ player - > { truth } ;
my $ gains = @ liars == 1 ? 'gains' : 'gain' ;
my $ comma = '' ;
foreach my $ liar ( @ liars ) {
2019-04-28 09:21:15 +02:00
if ( $ self - > { metadata } - > { hash } - > { settings } - > { stats } ) {
my $ player_id = $ self - > { stats } - > get_player_id ( $ liar - > { name } , $ self - > { channel } ) ;
my $ player_data = $ self - > { stats } - > get_player_data ( $ player_id ) ;
$ player_data - > { players_deceived } + + ;
$ self - > { stats } - > update_player_data ( $ player_id , $ player_data ) ;
}
2019-04-24 12:55:48 +02:00
2018-01-29 06:53:40 +01:00
$ liars_text . = "$comma$liar->{name}'s" ;
$ liars_no_apostrophe . = "$comma$liar->{name}" ;
$ comma = ', ' ;
$ liar - > { score } += $ state - > { lie_points } ;
2019-04-24 12:55:48 +02:00
$ liar - > { good_lie } = 1 ;
2018-01-29 06:53:40 +01:00
}
2019-04-28 09:21:15 +02:00
if ( $ self - > { metadata } - > { hash } - > { settings } - > { stats } ) {
my $ player_id = $ self - > { stats } - > get_player_id ( $ player - > { name } , $ self - > { channel } ) ;
my $ player_data = $ self - > { stats } - > get_player_data ( $ player_id ) ;
$ player_data - > { bad_guesses } + + ;
$ self - > { stats } - > update_player_data ( $ player_id , $ player_data ) ;
}
2019-04-24 12:55:48 +02:00
2018-02-26 09:46:59 +01:00
$ self - > send_message ( $ self - > { channel } , "$player->{name} fell for $liars_text lie: \"$lie\". $liars_no_apostrophe $gains +$state->{lie_points} points!" ) ;
2018-02-01 07:11:26 +01:00
$ player - > { deceived } = $ lie ;
2018-01-29 06:53:40 +01:00
}
2018-02-20 09:16:22 +01:00
if ( $ state - > { current_lie_player } >= @ { $ state - > { players } } ) {
if ( @ liars ) {
delete $ state - > { tick_drift } ;
} else {
$ state - > { tick_drift } = $ tock - 1 ;
}
return 'next' ;
} else {
return 'wait' ;
}
2018-01-29 06:53:40 +01:00
}
return 'wait' ;
}
sub showtruth {
my ( $ self , $ state ) = @ _ ;
2019-05-07 06:08:09 +02:00
if ( $ state - > { ticks } % 3 == 0 ) {
2019-04-24 12:55:48 +02:00
my $ player_id ;
my $ player_data ;
2018-01-30 06:54:52 +01:00
my $ players ;
my $ comma = '' ;
my $ count = 0 ;
foreach my $ player ( @ { $ state - > { players } } ) {
2019-04-28 09:21:15 +02:00
if ( $ self - > { metadata } - > { hash } - > { settings } - > { stats } ) {
$ player_id = $ self - > { stats } - > get_player_id ( $ player - > { name } , $ self - > { channel } ) ;
$ player_data = $ self - > { stats } - > get_player_data ( $ player_id ) ;
2019-04-24 12:55:48 +02:00
2019-04-28 09:21:15 +02:00
$ player_data - > { questions_played } + + ;
2019-05-09 22:25:33 +02:00
$ player_data - > { nick } = $ player - > { name } ; # update nick in stats database once per question (nick changes, etc)
2019-04-28 09:21:15 +02:00
}
2019-04-24 12:55:48 +02:00
if ( exists $ player - > { deceived } ) {
2019-04-28 09:21:15 +02:00
if ( $ self - > { metadata } - > { hash } - > { settings } - > { stats } ) {
$ self - > { stats } - > update_player_data ( $ player_id , $ player_data ) ;
}
2019-04-24 12:55:48 +02:00
next ;
}
2018-01-30 06:54:52 +01:00
if ( exists $ player - > { truth } and $ player - > { truth } eq $ state - > { correct_answer } ) {
2019-04-28 09:21:15 +02:00
if ( $ self - > { metadata } - > { hash } - > { settings } - > { stats } ) {
$ player_data - > { good_guesses } + + ;
$ self - > { stats } - > update_player_data ( $ player_id , $ player_data ) ;
}
2018-01-30 06:54:52 +01:00
$ count + + ;
$ players . = "$comma$player->{name}" ;
$ comma = ', ' ;
$ player - > { score } += $ state - > { truth_points } ;
}
2018-01-29 06:53:40 +01:00
}
2018-01-30 06:54:52 +01:00
if ( $ count ) {
2018-02-26 09:46:59 +01:00
$ self - > send_message ( $ self - > { channel } , "$players got the correct answer: \"$state->{correct_answer}\". +$state->{truth_points} points!" ) ;
2018-01-30 06:54:52 +01:00
} else {
2018-02-26 09:46:59 +01:00
$ self - > send_message ( $ self - > { channel } , "Nobody found the truth! The answer was: $state->{correct_answer}" ) ;
2018-01-30 06:54:52 +01:00
}
2018-01-29 06:53:40 +01:00
2018-02-01 07:11:26 +01:00
$ self - > add_new_suggestions ( $ state ) ;
2018-01-30 06:54:52 +01:00
return 'next' ;
} else {
return 'wait' ;
2018-01-29 06:53:40 +01:00
}
2018-01-30 06:54:52 +01:00
}
2018-01-29 06:53:40 +01:00
2018-01-30 06:54:52 +01:00
sub reveallies {
my ( $ self , $ state ) = @ _ ;
2018-01-29 06:53:40 +01:00
2018-01-30 06:54:52 +01:00
if ( $ state - > { ticks } % 3 == 0 ) {
my $ text = 'Revealing lies! ' ;
my $ comma = '' ;
foreach my $ player ( @ { $ state - > { players } } ) {
next if not exists $ player - > { lie } ;
$ text . = "$comma$player->{name}: $player->{lie}" ;
$ comma = '; ' ;
2019-04-24 12:55:48 +02:00
if ( $ player - > { good_lie } ) {
2019-04-28 09:21:15 +02:00
if ( $ self - > { metadata } - > { hash } - > { settings } - > { stats } ) {
my $ player_id = $ self - > { stats } - > get_player_id ( $ player - > { name } , $ self - > { channel } ) ;
my $ player_data = $ self - > { stats } - > get_player_data ( $ player_id ) ;
$ player_data - > { good_lies } + + ;
$ self - > { stats } - > update_player_data ( $ player_id , $ player_data ) ;
}
2019-04-24 12:55:48 +02:00
}
2018-01-30 06:54:52 +01:00
}
2018-02-26 09:46:59 +01:00
$ self - > send_message ( $ self - > { channel } , "$text" ) ;
2018-01-30 06:54:52 +01:00
return 'next' ;
} else {
return 'wait' ;
}
2018-01-29 06:53:40 +01:00
}
sub showscore {
my ( $ self , $ state ) = @ _ ;
2018-01-30 06:54:52 +01:00
if ( $ state - > { ticks } % 3 == 0 ) {
my $ text = '' ;
my $ comma = '' ;
foreach my $ player ( sort { $ b - > { score } <=> $ a - > { score } } @ { $ state - > { players } } ) {
2018-02-15 04:09:57 +01:00
$ text . = "$comma$player->{name}: " . $ self - > commify ( $ player - > { score } ) ;
2018-01-30 06:54:52 +01:00
$ comma = '; ' ;
}
2018-01-29 06:53:40 +01:00
2018-01-30 06:54:52 +01:00
$ text = "none" if not length $ text ;
2018-01-29 06:53:40 +01:00
2018-02-26 09:46:59 +01:00
$ self - > send_message ( $ self - > { channel } , "$color{green}Scores:$color{reset} $text" ) ;
2018-01-30 06:54:52 +01:00
return 'next' ;
} else {
return 'wait' ;
}
2018-01-29 06:53:40 +01:00
}
2018-02-24 00:51:17 +01:00
sub showfinalscore {
my ( $ self , $ state ) = @ _ ;
if ( $ state - > { newstate } ) {
2019-04-24 12:55:48 +02:00
my $ player_id ;
my $ player_data ;
2018-02-25 03:17:55 +01:00
my $ mentions = "" ;
my $ text = "" ;
my $ comma = "" ;
my $ i = @ { $ state - > { players } } ;
2018-02-24 00:51:17 +01:00
$ state - > { finalscores } = [] ;
2018-02-25 03:17:55 +01:00
foreach my $ player ( sort { $ a - > { score } <=> $ b - > { score } } @ { $ state - > { players } } ) {
2019-04-28 09:21:15 +02:00
if ( $ self - > { metadata } - > { hash } - > { settings } - > { stats } ) {
$ player_id = $ self - > { stats } - > get_player_id ( $ player - > { name } , $ self - > { channel } ) ;
$ player_data = $ self - > { stats } - > get_player_data ( $ player_id ) ;
2019-04-24 12:55:48 +02:00
2019-04-28 09:21:15 +02:00
$ player_data - > { games_played } + + ;
$ player_data - > { avg_score } *= $ player_data - > { games_played } - 1 ;
$ player_data - > { avg_score } += $ player - > { score } ;
$ player_data - > { avg_score } /= $ player_data - > { games_played } ;
$ player_data - > { low_score } = $ player - > { score } if $ player_data - > { low_score } == 0 ;
2019-04-24 12:55:48 +02:00
2019-04-28 09:21:15 +02:00
if ( $ player - > { score } > $ player_data - > { high_score } ) {
$ player_data - > { high_score } = $ player - > { score } ;
} elsif ( $ player - > { score } < $ player_data - > { low_score } ) {
$ player_data - > { low_score } = $ player - > { score } ;
}
2019-04-24 12:55:48 +02:00
}
2018-02-25 03:17:55 +01:00
if ( $ i >= 4 ) {
2019-06-26 18:34:19 +02:00
$ mentions = "$player->{name}: " . $ self - > commify ( $ player - > { score } ) . "$comma$mentions" ;
2018-02-25 03:17:55 +01:00
$ comma = "; " ;
if ( $ i == 4 ) {
$ mentions = "Honorable mentions: $mentions" ;
}
2019-04-28 09:21:15 +02:00
if ( $ self - > { metadata } - > { hash } - > { settings } - > { stats } ) {
$ self - > { stats } - > update_player_data ( $ player_id , $ player_data ) ;
}
2018-02-25 03:17:55 +01:00
$ i - - ;
next ;
} elsif ( $ i == 3 ) {
2019-04-24 12:55:48 +02:00
$ player_data - > { times_third } + + ;
2018-02-25 03:17:55 +01:00
$ text = sprintf ( "%15s%-13s%7s" , "Third place: " , $ player - > { name } , $ self - > commify ( $ player - > { score } ) ) ;
} elsif ( $ i == 2 ) {
2019-04-24 12:55:48 +02:00
$ player_data - > { times_second } + + ;
2018-02-25 03:17:55 +01:00
$ text = sprintf ( "%15s%-13s%7s" , "Second place: " , $ player - > { name } , $ self - > commify ( $ player - > { score } ) ) ;
} elsif ( $ i == 1 ) {
2019-04-24 12:55:48 +02:00
$ player_data - > { times_first } + + ;
2018-02-25 03:17:55 +01:00
$ text = sprintf ( "%15s%-13s%7s" , "WINNER: " , $ player - > { name } , $ self - > commify ( $ player - > { score } ) ) ;
}
2019-04-28 09:21:15 +02:00
if ( $ self - > { metadata } - > { hash } - > { settings } - > { stats } ) {
$ self - > { stats } - > update_player_data ( $ player_id , $ player_data ) ;
}
2018-02-25 03:17:55 +01:00
push @ { $ state - > { finalscores } } , $ text ;
$ i - - ;
2018-02-24 00:51:17 +01:00
}
2018-02-25 03:17:55 +01:00
push @ { $ state - > { finalscores } } , $ mentions if length $ mentions ;
2018-02-24 00:51:17 +01:00
}
2018-02-26 09:46:59 +01:00
my $ tock ;
2018-02-25 03:17:55 +01:00
if ( $ state - > { first_tock } ) {
2018-02-26 09:46:59 +01:00
$ tock = 2 ;
2018-02-25 03:17:55 +01:00
} else {
2019-05-07 06:08:09 +02:00
$ tock = 3 ;
2018-02-25 03:17:55 +01:00
}
2018-02-26 09:46:59 +01:00
if ( $ state - > { ticks } % $ tock == 0 ) {
2018-02-25 03:17:55 +01:00
$ state - > { tocked } = 1 ;
2018-02-24 00:51:17 +01:00
if ( not @ { $ state - > { finalscores } } ) {
2018-02-26 09:46:59 +01:00
$ self - > send_message ( $ self - > { channel } , "$color{green}Final scores: $color{reset}none" ) ;
2018-02-24 00:51:17 +01:00
return 'next' ;
}
if ( $ state - > { first_tock } ) {
2018-02-26 09:46:59 +01:00
$ self - > send_message ( $ self - > { channel } , "$color{green}Final scores:$color{reset}" ) ;
2018-02-24 00:51:17 +01:00
return 'wait' ;
}
2018-02-25 03:17:55 +01:00
my $ text = shift @ { $ state - > { finalscores } } ;
2018-02-26 09:46:59 +01:00
$ self - > send_message ( $ self - > { channel } , "$text" ) ;
2018-02-24 00:51:17 +01:00
if ( not @ { $ state - > { finalscores } } ) {
return 'next' ;
} else {
return 'wait' ;
}
} else {
return 'wait' ;
}
}
2018-01-29 06:53:40 +01:00
# state subroutines
sub nogame {
my ( $ self , $ state ) = @ _ ;
2019-05-09 22:25:33 +02:00
if ( $ self - > { stats_running } ) {
$ self - > { stats } - > end ;
delete $ self - > { stats_running } ;
}
2018-01-29 06:53:40 +01:00
$ state - > { result } = 'nogame' ;
return $ state ;
}
sub getplayers {
my ( $ self , $ state ) = @ _ ;
my $ players = $ state - > { players } ;
my @ names ;
my $ unready = @$ players ? @$ players : 1 ;
foreach my $ player ( @$ players ) {
if ( not $ player - > { ready } ) {
2018-02-26 09:46:59 +01:00
push @ names , "$player->{name} $color{red}(not ready)$color{reset}" ;
2018-01-29 06:53:40 +01:00
} else {
$ unready - - ;
push @ names , $ player - > { name } ;
}
}
2019-04-24 03:41:57 +02:00
my $ min_players = $ self - > { metadata } - > { hash } - > { settings } - > { min_players } // 2 ;
if ( @$ players >= $ min_players and not $ unready ) {
2018-02-26 09:46:59 +01:00
$ self - > send_message ( $ self - > { channel } , "All players ready!" ) ;
2018-01-29 06:53:40 +01:00
$ state - > { result } = 'allready' ;
2018-02-02 05:15:54 +01:00
return $ state ;
}
my $ tock ;
if ( $ state - > { first_tock } ) {
2020-01-19 11:35:33 +01:00
$ tock = $ self - > { tock_duration } ;
2018-01-29 06:53:40 +01:00
} else {
2020-01-15 03:10:53 +01:00
$ tock = 300 ;
2018-02-02 05:15:54 +01:00
}
2018-01-30 06:54:52 +01:00
2018-02-02 05:15:54 +01:00
if ( $ state - > { ticks } % $ tock == 0 ) {
2018-02-25 03:17:55 +01:00
$ state - > { tocked } = 1 ;
2018-01-30 06:54:52 +01:00
2018-05-21 03:39:27 +02:00
if ( not $ unready ) {
2019-04-22 03:56:46 +02:00
$ self - > send_message ( $ self - > { channel } , "Game cannot begin with one player." ) ;
2018-05-21 03:39:27 +02:00
}
2018-02-26 09:46:59 +01:00
if ( + + $ state - > { counter } > 6 ) {
$ self - > send_message ( $ self - > { channel } , "Not all players were ready in time. The game has been stopped." ) ;
2018-02-02 05:15:54 +01:00
$ state - > { result } = 'stop' ;
2018-02-09 21:47:06 +01:00
$ state - > { players } = [] ;
2018-02-02 05:15:54 +01:00
return $ state ;
2018-01-30 06:54:52 +01:00
}
2018-02-02 05:15:54 +01:00
$ players = join ', ' , @ names ;
2018-02-26 09:46:59 +01:00
if ( not @ names ) {
$ players = 'none' ;
2019-05-06 08:11:45 +02:00
if ( $ state - > { counter } >= 0 ) {
2018-02-26 09:46:59 +01:00
$ self - > send_message ( $ self - > { channel } , "All players have left the queue. The game has been stopped." ) ;
$ self - > { current_state } = 'nogame' ;
$ self - > { result } = 'nogame' ;
return $ state ;
}
}
2018-02-02 05:15:54 +01:00
my $ msg = "Waiting for more players or for all players to ready up. Current players: $players" ;
2018-02-26 09:46:59 +01:00
$ self - > send_message ( $ self - > { channel } , "$msg" ) ;
2018-01-29 06:53:40 +01:00
}
2018-02-02 05:15:54 +01:00
$ state - > { result } = 'wait' ;
2018-01-29 06:53:40 +01:00
return $ state ;
}
sub round1 {
my ( $ self , $ state ) = @ _ ;
2019-04-28 09:21:15 +02:00
if ( $ self - > { metadata } - > { hash } - > { settings } - > { stats } ) {
$ self - > { stats } - > begin ;
$ self - > { stats_running } = 1 ;
}
2018-02-01 07:11:26 +01:00
$ state - > { truth_points } = 500 ;
$ state - > { lie_points } = 1000 ;
$ state - > { my_lie_points } = $ state - > { lie_points } * 0.25 ;
2018-01-29 06:53:40 +01:00
$ state - > { result } = 'next' ;
return $ state ;
}
sub round1q1 {
my ( $ self , $ state ) = @ _ ;
2019-05-03 08:13:27 +02:00
if ( $ state - > { ticks } % 2 == 0 || $ state - > { reroll_category } ) {
2018-02-24 00:51:17 +01:00
$ state - > { init } = 1 ;
$ state - > { counter } = 0 ;
$ state - > { max_count } = $ self - > { choosecategory_max_count } ;
2019-05-03 08:13:27 +02:00
$ self - > send_message ( $ self - > { channel } , "Round 1/3, question 1/3! $state->{lie_points} for each lie. $state->{truth_points} for the truth." ) unless $ state - > { reroll_category } ;
2018-02-24 00:51:17 +01:00
$ state - > { result } = 'next' ;
} else {
$ state - > { result } = 'wait' ;
}
2018-01-29 06:53:40 +01:00
return $ state ;
}
sub r1q1choosecategory {
my ( $ self , $ state ) = @ _ ;
$ state - > { result } = $ self - > choosecategory ( $ state ) ;
return $ state ;
}
sub r1q1showquestion {
my ( $ self , $ state ) = @ _ ;
2018-01-30 06:54:52 +01:00
my $ result = $ self - > getnewquestion ( $ state ) ;
if ( $ result eq 'next' ) {
$ self - > showquestion ( $ state ) ;
2018-02-01 07:11:26 +01:00
$ state - > { max_count } = $ self - > { picktruth_max_count } ;
2018-01-30 06:54:52 +01:00
$ state - > { counter } = 0 ;
$ state - > { init } = 1 ;
$ state - > { current_lie_player } = 0 ;
$ state - > { result } = 'next' ;
} else {
$ state - > { result } = 'wait' ;
}
2018-01-29 06:53:40 +01:00
return $ state ;
}
sub r1q1getlies {
my ( $ self , $ state ) = @ _ ;
$ state - > { result } = $ self - > getlies ( $ state ) ;
if ( $ state - > { result } eq 'next' ) {
$ state - > { counter } = 0 ;
$ state - > { init } = 1 ;
}
return $ state ;
}
sub r1q1findtruth {
my ( $ self , $ state ) = @ _ ;
$ state - > { result } = $ self - > findtruth ( $ state ) ;
return $ state ;
}
sub r1q1showlies {
my ( $ self , $ state ) = @ _ ;
$ state - > { result } = $ self - > showlies ( $ state ) ;
return $ state ;
}
sub r1q1showtruth {
my ( $ self , $ state ) = @ _ ;
$ state - > { result } = $ self - > showtruth ( $ state ) ;
return $ state ;
}
2018-01-30 06:54:52 +01:00
sub r1q1reveallies {
my ( $ self , $ state ) = @ _ ;
$ state - > { result } = $ self - > reveallies ( $ state ) ;
return $ state ;
}
2018-01-29 06:53:40 +01:00
sub r1q1showscore {
my ( $ self , $ state ) = @ _ ;
$ state - > { result } = $ self - > showscore ( $ state ) ;
return $ state ;
}
sub round1q2 {
my ( $ self , $ state ) = @ _ ;
2019-05-03 08:13:27 +02:00
if ( $ state - > { ticks } % 2 == 0 || $ state - > { reroll_category } ) {
2018-02-24 00:51:17 +01:00
$ state - > { init } = 1 ;
$ state - > { counter } = 0 ;
$ state - > { max_count } = $ self - > { choosecategory_max_count } ;
2019-05-03 08:13:27 +02:00
$ self - > send_message ( $ self - > { channel } , "Round 1/3, question 2/3! $state->{lie_points} for each lie. $state->{truth_points} for the truth." ) unless $ state - > { reroll_category } ;
2018-02-24 00:51:17 +01:00
$ state - > { result } = 'next' ;
} else {
$ state - > { result } = 'wait' ;
}
2018-01-29 06:53:40 +01:00
return $ state ;
}
sub r1q2choosecategory {
my ( $ self , $ state ) = @ _ ;
$ state - > { result } = $ self - > choosecategory ( $ state ) ;
return $ state ;
}
sub r1q2showquestion {
my ( $ self , $ state ) = @ _ ;
2018-01-30 06:54:52 +01:00
my $ result = $ self - > getnewquestion ( $ state ) ;
if ( $ result eq 'next' ) {
$ self - > showquestion ( $ state ) ;
2018-02-01 07:11:26 +01:00
$ state - > { max_count } = $ self - > { picktruth_max_count } ;
2018-01-30 06:54:52 +01:00
$ state - > { counter } = 0 ;
$ state - > { init } = 1 ;
$ state - > { current_lie_player } = 0 ;
$ state - > { result } = 'next' ;
} else {
$ state - > { result } = 'wait' ;
}
2018-01-29 06:53:40 +01:00
return $ state ;
}
sub r1q2getlies {
my ( $ self , $ state ) = @ _ ;
$ state - > { result } = $ self - > getlies ( $ state ) ;
if ( $ state - > { result } eq 'next' ) {
$ state - > { counter } = 0 ;
$ state - > { init } = 1 ;
}
return $ state ;
}
sub r1q2findtruth {
my ( $ self , $ state ) = @ _ ;
$ state - > { result } = $ self - > findtruth ( $ state ) ;
return $ state ;
}
sub r1q2showlies {
my ( $ self , $ state ) = @ _ ;
$ state - > { result } = $ self - > showlies ( $ state ) ;
return $ state ;
}
sub r1q2showtruth {
my ( $ self , $ state ) = @ _ ;
$ state - > { result } = $ self - > showtruth ( $ state ) ;
return $ state ;
}
2018-01-30 06:54:52 +01:00
sub r1q2reveallies {
my ( $ self , $ state ) = @ _ ;
$ state - > { result } = $ self - > reveallies ( $ state ) ;
return $ state ;
}
2018-01-29 06:53:40 +01:00
sub r1q2showscore {
my ( $ self , $ state ) = @ _ ;
$ state - > { result } = $ self - > showscore ( $ state ) ;
return $ state ;
}
sub round1q3 {
my ( $ self , $ state ) = @ _ ;
2019-05-03 08:13:27 +02:00
if ( $ state - > { ticks } % 2 || $ state - > { reroll_category } ) {
2018-02-24 00:51:17 +01:00
$ state - > { init } = 1 ;
$ state - > { max_count } = $ self - > { choosecategory_max_count } ;
$ state - > { counter } = 0 ;
$ state - > { result } = 'wait' ;
2019-05-03 08:13:27 +02:00
$ self - > send_message ( $ self - > { channel } , "Round 1/3, question 3/3! $state->{lie_points} for each lie. $state->{truth_points} for the truth." ) unless $ state - > { reroll_category } ;
2018-02-24 00:51:17 +01:00
} else {
$ state - > { result } = 'next' ;
}
2018-01-29 06:53:40 +01:00
return $ state ;
}
sub r1q3choosecategory {
my ( $ self , $ state ) = @ _ ;
$ state - > { result } = $ self - > choosecategory ( $ state ) ;
return $ state ;
}
sub r1q3showquestion {
my ( $ self , $ state ) = @ _ ;
2018-01-30 06:54:52 +01:00
my $ result = $ self - > getnewquestion ( $ state ) ;
if ( $ result eq 'next' ) {
$ self - > showquestion ( $ state ) ;
2018-02-01 07:11:26 +01:00
$ state - > { max_count } = $ self - > { picktruth_max_count } ;
2018-01-30 06:54:52 +01:00
$ state - > { counter } = 0 ;
$ state - > { init } = 1 ;
$ state - > { current_lie_player } = 0 ;
$ state - > { result } = 'next' ;
} else {
$ state - > { result } = 'wait' ;
}
2018-01-29 06:53:40 +01:00
return $ state ;
}
sub r1q3getlies {
my ( $ self , $ state ) = @ _ ;
$ state - > { result } = $ self - > getlies ( $ state ) ;
if ( $ state - > { result } eq 'next' ) {
$ state - > { counter } = 0 ;
$ state - > { init } = 1 ;
}
return $ state ;
}
sub r1q3findtruth {
my ( $ self , $ state ) = @ _ ;
$ state - > { result } = $ self - > findtruth ( $ state ) ;
return $ state ;
}
sub r1q3showlies {
my ( $ self , $ state ) = @ _ ;
$ state - > { result } = $ self - > showlies ( $ state ) ;
return $ state ;
}
sub r1q3showtruth {
my ( $ self , $ state ) = @ _ ;
$ state - > { result } = $ self - > showtruth ( $ state ) ;
return $ state ;
}
2018-01-30 06:54:52 +01:00
sub r1q3reveallies {
my ( $ self , $ state ) = @ _ ;
$ state - > { result } = $ self - > reveallies ( $ state ) ;
return $ state ;
}
2018-01-29 06:53:40 +01:00
sub r1q3showscore {
my ( $ self , $ state ) = @ _ ;
$ state - > { result } = $ self - > showscore ( $ state ) ;
return $ state ;
}
sub round2 {
my ( $ self , $ state ) = @ _ ;
2018-02-01 07:11:26 +01:00
$ state - > { truth_points } = 750 ;
$ state - > { lie_points } = 1500 ;
$ state - > { my_lie_points } = $ state - > { lie_points } * 0.25 ;
2018-01-29 06:53:40 +01:00
$ state - > { result } = 'next' ;
return $ state ;
}
sub round2q1 {
my ( $ self , $ state ) = @ _ ;
2019-05-03 08:13:27 +02:00
if ( $ state - > { ticks } % 2 == 0 || $ state - > { reroll_category } ) {
2018-02-24 00:51:17 +01:00
$ state - > { init } = 1 ;
$ state - > { max_count } = $ self - > { choosecategory_max_count } ;
$ state - > { counter } = 0 ;
2019-05-03 08:13:27 +02:00
$ self - > send_message ( $ self - > { channel } , "Round 2/3, question 1/3! $state->{lie_points} for each lie. $state->{truth_points} for the truth." ) unless $ state - > { reroll_category } ;
2018-02-24 00:51:17 +01:00
$ state - > { result } = 'next' ;
} else {
$ state - > { result } = 'wait' ;
}
2018-01-29 06:53:40 +01:00
return $ state ;
}
sub r2q1choosecategory {
my ( $ self , $ state ) = @ _ ;
$ state - > { result } = $ self - > choosecategory ( $ state ) ;
return $ state ;
}
sub r2q1showquestion {
my ( $ self , $ state ) = @ _ ;
2018-01-30 06:54:52 +01:00
my $ result = $ self - > getnewquestion ( $ state ) ;
if ( $ result eq 'next' ) {
$ self - > showquestion ( $ state ) ;
2018-02-01 07:11:26 +01:00
$ state - > { max_count } = $ self - > { picktruth_max_count } ;
2018-01-30 06:54:52 +01:00
$ state - > { counter } = 0 ;
$ state - > { init } = 1 ;
$ state - > { current_lie_player } = 0 ;
$ state - > { result } = 'next' ;
} else {
$ state - > { result } = 'wait' ;
}
2018-01-29 06:53:40 +01:00
return $ state ;
}
sub r2q1getlies {
my ( $ self , $ state ) = @ _ ;
$ state - > { result } = $ self - > getlies ( $ state ) ;
if ( $ state - > { result } eq 'next' ) {
$ state - > { counter } = 0 ;
$ state - > { init } = 1 ;
}
return $ state ;
}
sub r2q1findtruth {
my ( $ self , $ state ) = @ _ ;
$ state - > { result } = $ self - > findtruth ( $ state ) ;
return $ state ;
}
sub r2q1showlies {
my ( $ self , $ state ) = @ _ ;
$ state - > { result } = $ self - > showlies ( $ state ) ;
return $ state ;
}
sub r2q1showtruth {
my ( $ self , $ state ) = @ _ ;
$ state - > { result } = $ self - > showtruth ( $ state ) ;
return $ state ;
}
2018-01-30 06:54:52 +01:00
sub r2q1reveallies {
my ( $ self , $ state ) = @ _ ;
$ state - > { result } = $ self - > reveallies ( $ state ) ;
return $ state ;
}
2018-01-29 06:53:40 +01:00
sub r2q1showscore {
my ( $ self , $ state ) = @ _ ;
$ state - > { result } = $ self - > showscore ( $ state ) ;
return $ state ;
}
sub round2q2 {
my ( $ self , $ state ) = @ _ ;
2019-05-03 08:13:27 +02:00
if ( $ state - > { ticks } % 2 == 0 || $ state - > { reroll_category } ) {
2018-02-24 00:51:17 +01:00
$ state - > { init } = 1 ;
$ state - > { max_count } = $ self - > { choosecategory_max_count } ;
$ state - > { counter } = 0 ;
2019-05-03 08:13:27 +02:00
$ self - > send_message ( $ self - > { channel } , "Round 2/3, question 2/3! $state->{lie_points} for each lie. $state->{truth_points} for the truth." ) unless $ state - > { reroll_category } ;
2018-02-24 00:51:17 +01:00
$ state - > { result } = 'next' ;
} else {
$ state - > { result } = 'wait' ;
}
2018-01-29 06:53:40 +01:00
return $ state ;
}
sub r2q2choosecategory {
my ( $ self , $ state ) = @ _ ;
$ state - > { result } = $ self - > choosecategory ( $ state ) ;
return $ state ;
}
sub r2q2showquestion {
my ( $ self , $ state ) = @ _ ;
2018-01-30 06:54:52 +01:00
my $ result = $ self - > getnewquestion ( $ state ) ;
if ( $ result eq 'next' ) {
$ self - > showquestion ( $ state ) ;
2018-02-01 07:11:26 +01:00
$ state - > { max_count } = $ self - > { picktruth_max_count } ;
2018-01-30 06:54:52 +01:00
$ state - > { counter } = 0 ;
$ state - > { init } = 1 ;
$ state - > { current_lie_player } = 0 ;
$ state - > { result } = 'next' ;
} else {
$ state - > { result } = 'wait' ;
}
2018-01-29 06:53:40 +01:00
return $ state ;
}
sub r2q2getlies {
my ( $ self , $ state ) = @ _ ;
$ state - > { result } = $ self - > getlies ( $ state ) ;
if ( $ state - > { result } eq 'next' ) {
$ state - > { counter } = 0 ;
$ state - > { init } = 1 ;
}
return $ state ;
}
sub r2q2findtruth {
my ( $ self , $ state ) = @ _ ;
$ state - > { result } = $ self - > findtruth ( $ state ) ;
return $ state ;
}
sub r2q2showlies {
my ( $ self , $ state ) = @ _ ;
$ state - > { result } = $ self - > showlies ( $ state ) ;
return $ state ;
}
sub r2q2showtruth {
my ( $ self , $ state ) = @ _ ;
$ state - > { result } = $ self - > showtruth ( $ state ) ;
return $ state ;
}
2018-01-30 06:54:52 +01:00
sub r2q2reveallies {
my ( $ self , $ state ) = @ _ ;
$ state - > { result } = $ self - > reveallies ( $ state ) ;
return $ state ;
}
2018-01-29 06:53:40 +01:00
sub r2q2showscore {
my ( $ self , $ state ) = @ _ ;
$ state - > { result } = $ self - > showscore ( $ state ) ;
return $ state ;
}
sub round2q3 {
my ( $ self , $ state ) = @ _ ;
2019-05-03 08:13:27 +02:00
if ( $ state - > { ticks } % 2 == 0 || $ state - > { reroll_category } ) {
2018-02-24 00:51:17 +01:00
$ state - > { init } = 1 ;
$ state - > { max_count } = $ self - > { choosecategory_max_count } ;
$ state - > { counter } = 0 ;
2019-05-03 08:13:27 +02:00
$ self - > send_message ( $ self - > { channel } , "Round 2/3, question 3/3! $state->{lie_points} for each lie. $state->{truth_points} for the truth." ) unless $ state - > { reroll_category } ;
2018-02-24 00:51:17 +01:00
$ state - > { result } = 'next' ;
} else {
$ state - > { result } = 'wait' ;
}
2018-01-29 06:53:40 +01:00
return $ state ;
}
sub r2q3choosecategory {
my ( $ self , $ state ) = @ _ ;
$ state - > { result } = $ self - > choosecategory ( $ state ) ;
return $ state ;
}
sub r2q3showquestion {
my ( $ self , $ state ) = @ _ ;
2018-01-30 06:54:52 +01:00
my $ result = $ self - > getnewquestion ( $ state ) ;
if ( $ result eq 'next' ) {
$ self - > showquestion ( $ state ) ;
2018-02-01 07:11:26 +01:00
$ state - > { max_count } = $ self - > { picktruth_max_count } ;
2018-01-30 06:54:52 +01:00
$ state - > { counter } = 0 ;
$ state - > { init } = 1 ;
$ state - > { current_lie_player } = 0 ;
$ state - > { result } = 'next' ;
} else {
$ state - > { result } = 'wait' ;
}
2018-01-29 06:53:40 +01:00
return $ state ;
}
sub r2q3getlies {
my ( $ self , $ state ) = @ _ ;
$ state - > { result } = $ self - > getlies ( $ state ) ;
if ( $ state - > { result } eq 'next' ) {
$ state - > { counter } = 0 ;
$ state - > { init } = 1 ;
}
return $ state ;
}
sub r2q3findtruth {
my ( $ self , $ state ) = @ _ ;
$ state - > { result } = $ self - > findtruth ( $ state ) ;
return $ state ;
}
sub r2q3showlies {
my ( $ self , $ state ) = @ _ ;
$ state - > { result } = $ self - > showlies ( $ state ) ;
return $ state ;
}
sub r2q3showtruth {
my ( $ self , $ state ) = @ _ ;
$ state - > { result } = $ self - > showtruth ( $ state ) ;
return $ state ;
}
2018-01-30 06:54:52 +01:00
sub r2q3reveallies {
my ( $ self , $ state ) = @ _ ;
$ state - > { result } = $ self - > reveallies ( $ state ) ;
return $ state ;
}
2018-01-29 06:53:40 +01:00
sub r2q3showscore {
my ( $ self , $ state ) = @ _ ;
$ state - > { result } = $ self - > showscore ( $ state ) ;
return $ state ;
}
sub round3 {
my ( $ self , $ state ) = @ _ ;
2018-02-01 07:11:26 +01:00
$ state - > { truth_points } = 1000 ;
$ state - > { lie_points } = 2000 ;
$ state - > { my_lie_points } = $ state - > { lie_points } * 0.25 ;
2018-01-29 06:53:40 +01:00
$ state - > { result } = 'next' ;
return $ state ;
}
sub round3q1 {
my ( $ self , $ state ) = @ _ ;
2019-05-03 08:13:27 +02:00
if ( $ state - > { ticks } % 2 == 0 || $ state - > { reroll_category } ) {
2018-02-24 00:51:17 +01:00
$ state - > { init } = 1 ;
$ state - > { max_count } = $ self - > { choosecategory_max_count } ;
$ state - > { counter } = 0 ;
2019-05-03 08:13:27 +02:00
$ self - > send_message ( $ self - > { channel } , "Round 3/3, question 1/3! $state->{lie_points} for each lie. $state->{truth_points} for the truth." ) unless $ state - > { reroll_category } ;
2018-02-24 00:51:17 +01:00
$ state - > { result } = 'next' ;
} else {
$ state - > { result } = 'wait' ;
}
2018-01-29 06:53:40 +01:00
return $ state ;
}
sub r3q1choosecategory {
my ( $ self , $ state ) = @ _ ;
$ state - > { result } = $ self - > choosecategory ( $ state ) ;
return $ state ;
}
sub r3q1showquestion {
my ( $ self , $ state ) = @ _ ;
2018-01-30 06:54:52 +01:00
my $ result = $ self - > getnewquestion ( $ state ) ;
if ( $ result eq 'next' ) {
$ self - > showquestion ( $ state ) ;
2018-02-01 07:11:26 +01:00
$ state - > { max_count } = $ self - > { picktruth_max_count } ;
2018-01-30 06:54:52 +01:00
$ state - > { counter } = 0 ;
$ state - > { init } = 1 ;
$ state - > { current_lie_player } = 0 ;
$ state - > { result } = 'next' ;
} else {
$ state - > { result } = 'wait' ;
}
2018-01-29 06:53:40 +01:00
return $ state ;
}
sub r3q1getlies {
my ( $ self , $ state ) = @ _ ;
$ state - > { result } = $ self - > getlies ( $ state ) ;
if ( $ state - > { result } eq 'next' ) {
$ state - > { counter } = 0 ;
$ state - > { init } = 1 ;
}
return $ state ;
}
sub r3q1findtruth {
my ( $ self , $ state ) = @ _ ;
$ state - > { result } = $ self - > findtruth ( $ state ) ;
return $ state ;
}
sub r3q1showlies {
my ( $ self , $ state ) = @ _ ;
$ state - > { result } = $ self - > showlies ( $ state ) ;
return $ state ;
}
sub r3q1showtruth {
my ( $ self , $ state ) = @ _ ;
$ state - > { result } = $ self - > showtruth ( $ state ) ;
return $ state ;
}
2018-01-30 06:54:52 +01:00
sub r3q1reveallies {
my ( $ self , $ state ) = @ _ ;
$ state - > { result } = $ self - > reveallies ( $ state ) ;
return $ state ;
}
2018-01-29 06:53:40 +01:00
sub r3q1showscore {
my ( $ self , $ state ) = @ _ ;
$ state - > { result } = $ self - > showscore ( $ state ) ;
return $ state ;
}
sub round3q2 {
my ( $ self , $ state ) = @ _ ;
2019-05-03 08:13:27 +02:00
if ( $ state - > { ticks } % 2 == 0 || $ state - > { reroll_category } ) {
2018-02-24 00:51:17 +01:00
$ state - > { init } = 1 ;
$ state - > { max_count } = $ self - > { choosecategory_max_count } ;
$ state - > { counter } = 0 ;
2019-05-03 08:13:27 +02:00
$ self - > send_message ( $ self - > { channel } , "Round 3/3, question 2/3! $state->{lie_points} for each lie. $state->{truth_points} for the truth." ) unless $ state - > { reroll_category } ;
2018-02-24 00:51:17 +01:00
$ state - > { result } = 'next' ;
} else {
$ state - > { result } = 'wait' ;
}
2018-01-29 06:53:40 +01:00
return $ state ;
}
sub r3q2choosecategory {
my ( $ self , $ state ) = @ _ ;
$ state - > { result } = $ self - > choosecategory ( $ state ) ;
return $ state ;
}
sub r3q2showquestion {
my ( $ self , $ state ) = @ _ ;
2018-01-30 06:54:52 +01:00
my $ result = $ self - > getnewquestion ( $ state ) ;
if ( $ result eq 'next' ) {
$ self - > showquestion ( $ state ) ;
2018-02-01 07:11:26 +01:00
$ state - > { max_count } = $ self - > { picktruth_max_count } ;
2018-01-30 06:54:52 +01:00
$ state - > { counter } = 0 ;
$ state - > { init } = 1 ;
$ state - > { current_lie_player } = 0 ;
$ state - > { result } = 'next' ;
} else {
$ state - > { result } = 'wait' ;
}
2018-01-29 06:53:40 +01:00
return $ state ;
}
sub r3q2getlies {
my ( $ self , $ state ) = @ _ ;
$ state - > { result } = $ self - > getlies ( $ state ) ;
if ( $ state - > { result } eq 'next' ) {
$ state - > { counter } = 0 ;
$ state - > { init } = 1 ;
}
return $ state ;
}
sub r3q2findtruth {
my ( $ self , $ state ) = @ _ ;
$ state - > { result } = $ self - > findtruth ( $ state ) ;
return $ state ;
}
sub r3q2showlies {
my ( $ self , $ state ) = @ _ ;
$ state - > { result } = $ self - > showlies ( $ state ) ;
return $ state ;
}
sub r3q2showtruth {
my ( $ self , $ state ) = @ _ ;
$ state - > { result } = $ self - > showtruth ( $ state ) ;
return $ state ;
}
2018-01-30 06:54:52 +01:00
sub r3q2reveallies {
my ( $ self , $ state ) = @ _ ;
$ state - > { result } = $ self - > reveallies ( $ state ) ;
return $ state ;
}
2018-01-29 06:53:40 +01:00
sub r3q2showscore {
my ( $ self , $ state ) = @ _ ;
$ state - > { result } = $ self - > showscore ( $ state ) ;
return $ state ;
}
sub round3q3 {
my ( $ self , $ state ) = @ _ ;
2019-05-03 08:13:27 +02:00
if ( $ state - > { ticks } % 2 == 0 || $ state - > { reroll_category } ) {
2018-02-24 00:51:17 +01:00
$ state - > { init } = 1 ;
$ state - > { max_count } = $ self - > { choosecategory_max_count } ;
$ state - > { counter } = 0 ;
2019-05-03 08:13:27 +02:00
$ self - > send_message ( $ self - > { channel } , "Round 3/3, question 3/3! $state->{lie_points} for each lie. $state->{truth_points} for the truth." ) unless $ state - > { reroll_category } ;
2018-02-24 00:51:17 +01:00
$ state - > { result } = 'next' ;
} else {
$ state - > { result } = 'wait' ;
}
2018-01-29 06:53:40 +01:00
return $ state ;
}
sub r3q3choosecategory {
my ( $ self , $ state ) = @ _ ;
$ state - > { result } = $ self - > choosecategory ( $ state ) ;
return $ state ;
}
sub r3q3showquestion {
my ( $ self , $ state ) = @ _ ;
2018-01-30 06:54:52 +01:00
my $ result = $ self - > getnewquestion ( $ state ) ;
if ( $ result eq 'next' ) {
$ self - > showquestion ( $ state ) ;
2018-02-01 07:11:26 +01:00
$ state - > { max_count } = $ self - > { picktruth_max_count } ;
2018-01-30 06:54:52 +01:00
$ state - > { counter } = 0 ;
$ state - > { init } = 1 ;
$ state - > { current_lie_player } = 0 ;
$ state - > { result } = 'next' ;
} else {
$ state - > { result } = 'wait' ;
}
2018-01-29 06:53:40 +01:00
return $ state ;
}
sub r3q3getlies {
my ( $ self , $ state ) = @ _ ;
$ state - > { result } = $ self - > getlies ( $ state ) ;
if ( $ state - > { result } eq 'next' ) {
$ state - > { counter } = 0 ;
$ state - > { init } = 1 ;
}
return $ state ;
}
sub r3q3findtruth {
my ( $ self , $ state ) = @ _ ;
$ state - > { result } = $ self - > findtruth ( $ state ) ;
return $ state ;
}
sub r3q3showlies {
my ( $ self , $ state ) = @ _ ;
$ state - > { result } = $ self - > showlies ( $ state ) ;
return $ state ;
}
sub r3q3showtruth {
my ( $ self , $ state ) = @ _ ;
$ state - > { result } = $ self - > showtruth ( $ state ) ;
return $ state ;
}
2018-01-30 06:54:52 +01:00
sub r3q3reveallies {
my ( $ self , $ state ) = @ _ ;
$ state - > { result } = $ self - > reveallies ( $ state ) ;
return $ state ;
}
2018-01-29 06:53:40 +01:00
sub r3q3showscore {
my ( $ self , $ state ) = @ _ ;
$ state - > { result } = $ self - > showscore ( $ state ) ;
return $ state ;
}
sub round4 {
my ( $ self , $ state ) = @ _ ;
2018-02-01 07:11:26 +01:00
$ state - > { truth_points } = 2000 ;
2018-05-21 03:39:27 +02:00
$ state - > { lie_points } = 3000 ;
2018-02-01 07:11:26 +01:00
$ state - > { my_lie_points } = $ state - > { lie_points } * 0.25 ;
2018-01-29 06:53:40 +01:00
$ state - > { result } = 'next' ;
return $ state ;
}
sub round4q1 {
my ( $ self , $ state ) = @ _ ;
2019-05-03 08:13:27 +02:00
if ( $ state - > { ticks } % 2 == 0 || $ state - > { reroll_category } ) {
2018-02-24 00:51:17 +01:00
$ state - > { init } = 1 ;
$ state - > { random_category } = 1 ;
$ state - > { max_count } = $ self - > { choosecategory_max_count } ;
$ state - > { counter } = 0 ;
2019-05-03 08:13:27 +02:00
$ self - > send_message ( $ self - > { channel } , "FINAL ROUND! FINAL QUESTION! $state->{lie_points} for each lie. $state->{truth_points} for the truth." ) unless $ state - > { reroll_category } ;
2018-02-24 00:51:17 +01:00
$ state - > { result } = 'next' ;
} else {
$ state - > { result } = 'wait' ;
}
2018-01-29 06:53:40 +01:00
return $ state ;
}
sub r4q1choosecategory {
my ( $ self , $ state ) = @ _ ;
$ state - > { result } = $ self - > choosecategory ( $ state ) ;
return $ state ;
}
sub r4q1showquestion {
my ( $ self , $ state ) = @ _ ;
2018-01-30 06:54:52 +01:00
my $ result = $ self - > getnewquestion ( $ state ) ;
if ( $ result eq 'next' ) {
$ self - > showquestion ( $ state ) ;
2018-02-01 07:11:26 +01:00
$ state - > { max_count } = $ self - > { picktruth_max_count } ;
2018-01-30 06:54:52 +01:00
$ state - > { counter } = 0 ;
$ state - > { init } = 1 ;
$ state - > { current_lie_player } = 0 ;
$ state - > { result } = 'next' ;
} else {
$ state - > { result } = 'wait' ;
}
2018-01-29 06:53:40 +01:00
return $ state ;
}
sub r4q1getlies {
my ( $ self , $ state ) = @ _ ;
$ state - > { result } = $ self - > getlies ( $ state ) ;
if ( $ state - > { result } eq 'next' ) {
$ state - > { counter } = 0 ;
$ state - > { init } = 1 ;
}
return $ state ;
}
sub r4q1findtruth {
my ( $ self , $ state ) = @ _ ;
$ state - > { result } = $ self - > findtruth ( $ state ) ;
return $ state ;
}
sub r4q1showlies {
my ( $ self , $ state ) = @ _ ;
$ state - > { result } = $ self - > showlies ( $ state ) ;
return $ state ;
}
sub r4q1showtruth {
my ( $ self , $ state ) = @ _ ;
$ state - > { result } = $ self - > showtruth ( $ state ) ;
return $ state ;
}
2018-01-30 06:54:52 +01:00
sub r4q1reveallies {
my ( $ self , $ state ) = @ _ ;
$ state - > { result } = $ self - > reveallies ( $ state ) ;
return $ state ;
}
2018-01-29 06:53:40 +01:00
sub r4q1showscore {
my ( $ self , $ state ) = @ _ ;
2018-02-24 00:51:17 +01:00
$ state - > { result } = $ self - > showfinalscore ( $ state ) ;
2018-01-29 06:53:40 +01:00
return $ state ;
}
sub gameover {
my ( $ self , $ state ) = @ _ ;
2018-02-24 00:51:17 +01:00
if ( $ state - > { ticks } % 3 == 0 ) {
2018-02-26 09:46:59 +01:00
$ self - > send_message ( $ self - > { channel } , "Game over!" ) ;
2018-01-29 06:53:40 +01:00
2018-02-24 00:51:17 +01:00
my $ players = $ state - > { players } ;
foreach my $ player ( @$ players ) {
$ player - > { ready } = 0 ;
$ player - > { missedinputs } = 0 ;
}
2018-02-04 05:42:27 +01:00
2019-05-03 08:13:27 +02:00
# save updated seen_timestamps
$ self - > save_questions ;
2018-02-24 00:51:17 +01:00
$ state - > { counter } = 0 ;
$ state - > { result } = 'next' ;
} else {
$ state - > { result } = 'wait' ;
}
2018-01-29 06:53:40 +01:00
return $ state ;
}
1 ;