Channel Lockdown Script

Discussion about Perl, TCL or Python scripts and C/C++ plugins (using and writing them).

Channel Lockdown Scr

Postby Schiz0 » 26 Nov 2005 22:06

I'm working on a script to lockdown a channel. Basicly announce that the channel is locked down in bright colors, then set a few modes. I orginally started writing it in TCL, because I'm the most familure with it (Due to working with eggdrops), but I realized that you can't register it with xchat, which makes unloading harder, and I did have a few problems with it. Here's what I wrote:

Code: Select all
alias lockdown {
   if {$_rest == ""} {
      # If I didn't specify a channel, use the current one
      set chan [getinfo channel]
      command $chan "me %C4,8%BCHANNEL IS BEING LOCKED DOWN"
            # %C4,8 = Red on Yellow
      command $chan "MODE $chan +RCm"
      command #chan "me %C4,8%B$chan is locked down"
      complete EAT_PLUGIN
   } else {
      # If I did specify a channel...
      command $_rest "me %C4,8%BCHANNEL IS BEING LOCKED DOWN"
      command $_rest "MODE $_rest +RCm"
      command #chan "me %C4,8%B$_rest is locked down"
      complete EAT_PLUGIN
   }
}

The problem with that is, 1. The colors aren't displayed....it just prints the %C formatting, and 2. It doesn't show up in the plugins list for easy unloading/loading.
I then started messing around with perl, but I got almost nowhere with it:
Code: Select all
Xchat::register( "Lockdown", "1.0", "Channel Lockdown Script", \&unload );
Xchat::hook_command( "lockdown", "lockdown" );

sub lockdown {

}

sub unload {
   Xchat::print( "Lockdown Script Unloaded" );
}


As for the sub lockdown...I'm not sure how perl if statements work...or how to use them...so I have no idea for that.
If anyone can help me out in getting either one of these scripts to work (I don't care which one), that would rock.

Thanks!
~Schiz0
Schiz0
 
Posts: 194
Joined: 12 Dec 2004 23:41
Location: USA

Postby Tom_B » 26 Nov 2005 23:11

This should do what you're doing:

Code: Select all
Xchat::register( "Lockdown", "1.0", "Channel Lockdown Script", \&unload );
Xchat::hook_command( "lockdown", "lockdown" );

sub lockdown {
   $channel = (undef eq $_[0][1]) ? Xchat::get_info("channel") : $_[0][1];
   Xchat::command("msg $channel Channel is being locked down.");
   Xchat::command("mode $chanel +RCm");
}


I'm guessing unlockdown would be the opposite using -RCm.
Tom_B
 
Posts: 33
Joined: 20 Nov 2005 02:04

Postby Schiz0 » 27 Nov 2005 01:26

Works awesome...other then one thing, of course. Haha....

When I'm in..say...channel #Schiz0, and I type /lockdown it sends the message, and sets the modes perfectly. But if I'm focused on any other channel, and I type /lockdown #Schiz0 it sends the message to #Schiz0, but it sets the modes on the current channel.
Also, is there a way to have it send the message with colors?
Thanks,
~Schiz0


** EDIT **
I found out why it was setting modes on the wrong channel.
Code: Select all
Xchat::command("mode $chanel +RCm");

Should of been:
Code: Select all
Xchat::command("mode $channel +RCm");


(Typo in the $channel var)

The colors question is still pending...
Thanks!
Schiz0
 
Posts: 194
Joined: 12 Dec 2004 23:41
Location: USA

Postby Khisanth » 27 Nov 2005 07:31

Tom_B wrote:This should do what you're doing:

Code: Select all
Xchat::register( "Lockdown", "1.0", "Channel Lockdown Script", \&unload );
Xchat::hook_command( "lockdown", "lockdown" );

sub lockdown {
   $channel = (undef eq $_[0][1]) ? Xchat::get_info("channel") : $_[0][1];
   Xchat::command("msg $channel Channel is being locked down.");
   Xchat::command("mode $chanel +RCm");
}


I'm guessing unlockdown would be the opposite using -RCm.


ACK! DON'T use
Code: Select all
undef eq $_[0][1]
use
Code: Select all
defined($_[0][1])
instead
perl would have caught the errors for you if you turned on warnings. strict is also very useful but you might not know enough Perl to "comply with it's requirements".

As for the colors, see viewtopic.php?t=84
Khisanth
 
Posts: 1724
Joined: 10 Jun 2004 05:23

Postby Flash » 27 Nov 2005 09:29

Unsure if this is the "proper" way of doing it, but to get colours just blat out the actual mirc codes.

Eg:

my $pretty_string = "\002Bold\002 \00310Colour 10\003 End of colours.";
Flash
 
Posts: 173
Joined: 29 Jan 2005 18:41

Postby Tom_B » 27 Nov 2005 14:04

ACK! DON'T use


Ah, thanks. I'm not that great at perl, and it shows :p
Tom_B
 
Posts: 33
Joined: 20 Nov 2005 02:04

Postby Alchera » 27 Nov 2005 14:40

Flash wrote:Unsure if this is the "proper" way of doing it, but to get colours just blat out the actual mirc codes.

Eg:

my $pretty_string = "\002Bold\002 \00310Colour 10\003 End of colours.";

Not really "mIRC" anything.

This post, although on an eggdrop site applies to XChat.

Code: Select all
\003x - x = colours 0 to 15 inclusive
"Live Outside The Square You Live In"
"Vivez hors du quartier où vous habitez"
User avatar
Alchera
 
Posts: 939
Joined: 28 May 2005 16:30
Location: Ballarat Victoria, Australia

Postby Schiz0 » 27 Nov 2005 17:45

Hmm.....I replaced it with Khisanth said...but now it's trying to send a message to: 8CHANNEL ...who doesn't exist..and btw, the color great now :-D

Here's what I have (I added an unlockdown sub too, just copyed and pasted, but changed the + to a - and the message):
Code: Select all
Xchat::register( "Lockdown", "1.0", "Channel Lockdown Script", \&unload );
Xchat::hook_command( "lockdown", "lockdown" );
Xchat::hook_command( "unlockdown", "unlockdown" );

sub lockdown {
   $channel = (defined($_[0][1]) ? Xchat::get_info("channel") : $_[0][1]);
   Xchat::command("mode $channel +RCm");
   Xchat::command("msg $channel \002\0034,8CHANNEL IS BEING LOCKED DOWN");
}

sub unlockdown {
   $channel = (defined($_[0][1]) ? Xchat::get_info("channel") : $_[0][1]);
   Xchat::command("mode $channel -RCm");
   Xchat::command("msg $channel \002\0034,8Channel is now back to normal.");
}

sub unload {
   Xchat::print( "Lockdown Script Unloaded" );
}

Xchat::print "Channel Lockdown Script loaded.";
Schiz0
 
Posts: 194
Joined: 12 Dec 2004 23:41
Location: USA

Postby Khisanth » 28 Nov 2005 04:24

Well lets consider the logic of
Code: Select all
$channel = (defined($_[0][1]) ? Xchat::get_info("channel") : $_[0][1]);


If $_[0][1] is defined then assign the return value of Xchat::get_info("channel") to $channel.
If $_[0][1] is is NOT defined then assign $_[0][1] to $channel.

Do you see what the problem is? :)
Khisanth
 
Posts: 1724
Joined: 10 Jun 2004 05:23


Return to Scripts and Plugins

Who is online

Users browsing this forum: Google [Bot] and 1 guest