| View previous topic :: View next topic |
| Author |
Message |
illusionist Voice
Joined: 09 Mar 2020 Posts: 25
|
Posted: Sun Jun 21, 2020 5:51 pm Post subject: [SOLVED] Kick Counter HeLp for Kick Via PVT Msg |
|
|
| Code: |
#Binds
bind pub o !kick pub_kick
bind msg o kick msg_kick
#Kick Process
proc msg_kick {nick uhost hand rest} {
global botnick
set chan [lindex $rest 0] ; set knick [lrange $rest 1 end]
if {$chan == "#" || $chan == ""} {putquick "NOTICE $nick :Command: /msg $botnick kick <#channel> <nickname(s)> \[!reason\]" ; return 0}
if {![string match "#*" $chan]} {set chan "#$chan"}
if {$knick == ""} {putquick "NOTICE $nick :Command: /msg $botnick kick $chan <nickname(s)> \[!reason\]" ; return 0}
if {![validchan $chan]} {putquick "NOTICE $nick :I am not on channel: $chan, check out my channel list." ; return 0}
if {![botisop $chan]} {putquick "NOTICE $nick :I appologize, but I am not an Operator on channel: $chan. Your command cannot be perform." ; return 0}
set knicks "" ; set ownicks "" ; set nonenicks "" ; set reason ""
foreach x $knick {
if {(![onchansplit $x $chan]) && (![isbotnick $x])} {
if {[string match "!*" $x]} {set reason "\002\037\0037(\017\00312\u00bb\0031\002j\002a\0034\002D\002u\0031\u00ae\00312\u00ab\0037\002\037)\017 $x"} else {if {[matchattr [nick2hand $x $chan] m]} {append ownicks " $x"} else {if {![onchan $x $chan]} {append nonenicks " $x"} else {append knicks "$x,"}}}
}
}
if {$nonenicks != ""} {putquick "NOTICE $nick :$nonenicks is not on channel: $chan."}
if {$ownicks != ""} {putquick "NOTICE $nick :$ownicks are my \[Master(s)\], and will I will not Kick them from channel: $chan."}
if {$knicks != ""} {
if {$reason == ""} {set reason "\002\037\0037(\017\00312\u00bb\0031\002j\002a\0034\002D\002u\0031\u00ae\00312\u00ab\0037\002\037)\017 \00315Requested by: \00314$nick"} ; putkick $chan $knicks $reason
putcmdlog "<<$nick>> !$hand! Kick: ${knicks} from channel: $chan. Reason: $reason."
} ; return 0
}
proc pub_kick {nick uhost hand chan rest} {
global botnick
set chans "" ; set channel [lindex $rest 0]
if {![string match "#*" $channel]} {set channel $chan ; append chans "$channel $rest "} else {append chans " $rest"}
set knicks [lindex $chans 1]
if {$knicks == ""} {putquick "NOTICE $nick :Command: ${jaDu}kick $chan <nickname(s)> \[!reason\]" ; return 0}
msg_kick $nick $uhost $hand $chans
}
|
| Quote: |
Help me To add a Kick Conter Script In This Short kick via msg Code
Thanks in advance
|
Last edited by illusionist on Wed Sep 01, 2021 11:07 pm; edited 5 times in total |
|
| Back to top |
|
 |
CrazyCat Revered One

