Dynadot .com transfer sale, only $10.12 with coupon code DYNA12, available while supplies last, ends October 1, 2026.

IRC Bot Script...

SpaceshipSpaceship
Spacemail by SpaceshipSpacemail by Spaceship
SpaceshipSpaceship
Watch

RageD

VIP Member
Impact
31
IRC Bot Script... -- Perl Script

Ok, I have tried taking on a new way... It includes the following:

use IO::Socket;
use Net::IRC;
use CGI qw/:standard:/;
use Data::Dumper;
use Getopt::Long;

Well, here it is:

Code:
#!/usr/bin/perl -w
# Project start:
#
# 8/1/2005 2:27:39 PM
#
#
#
#  (C) Copyright 2005-2006 RageD.  All Rights Reserved.
#
#  Bot for personal use!

use Net::IRC;
use CGI qw/:standard/;
use IO::Socket;
use Data::Dumper;
use Getopt::Long;

my %opts;

readconfig();

# command line overrides CONFIG
GetOptions(\%opts,
    "logfile",
    "servername",
    "port|s=s",
    "botnick|n=s",
    "botchan|c=s",
    "owneremail",
    "botpass",
    "ownernick",
    "cmdprefix",
) or debug("Error: Could not parse command line. Try $0 --help\n",1);


my $logfile = "$opts{logfile}";
$chan = "$opts{botchan}";
my $server = "$opts{servername}";
my $port = "$opts{port}";
my $nick = "$opts{botnick}";
my $ircname = "b0t";
my $username = "b0t";
my $owner_email = "$opts{owneremail}";
my $pass = "$opts{botpass}";
$owner = "$opts{ownernick}";

my $answer = "";

# PUBLIC user Commands

# Easter Eggs
my $handjob = "$opts{cmdprefix}handjob";
my $eat = "$opts{cmdprefix}eat";
my $say = "$opts{cmdprefix}say";

# USER REGULAR CMDs..
my $hop = "$opts{cmdprefix}hop";
my $dehop = "$opts{cmdprefix}dehop";

$irc = new Net::IRC;

$conn = $irc->newconn(Server => ($ARGV[0] || $server),
Port => $port,
Nick => "$nick",
Ircname => "$ircname",
Username => "$username")
or die "Can't connect to IRC server.\n";

chat_log("Connecting to IRC ... \n");


# What to do when the bot successfully connects.
sub on_connect {
my $self = shift;
print "Connected...\n";
chat_log("Connected\n");
chat_log("Identifying to Nickserv (Registering if not already!)\n");
$self->privmsg("nickserv", "REGISTER $pass $owner_email");
$self->privmsg("nickserv", "IDENTIFY $pass");
chat_log("Joining $chan\n");
$self->join("$chan");
print "Marking myself as a bot on $server\n";
$self->mode($self->nick, "+B");
# print "Opering Up!\n";
# $self->oper("uid","pass");
}

# Handles some messages you get when you connect
sub on_init {
my ($self, $event) = @_;
my (@args) = ($event->args);
shift (@args);
chat_log("*** @args\n");
}

# What to do when someone leaves a channel the bot is on.
sub on_part {
my ($self, $event) = @_;
my ($channel) = ($event->to)[0];
my ($nick) = $event->nick;
chat_log("*** $nick has left channel $channel\n");
}

# People will join the channel right?  I ASKED YOU A QUESTION!  **** YOU HO!!
sub on_join {
my ($self, $event) = @_;
my ($channel) = ($event->to)[0];
my ($nick) = $event->nick;
my ($userhost) = $event->userhost;
chat_log("*** $nick ($userhost) has joined channel $channel\n");
$self->mode("$chan", "+h $nick");
chat_log("*** $nick was halfopped in $channel upon join!\n");
}

# I'm sorry baby..  Just answer messages now!
sub on_msg {
my ($valid);
my ($self, $event) = @_;
my ($nick) = $event->nick;
my ($text) = $event->args;
my ($channel) = "#testing";
my ($arg) = ($event->args);
$text = clean($text);
if ($event->nick eq "$owner") {
if ($arg =~ /$channel/i) {
$self->join($arg);
}
}
else {
$answer = "Bot is Incomplete, Please Message RageD";
$self->privmsg($nick, $answer);
chat_log("<$nick> $text\nResponse: $answer");
}
}

