User Control Panel
Advertisements

HELP US, HELP YOU!

Wiredbots Alert Code
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Bot Depot Forum Index -> MSN Protocol
View unanswered posts
Author Message
Vorx
Senior Member
Senior Member


Joined: 21 Dec 2003
Posts: 152

Reputation: 32Reputation: 32Reputation: 32

PostPosted: Fri Jan 02, 2004 7:17 pm    Post subject: Reply with quote

Hi, I know a lot of people are looking for an Alert command, especially for wiredbots so as I'm feeling generous and as so many people have helped me, i'll post mine here.

I've added it as a download so save it into your commands folder as alert.pl

A few things you might want to change:

You might want to change the : in this line:
Code:
<br />if ($msg =~ /^:alert (.*)$/)<br />

The colon is only there because it's my command prefix, so if you call your commands with # ! etc then just replace it.

You will want to change the Alert text from BOTRIX to whatever you want to display.

You can remove this line if you want (including $admin and $owner if you want)
Code:
<br />if ($victim =~ /$mod/) {<br />

But this line could be useful to check for mods, admins and owners etc, if you want to add more then just make a copy of the code between:

######### Mod #########

and

######### Admin ########

Also, you'll need a file called oldname.txt in your main bin folder and write in the name you'd like your bot to revert to after it's shown the alert. (e.g. My bot's name is BOTRIX so in the oldname.txt it simply says BOTRIX.)

I've commented out a few lines for my bot, so experiment with them uncommented etc and let me know if you can make the code cleaner or more efficient.

Right, I think that's it! If you have any questions then feel free to post them in this topic and i'll get back to you ASAP.

Hope it works ok, it works fine for me Very Happy
Back to top
Nate
God Like
God Like


Joined: 12 Nov 2003
Posts: 553

Reputation: 41.3Reputation: 41.3Reputation: 41.3Reputation: 41.3

PostPosted: Fri Jan 02, 2004 7:28 pm    Post subject: Reply with quote

If it's a file in the commands folder you don't have to RE-check if the command is in the message. If the command's not in the message that sub *lazy* never been called. :rolleyes:
Back to top
Vorx
Senior Member
Senior Member


Joined: 21 Dec 2003
Posts: 152

Reputation: 32Reputation: 32Reputation: 32

PostPosted: Fri Jan 02, 2004 7:35 pm    Post subject: Reply with quote

Hi,

Oh right thanks, so I don't actually need this line then:

Code:
<br /> if ($msg =~ /^:alert (.*)$/) <br />


Is that correct?
Back to top
Micky G
Member
Member


Joined: 30 Dec 2003
Posts: 144

Reputation: 31.5Reputation: 31.5Reputation: 31.5

PostPosted: Fri Jan 02, 2004 7:43 pm    Post subject: Reply with quote

Doesnt work

ERROR
Code:
Including alert.pl..Bareword found where operator expected<br />line 15, near "/^/alert"<br />        (Missing operator before alert?)<br />Scalar found where operator expected at commands/alert.pl<br />        (Missing operator before $/?)<br />syntax error at commands/alert.pl line 15, near "/^/alert<br />syntax error at commands/alert.pl line 31, near "else"<br />Compilation failed in require at C:\Documents and Settings<br />Files\BotWD\WiredBots MSN\bot.pl line 70, <DATA> line 1.

ERROR!
Back to top
Mojave
Almost An Agent
Almost An Agent


Joined: 01 Nov 2003
Posts: 1434

Reputation: 66.4

PostPosted: Fri Jan 02, 2004 8:00 pm    Post subject: Reply with quote

If / is your command character you need to escape it in regular expressions: \/
Back to top
Mojave
Almost An Agent
Almost An Agent


Joined: 01 Nov 2003
Posts: 1434

Reputation: 66.4

PostPosted: Fri Jan 02, 2004 8:07 pm    Post subject: Reply with quote

Vorx, other things you can fix:

You should get arguments to a function ($victim,$msg,$self) ONCE as the first line in your function. You'll only create major headaches for yourself later if you get function arguments randomly later in the code.

The code for your three different types of people is EXACTLY THE SAME except for changing the work Mod to Admin to Owner, so get the word you want FIRST at the top and then you only need one copy of the rest of the code.

You should simply save the old name in a variable rather than writing it and reading it from a file. Unfortunately WiredBots code was badly written and got people into this bad habit.

Your 100 line command should only be about 30 lines or less.
Back to top
Micky G
Member
Member