Joined: 13 Jan 2002 Posts: 1032 Location: France
|
Posted: Sun Jun 21, 2020 6:39 pm Post subject: |
|
|
So you just want to count the number of kicks ? I simply add 2 lines.
Note that the counter will be reset each time you restart / rehash the eggdrop.
| Code: | #Binds
bind pub o !kick pub_kick
bind msg o kick msg_kick
# Counter
set counter 0
#Kick Process
proc msg_kick {nick uhost hand rest} {
global botnick
set chan [lindex $rest 0] ; set knick [lrange $rest 1 end]
if {$chan == "#" || $chan == ""} {putquick "NOTICE $nick :Command: /msg $botnick kick <#channel> <nickname(s)> \[!reason\]" ; return 0}
if {![string match "#*" $chan]} {set chan "#$chan"}
if {$knick == ""} {putquick "NOTICE $nick :Command: /msg $botnick kick $chan <nickname(s)> \[!reason\]" ; return 0}
if {![validchan $chan]} {putquick "NOTICE $nick :I am not on channel: $chan, check out my channel list." ; return 0}
if {![botisop $chan]} {putquick "NOTICE $nick :I appologize, but I am not an Operator on channel: $chan. Your command cannot be perform." ; return 0}
set knicks "" ; set ownicks "" ; set nonenicks "" ; set reason ""
foreach x $knick {
if {(![onchansplit $x $chan]) && (![isbotnick $x])} {
if {[string match "!*" $x]} {set reason "\002\037\0037(\017\00312\u00bb\0031\002j\002a\0034\002D\002u\0031\u00ae\00312\u00ab\0037\002\037)\017 $x"} else {if {[matchattr [nick2hand $x $chan] m]} {append ownicks " $x"} else {if {![onchan $x $chan]} {append nonenicks " $x"} else {append knicks "$x,"}}}
}
}
if {$nonenicks != ""} {putquick "NOTICE $nick :$nonenicks is not on channel: $chan."}
if {$ownicks != ""} {putquick "NOTICE $nick :$ownicks are my \[Master(s)\], and will I will not Kick them from channel: $chan."}
if {$knicks != ""} {
if {$reason == ""} {set reason "\002\037\0037(\017\00312\u00bb\0031\002j\002a\0034\002D\002u\0031\u00ae\00312\u00ab\0037\002\037)\017 \00315Requested by: \00314$nick"} ;
putkick $chan $knicks $reason
# kick is done, update counter
incr ::counter 1
putcmdlog "<<$nick>> !$hand! Kick: ${knicks} from channel: $chan. Reason: $reason."
} ; return 0
}
proc pub_kick {nick uhost hand chan rest} {
global botnick
set chans "" ; set channel [lindex $rest 0]
if {![string match "#*" $channel]} {set channel $chan ; append chans "$channel $rest "} else {append chans " $rest"}
set knicks [lindex $chans 1]
if {$knicks == ""} {putquick "NOTICE $nick :Command: ${jaDu}kick $chan <nickname(s)> \[!reason\]" ; return 0}
msg_kick $nick $uhost $hand $chans
} |
_________________ https://www.eggdrop.fr - French IRC network
Offer me a coffee - Do not ask me help in PM, we are a community. |
|
| Back to top |
|
 |
illusionist Voice
Joined: 09 Mar 2020 Posts: 25
|
Posted: Sun Jun 21, 2020 6:58 pm Post subject: |
|
|
Will this kick counter works in every kick message?
Like
SomeNick was Kicked By Bot (Requested By Owner Kick No.12) |
|
| Back to top |
|
 |
CrazyCat Revered One

Joined: 13 Jan 2002 Posts: 1032 Location: France
|
Posted: Mon Jun 22, 2020 12:52 am Post subject: |
|
|
With this short correction, yes.
| Code: | #Binds
bind pub o !kick pub_kick
bind msg o kick msg_kick
# Counter
set counter 0
#Kick Process
proc msg_kick {nick uhost hand rest} {
global botnick
set chan [lindex $rest 0] ; set knick [lrange $rest 1 end]
if {$chan == "#" || $chan == ""} {putquick "NOTICE $nick :Command: /msg $botnick kick <#channel> <nickname(s)> \[!reason\]" ; return 0}
if {![string match "#*" $chan]} {set chan "#$chan"}
if {$knick == ""} {putquick "NOTICE $nick :Command: /msg $botnick kick $chan <nickname(s)> \[!reason\]" ; return 0}
if {![validchan $chan]} {putquick "NOTICE $nick :I am not on channel: $chan, check out my channel list." ; return 0}
if {![botisop $chan]} {putquick "NOTICE $nick :I appologize, but I am not an Operator on channel: $chan. Your command cannot be perform." ; return 0}
set knicks "" ; set ownicks "" ; set nonenicks "" ; set reason ""
foreach x $knick {
if {(![onchansplit $x $chan]) && (![isbotnick $x])} {
if {[string match "!*" $x]} {set reason "\002\037\0037(\017\00312\u00bb\0031\002j\002a\0034\002D\002u\0031\u00ae\00312\u00ab\0037\002\037)\017 $x"} else {if {[matchattr [nick2hand $x $chan] m]} {append ownicks " $x"} else {if {![onchan $x $chan]} {append nonenicks " $x"} else {append knicks "$x,"}}}
}
}
if {$nonenicks != ""} {putquick "NOTICE $nick :$nonenicks is not on channel: $chan."}
if {$ownicks != ""} {putquick "NOTICE $nick :$ownicks are my \[Master(s)\], and will I will not Kick them from channel: $chan."}
if {$knicks != ""} {
incr ::counter 1
if {$reason == ""} {set reason "\002\037\0037(\017\00312\u00bb\0031\002j\002a\0034\002D\002u\0031\u00ae\00312\u00ab\0037\002\037)\017 \00315Requested by: \00314$nick No. $::counter"} ;
putkick $chan $knicks $reason
putcmdlog "<<$nick>> !$hand! Kick: ${knicks} from channel: $chan. Reason: $reason."
} ; return 0
}
proc pub_kick {nick uhost hand chan rest} {
global botnick
set chans "" ; set channel [lindex $rest 0]
if {![string match "#*" $channel]} {set channel $chan ; append chans "$channel $rest "} else {append chans " $rest"}
set knicks [lindex $chans 1]
if {$knicks == ""} {putquick "NOTICE $nick :Command: ${jaDu}kick $chan <nickname(s)> \[!reason\]" ; return 0}
msg_kick $nick $uhost $hand $chans
} |
_________________ https://www.eggdrop.fr - French IRC network
Offer me a coffee - Do not ask me help in PM, we are a community. |
|
| Back to top |
|
 |
