Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package PipSqueek::Plugin::Freezer;
- use base qw(PipSqueek::Plugin);
- use DBI;
- use DBD::mysql;
- use Time::localtime;
- sub plugin_initialize {
- my $self = shift;
- # CONFIG VARIABLES
- my $platform = "mysql";
- my $database = "orbiter_radio";
- my $host = "localhost";
- my $port = "3308";
- my $tablename = "freezer";
- my $user = "Radiobot";
- my $pass = "Yeah, oops";
- # set the data source name
- my $dsn = "dbi:$platform:$database:$host:$port";
- # now connect and get a database handle
- $dbh = DBI->connect($dsn, $user, $pass)
- or die $DBI::errstr;
- $Penguin[0] = "Have you ever wrestled a penguin? No? Then you go try that.";
- $Penguin[1] = "The Penguin Resists!";
- $Penguin[2] = "Uhh... I don't think he wants to move right now.";
- $Penguin[3] = "Yeah, he's WAY too busy fapping for that.";
- $Penguin[4] = "Not a chance in hell. He'd just try to buttfuck me or something.";
- $Penguin[5] = "Have you ever wrestled a penguin? No? Then you go try that.";
- $Penguin[6] = "I'm... I'm scared he'll hurt me";
- $self->plugin_handlers({
- 'multi_freezer' => 'freezer', # list items in freezer. Needs limiting to avoid floods.
- 'multi_freezer+' => 'freezer_add', # add item to freezer. May need an item-exists check.
- 'multi_freezer-' => 'freezer_rem', # remove item from freezer. Needs to be checked against "removable" variable for the "You can't remove the penguin" jokes.
- });
- }
- sub freezer {
- my ($self, $message) = @_;
- # Find the items we're interested in, who added them, and when
- my $query = 'SELECT * FROM freezer';
- my $sth = $dbh->prepare($query);
- # run the query
- $sth->execute()
- or die "Fail."; # REALLY informative error :P
- # format and display query result. Not currently checked against the 40 limit - i.e if there are more than forty the bot won't tell you.
- $self->respond($message, "Items in Xyon's freezer at the moment include:");
- while(@row = $sth->fetchrow_array()) {
- $self->respond($message, "$row[1]: $row[2] (added by $row[3])");
- }
- return $self->respond($message, "End of list.");
- }
- sub freezer_add {
- my ($self,$message)=@_;
- my $item = $message->command_input(); # Takes the item they want to add.
- my $nick = $message->{nick}; # For the "who added this" data
- my $tm = localtime; # Get the date and time. Not sure whose timezone this works in atm >.<
- my ($DAY, $MONTH, $YEAR, $HOUR, $MINUTE, $SECOND) = ($tm->mday, $tm->mon+1, $tm->year+1900, $tm->hour, $tm->min, $tm->sec);
- # list number sorting
- my $query = 'SELECT listnum FROM freezer ORDER BY listnum desc limit 1';
- my $sth = $dbh->prepare($query);
- # A bit of a hackjob, but it works...
- $sth->execute();
- my $listnumtemp = $sth->fetchrow();
- my $listnum = ($listnumtemp)+1;
- #First, make sure they gave us an item to add
- if ($item eq "") {
- return $self->respond($message, "You have to actually give me an item to add to the freezer, dummy.");
- }
- if ($item eq "freezer" || $item eq "Freezer") {
- return $self->respond($message, "Sorry, but you don't have the authority to buttfuck physics like that, $nick");
- }
- # If they did, make sure the freezer isn't full.
- my $check = 'SELECT * FROM freezer WHERE listnum > 7';
- my $sthcheck = $dbh->prepare($check);
- # Run the query
- $sthcheck->execute();
- # A bit of a hackjob, but it works...
- my $freezerfull = $sthcheck->fetchrow();
- if ($freezerfull != NULL)
- {
- return $self->respond($message, "Sorry, the freezer is full!"); # Can't add !
- }
- # freezer isn't full, carry on
- else {
- my $query = 'INSERT INTO freezer(listnum, item_name, added_by, added_on, removable) values (?,?,?,?,?)';
- my $sth = $dbh->prepare($query) or die "WTF $DBI::errstr;";
- $sth->execute("$listnum", "$item", "$nick", "$YEAR-$MONTH-$DAY $HOUR:$MINUTE:$SECOND", 1)
- or die "Failed to access database properly. Prod Xyon until he fixes it. $DBI::errstr\n";
- return $self->respond($message, "Item '$item' added to freezer."); # confirm.
- }
- }
- sub freezer_rem {
- my ($self,$message)=@_;
- my $item = $message->command_input(); # Takes the item they want to remove.
- # firstly, check for the penguin!
- if ($item eq "1")
- {
- my $range = 6;
- my $num = int(rand($range));
- return $self->respond($message, $Penguin[$num]);
- }
- if ($item eq "2")
- {
- return $self->respond($message, "The Penguin reminds you that removing his fappage material is unwise.");
- }
- if ($item eq "") {
- return $self->respond($message, "Take it out? Take what out? WHAT?");
- }
- my $query = 'SELECT * FROM freezer WHERE listnum = ?';
- my $sth = $dbh->prepare($query);
- $sth->execute($item);
- my $itemexists = $sth->fetchrow();
- if ($itemexists eq 'NULL') {
- return $self->respond($message, "Sorry, I can't find that in the freezer.");
- }
- else {
- my $deljob = 'DELETE FROM freezer WHERE listnum = ?';
- my $sth1 = $dbh->prepare($deljob);
- $sth1->execute($item) or die "Query fail: $DBI::errstr;";
- return $self->respond($message, "Item removed from freezer.");
- }
- }
- 1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement