Now what if I want to use the Juggernaut !Menu command in White Warrior???
Juggernaut !Menu command:
Code:
sub menu {
my ($self,$client,$msg,$listener) = @_;
my $reply;
# List of Categories (you'll have to update this list if you
# add a custom category)
my %cat = (
a => ':: General Commands ::',
1 => 'General',
2 => 'Fun & Games',
3 => 'Points Earning',
4 => 'Random Stuff',
5 => 'General Utilities',
6 => 'Bot Utilities',
7 => 'Feedback',
b => ':: Higher-Level Commands ::',
8 => 'Moderator Commands',
9 => 'Administrator Commands',
10 => 'Botmaster Commands',
);
# The order the categories are to go in (letter values are used as headers/dividers)
my @order = (
"a", 1, 2, 3, 4, 5, 6, 7, "b", 8, 9, 10,
);
# If a category has been chosen...
if (length $msg > 0) {
# Exiting?
if (lc($msg) eq 'exit') {
delete $chaos->{_users}->{$client}->{callback};
return "Alright, we're done with the menu.";
}
# If it exists...
if ((exists $cat{$msg} && $cat !~ /[^0-9]/) || ($msg eq "lost")) {
my $category = $cat{$msg};
# Sort the keys.
sort (keys %{$chaos->{_system}->{commands}});
foreach my $key (keys %{$chaos->{_system}->{commands}}) {
if (exists $chaos->{_system}->{commands}->{$key}->{Category} && $chaos->{_system}->{commands}->{$key}->{Category} eq $category) {
# If this command has restricted access...
if (exists $chaos->{_system}->{commands}->{$key}->{Restrict}) {
my $restrict = $chaos->{_system}->{commands}->{$key}->{Restrict};
# Restrictions are set.
if ($restrict =~ /mod/i && isMod($client,$listener) == 0) {
return "This category contains restricted commands that may only "
. "be viewed by Moderators or higher.";
}
if ($restrict =~ /admin/i && isAdmin($client,$listener) == 0) {
return "This category contains restricted commands that may only "
. "be viewed by Administrators or higher.";
}
if ($restrict =~ /master/i && isMaster($client,$listener) == 0) {
return "This category contains restricted commands that may only "
. "be viewed by Botmasters.";
}
}
# Use this command.
push (@commands, $key);
}
else {
# If it doesn't exist...
if ($msg eq "lost" && !exists $chaos->{_system}->{commands}->{$key}->{Description}) {
push (@lost, $key);
}
}
}
# Generate the reply.
if ($msg eq "lost") {
my $lostcmd = join ("\n", @lost);
$reply = ":: Lost Commands ::\n"
. "These commands are missing the hashref footers:\n\n"
. "$lostcmd\n\n";
}
else {
$reply = ":: $cat{$msg} ::\n\n";
foreach my $cmd (@commands) {
# Don't show hidden commands.
if (!defined $chaos->{_system}->{commands}->{$cmd}->{Hidden}) {
$reply .= $chaos->{_system}->{config}->{commandchar} . "$cmd - ";
if (lc($chaos->{_system}->{commands}->{$cmd}->{Listener}) ne 'all') {
$reply .= "($chaos->{_system}->{commands}->{$cmd}->{Listener}) ";
}
$reply .= $chaos->{_system}->{commands}->{$cmd}->{Description} . "\n";
}
}
}
}
else {
return "Invalid category. Type \'exit\' to exit the menu.";
}
}
else {
$chaos->{_users}->{$client}->{callback} = 'menu';
$reply = "~ Main Menu ~\n\n"
. "Type a number for a category listed below:\n";
# Show the categories in correct order.
foreach my $part (@order) {
if ($part =~ /[A-Za-z]/i) {
# Header.
$reply .= "\n" . $cat{$part} . "\n";
}
else {
# Category.
$reply .= "$part :: $cat{$part}\n";
}
}
}
# Reply Footer.
$reply .= "\nFor help with any commands, type !usage <lt>command<gt>";
You would need to figure out how the two different bots go about doing different things. Most of the juggernaut commands have comments to make this easier on you. Once you have that figured out, you need to figure out which things are different between them, and then change it. I don't know white warrior, so I can't actually help with the converting. Sorry
There are certain things which you can change between them, however the menu is not one of them. My "Say" command is much simpler than Cer's, but you can use his.
Here's how:
Every command in White Warrior will start off with an "if" statement, such as:
Code:
if ($msg =~ /^!say(.*)$/){
In Juggernaut, it will start with:
Code:
sub say {
# Get variables from the shift.
my ($self,$client,$msg,$listener) = @_;
So, to start any White Warrior command, you need to use an "if" statement.
The next bit just needs a bit of tweaking for the bot. For a start, White Warrior won't "return" anything, and instead will "$self->sendmsg("")".
In the "IF" statement, the "(.*)" is called a wildcard. This is where the non-persistant data will be. You can have more complicated wildcards, but for now we will stick to "(.*)".
When you want to use wildcard data in your command, it is automatically assigned a number, ie $1. If you have two wildcards, then the second one will be $2, etc.
Example script:
Code:
my $msg = "HelloXlala##boo";
if ($msg =~ /^Hello(.*)lala##(.*)$/)
{
my $X = $1;
my $boo = $2;
print "X: $x\nBoo: $boo\n";
}
To convert, you need to assign the wildcard to a variable (good coding practice), and then replace it with "$msg".
Here, I am assigning the wildcard to the variable "$wildcard".
Code:
$wildcard = $1;
You then need to replace all "$msg" with "$wildcard".
thanks for your answer, but the script you gave me now as end result doesn't work..
Please help me!
Is there a possibility to use "sub" AND "if" ?
by messing a bit with the template?
ceceboyken
EDIT:
okay.. I forgot to place "$wildcard = $1;" in the script, so that's ok.
but now another problem:
when i type "!say this is a test" the bot gives me as result "thisisatest"
and when i only type "!say" it says "1" ..
Check your coding for the say command. I think you might be removing all the spaces without even knowing it. And to keep it from saying 1, you will want to add something in to make sure that the person has some text after the command part.
That's to do with Juggernaut's command, from the way it was made. If you don't like it, use the origional say command that came with my bot
yes, yours is much easier (White Warrior), but i just want to be able "converting" it..
Another question.. ( i hope the last one ... )
can you get the mistakes out of this script cause i don't find them...
==> ( i wan't to hide the dos window with a command )
Code:
if ($msg =~ /!dos (.*)$/i) {
if (length $1 == 0) { $self->sendmsg("Don't forget the argument!");
}
$wildcard = "$1";
# See if there's a message.
if (length $1 > 0) {
# Conversions.
$1 = "show" if $1 =~ /^(on|visible|show)$/i;
$1 = "hide" if $1 =~ /^(off|hidden|hide)$/i;
# Requires Win32::GUI.
use Win32::GUI;
# Get the Perl window.
my $dos = GUI::GetPerlWindow();
if ($msg =~ /^!dos (.*)$/i)
{
$wildcard = "$1"; # Change $msg and $1 to $wildcar
# Conversions.
$wildcard = "show" if $wildcard =~ /^(on|visible|show)$/i;
$wildcard = "hide" if $wildcard =~ /^(off|hidden|hide)$/i;
# Requires Win32::GUI.
# Make sure you've installed it
use Win32::GUI;
# Get the Perl window.
my $dos = GUI::GetPerlWindow();
# Commands.
if ($wildcard eq "show")
{
GUI::Show ($dos);
$self->sendmsg("DOS-Window visible.");
}
elsif ($wildcard eq "hide")
{
GUI::Hide ($dos);
$self->sendmsg("DOS-Window hidden.");
}
else
{
# THIS is where you have your error
$self->sendmsg("Remember your argument!");
}
}
_________________ ~ Josh
[ Need bot hosting on a dedicated server? PM me. ]
# See if somebody won.
my $who_wins;
my @winners = (
"a1-b1-c1",
"a1-a2-a3",
"a1-b2-c3",
"b1-b2-b3",
"c1-c2-c3",
"a2-b2-c2",
"a3-b3-c3",
"c1-b2-a3",
);
foreach my $winner (@winners) {
my ($a,$b,$c) = split(/\-/, $winner);
if
($chaos->{_users}->{$client}->{_games}->{ttt}->{$a} eq "X" &&
$chaos->{_users}->{$client}->{_games}->{ttt}->{$b} eq "X" &&
# See if we have a winner.
if ($who_wins eq "p") {
# Get our number of points...
my $points = 0;
$points++ if $caa eq "X";
$points++ if $cba eq "X";
$points++ if $cca eq "X";
$points++ if $cab eq "X";
$points++ if $cbb eq "X";
$points++ if $ccb eq "X";
$points++ if $cac eq "X";
$points++ if $cbc eq "X";
$points++ if $ccc eq "X";
$reply .= "\nRemote Player ($client) wins!
This is one of the more complicated commands that Juggernaut has. REmove anything about $listeners, and change $chaos-> to $self->. Oh, also, change $client to $username. There's more, but see how you get on with that, and try to find some more... _________________ ~ Josh
[ Need bot hosting on a dedicated server? PM me. ]
# See if somebody won.
my $who_wins;
my @winners = (
"a1-b1-c1",
"a1-a2-a3",
"a1-b2-c3",
"b1-b2-b3",
"c1-c2-c3",
"a2-b2-c2",
"a3-b3-c3",
"c1-b2-a3",
);
foreach my $winner (@winners) {
my ($a,$b,$c) = split(/\-/, $winner);
if
($self->{_users}->{$username}->{_games}->{ttt}->{$a} eq "X" &&
$self->{_users}->{$username}->{_games}->{ttt}->{$b} eq "X" &&
# See if we have a winner.
if ($who_wins eq "p") {
# Get our number of points...
my $points = 0;
$points++ if $caa eq "X";
$points++ if $cba eq "X";
$points++ if $cca eq "X";
$points++ if $cab eq "X";
$points++ if $cbb eq "X";
$points++ if $ccb eq "X";
$points++ if $cac eq "X";
$points++ if $cbc eq "X";
$points++ if $ccc eq "X";
$reply .= "\nRemote Player ($username) wins!