Advertisement
TakatsukiYayoi

Takanya v1

Apr 21st, 2013
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 2.14 KB | None | 0 0
  1. #!/usr/bin/perl
  2. # RamenServ
  3. # Takanya's Script
  4. # for Perl/HexChat
  5. # By TakatsukiYayoi
  6. #
  7. # What this does:
  8. #  >> gives out ramen to anyone entering
  9. #       !ramen in the channel
  10. #
  11.  
  12. # <donttouch>
  13.  
  14. # For good Perl programming
  15. use strict;
  16. use warnings;
  17.  
  18. # Use the Xchat module (this is an XChat script, d'oh!)
  19. use Xchat qw( :all );
  20.  
  21. # Use a few other modules this thing needs
  22. use DBD::SQLite; # For stats tracking (Yes, Yayoi loves SQLite :D)
  23. use Time::HiRes qw( gettimeofday ); # For last command usage tracking
  24.  
  25. # </donttouch>
  26.  
  27. # Put your ramen flavors here.
  28. # Format is ("a flavor","another flavor","another flavor")
  29. # As many as you want.
  30. # The script will write "<n> bowl(s) of <flavor> ramen",
  31. # So you might want to consider that.
  32.  
  33. my @flavors = ("pork","salt","miso","tonkatsu","soy","chicken","beef");
  34.  
  35. # ------ MAIN CODE BE HERE ------
  36.  
  37. my $customer = ""; # We'll use this later.
  38. my $noMoarOrders = 0; # We'll use this later.
  39.  
  40. # Register this script
  41. register ( "Takanya\'s RamenServ", "0.0.02", "Ramen for everyone!", "" );
  42.  
  43. # Listen for channel messages
  44. hook_print ('Channel Message',\&order_ramen);
  45.  
  46. # Tell the user that the script is armed and ready
  47. Xchat::prnt ("Takanya is ready to serve ramen!");
  48.  
  49. # Quick Check: respond only is the message is "!ramen"
  50. sub order_ramen { $customer = $_[0][0]; &cook_ramen if ($_[0][1] =~ m/^!ramen$/i && !($noMoarOrders)); }
  51.  
  52. # Main sub
  53. sub cook_ramen {
  54.  my $bowls = &eggroll(5);
  55.  $bowls++; # This means no zero bowls given
  56.  my $flavor = &eggroll(scalar(@flavors) - 1);
  57.  my $ss = ($bowls == 1) ? "" : "s";
  58.  $bowls = ($bowls == 1) ? "a" : $bowls;
  59.  
  60.  &delaycommand ("me gives $customer $bowls bowl$ss of $flavors[$flavor] ramen.");
  61.  # CBACBACBACBACBATOSTATS
  62.  
  63.  # Arm the floodprot timer
  64.  $noMoarOrders = 1;
  65.  hook_timer( 1500, sub { $noMoarOrders = 0; return REMOVE; });
  66.  return EAT_NONE;
  67. }
  68.  
  69. # Randomizer
  70. sub eggroll {
  71.  my $maxvalue=$_[0];
  72.  int(rand($maxvalue));
  73. }
  74.  
  75. # Blatant copypasta
  76. sub delaycommand {
  77.   my $command = $_[0];
  78.     hook_timer( 0,
  79.          sub {
  80.            command($command);
  81.            return REMOVE;
  82.           }
  83.       );
  84.   return EAT_NONE;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement