Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

10 443 Posts in 5 818 Topics- by 1 216 Members - Latest Member: santini862

16 October 2019, 12:37
Select Language English | Russian ru | German
Main PageIRC Client KVIrc forumKVIrc discussionKVIrc scriptingClear all windows (with arguments)
Pages: [1] 2
Print
Author Topic: Clear all windows (with arguments)  (Read 26576 times)
0 Members and 1 Guest are viewing this topic.
b0nk
Новичок
*

Репутация: 0
Gender: Male
Posts: 13



View Profile
« on: 8 December 2012, 06:49 »

Here's how the script should behave:

/clearall - Clears the output of all windows in all IRC contexts(networks).
/clearall q - Clears the output of all query windows in the current IRC context.
/clearall c - Clears the output of all channel windows in the current context.
/clearall c t - Does the same as above but prints the topic after clearing the output.
/clearall a - Clears the output of all windows in the current IRC context.
/clearall a t - Does the same as above but prints the topic on all channel windows (and not query windows of course).

The code returns:

[KVS] Compilation Error: Found character ')' (unicode 29) where an instruction was expected
[KVS]   in script context "clearall", line 19, near character 35
[KVS] Runtime Error: Error in inner alias command call 'clearall', called from this context
[KVS]   in script context "commandline::kvs", line 1, near character 1

So let's first make this script work before we start improving it. I feel like it could have more funcionalities.
I wrote this at 3am so maybe I'm making an obvious mistake in the code but help me out here.

Code:
%arg1 = $0;
%arg2 = $1;

%querys = "q";
%channels = "c";
%topic = "t";
%all = "a";

%chan = "channel";


if($str.cmp(%arg1,%querys) == 0){

foreach(%i,$window.list(query))
window.clearOutput %i;
halt;
}

if($str.cmp(%arg1,%channels) == 0)){

foreach(%i,$window.list(channel,$ic)){
window.clearOutput %i;

if($str.cmp(%arg2,%topic) == 0)
topic %i;
}
halt;
}

if($str.cmp(%arg1,%all) == 0)){

foreach(%i,$window.list(all)){
window.clearOutput %i;
%type = $window.type %i;

if($str.cmp(%type, %chan) == 0 && $str.cmp(%arg2,%topic) == 0)
topic %i;
}
halt;
}

if(!$0)){

foreach(%i,$window.list(all,all))
window.clearOutput %i;
halt;
}

echo "Bad arguments!";
echo "Usage: /clearall <arg1> <arg2>";
echo "arg1: c -> channels";
echo "arg1: q -> querys";
echo "arg1: a -> all windows";
echo "arg2: t -> prints channel topic after clearing OPTIONAL (do not use with 'q')";
« Last Edit: 10 December 2012, 21:44 by b0nk » Logged
alexzulu
Постоялец
***

Репутация: 34
Posts: 211



View Profile Email
« Reply #1 on: 8 December 2012, 12:38 »

