The Bot:
- Code: Select all
#!/usr/bin/perl
# Cert Study Bot
# by drusepth
# on 12/24/09
use strict;
use warnings;
use IO::Socket;
use constant DEBUG => 0;
use constant OFF => 0;
use constant ON => 1;
my %_SETTINGS = (
# Configurable
'network' => 'irc.tddirc.net',
'port' => 6667,
'nickname' => 'Certbot',
'channel' => '#A+'
);
my %_TRIVIA = (
'chance' => 20, # seconds to answer question
'wait' => 2, # seconds after each question before next
'lastasked' => 0, # epoch time the last question was asked
'f_asked' => OFF, # flag saying we're waiting on an answer
'f_on' => OFF, # flag turning on/off trivia
'f_qid' => -1 # id of current question/answer pair
);
# Questions
our %_QUESTIONS;
do 'questions/A+.pl';
my %_SCORES;
my (@questions, @answers);
my $i = 0;
while (my ($q, $a) = each(%_QUESTIONS)) {
$questions[$i] = $q;
$answers[$i] = $a;
$i++;
}
# go go go go go go go
my $sock = new IO::Socket::INET "$_SETTINGS{'network'}:$_SETTINGS{'port'}"
or die "Cannot create connection to $_SETTINGS{'network'} on port $_SETTINGS{'port'}: $!\n";
sendPayload("USER", "$_SETTINGS{'nickname'} "x3 . ":$_SETTINGS{'nickname'}");
sendPayload("NICK", $_SETTINGS{'nickname'});
while ( my $text = <$sock>) {
print $text if DEBUG == ON;
chomp $text;
my ($host, $username, $said) = ( get_host($text), get_username($text), get_said($text) );
my @incoming = split(/ /, $text);
if ($incoming[1] and ($incoming[1] eq "376" or $incoming[1] eq "422")) {
sendPayload("JOIN", $_SETTINGS{'channel'});
}
if ($incoming[1] eq "366") {
$_TRIVIA{'f_on'} = ON;
}
if ($incoming[0] eq "PING") {
sendPayload("PONG", $incoming[1]);
next;
}
# Trivia
next unless $_TRIVIA{'f_on'} == ON;
if ($_TRIVIA{'f_asked'} == OFF and time >= $_TRIVIA{'lastasked'} + $_TRIVIA{'wait'}) {
# Random question
$_TRIVIA{'f_qid'} = int rand scalar @questions;
# Ready to ask a new question
sendPayload("PRIVMSG", $_SETTINGS{'channel'}, ":Question:", $questions[$_TRIVIA{'f_qid'}], " >You have", $_TRIVIA{'chance'}, "seconds<");
$_TRIVIA{'lastasked'} = time;
$_TRIVIA{'f_asked'} = ON;
next;
}
if ($_TRIVIA{'f_asked'} == ON and time < $_TRIVIA{'lastasked'} + $_TRIVIA{'chance'}) {
# Time to answer isn't up
sendPayload("PRIVMSG", $_SETTINGS{'channel'}, ":Received answer", $said, "from", $username) if DEBUG == ON;
if (lc $said eq lc $answers[$_TRIVIA{'f_qid'}]) {
$_TRIVIA{'f_asked'} = OFF;
$_TRIVIA{'lastasked'} = time;
if (!$_SCORES{$username}) {
$_SCORES{$username} = 1;
} else {
$_SCORES{$username}++;
}
sendPayload("PRIVMSG", $_SETTINGS{'channel'}, ":$username got the answer: $answers[$_TRIVIA{'f_qid'}]! They now have $_SCORES{$username} points! Next question in", $_TRIVIA{'wait'}, "seconds.");
}
next;
}
if ($_TRIVIA{'f_asked'} == ON and time >= $_TRIVIA{'lastasked'} + $_TRIVIA{'chance'}) {
# Answer incoming but time is up
sendPayload("PRIVMSG", $_SETTINGS{'channel'}, ":Too late! The answer was", $answers[$_TRIVIA{'f_qid'}]);
$_TRIVIA{'f_asked'} = OFF;
$_TRIVIA{'lastasked'} = time;
next;
}
}
# Functions
sub sendPayload {
my $p = join (' ', @_);
print "[>] " . $p . "\n" if DEBUG == 1;
print $sock $p . "\r\n";
}
sub get_username {
return substr($_[0], 1, index($_[0], "!") - 1);
}
sub get_host {
return substr($_[0], index($_[0], "!") + 1, index($_[0], " ") - index($_[0], "!") - 1);
}
sub get_said {
my $offset = length(get_username($_[0])) + length(get_host($_[0])) + length("PRIVMSG") + length($_SETTINGS{'channel'}) + 6;
if (length($_[0]) >= $offset) {
my $said = substr($_[0], $offset);
$said = substr($said, 0, length($said) - 1);
return $said;
} else {
return "x";
}
}
questions/A+.pl:
- Code: Select all
# APlus Certification is offered by CompTIA ®. Undoubtedly, A+ Certification
# is the most widely recognized certification in the field of computer hardware.
# A+ exam is targeted for computer service technicians with at least 6 months
# on-the-job experience. To get A+ certified, one need to pass both A+ Core Hardware
# Technologies exam, 220-301 and A+ OS (Operating Systems) exam, 220-302.
# CompTIA A+ Essentials measures the necessary competencies of an entry-level IT
# professional with a recommended 500 hours of hands-on experience in the lab or
# field. It tests for the fundamentals of computer technology, networking and security,
# as well as the communication skills and professionalism now required of all
# entry-level IT professionals.
our %_QUESTIONS = (
'What is the storage capacity of a 3 1/2" Double Sided Double Density (DSDD) Floppy disk?'
=> '720KB',
'What is the storage capacity of a 3 1/2" Double Sided High Density (DSHD) Floppy disk?'
=> '1.44MB',
'What is the storage capacity of a 3 1/2" Double Sided Extra Density (DSED) Floppy disk?'
=> '2.88MB',
'When talking about floppy disks, what does DSHD stand for?'
=> 'Double Sided High Density',
'When talking about floppy disks, what does DSDD stand for?'
=> 'Double Sided Double Density',
'When talking about floppy disks, what does DSED stand for?'
=> 'Double Sided Extra Density',
'How many different colors can a CGA monitor display?'
=> '16',
'How many different colors can a EGA monitor display?'
=> '64',
'How many different colors can a VGA monitor display?'
=> '256',
'How many millions of different colors can a SVGA monitor display??'
=> '16',
'What is the maximum resolution of a VGA monitor?'
=> '640x480',
'What is the connector type that goes with CGA / EGA monitor?'
=> 'DB-9',
'What is the connector type that goes with VGA / SVGA monitor?'
=> 'DB-15',
'There are 15 interrupt request (IRQ) numbers that correspond to locations in the computer that a bus line can be interrupted at. IRQ0 is used with ______ ____.'
=> 'System Time',
'There are 15 interrupt request (IRQ) numbers that correspond to locations in the computer that a bus line can be interrupted at. IRQ1 is used with the ________.'
=> 'Keyboard',
'There are 15 interrupt request (IRQ) numbers that correspond to locations in the computer that a bus line can be interrupted at. IRQ3 is used with COM ports 2 and _.'
=> '4',
'There are 15 interrupt request (IRQ) numbers that correspond to locations in the computer that a bus line can be interrupted at. IRQ3 is used with COM ports 4 and _.'
=> '2',
'There are 15 interrupt request (IRQ) numbers that correspond to locations in the computer that a bus line can be interrupted at. IRQ4 is used with COM ports 1 and _.'
=> '3',
'There are 15 interrupt request (IRQ) numbers that correspond to locations in the computer that a bus line can be interrupted at. IRQ4 is used with COM ports 3 and _.'
=> '1',
'There are 15 interrupt request (IRQ) numbers that correspond to locations in the computer that a bus line can be interrupted at. IRQ5 is used with the parallel port ____.'
=> 'LPT2',
'There are 15 interrupt request (IRQ) numbers that correspond to locations in the computer that a bus line can be interrupted at. IRQ6 is used with the ______ _____ controller.'
=> 'Floppy drive',
'There are 15 interrupt request (IRQ) numbers that correspond to locations in the computer that a bus line can be interrupted at. IRQ7 is used with the parallel port ____.'
=> 'LPT1',
'There are 15 interrupt request (IRQ) numbers that correspond to locations in the computer that a bus line can be interrupted at. IRQ8 is used with the ____ ____ _____.'
=> 'Real Time Clock',
'There are 15 interrupt request (IRQ) numbers that correspond to locations in the computer that a bus line can be interrupted at. IRQ12 is used with the _____.'
=> 'Mouse',
'How many pins does a DIN-5 connector have?'
=> '5',
'How many pins does a Mini DIN-6 connector have?'
=> '6',
'What peripheral would you plug in with a Mini DIN-6 connector?'
=> 'Keyboard',
'What is the port address for the serial port COM1?'
=> '3F8-3FF',
'What is the port address for the serial port COM2?'
=> '2F8-2FF',
'What is the port address for the serial port COM3?'
=> '3E8-3EF',
'What is the port address for the serial port COM4?'
=> '2E8-2EF',
'What is the port address for the parallel port LPT1?'
=> '378-37F',
'What is the port address for the parallel port LPT2?'
=> '278-27F',
'What is the port address for the floppy drive controller?'
=> '3F0-3F7',
'What three-letter control signal on a serial cable indicates that the data set is ready?'
=> 'DSR',
'How many devices can a 16-bit SCSI-2 support?'
=> '16',
'How many devices can an 8-bit SCSI-2 support?'
=> '8',
'You are told that a monitor at a client\'s place is having a problem. You are about to remove the cover of the monitor. A colleague tells you to wear a wrist strap to prevent electrostatic discharge (ESD) damage to the monitor. Do you follow his directions? (yes/no)'
=> 'No',
'While booting up a client\'s computer, you receive an error message with the code 106. You remember that POST errors 100-199 are clumped into one location of failure, so you check the ______ _____ for failures.'
=> 'System Board',
'While booting up a client\'s computer, you receive an error message with the code 263. You remember that POST errors 200-299 are clumped into one location of failure. In this case, you know that location is the ______.'
=> 'Memory',
'While booting up a client\'s computer, you receive an error message with the code 385. You remember that POST errors 300-399 are clumped into one location of failure, so you check the ________ for failures.'
=> 'Keyboard',
'While booting up a client\'s computer, you receive an error message with the code 406. You remember that POST errors 400-499 are usually caused by __________ video problems.'
=> 'monochrome',
'While booting up a client\'s computer, you receive an error message with the code 563. You remember that POST errors 500-599 are usually caused by __________ video problems.'
=> 'color',
'While booting up a client\'s computer, you receive an error message with the code 666. You remember that POST errors 600-699 are clumped into one location of failure, so you check the ______ ____ for failures.'
=> 'Floppy disk',
'While booting up a client\'s computer, you receive an error message with the code 1723. You remember that POST errors 1700-1799 are clumped into one location of failure, so you check the ______ ____ for failures.'
=> 'Hard disk',
'True or False: An MCA bus supports PnP, bus mastering, & burst mode.'
=> 'False',
'True or False: An MCA bus supports PnP and bus mastering, but not burst mode.'
=> 'True',
'True or False: A PCI bus supports PnP, bus mastering, & burst mode.'
=> 'True',
'Of the following, which is NOT a type of motherboard expansion slot? (ISA / PCI / AGP / ATX)'
=> 'ATX',
'Which IRQ does COM1 commonly use?'
=> '4',
'Of the following, which is NOT a type of computer hard drive? (IDE / EIDE / SCSI / FDD)'
=> 'FDD',
'Which of the following retains the information it\'s storing when the power to the system is turned off? (CPU / RAM / ROM / DRAM / DIMM)'
=> 'ROM',
'Does a computer\'s RAM retain the information it\'s storing when the power to the system is turned off? (Yes/No)'
=> 'No',
'Does a computer\'s ROM retain the information it\'s storing when the power to the system is turned off? (Yes/No)'
=> 'Yes',
'Does a computer\'s CPU retain the information it\'s storing when the power to the system is turned off? (Yes/No)'
=> 'No',
'Many ribbon cables have a red line along one edge that indicates the side of the ribbon that should be aligned with this pin on the matching connector.'
=> '1',
'Which IRQ does the system timer commonly use?'
=> '0',
'What is the BIOS an acrynym for?'
=> 'Basic Input Output System',
'Which of the following is NOT a kind of RAM? (DIMM / SIMM / ROM / SLIPP)'
=> 'ROM',
'When working on a computer taken into you by a client, you determine that there are bad sectors on the hard drive. A colleague suggests that you run the FDISK command to fix them. Will this help? (Yes/No)'
=> 'No',
'True or false: the FDISK command is used to create partitions on a hard drive.'
=> 'True',
'What type of connector is used to plug a telephone line into a modem?'
=> 'RJ-11',
'Which IRQ does LPT1 commonly use?'
=> '7',
'You\'re observing a colleague plug in the P8 and P9 power connectors in a system board. You notice that the black wires of both connectors are right next to each other. Did your colleague make a mistake? (Yes/No)'
=> 'No',
'A SIMM can either have 72 or __ pins.'
=> '30',
'A SIMM can either have 30 or __ pins.'
=> '72',
'How many pins does a DIMM have?'
=> '168',
'True or false: parity is a system for balancing the voltage coming out of the power supply. (True/False)'
=> 'False',
'True or false: parity is an extra bit stored with data in RAM that is used to check for errors when the data is read back. (True/False)'
=> 'True',
'You\'re cleaning a client\'s PC and you notice the power supply is exceptionally dirty. Your colleague suggests using compressed air. Do you follow his advice? (Yes/No)'
=> 'Yes',
'You\'ve played nothing but flash games online for the last six months. These flash games haven\'t required keyboard input, and so your keyboard has gathered a fair amount of dust. You think the best way to clean it would be to just remove the bezel and blow out the dust. Are you right? (Yes/No)'
=> 'Yes',
'What kind of connectors are used to connect a PC power supply to a hard drive?'
=> 'Molex',
'IRQ stands for ________ _______.'
=> 'Interrupt Request',
'Two crazy software engineers are dismantling computers in two rooms. One room is 50 degrees Fahrenheit, and the other is 80 degrees Fahrenheit. Both rooms are moderately dry. Without any precautions, which engineer has a greater chance of encountering electrostatic discharge? (Hot/Cold)'
=> 'Cold',
'Which of the following file types can not be ran simply by typing them at the DOS prompt? (com / bat / dat / exe)'
=> 'dat',
'A cluster is the minimum file allocation unit. A cluster is composed of these. (RAM / ROM / sectors / sections / clustettes / bytes)'
=> 'sectors',
);
