Henrybk

Sintax answerbot 2.0

Jul 23rd, 2015
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 3.38 KB | None | 0 0
  1. sub CheckRecieved {
  2.     my ($recievedMessage, %playerInfo) = @_;
  3.     my %hash;
  4.     $hash{1} = {
  5.                     name => 'introduction',
  6.                     pattern => qr/(hi|hello|hey)/i
  7.     };
  8.     $hash{2} = {
  9.                     name => 'goodbyes',
  10.                     pattern => qr/(bye|sya|adios)/i
  11.     };
  12.     $hash{3} = {
  13.                     name => 'thanks',
  14.                     pattern => qr/(thanks|thx|god bless you)/i
  15.     };
  16.     $playerInfo{all}++;
  17.     foreach my $iteration (sort keys %hash) {
  18.         next unless ($recievedMessage =~ $hash{$iteration}{pattern});
  19.         $playerInfo{$hash{$iteration}{name}}++;
  20.         $playerInfo{lastrecived} = $hash{$iteration}{name};
  21.         return (%playerInfo);
  22.     }
  23.     $playerInfo{unknown}++;
  24.     $playerInfo{lastrecived} = 'unknown';
  25.     return (%playerInfo);
  26. }
  27.  
  28. sub AnswerDatabase {
  29.     my %playerInfo = %{$_[0]};
  30.     my %answers;
  31.     $answers{introduction} = {
  32.                     1 => {
  33.                             condition => (($playerInfo{goodbyes} > 0)? 1 : 0),
  34.                             answers => [
  35.                                             "Why are you introducing yourself you you has already said goodbye?",
  36.                                             "I thought the conversation was over",
  37.                                             "When you said bye i thought it was for real"
  38.                                         ]
  39.                     },
  40.                     2 => {
  41.                             condition => (($playerInfo{introduction} == 1)? 1 : 0),
  42.                             answers => [
  43.                                             "Hi",
  44.                                             "Hey man",
  45.                                             "How you doing",
  46.                                             "Cool",
  47.                                             "Hello"
  48.                                         ]
  49.                     },
  50.                     3 => {
  51.                             condition => (($playerInfo{introduction} == 2)? 1 : 0),
  52.                             answers => [
  53.                                             "I think we have already met",
  54.                                             "Hi again",
  55.                                             "we have already been introduced",
  56.                                             "hello again"
  57.                                         ]
  58.                     }
  59.     };
  60.     $answers{goodbyes} = {
  61.                     1 => {
  62.                             condition => (($playerInfo{thanks} > 0)? 1 : 0),
  63.                             answers => [
  64.                                             "Good I was able to help, goodbye",
  65.                                             "Good i helped",
  66.                                             "Call whenever you need",
  67.                                         ]
  68.                     },
  69.                     2 => {
  70.                             condition => (($playerInfo{goodbyes} == 1)? 1 : 0),
  71.                             answers => [
  72.                                             "Bye",
  73.                                             "Bye Bye",
  74.                                             "See ya",
  75.                                             "So long",
  76.                                             "Adios"
  77.                                         ]
  78.                     },
  79.                     3 => {
  80.                             condition => (($playerInfo{goodbyes} == 2)? 1 : 0),
  81.                             answers => [
  82.                                             "Bye Again",
  83.                                             "Bye Bye Bye",
  84.                                             "Hasta again"
  85.                                         ]
  86.                     }
  87.     };
  88.     $answers{thanks} = {
  89.                     1 => {
  90.                             condition => (($playerInfo{thanks} == 1)? 1 : 0),
  91.                             answers => [
  92.                                             "You're welcome",
  93.                                             "My pleasure",
  94.                                             "No worries"
  95.                                         ]
  96.                     },
  97.                     2 => {
  98.                             condition => (($playerInfo{thanks} == 2)? 1 : 0),
  99.                             answers => [
  100.                                             "Good to help again",
  101.                                             "You're welcome again",
  102.                                             "No worries at all"
  103.                                         ]
  104.                     }
  105.     };
  106.     $answers{unknown} = {
  107.                     1 => {
  108.                             condition => (($playerInfo{unknown} == 1)? 1 : 0),
  109.                             answers => [
  110.                                             "WHAT DID YOU SAY TO MY FACE BITCH ASS?",
  111.                                             "I'M GONNA WHOP YO ASS BITCH"
  112.                                         ]
  113.                     },
  114.                     2 => {
  115.                             condition => (($playerInfo{unknown} == 2)? 1 : 0),
  116.                             answers => [
  117.                                             "YOU HERE AGAIN IN MA YARD BOY?",
  118.                                             "AAAMAAA WHOOOOP THEEEM ASSESSS"
  119.                                         ]
  120.                     }
  121.     };
  122.     foreach my $iteration (sort keys %{$answers{$playerInfo{lastrecived}}}) {
  123.         next unless ($answers{$playerInfo{lastrecived}}{$iteration}{condition} == 1);
  124.         return ($answers{$playerInfo{lastrecived}}{$iteration}{answers}[rand @{$answers{$playerInfo{lastrecived}}{$iteration}{answers}}]);
  125.     }
  126.     return 'Nope';
  127. }
Advertisement
Add Comment
Please, Sign In to add comment