illusionist Voice
Joined: 09 Mar 2020 Posts: 25
|
Posted: Mon Jun 22, 2020 1:34 am Post subject: Thanks Sir after Corrections it looks Like |
|
|
Thanks Sir its Working Now ...
** P0D has been kicked by aXa ((»jaDu®«) Requested by: aXa Kick No. 4)
** P0D has been kicked by aXa ((»jaDu®«) Requested by: aXa Kick No. 5)
I'm Lil worry about rehash/restart... The Kick counter automatically turned to 0..
And count new kicks from 0..
is there any solution to keep kick counter record in separate text file ?? |
|
| Back to top |
|
 |
illusionist Voice
Joined: 09 Mar 2020 Posts: 25
|
Posted: Mon Jun 22, 2020 3:11 am Post subject: |
|
|
Thanks CrazyCat
Finally i SoLved My Problem... With The Help Of My Friend Zohaib.. |
|
| Back to top |
|
 |
simo Owner
Joined: 22 Mar 2015 Posts: 941
|
Posted: Mon Jun 22, 2020 5:06 am Post subject: |
|
|
if you do this it wont get the entire custom reason tho
!kick nick nick nick !some custom kick reason here
it wil only get first param wich is: some |
|
| Back to top |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3741 Location: Mint Factory
|
Posted: Mon Jun 22, 2020 6:50 am Post subject: |
|
|
Actually it won't get any reason at all given:
| Code: |
set chan [lindex $rest 0]
set knick [lrange $rest 1 end]
|
_________________ Once the game is over, the king and the pawn go back in the same box. |
|
| Back to top |
|
 |