# What to do when we receive channel text.
sub on_public {
my ($self, $event) = @_;
my @to = $event->to;
my ($nick, $mynick) = ($event->nick, $self->nick);
my ($arg) = ($event->args);
my ($part) = "$opts{cmdprefix}part";
my ($op) = "$opts{cmdprefix}op";
my ($deop) = "$opts{cmdprefix}deop";
my ($voice) = "$opts{cmdprefix}voice";
my ($devoice) = "$opts{cmdprefix}devoice";
my ($hop) = "$opts{cmdprefix}hop";
my ($dehop) = "$opts{cmdprefix}dehop";
my ($quit) = "$opts{cmdprefix}quit";
my ($kb) = "$opts{cmdprefix}kb";
my ($ident) = "$opts{cmdprefix}ident";
my ($quotexyz) = "$opts{cmdprefix}quote";
my ($kick) = "$opts{cmdprefix}kick";

# Note that $event->to() returns a list (or arrayref, in scalar
# context) of the message's recipients, since there can easily be
# more than one.

$arg = clean($arg);
# chat_log("<$nick> $arg\n");
$c = "[" . $nick . "\/" . "@to" . "]";
chat_log("$c $arg\n");

$access = 0;
$nik = $event->nick;
open(PHILE,"data/bot.conf");
@plines = <PHILE>;
close(PHILE);
foreach $line (@plines)
{
$line =~ s/\n+//;
if ($line eq $nik) { $access = 1; last; }
}

if (($access == 1) || ($nik eq $owner)) {
@argarray = split(/ /, $arg);
if ($arg =~ /$kick/i) {
$msg = "$arg";
$msg =~ s/$argarray[1]//;
$msg =~ s/\!kick//;
$msg =~ s/\s+//;
$self->kick("$chan", "$nick $msg");
chat_log("*** Kicked $nick from $chan with reason $msg\n");
}
elsif ($arg =~ /$part/i) {
$self->part($chan);
chat_log("*** Left $chan\n");
}
elsif ($arg =~ /$quit/i) {
$self->quit("quitting...");
exit;
}
elsif ($arg =~ /$op/i) {
$self->mode("$chan", "+o $nick");
chat_log("*** Opped $nick in $chan");
}
elsif ($arg =~ /$deop/i) {
$self->mode(@to, "-o $argarray[1]");
print "Deoped $argarray[1] on @to\n";
}
elsif ($arg =~ /$devoice/i) {
$self->mode(@to, "-v $argarray[1]");
print "Devoiced $argarray[1] on @to\n";
}
elsif ($arg =~ /$voice/i) {
$self->mode(@to, "+v $argarray[1]");
print "Voiced $argarray[1] on @to\n";
}
elsif ($arg =~ /$kick/i) {
$self->kick(@to, $argarray[1]);
print "Kicked $argarray[1] from @to\n";
}
elsif ($arg =~ /$kb/i) {
$self->mode($chan, "+b $nick");
$msg = "$arg";
$msg =~ s/$nick//;
$msg =~ s/\!kb//;
$msg =~ s/\s+//;
$self->kick($nick, $argarray[1], "$msg");
chat_log("Kicked $nick from $chan with reason $msg\n");
chat_log("KickBanned $nick from $chan\n");
}
elsif ($arg =~ /$ident/i) {
$self->privmsg("nickserv", "identify $pass");
print "Identified\n";
}
elsif ($arg =~ /hello/i) {
$self->privmsg(@to, "Hello $nik ! wazzup?");
}
elsif ($arg =~ /brick/i) {
$self->privmsg(@to, "A large pile of bricks has been thrown on $argarray[1] !");
}
elsif ($arg =~ /\!say/i) {
$msg = "$arg";
$msg =~ s/\!say//;
$msg =~ s/\n+//;
$self->privmsg("$chan", "$msg");
chat_log("$nick Made me Say: $msg\n");
}
else { $answer = "Master!"; };
}

if ($arg =~ /^$quotexyz/i) {
$quoteacc = 0;
$nik = $event->nick;
open(PHILE,"quoteaccess.txt");
@plines = <PHILE>;
close(PHILE);
foreach $line (@plines)
{
$line =~ s/\n+//;
if ($line eq $nik) { $quoteacc = 1; last; }
}
if ($nik eq $owner) { $quoteacc = 1; }
if ($quoteacc == 0) {
$self->privmsg($nik, "You Do Not Have The Access To Use This Command so ****off");
}
else {
&randquote;
$self->privmsg(@to, "Quote: $quotex");
print "[@to] Quote: $quotex";
}
}

}

