This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

[SOLVED] Kick Counter HeLp for Kick Via PVT Msg

Support & discussion of released scripts, and announcements of new releases.
i
illusionist
Voice
Posts: 25
Joined: Mon Mar 09, 2020 11:22 am

[SOLVED] Kick Counter HeLp for Kick Via PVT Msg

Post by illusionist »

Code: Select all

#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
}
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.
User avatar
CrazyCat
Revered One
Posts: 1306
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

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: Select all

#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
} 
i
illusionist
Voice
Posts: 25
Joined: Mon Mar 09, 2020 11:22 am

Post by illusionist »

Will this kick counter works in every kick message?
Like
SomeNick was Kicked By Bot (Requested By Owner Kick No.12)
User avatar
CrazyCat
Revered One
Posts: 1306
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

With this short correction, yes.

Code: Select all

#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
} 
i
illusionist
Voice
Posts: 25
Joined: Mon Mar 09, 2020 11:22 am

Thanks Sir after Corrections it looks Like

Post by illusionist »

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 ??
i
illusionist
Voice
Posts: 25
Joined: Mon Mar 09, 2020 11:22 am

Post by illusionist »

Thanks CrazyCat
Finally i SoLved My Problem... With The Help Of My Friend Zohaib..
s
simo
Revered One
Posts: 1107
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

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
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Actually it won't get any reason at all given:

Code: Select all

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.
i
illusionist
Voice
Posts: 25
Joined: Mon Mar 09, 2020 11:22 am

Post by illusionist »

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: Select all

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....


User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Code: Select all

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: Select all

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: Select all

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: Select all

set cut [lrange $text 1 end]
For example:

Code: Select all

% 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: Select all

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: Select all

% 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: Select all

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: Select all

# 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.
User avatar
CrazyCat
Revered One
Posts: 1306
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

Peharps the count kicks proc could be smaller:

Code: Select all

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
}
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

I tried to compress stuff as well, but for some reason it doesn't seem to be working:

Code: Select all

% 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: Select all

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.
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

Post by SpiKe^^ »

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
.
User avatar
CrazyCat
Revered One
Posts: 1306
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

I tested without using a proc and it works.
In the proc, it fails :( (using a+, r+ or w+)

Code: Select all

% 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
i
illusionist
Voice
Posts: 25
Joined: Mon Mar 09, 2020 11:22 am

Post by illusionist »

Thanks for help
Last edited by illusionist on Wed Sep 01, 2021 11:08 pm, edited 1 time in total.
Post Reply