illusionist Voice
Joined: 09 Mar 2020 Posts: 25
|
Posted: Mon Jun 22, 2020 3:09 pm Post subject: |
|
|
caeser is right....
!kick nick !reason
It just pick the one 1st word from the reason Line ..
if any one can fix it ... Really appreciate ...
| Code: | proc count:kicks {} {
set increment_count "~/eggdrop/axa/axacount.txt"
if { ![file exists $increment_count] } { putlog "axacount.txt does not exist.";return }
set open_text [open $increment_count "r"]
set KICKCOUNT [read -nonewline $open_text]
close $open_text
incr KICKCOUNT
set re_open_text [open $increment_count "w"]
puts $re_open_text $KICKCOUNT
close $re_open_text
return $KICKCOUNT
} | im using this kick code ... And its work in $kickreason Line perfectly....
❤ |
|
| Back to top |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3741 Location: Mint Factory
|
Posted: Tue Jun 23, 2020 3:41 am Post subject: |
|
|
| Code: |
if {[string match "!*" $x]} {set reason "\002\037\0037(\017\00312\u00bb\0031\002j\002a\0034\002D\002u\0031\u00ae\00312\u00ab\0037\002\037)\017 $x"} else {if {[matchattr [nick2hand $x $chan] m]} {append ownicks " $x"} else {if {![onchan $x $chan]} {append nonenicks " $x"} else {append knicks "$x,"}}}
|
this is the line that builds the "reason", so you could go with something like:
| Code: |
if {[string match "!*" $x]} { set cut [string range $rest [expr [string first ! $rest] +1] end]; set reason "\002\037\0037(\017\00312\u00bb\0031\002j\002a\0034\002D\002u\0031\u00ae\00312\u00ab\0037\002\037)\017 $cut"} else {if {[matchattr [nick2hand $x $chan] m]} {append ownicks " $x"} else {if {![onchan $x $chan]} {append nonenicks " $x"} else {append knicks "$x,"}}}
|
The code is poorly implemented as I would cut the channel name, user list (if any) and reason (if any) from the user's input and loop only on the user list to do whatever checks.
How? Well, for starters I would use string first to see if there's a # and then an ! in the text the user sent to make the cuts.
For example:
| Code: |
if {[string first # $text] < 0 || [llength $text] < 2} {
puthelp "NOTICE $nick :Syntax: /msg $::botnick kick <#channel> <user list> \[!reason\]"
return
} else {
set chan [lindex [split $text] 0]
}
|
If there isn't a # in the user's text or given just one "element" then will give him the message with proper syntax, else I know the channel is the first element in the list.
From here I would make the first cut and take the chunk after the channel until the end:
| Code: |
set cut [lrange $text 1 end]
|
For example:
| Code: |
% set text "#channel user1 user2 user3 !some lengthy reason here"
#channel user1 user2 user3 !some lengthy reason here
% set cut [lrange $text 1 end]
user1 user2 user3 !some lengthy reason here
|
Now we check if there's a reason and split the user list and the actual reason, again using string first:
| Code: |
set pos [string first ! $cut]
if {$pos < 0} {
set knicks [lrange $text 1 end]
set reason "Requested by: $nick"
} else {
set knicks [string range $cut 0 [expr $pos -2]]
set reason [string range $cut [expr $pos +1] end]
}
|
if there's no ! in the user's input then it cuts the list user sent from 1st to the end and marks it as user list and make a default reason. If there's one then this magic happens:
| Code: |
% set pos [string first ! $cut]
18
% string range $cut 0 $pos
user1 user2 user3 !
# we need to do a -2 on the $pos to remove the space and the ! sign
% set knicks [string range $cut 0 [expr $pos -2]]
user1 user2 user3
% string range $cut $pos end
!some lengthy reason here
# we do a +1 on $pos so the ! sign doesn't appear in the reason
% set reason [string range $cut [expr $pos +1] end]
some lengthy reason here
|
As for your kicks count proc, here's my version:
| Code: |
proc count:kicks args {
set file "~/eggdrop/axa/axacount.txt"
set fh [open $file "a+"]
seek $fh 0
set count [read -nonewline $fh]
seek $fh 0
puts $fh [expr $count + 1]
seek $fh 0
set count [read -nonewline $fh]
return $count
}
|
What this dose?
- sets file variable
- opens file for reading and writing, creates an empty file it doesn't exist and most important sets the initial access position to the end of the file.
- with seek we set the position to 1st line (line 0)
- read the file content
- set access position to 0
- write in the file the incremented value
- set access position to 0
- read from the file
- return the read value
| Code: |
# file doesn't exist
% countKicks
1
% countKicks
2
% countKicks
3
% countKicks
4
|
_________________ Once the game is over, the king and the pawn go back in the same box. |
|
| Back to top |
|
 |
CrazyCat Revered One

Joined: 13 Jan 2002 Posts: 1032 Location: France
|
Posted: Tue Jun 23, 2020 8:08 am Post subject: |
|
|
Peharps the count kicks proc could be smaller:
| Code: | proc count:kicks args {
set file "~/eggdrop/axa/axacount.txt"
set fh [open $file "a+"]
seek $fh 0
set count [expr [read -nonewline $fh] + 1]
seek $fh 0
puts $fh $count
return $count
} |
_________________ https://www.eggdrop.fr - French IRC network
Offer me a coffee - Do not ask me help in PM, we are a community. |
|
| Back to top |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3741 Location: Mint Factory
|
Posted: Tue Jun 23, 2020 10:13 am Post subject: |
|
|
I tried to compress stuff as well, but for some reason it doesn't seem to be working:
| Code: |
% proc count:kicks args {
set file "/home/cezar/test.txt"
set fh [open $file "a+"]
seek $fh 0
set count [expr [read -nonewline $fh] + 1]
seek $fh 0
puts $fh $count
return $count
}
% count:kicks
1
% count:kicks
1
% count:kicks
1
% puts $tcl_version
8.6
|
I'm on Ubuntu and my version is:
| Code: |
cezar@Delta:~$ apt list tcl
Listing... Done
tcl/bionic,now 8.6.0+9 amd64 [installed]
|
Is the code that you posted working for you? _________________ Once the game is over, the king and the pawn go back in the same box. |
|
| Back to top |
|
 |
SpiKe^^ Owner

Joined: 12 May 2006 Posts: 792 Location: Tennessee, USA
|
Posted: Tue Jun 23, 2020 10:16 am Post subject: |
|
|
Don't use append (a+)
Use w or w+ _________________ SpiKe^^
Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
. |
|
| Back to top |
|
 |
CrazyCat Revered One

Joined: 13 Jan 2002 Posts: 1032 Location: France
|
Posted: Tue Jun 23, 2020 10:40 am Post subject: |
|
|
I tested without using a proc and it works.
In the proc, it fails (using a+, r+ or w+)
| Code: | % set fh [open "~/axacount.txt" "a+"]
file7
% seek $fh 0
% set count [expr [read -nonewline $fh] + 1]
1
% seek $fh 0
% puts $fh $count
% seek $fh 0
% set count [expr [read -nonewline $fh] + 1]
2 |
_________________ https://www.eggdrop.fr - French IRC network
Offer me a coffee - Do not ask me help in PM, we are a community. |
|
| Back to top |
|
 |
illusionist Voice
Joined: 09 Mar 2020 Posts: 25
|
Posted: Tue Jun 23, 2020 6:05 pm Post subject: |
|
|
Thanks for help
Last edited by illusionist on Wed Sep 01, 2021 11:08 pm; edited 1 time in total |
|
| Back to top |
|
 |
|