# What to do when we receive a message via DCC CHAT (nothing right now).
sub on_chat {
my ($self, $event) = @_;
my ($sock) = ($event->to)[0];
}

# Prints the names of people in a channel when we enter.
sub on_names {
my ($self, $event) = @_;
my (@list, $channel) = ($event->args);

# splice() only works on real arrays. Sigh.
($channel, @list) = splice @list, 2;

chat_log("Users on $channel: @list\n");
}

sub on_public {
my ($self, $event) = @_;
my @to = $event->to;
my ($nick, $mynick) = ($event->nick, $self->nick);
my ($arg) = ($event->args);

if ($arg =~ /$handjob/i) {
$self->me("$chan", "gives $nick a handjob");
print "Giving Handjob at the moment...";
}
if ($arg =~ /$eat/i) {
$self->me("$chan", "eats out $nick\'s pussy!");
print "Eating out $nick at the moment [Yum]";
}
if ($arg =~ /$hop/i) {
$self->mode("$chan", "+h $nick");
chat_log("*** Halfopped $nick in $chan\n");
}
if ($arg =~ /$dehop/i) {
$self->mode("$chan", "-h $nick");
chat_log("*** Dehalfopped $nick in $chan\n");
}
if ($arg =~ /$say/i) {
$self->privmsg("$chan", "$_");
}
else { print "Apparently there is a bug with a cmd..  Contact RageD\n"; }
}

# What to do when we receive a DCC SEND or CHAT request.
sub on_dcc {
my ($self, $event) = @_;
my $type = ($event->args)[1];
}

# Yells about incoming CTCP PINGs.
sub on_ping {
my ($self, $event) = @_;
my $nick = $event->nick;

$self->ctcp_reply($nick, join (' ', ($event->args)));
chat_log("*** CTCP PING request from $nick received\n");
}

# Gives lag results for outgoing PINGs.
sub on_ping_reply {
my ($self, $event) = @_;
my ($args) = ($event->args)[1];
my ($nick) = $event->nick;

$args = time - $args;
chat_log("*** CTCP PING reply from $nick: $args sec.\n");
}

# Change our nick if someone stole it.
sub on_nick_taken {
my ($self) = shift;

$self->nick(substr($self->nick, -1) . substr($self->nick, 0, 8));
}

# Display formatted CTCP ACTIONs.
sub on_action {
my ($self, $event) = @_;
my ($nick, $args) = ($event->nick, $event->args);

# :FIXME: this should not be necessary:
#shift @args;
$nick = "[" . $nick . "]";
chat_log("* $nick $args\n");
}

# Reconnect to the server when we die.
sub on_disconnect {
my ($self, $event) = @_;
chat_log ("Disconnected, reconnecting...\n");
$self->connect();
}

# ctcp version reply.
sub on_cversion {
my ($self, $event) = @_;
my $nick = $event->nick;
$self->ctcp_reply( $nick, "VERSION Perl bot v0.0.1.3 by RageD [Incomplete Version]");
}

# Look at the topic for a channel you join.
sub on_topic {
my ($self, $event) = @_;
# Reply With Quote
my @args = $event->args();

# Note the use of the same handler sub for different events.

if ($event->type() eq 'notopic') {
chat_log("No topic set for $args[1].\n");

# If it's being done _to_ the channel, it's a topic change.
} elsif ($event->type() eq 'topic' and $event->to()) {
chat_log("Topic change for ", $event->to(), ": $args[0]\n");

} else {
chat_log("The topic for $args[1] is \"$args[2]\" \n");
}
}