line 19
Code:
if($str.cmp(%arg1,%channels)) == 0){
fixed
Code:
if($str.cmp(%arg1,%channels) == 0){
Logged

Network: freenode. Channels: #kvirc and #kvirc-ru
b0nk
Новичок
*

Репутация: 0
Gender: Male
Posts: 13



View Profile
« Reply #2 on: 10 December 2012, 01:24 »

Thank you alexzulu. I knew it was a dumb mistake.

After a few fixes, the only thing not working like it should is running

Code:
/clearall a t

Code:
%arg1 = $0;
%arg2 = $1;

%querys = "q";
%channels = "c";
%topic = "t";
%all = "a";

%chan = "channel";


if($str.cmp(%arg1,%querys) == 0){

foreach(%i,$window.list(query))
window.clearOutput %i;
halt;
}

if($str.cmp(%arg1,%channels) == 0){

foreach(%i,$window.list(channel,$ic)){
window.clearOutput %i;

if($str.cmp(%arg2,%topic) == 0)
topic $target(%i);
}
halt;
}

if($str.cmp(%arg1,%all) == 0){

foreach(%i,$window.list(all)){
window.clearOutput %i;
%type = $window.type %i;

if($str.cmp(%type,%chan) == 0)
if($str.cmp(%arg2,%topic) == 0)
topic $target(%i);
}
halt;
}

if(!$0){

foreach(%i,$window.list(all,all))
window.clearOutput %i;
halt;
}

echo "Bad arguments!";
echo "Usage: /clearall <arg1> <arg2>";
echo "arg1: c -> channels";
echo "arg1: q -> querys";
echo "arg1: a -> all windows";
echo "arg2: t -> prints channel topic after clearing OPTIONAL (do not use with 'q')";

It clears the outputs of all windows in the IRC context - Good.
It doesn't print the channel topic on channel windows like on
Code:
/clearall c t
- Bad.
« Last Edit: 10 December 2012, 21:44 by b0nk » Logged
ambossarm
Постоялец
***

Репутация: 11
Gender: Male
Posts: 148



View Profile
« Reply #3 on: 10 December 2012, 02:34 »

no clue what exactly you mean. I would check arg1 at the beginning and set q,c and/or t. After that one if for each flag. Isn't your $str.cmp logic inverted?

Should %type not be $window.type(%i) instead with a space?
Logged
b0nk
Новичок
*

Репутация: 0
Gender: Male
Posts: 13



View Profile
« Reply #4 on: 10 December 2012, 05:49 »

Quote
Should %type not be $window.type(%i) instead with a space?

This was it. It works as intended now.

Code:
%arg1 = $0;
%arg2 = $1;

%querys = "q";
%channels = "c";
%topic = "t";
%all = "a";

%chan = "channel";


if($str.cmp(%arg1,%querys) == 0){

foreach(%i,$window.list(query))
window.clearOutput %i;
halt;
}

if($str.cmp(%arg1,%channels) == 0){

foreach(%i,$window.list(channel,$ic)){
window.clearOutput %i;

if($str.cmp(%arg2,%topic) == 0)
topic $target(%i);
}
halt;
}

if($str.cmp(%arg1,%all) == 0){

foreach(%i,$window.list(all)){
window.clearOutput %i;
%type = $window.type(%i);

if($str.cmp(%type,%chan) == 0)
if($str.cmp(%arg2,%topic) == 0)
topic $target(%i);
}
halt;
}

if(!$0){

foreach(%i,$window.list(all,all))
window.clearOutput %i;
halt;
}

echo "Bad arguments!";
echo "Usage: /clearall <arg1> <arg2>";
echo "arg1: c -> channels";
echo "arg1: q -> querys";
echo "arg1: a -> all windows";
echo "arg2: t -> prints channel topic after clearing OPTIONAL (do not use with 'q')";
« Last Edit: 10 December 2012, 21:44 by b0nk » Logged
Rizon
Новичок
*

Репутация: 0
Posts: 17


Noctis


View Profile WWW Email
« Reply #5 on: 10 December 2012, 19:25 »

Very good friend, and I use it in my KVirc as an alias, hey can you make an addon of this script? Would be great if you would make GUI and you will have to alexzulu to put in the repository so kvirc.info/addons/4
Logged

Yeah =) time zero : http://kvircode.blogspot.com
b0nk
Новичок
*

Репутация: 0
Gender: Male
Posts: 13



View Profile
« Reply #6 on: 10 December 2012, 21:33 »

I changed the code a bit.

Running "/clearall a (t)" will no longer clears the IRC context (I think it's better this way).
Only "/clearall" (no arguments) will clear all windows.

Code:
%arg1 = $0;
%arg2 = $1;

%querys = "q";
%channels = "c";
%topic = "t";
%all = "a";

%chan = "channel";
%console = "console";


if($str.cmp(%arg1,%querys) == 0){

foreach(%i,$window.list(query))
window.clearOutput %i;
halt;
}

if($str.cmp(%arg1,%channels) == 0){

foreach(%i,$window.list(channel,$ic)){
window.clearOutput %i;

if($str.cmp(%arg2,%topic) == 0)
topic $target(%i);
}
halt;
}

if($str.cmp(%arg1,%all) == 0){

foreach(%i,$window.list(all)){
%type = $window.type(%i);
if($str.cmp(%type,%console) != 0)
window.clearOutput %i;

if($str.cmp(%type,%chan) == 0)
if($str.cmp(%arg2,%topic) == 0)
topic $target(%i);
}
halt;
}

if(!$0){

foreach(%i,$window.list(all,all)){
%type = $window.type(%i);
if($str.cmp(%type,%console) != 0)
window.clearOutput %i;
}
halt;
}

echo "Bad arguments!";
echo "Usage: /clearall <arg1> <arg2>";
echo "arg1: c -> channels";
echo "arg1: q -> querys";
echo "arg1: a -> all windows";
echo "arg2: t -> prints channel topic after clearing OPTIONAL (do not use with 'q')";

Rizon:
I wouldn't know exactly how to do that. I have no experience making addons.
All scripts I make are used as aliases.
« Last Edit: 10 December 2012, 21:43 by b0nk » Logged
alexzulu
Постоялец
***

Репутация: 34
Posts: 211



View Profile Email
« Reply #7 on: 11 December 2012, 01:56 »

script will be placed in repository tomorrow.
Logged

Network: freenode. Channels: #kvirc and #kvirc-ru
alexzulu
Постоялец
***

Репутация: 34
Posts: 211



View Profile Email
« Reply #8 on: 11 December 2012, 17:22 »

optimized.Smiley
Code:
alias(clearall::clearall)
{
if($0 == "q" || $0 == "c" || $0 == "a" || !$0){
if($0 == "q"){
if($window.list(query)){
foreach(%i,$window.list(query))
window.clearOutput %i;
}
}
if($0 == "c"){
if($window.list(channel)){
foreach(%i,$window.list(channel)){
window.clearOutput %i;
if($1 == "t")
topic $target(%i);
}
}
}
if($0 == "a" || !$0){
foreach(%i,$window.list(all)){
%type = $window.type(%i);
if(%type == "console" || %type == "channel")
window.clearOutput %i;
if(%type == "channel" && $1 == "t")
topic $target(%i);
}
}
} else {
echo "Bad arguments!";
echo "Usage: /clearall <arg1> <arg2>";
echo "arg1: c -> channels";
echo "arg1: q -> querys";
echo "arg1: a -> all windows";
echo "arg2: t -> prints channel topic after clearing OPTIONAL (do not use with 'q')";
}
}
« Last Edit: 11 December 2012, 18:20 by alexzulu » Logged

Network: freenode. Channels: #kvirc and #kvirc-ru
b0nk
Новичок
*

Репутация: 0
Gender: Male
Posts: 13



View Profile
« Reply #9 on: 11 December 2012, 21:27 »

Thank you alexzulu. It's even easier to read aswell, at least for me.
« Last Edit: 11 December 2012, 22:27 by b0nk » Logged
alexzulu
Постоялец
***

Репутация: 34
Posts: 211



View Profile Email
« Reply #10 on: 11 December 2012, 22:09 »

addons package http://kvirc.info/addons/pool/4/clearall-0.0.1.tar.gz with toolbar
Logged

Network: freenode. Channels: #kvirc and #kvirc-ru
b0nk
Новичок
*

Репутация: 0
Gender: Male
Posts: 13



View Profile
« Reply #11 on: 11 December 2012, 22:27 »

There's a mistake there.
In this if block
Code:
if($0 == "a" || !$0){

Change:
line 20
Code:
if(%type == "console" || %type == "channel")
to
Code:
if(%type == "query" || %type == "channel")

I've also made a change to the code.
Calling "/clearall a t" will clear all the windows in the IRC context including the console but now it show the topic on channel windows AND the MOTD on the console.

Code:
if($0 == "q" || $0 == "c" || $0 == "a" || !$0){
if($0 == "q"){
if($window.list(query)){
foreach(%i,$window.list(query))
window.clearOutput %i;
}
}
if($0 == "c"){
if($window.list(channel)){
foreach(%i,$window.list(channel)){
window.clearOutput %i;
if($1 == "t")
topic $target(%i);
}
}
}
if($0 == "a" || !$0){
foreach(%i,$window.list(all)){
window.clearOutput %i;
%type = $window.type(%i);

if(%type == "channel" && $1 == "t")
topic $target(%i);
if(%type == "console" && $1 == "t")
motd $target(%i);
}
}
}
else{
echo "Bad arguments!";
echo "Usage: /clearall <arg1> <arg2>";
echo "No arguments will clear all windows";
echo "arg1: c -> channels";
echo "arg1: q -> querys";
echo "arg1: a -> all windows";
echo "arg2: t -> prints channel topic and motd after clearing (OPTIONAL) (do not use with 'q')";
}

Also, I tried the addon in the repo.
The buttons on top are a bit limited, all they do is clear and none of them print the channel topic on channel windows.

If anything fails post here and thank you again for the addition to the repo.
Logged
Rizon
Новичок
*

Репутация: 0
Posts: 17


Noctis


View Profile WWW Email
« Reply #12 on: 12 December 2012, 17:10 »

can you put in the addon, the option  c t? is very usefull. i love this option.
Logged

Yeah =) time zero : http://kvircode.blogspot.com
alexzulu
Постоялец
***

Репутация: 34
Posts: 211



View Profile Email
« Reply #13 on: 12 December 2012, 19:29 »

/clearall::clearall a t
Logged

Network: freenode. Channels: #kvirc and #kvirc-ru
alexzulu
Постоялец
***

Репутация: 34
Posts: 211



View Profile Email
« Reply #14 on: 12 December 2012, 20:15 »

addon reload. new variant.
Logged

Network: freenode. Channels: #kvirc and #kvirc-ru
Pages: [1] 2
Print
Jump to:  

Theme orange-lt created by panic