Communauté sur les Eggdrops - Community about Eggdrops
[Solved] remove access after sometime - Printable Version

+- Communauté sur les Eggdrops - Community about Eggdrops (https://forum.eggdrop.fr)
+-- Forum: English help (https://forum.eggdrop.fr/forumdisplay.php?fid=25)
+--- Forum: Tcl Scripts (https://forum.eggdrop.fr/forumdisplay.php?fid=29)
+---- Forum: Scripts requests (https://forum.eggdrop.fr/forumdisplay.php?fid=33)
+---- Thread: [Solved] remove access after sometime (/showthread.php?tid=1851)



remove access after sometime - mabrook - 02/10/2021

hi all,

just want to ask a help from this community for a script.



To do;

it scan Undernet users with access on specific channel. then, after scanning and find out inactive users that have an access in that specific channel.
we need to set from the script about 30days inactive and the bot (with channel admin access) will remove the channel access.

<user>!activeuser
<bot>Please wait while scanning #channel users access...

after scanning, the bot notice or private msg to the bot owner:

<bot>Inactive users for #channel: User1 (20days), User2 (25days), User3(30days), User4(10days)
<bot> Do you want to remove inactive user/s beyond 30days. yes or no? Type in channel: !removeuser yes or /msg Bot remove yes

from the channel:
<user>!removeuser
<bot>Removing inactive users (30days) in #chanel.
<bot>Done.


from privmsg:
<bot>Removing inactive channel users in #channel.
<bot>Done.


or if you know similar script, please share..



thank you all.


RE: remove access after sometime - ZarTek - 02/10/2021

What kind of services does Undernet use? Is there a command to have the list of channel users?

I think if I understood correctly that the eggdrop must be op room and have access to its commands to be able to list, remove users.

I don't know if Undernet indicates when the user last joined the room (something like seen?)


If this is not the case, you have to build a database, with the joint channels of the users and the time. Compare this database, with the list of users added to the shows and all those beyond 30 days executed the order to remove them


RE: remove access after sometime - mabrook - 02/10/2021

(02/10/2021, 10:55)ZarTek Wrote: What kind of services does Undernet use? Is there a command to have the list of channel users?

I think if I understood correctly that the eggdrop must be op room and have access to its commands to be able to list, remove users.

I don't know if Undernet indicates when the user last joined the room (something like seen?)


If this is not the case, you have to build a database, with the joint channels of the users and the time. Compare this database, with the list of users added to the shows and all those beyond 30 days executed the order to remove them


Undernet command list: https://www.undernet.org/docs/x-commands-english

Yes, eggdrop must be op in the channel and login the channel admin access.

undernet command to find the user:

<user>/msg x info username
-> *x* info username
-X- Information about:  username (1923676)
-X- Currently logged on via:
-X-  OFFLINE
-X- Flags set: LANG=EN
-X- LAST SEEN: 3 days, 16:11:08 ago.


RE: remove access after sometime - CrazyCat - 02/10/2021

I don't think that having a double management system (X and eggdrop) is a good idea.

If I were in your shoes, I'll do another way:
  • user is added into eggdrop with the access you want (!adduser nick 400)
  • eggdrop records the user in its userlist with an user defined (user access) info for the channel
  • eggdrop adds access into X

Then, the !activeuser and !removeuser commands can cycle the eggdrop userlist and do a getuser handle LASTON to give you the info and/or remove user from access list


RE: remove access after sometime - ZarTek - 02/10/2021

Anyway there are always several possibilities for the same result. I don't think there is any point in cluttering up eggdrop by creating users on it (unless it is necessary .. for other things).

If it is possible to list users register on the show with "/msg x ...." we know how to extract the users list and executed "/msg x info username" to act on the "LAST SEEN" to send the remove use if more than X days not seen ...
The advantage is that the IRC service will be up to date. Because if we create eggdrop side, in case of disconnection it could miss the seal information ..




If for reasons of requests to the limited services.
A database can be created on the eggdrop side which retains the joints / parts.

After, register the user at the eddgrop with the joint and set a last seen I don't think it's better.


RE: remove access after sometime - mabrook - 02/10/2021

ey guys, just found this script.. but not yet tested.. but the idea is very clear



tcl
###################################################################################
#
# UserCheck 1.1b TCL
#
#This tcl on a timer will check if the users who have access @ X (chanserv)
#are on the channel where the tcl is activated
#
#If not there are 2 ways to action :
#
#1) x suspend + message on chan ( that contains the users that are not on chan )
#2) message on chan ( that contains the users that are not on chan )
#
#Version 1.1
#
#Added some commands
#
#!usercheck -list (will list the users that were found outside the chan)
#!usercheck -clear (era the list of users)
#
#!usercheck -except add <user> (add an except. This user will not be checked)
#		    list (list the except users)					
#		    del <user> (erase a user from exception list)					
#
#Added a module that if a user is found outside the chan the bot saves
#the time when he was found. Onjoin the user will be messaged with the
#time that he was spotted outside the chan.
#
#For the users who are spotted outside the chan and do not join for 
#<N> days  the bot will remuser them.
#
#Version 1.1b
#
#Solved a little issue about deleting data in the checking of expired entrys.
#
#Activate : .chanset #canal +usercheck | .set +usercheck
#
#						BLaCkShaDoW ProductionS
######################################################################################
 
#Set here the check time ( minutes )
 
set userc(time) "60"
 
 
#Set here the flags that are needed to check the usercheck list ( the except list)
 
set userc(flags) "mn|MN"
 
 
#Set here the number of days that the bot will keep the record of a user.
#If it past the user will be erased + remuser.
 
set userc(days) "30"
 
 
#Set here the action method ( 1 - suspend + channel message ; 0 - channel message )
 
set userc(method) "0"
 
 
#Set here the level of suspesion ( if a user is spotted logged and outside the chan)
 
set userc(slevel) "400"
 
#Set here the number of days for the suspend
 
set userc(sdays) "3d"
 
 
##########################################################
#
#			The End
#
##########################################################
 
setudef flag usercheck
 
set user_file "usercheck"
set excepts_file "usercheck.excepts"
 
if {![file exists $excepts_file]} {
	set file [open $excepts_file w]
	close $file
}
 
if {![file exists $user_file]} {
	set file [open $user_file w]
	close $file
}
 
 
 
bind pub $userc(flags) !usercheck usercheck:cmd
bind join - * usercheck:join
 
if {![info exists xstatus:timer_running]} {
timer $userc(time) xstatus:timer
set xstatus:timer_running 1
}
 
 
proc xstatus:timer:again {} {
 
xstatus:timer
 
}
 
 
proc xstatus:timer {} {
global userc
 
	set xmask "*!*@undernet.org"
 
 
if {[isignore "$xmask"]} {
 
	killignore $xmask
 
}
 
if {![info exists userc(channels_i)]} {
 
	set userc(channels_i) 0
 
}
 
if {![info exists userc(channels)]} {
foreach chan [channels] {
if {[channel get $chan usercheck]} {
 
	lappend userc(channels) [join $chan]
 
		}
	}
}
 
 
 
if {[info exists userc(channels)]} {
 
	set channel [lindex $userc(channels) $userc(channels_i)]
 
if {[validchan $channel]} {
 
	putserv "PRIVMSG X :status $channel"
	set ::xchan $channel
 
	bind notc - * xstatus:check:timer
	utimer 30 [list user:expire:check $channel]
 
}
 
} else {
 
timer $userc(time) xstatus:timer
return 1
 
}
 
 
 
incr userc(channels_i) +1
 
if {[lindex $userc(channels) $userc(channels_i)] != ""} {
 
utimer 15 [list xstatus:timer:again]
 
	} else {
 
if {[info exists userc(channels_i)]} {
 
	unset userc(channels_i)
 
}
 
if {[info exists userc(channels)]} {
 
	unset userc(channels)
 
}
 
timer $userc(time) xstatus:timer
return 1
 
	}
}
 
 
proc xstatus:check:timer {nick host hand text {dest ""}} {
	global userc user_file excepts_file
 
	set chans $::xchan
	set xmask "*!*@undernet.org"
 
if {$nick != "X"} { return 0 }
 
if {[isignore "$xmask"]} {
 
	killignore $xmask
 
}
 
if {[string match -nocase "*Auth:*" $text]} {
foreach word [split $text] {
	set word [filter $word]
	set username [join [scan $word %\[^/\]]]
	set nickname [join [scan $word %*\[^/\]/%s]]
 
if {($nickname != "") && ($username != "")} {
 
if {![onchan $nickname $chans]} {
 
	set file [open $excepts_file "r"]
	set database [read -nonewline $file]
	close $file
	set data [split $database "\n"]
 
	foreach line $data {
 
	set user_read [lindex [split $line] 1]
	set chan_read [lindex [split $line] 0]
 
	if {[string match -nocase $username $user_read] && [string match -nocase $chans $chan_read]} {
 
	set protected($username) 1
 
	}
}
 
if {![info exists protected($username)]} {
 
	lappend usernames [join $username ", "]
	user:save $usernames $chans
 
if {$userc(method) == "1"} {
 
putserv "PRIVMSG X :suspend $chans $username $userc(sdays) $userc(slevel)"
 
						}
					} 
				}
			}
		}
	}
 
	if {[info exists usernames]} {
 
	set nr_username [llength $usernames]
 
	puthelp "PRIVMSG $chans :ALERT ! Found ($nr_username) users that are Online but not on chan. These are : $usernames"
 
	}
 
}
 
 
proc filter {str} {
  regsub -all -- {\003([0-9]{1,2}(,[0-9]{1,2})?)?|\017|\037|\002|\026|\006|\007} $str "" str
  return $str
}
 
proc user:save {userlist chan} {
	global user_file
	set userlist [join $userlist]
	set time [unixtime]
 
foreach user $userlist {
 
	set file [open $user_file "r"]
	set database [read -nonewline $file]
	close $file
	set data [split $database "\n"]
 
foreach line $data {
 
	set read_chan [lindex [split $line] 0]
	set read_username [lindex [split $line] 1]
 
if {[string match -nocase $chan $read_chan] && [string match -nocase $user $read_username]} {
 
set found_user($user) 1
 
	}
}
 
if {![info exists found_user($user)]} {
 
set file [open $user_file a]
puts $file "$chan $user $time"
close $file
 
		}
	}
}		
 
proc usercheck:cmd {nick host hand chan arg} {
	global user_file excepts_file
 
	set option [lindex [split $arg] 0]
	set option_2 [lindex [split $arg] 1]
	set user_add [lindex [split $arg] 2]
 
if {$option == ""} {
 
	puthelp "NOTICE $nick :Use !usercheck -list | -clear | -except add <user> / del <user> / list"
 
	return 0
 
}
 
	switch -exact -- [string tolower $option] {
 
 
	-except {
 
if {$option_2 == ""} {
 
	puthelp "NOTICE $nick :Use !usercheck -except add <user> / del <user> / list"
 
	return 0
 
	}
 
	switch -exact -- [string tolower $option_2] {
 
	add {
 
if {$user_add == ""} {
 
	puthelp "NOTICE $nick :Use !usercheck -execept add <user>"
 
	return 0
 
	}
 
	set file [open $excepts_file "r"]
	set database [read -nonewline $file]
	close $file
	set data [split $database "\n"]
 
foreach line $data {
 
	set user_read [lindex [split $line] 1]
	set chan_read [lindex [split $line] 0]
 
if {[string match -nocase $user_add $user_read] && [string match -nocase $chan $chan_read]} {
 
	puthelp "NOTICE $nick :Error. $user_read is already in my exception list."
 
	return 0
 
	}
}
 
	set file [open $excepts_file a]
	puts $file "$chan $user_add"
	close $file
 
	puthelp "NOTICE $nick :Added as exception user : $user_add"
 
}
 
	list {
 
	set counter 0
	set file [open $excepts_file "r"]
	set database [read -nonewline $file]
	close $file
	set data [split $database "\n"]
 
	puthelp "NOTICE $nick :Exception list :"
 
foreach line $data {
 
	set user_read [lindex [split $line] 1]
	set chan_read [lindex [split $line] 0]
 
if {[string match -nocase $chan $chan_read]} {
 
	set found_entry 1
	set counter [expr $counter + 1]
 
	puthelp "NOTICE $nick :$counter) $user_read"
 
	}
}
 
 
	if {![info exists found_entry]} {
 
	puthelp "NOTICE $nick :NONE"
 
	}	
}
 
	del {
 
if {$user_add == ""} {
 
	puthelp "NOTICE $nick :Use !usercheck -except del <user>"
 
	return 0
 
	}
 
 
	set counter 0
	set file [open $excepts_file "r"]
	set database [read -nonewline $file]
	close $file
	set data [split $database "\n"]
 
foreach line $data {
	set counter [expr $counter + 1]
	set user_read [lindex [split $line] 1]
	set chan_read [lindex [split $line] 0]
 
if {[string match -nocase $user_add $user_read] && [string match -nocase $chan $chan_read]} {
 
	set found_entry 1
 
	if {$line != ""} {
	set counter [expr $counter - 1]
	set delete [lreplace $data $counter $counter]
	set files [open $excepts_file "w"]
	puts $files [join $delete "\n"]
	close $files
 
		}
	}
}
 
	set file [open $excepts_file "r"]
	set data [read -nonewline $file]
	close $file
 
if {$data == ""} {
	set files [open $excepts_file "w"]
	close $files
}
 
if {![info exists found_entry]} {
 
	puthelp "NOTICE $nick :Error. $user_add isn't in my exception list."
 
} else {
 
	puthelp "NOTICE $nick :Erased $user_add from my exception list"
 
			}
		}	
	}
}
 
	-clear {
 
	set count_check 0
	set line_check 0
 
	set file [open $user_file "r"]
	set database [read -nonewline $file]
	close $file
	set data [split $database "\n"]
 
foreach line $data {
	set read_chan [lindex [split $line] 0]
if {[string match -nocase $chan $read_chan]} {
	set count_check [expr $count_check + 1]
 
	lappend user_delete $read_chan
 
}
}
 
if {[info exists user_delete]} {
 
	info:remove $user_delete
 
}	
	puthelp "NOTICE $nick :Cleared ($count_check) entrys."
}
 
 
	-list {
 
	puthelp "NOTICE $nick :UserCheck List is :"
 
	set count_check 0
	set file [open $user_file "r"]
	set database [read -nonewline $file]
	close $file
	set data [split $database "\n"]
if {$data == ""} {
 
	puthelp "NOTICE $nick :NONE"
	return 0
 
}
 
foreach line $data {
set read_chan [lindex [split $line] 0]
if {[string match -nocase $chan $read_chan]} {
 
set count_check [expr $count_check + 1]
 
}
}
 
putserv "NOTICE $nick :Found 1 $count_check  users"
 
foreach line $data {
 
	set read_chan [lindex [split $line] 0]
	set read_username [lindex [split $line] 1]
	set read_time [lindex [split $line] 2]
 
if {[string match -nocase $chan $read_chan]} {
 
 
	set found_username 1
 
	puthelp "NOTICE $nick :User : 1 $read_username | Spotted time : 1[ctime $read_time]"
 
 
}
}
 
if {![info exists found_username]} {
 
	puthelp "NOTICE $nick :NONE"
 
			}
		}
	}
}
 
proc user:expire:check {chan} {
	global user_file userc
 
	putlog "Checking entrys on $chan.."
	set file [open $user_file "r"]
	set database [read -nonewline $file]
	close $file
	set data [split $database "\n"]
foreach line $data {
	if {$line != ""} {
	set channel [lindex [split $line] 0]
if {[string match -nocase $chan $channel]} {
	set time_show [lindex [split $line] 2]
	set user_show [lindex [split $line] 1]
	if {[expr [unixtime] - $time_show] > [expr $userc(days) * 2880]} {
lappend user_list $user_show
			}
		}	
	}
}
 
if {[info exists user_list]} {
	putlog "Found [llength $user_list] expired entryes on $chan"
	user:remove $user_list $chan
	}
}
 
 
proc user:remove {userlist chan} {
	global user_file
	set list [join $userlist]
foreach tm $list {
if {$tm != ""} {
	puthelp "PRIVMSG X :remuser $chan $tm"
	set file [open $user_file "r"]
	set database [read -nonewline $file]
	close $file
	set data [split $database "\n"]
	set i [lsearch -glob [string tolower $data] [string tolower "$chan $tm *"]]
if {$i > -1} {
	set line [lindex $data $i]
	set delete [lreplace $data $i $i]
	set file [open $user_file "w"] 
	puts $file [join $delete "\n"]
	close $file	
 
			}
		}
	}
}
 
 
proc entry:remove {user chan} {
	global user_file
 
	set file [open $user_file "r"]
	set database [read -nonewline $file]
	close $file
	set data [split $database "\n"]
	set i [lsearch -glob [string tolower $data] [string tolower "$chan $user *"]]
if {$i > -1} {
	set line [lindex $data $i]
	set delete [lreplace $data $i $i]
	set file [open $user_file "w"] 
	puts $file [join $delete "\n"]
	close $file	
	}
}
 
 
proc info:remove {userlist} {
	global user_file
 
 
	set list [join $userlist]
foreach tm $list {
if {$tm != ""} {
	set file [open $user_file "r"]
	set database [read -nonewline $file]
	close $file
	set data [split $database "\n"]
	set i [lsearch -glob $data "$tm *"]
if {$i > -1} {
	set line [lindex $data $i]
	set delete [lreplace $data $i $i]
	set file [open $user_file "w"] 
	puts $file [join $delete "\n"]
	close $file	
 
			}
		}
	}
}
 
 
proc usercheck:join {nick host hand chan} {
if {[channel get $chan usercheck]} {
if {[isbotnick $nick]} { return 0 }
if {[onchan $nick $chan]} {
 
set ::usercheck_channel $chan
set ::usercheck_nick $nick
 
utimer 5 [list putserv "WHOIS $nick $nick"]
 
bind RAW - 330 usercheck:logged
 
		}
	}
}
 
proc usercheck:logged {from keyword arguments} {
	global user_file
	set nick $::usercheck_nick
	set chan $::usercheck_channel
	set found_user [lindex $arguments 2]
 
if {[channel get $chan usercheck]} {
 
	set file [open $user_file "r"]
	set database [read -nonewline $file]
	close $file
	set data [split $database "\n"]
 
	foreach line $data {
 
	set chan_show [lindex [split $line] 0]
	set time_show [lindex [split $line] 2]
	set user_show [lindex [split $line] 1]
 
if {[string match -nocase $chan $chan_show] && [string match -nocase $found_user $user_show]} {
 
		puthelp "PRIVMSG $nick :- ALERT - You have been spotted outside of chan (having access on 4$chan) on date 4 [ctime $time_show]"		
 
		entry:remove $found_user $chan
 
			}
		}
	}
}
 
 
putlog "UserCheck 1.1b by BLaCkShaDoW Loaded"



i will test it by tomorrow..   :)


RE: remove access after sometime - CrazyCat - 03/10/2021

Wow, lot of redondant code, seems to be an old code from BlackShadow :)
Tell us if it works (I think it does), but I'm sure it can be optimised


RE: remove access after sometime - mabrook - 04/10/2021

i've tested it :


Code:
#Set here the number of days that the bot will keep the record of a user.
#If it past the user will be erased + remuser.

set userc(days) "1"
set to 1day to get the result but,,,

but nothing happened.. i think this needs update..


RE: remove access after sometime - CrazyCat - 04/10/2021

Well...
First, this variable is used in if {[expr [unixtime] - $time_show] > [expr $userc(days) * 2880]} {
2880 is really strange, as it is the number of minutes in 48h (2 days), and I think the real value to use is the number of seconds in 24h (60*60*24 = 86400). But it doesn't explain why it doesn't work, as the actual calculation will match pple who aren't seen since 48 minutes.

I'll have a look on how the script may work, and try to correct it


RE: remove access after sometime - mabrook - 04/10/2021

thanks for the reply CrazyCat,

i'm waiting for the bot to send msg, but need to type in the channel !usercheck -list


after an hour of waiting i tried !usercheck -list and the bot reply via notice


Code:
<@user> !usercheck -list
-Bot- Found  3  users
-Bot- UserCheck List is :
-Bot- User :  username1 | Spotted time : Mon Oct  4 03:21:02 2021
-Bot- User :  username2 | Spotted time : Mon Oct  4 03:21:02 2021
-Bot- User :  username3 | Spotted time : Mon Oct  4 03:21:02 2021
now, since i set this to


Code:
#Set here the number of days that the bot will keep the record of a user.
#If it past the user will be erased + remuser.

set userc(days) "1"

will wait for 24hours cycle and after that let's see if the bot remove the access automatically.

and if this work perfect. this might be the script I've been looking for.,


and after sometime it shows in the channel:


Code:
<@Bot> ALERT ! Found (3) users that are Online but not on chan. These are : xyz DaemonSpade ComputerTech

update...

i think the script is working perfect..


Code:
-X- BOT499ACCESS removed DaemonSpade from channel #pilipinas
-X- BOT499ACCESS removed ComputerTech from channel #pilipinas



RE: remove access after sometime - mabrook - 20/10/2021

how can i make this post as "SOLVED" ?