# Log to a file
sub chat_log {
open (LOG, ">>$logfile") || warn "Can't open $logfile [$!]\n";
print LOG "@_";
close(LOG) || warn "Can't close $logfile [$!]\n";
$stuff = "@_";
$stuff =~ s/\n+//;
print "$stuff\n";

}

sub randquote2 {

$phile = 'quotes.txt';

open(FILE,"$phile");
@lines = <FILE>;
close(FILE);
srand;

$quotex = "$lines[int rand(@lines)]";

}

sub randquote {
open(QUOTE, "quotes.txt");
@quotesline=<QUOTE>;
$countlines=@quotesline;
$randquote=int(rand($countlines));
$quotex = $quotesline[$randquote];
}

sub clean {
my $string = "@_";
$string =~ s/"//g;
$string =~ s/;//g;
$string =~ s/%//g;
$string =~ s/\`//g;
$string =~ s/\\//g;
$string =~ s/\///g;
$string =~ s/(\w+)/$1/gi;
if (length($string) > 0) {
return $string;
}
else { return "whatever"; }





}
sub readconfig {
    if (! -e "data/bot.conf") {
        debug("Error: Cannot find bot.conf Copy it to data directory, ".
              "please.",1);
    }
    else {
        open(CONF,"<data/bot.conf") or do {
            debug("Failed to open config file bot.conf: $!",1);
        };
        my($line,$key,$val);
        while ($line=<CONF>) {
            next() if $line =~ /^#/; # skip comments
            $line =~ s/[\r\n]//g;
            $line =~ s/^\s+//g;
            next() if !length($line); # skip blank lines
            ($key,$val) = split(/\s+/,$line,2);
            $key = lc($key);
            if (lc($val) eq "on" || lc($val) eq "yes") { $val = 1; }
            elsif (lc($val) eq "off" || lc($val) eq "no") { $val = 0; }
            if ($key eq "die") {
                die("Please edit the file bot.conf to setup your bot's ".
                    "options. Also, read the README file if you haven't ".
                    "yet.\n");
            }
            elsif ($key eq "server") { push(@{$opts{servers}},$val); }
            elsif ($key eq "okurl") { push(@{$opts{okurl}},$val); }
            else { $opts{$key} = $val; }
        }
    }
}


chat_log("Installing handler routines...");

$conn->add_handler('cping', \&on_ping);
$conn->add_handler('crping', \&on_ping_reply);
$conn->add_handler('msg', \&on_msg);
$conn->add_handler('chat', \&on_chat);
$conn->add_handler('public', \&on_public);
$conn->add_handler('caction', \&on_action);
$conn->add_handler('join', \&on_join);
$conn->add_handler('part', \&on_part);
$conn->add_handler('cdcc', \&on_dcc);
$conn->add_handler('topic', \&on_topic);
$conn->add_handler('notopic', \&on_topic);
$conn->add_handler('cversion', \&on_cversion);
$conn->add_global_handler([ 251,252,253,254,302,255 ], \&on_init);
$conn->add_global_handler('disconnect', \&on_disconnect);
$conn->add_global_handler(376, \&on_connect);
$conn->add_global_handler(433, \&on_nick_taken);
$conn->add_global_handler(353, \&on_names);
$conn->add_handler( 'public', \&on_public);


$irc->start;

Now, for the question :P...

How can I make the cmds for the $owner work? Like, for example I have

if ($event->nick eq $owner) {
if (arg =~ /$blah/i) {
$self->privmsg("$owner", "blah");
}
else { print "something went wrong...\n"; }
}

Now how would I make that work? I try over & over, but no go...

-Thanks

-RageD

P.S. It does run, most commands work... But $owner only ones do not...

Wait, nevermind, I fixed :P... I had syntaxed wrong! :P

-RageD
 
Last edited:
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
Appraise.net

We're social

Escrow.com
Spaceship
Escrowly
CryptoExchange.com
Domain Recover
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back