Joined: 30 Dec 2003
Posts: 144

Reputation: 31.5Reputation: 31.5Reputation: 31.5

PostPosted: Fri Jan 02, 2004 8:08 pm    Post subject: Reply with quote

Nope Heres the code ive used -
Code:
sub alert {<br /><br />######## Mod ########<br /><br />if ($victim =~ /$mod/) {<br />#Do the command<br />  <br />  my ($victim,$msg,$self) = @_;  # get the stuff passed by commands.pl<br />      <br />  open( FILE, "oldname.txt" );<br />  $oldname = <FILE>;<br />  close(FILE);<br />  <br />     <br />  if ($msg =~ /^\/alert (.*)$/) <br />  { <br />      # $1 now contains what was in the location of (.*)<br />      $self->set_name("BOTRIX Mod: $1");         # changed $msn to $self, which should work<br />      $self->set_status("HDN");<br />      $self->set_status("NLN");<br />      $self->set_name("$oldname");<br />      #send a confirmination messages <br />      return;<br />      # "Alert ($1) sent!";<br />  }<br />  else<br />  {<br />     return "Alert Failed.  ($msg) did not match";<br />  } <br />}<br />else {<br />$reply = "You are not a moderator.\n";<br />}<br /><br />####### Admin #######<br /><br /><br />if ($victim =~ /$admin/) {<br />#Do the command<br />  <br />  my ($victim,$msg,$self) = @_;  # get the stuff passed by commands.pl<br />      <br />  open( FILE, "oldname.txt" );<br />  $oldname = <FILE>;<br />  close(FILE);<br />  <br />     <br />  if ($msg =~ /^\/alert (.*)$/) <br />  { <br />      # $1 now contains what was in the location of (.*)<br />      $self->set_name("BOTRIX Admin: $1");         # changed $msn to $self, which should work<br />      $self->set_status("HDN");<br />      $self->set_status("NLN");<br />      $self->set_name("$oldname");<br />      #send a confirmination messages <br />      return;<br />      # "Alert ($1) sent!";<br />  }<br />  else<br />  {<br />     return "Alert Failed.  ($msg) did not match";<br />  } <br />}<br />else {<br />$reply = "You are not an admin.\n";<br />}<br />######## Owner ########<br /><br /><br />if ($victim =~ /$owner/) {<br />#Do the command<br />  <br />  my ($victim,$msg,$self) = @_;  # get the stuff passed by commands.pl<br />      <br />  open( FILE, "oldname.txt" );<br />  $oldname = <FILE>;<br />  close(FILE);<br />  <br />     <br />  if ($msg =~ /^\/alert (.*)$/) <br />  { <br />      # $1 now contains what was in the location of (.*)<br />      $self->set_name("BOTRIX Owner: $1");         # changed $msn to $self, which should work<br />      $self->set_status("HDN");<br />      $self->set_status("NLN");<br />      $self->set_name("$oldname");<br />      #send a confirmination messages <br />      return;<br />      # "Alert ($1) sent!";<br />  }<br />  else<br />  {<br />     return "Alert Failed.  ($msg) did not match";<br />  } <br />}<br />else {<br />$reply = "You are not the owner.\n";<br />}<br />}<br />}<br />1;
Back to top
Vorx
Senior Member
Senior Member


Joined: 21 Dec 2003
Posts: 152

Reputation: 32Reputation: 32Reputation: 32

PostPosted: Fri Jan 02, 2004 8:10 pm    Post subject: Reply with quote

Thanks Mojave, I'm not sure I understand though, so could you give me a few lines of code that I should change it to please.
Back to top
Mojave
Almost An Agent
Almost An Agent


Joined: 01 Nov 2003
Posts: 1434

Reputation: 66.4

PostPosted: Fri Jan 02, 2004 8:24 pm    Post subject: Reply with quote

Something like this. You had some code that was never reached (setting replies to "You are not ***"), so I took those out. Hmm, I'm editing it some more, b/c you're right, you don't need to check for ":alert".

Code:
sub alert {<br />   my ($victim,$msg,$self) = @_;  # get the stuff passed by commands.pl<br /><br />   $msg =~ s/^:alert //gi;<br /><br />   open( FILE, "oldname.txt" );<br />   my $oldname = <FILE>;<br />   close(FILE);<br /><br />   my $type = "None";<br /><br />   if ($victim =~ /$mod/)     { $type = "Mod"; }<br />   elsif ($victim =~ /$admin/)   { $type = "Admin"; }<br />   elsif ($victim =~ /$owner/)   { $type = "Owner"; }<br />   else           { return "You are nothing"; }<br /><br />   $self->set_name("BOTRIX $type: $msg");         # changed $msn to $self, which should work<br />   $self->set_status("HDN");<br />   $self->set_status("NLN");<br />   $self->set_name("$oldname");<br />   #send a confirmination messages<br />   return;<br />   # "Alert ($1) sent!";<br />}<br /><br />1;
Back to top
Vorx
Senior Member
Senior Member


Joined: 21 Dec 2003
Posts: 152

Reputation: 32Reputation: 32Reputation: 32

PostPosted: Fri Jan 02, 2004 8:28 pm    Post subject: Reply with quote

OK thanks Mojave, please post the code once you've done your editing Smile

I really appreciate it, thanks!


#### EDIT ####

Hi, i've just tested the code, and when I say :alert message it just popups with:

[QUOTE]
BOTRIX Owner:
Has just signed in
[QUOTE]

Just thought i'd let you know, I might be able to fix it myself.
Back to top
Micky G
Member
Member


Joined: 30 Dec 2003
Posts: 144

Reputation: 31.5Reputation: 31.5Reputation: 31.5

PostPosted: Fri Jan 02, 2004 8:29 pm    Post subject: Reply with quote

Cant get round this - When i do my /alert Test It comes out as
Quote:
Alert Failed.  (/alert Test) did not match


Does this mean its a problem with Not being Mod, Admin, Owner?

EDIT

I aslo get -
Code:
Use of uninitialized value in regexp compilation at commands/alert.pl Line 10
Back to top
Mojave
Almost An Agent
Almost An Agent


Joined: 01 Nov 2003
Posts: 1434

Reputation: 66.4

PostPosted: Fri Jan 02, 2004 8:33 pm    Post subject: Reply with quote

OK, here it is attached. This should work. It compiles, but not tested otherwise.

Also, look into saving the bot's old name in a global variable ($oldname) somewhere in your bot code, so you don't have to keep opening this oldname.txt file.
Back to top
Vorx
Senior Member
Senior Member


Joined: 21 Dec 2003
Posts: 152

Reputation: 32Reputation: 32Reputation: 32

PostPosted: Fri Jan 02, 2004 8:43 pm    Post subject: Reply with quote

Thanks it works fine Smile

To make a global variable in bot.pl where abouts would I put it?

Also, would it be something like:

$oldname = 'BOTRIX';

Thanks again for all your help Smile
Back to top
Mojave
Almost An Agent
Almost An Agent


Joined: 01 Nov 2003
Posts: 1434

Reputation: 66.4

PostPosted: Fri Jan 02, 2004 9:32 pm    Post subject: Reply with quote

In bot.pl, up near where you set your bot's $handle, $password and $admin, add a line:

Code:
$botname = 'BOTRIX';


Then you can delete the file code from alert.pl. I've attached a new one. Now only 21 lines and more readable too. Not bad. Razz
Back to top
Keenie
Almost An Agent
Almost An Agent


Joined: 31 Oct 2003
Posts: 1071

Reputation: 52.4

PostPosted: Sat Jan 03, 2004 7:16 am    Post subject: Reply with quote

better to store the oldname somewhere, so you dont have to rely on opening files
this is what mine looks like Smile

Code:
sub popup<br />{<br />   my ($victim,$msg,$self) = @_;<br />   if($msg eq "!popup") <br />   {<br />      $reply = "Popup a message like when someone signs in. Example !popup Reboot in 30 seconds.";<br />      $colour = "006500";<br />   }<br />   else<br />   {<br />      if ($admins->{$victim} == 1)<br />      {<br />         $msg =~ s/!popup //g;<br />         $popname = uri_escape($msg);<br />         <br /><br />         $msn->set_name($popname);<br />         $msn->set_status("HDN");<br />         $msn->set_status("NLN");<br />         $msn->set_name($details->{'name'});<br />        <br />         $reply = "Popped up '$msg'";<br />      }<br />      else<br />      {<br />         $reply = "Sorry. This command is admin only";<br />      }<br />   $colour = "ff";<br />}<br />return ($reply, $colour);<br />}<br />1;<br />
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Bot Depot Forum Index -> MSN Protocol All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 



Protected by phpBB Security phpBB-TweakS
phpBB Security Has Blocked 9 Exploit Attempts.
Antispam Captcha Mod by phpbb-security.com
Powered by phpBB © 2001, 2005 phpBB Group