egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Help for tcl modification

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests
View previous topic :: View next topic  
Author Message
Suratka
Voice


Joined: 25 Jun 2016
Posts: 19

PostPosted: Mon Mar 01, 2021 3:05 pm    Post subject: Help for tcl modification Reply with quote

Hello friends. I need a favor. I have installed a tcl that records the links that are posted in the channel. create the various files_nick_user.log in a logs folder and when in public we type :! link nick
Eggdrop returns the last three links NICK posted on the channel.
This tcl only works on one channel at a time. in fact the channel must be set in the tcl. I wish it could work on multiple channels.
Now the tcl is set to one channel only, and records user links in that channel only, but the command! Link nick returns the response in other non-enabled channels as well. I would like to avoid this.
Indeed if possible, I would like you to create db files belonging to each channel I enable. so I would like to modify the tcl in such a way that it is multichan settable and that it keeps the db for each channel.
it's possible?


Code:
#####################################################
#    link logger v 1.1 by m00nie
#            www.m00nie.com
#
#   Mostly written as a way to practice TCL....
# V1.1 Added Global Stats
# V1.0 Original release
#####################################################
# Settings to edit below
#####################################################
# chan to use
set linklog(chanset) "#siamosolonoi"

# Debug? Enabling debug is very verbose!
set linklog(debug) 1

# Users to ignore? E.g other bots
set linklog(ignore) "some people"

# Command to search for link
set linklog(call) "!link"

# Command for stats
set linklog(stats) "!linkstats"

# Location of the file to store links
set linklog(location) "/home/server/arale/loglink/links_"

# output line start
set linklog(out) "\002\[\002Link\002\]\002 "


#####################################################
# No need to edit anything from below here
#####################################################

set linklog(debugstring) "Link Logger Debug: "

bind pub - $linklog(call) linkcall
bind pub - $linklog(stats) linkstats
bind pubm - "$linklog(chanset) *://*" linklogger

###################
# Link logging process
###################
proc linklogger {nick host hand chan arg} {
   global linklog
   if {$linklog(debug) == 1} {
      putlog "$linklog(debugstring) nick = $nick"
      putlog "$linklog(debugstring) host = $host"
      putlog "$linklog(debugstring) hand = $hand"
      putlog "$linklog(debugstring) chan = $chan"
      putlog "$linklog(debugstring) arg = $arg"
   }
   ###################
   # Checking the channel has been set
   ###################
       
   if {$chan != $linklog(chanset)} {
      if {$linklog(debug) == 1} {
         putlog "$linklog(debugstring) $chan is not set to log links!"
         putlog "$linklog(debugstring) chan is set to $linklog(chanset)"
         return
      }
   return
   }
   ###################
   # Check is user ignored
   ###################
   set linklog(ignoretest) [regexp -nocase $nick $linklog(ignore)]
   if {$linklog(ignoretest) == 1} {
       if {$linklog(debug) == 1} {
         puts "$linklog(debugstring) $nick is being ignored"
         puts "$linklog(debugstring) Ingnore variable is $linklog(ignore)"
         return
       }
   return
   }
   ###################
   # Check for a link
   ###################
   if {[regexp -- {(https?://[a-z0-9\-]+\.[a-z0-9\-\.]+(?:/|(?:/[a-zA-Z0-9!#\$%&'\*\+,\-\.:;=\?@\[\]_~]+)*))} $arg match linklog(url)]} {
      if {$linklog(debug) == 1} {
         putlog "$linklog(debugstring) Found link, chan set and not ignoring user!"
         putlog "Link is $linklog(url)"
      }
      ###################
      # Open the file append and close
      ###################
      set time [clock seconds]
      set linklog(fileappend) [open $linklog(location)$nick a]
      if {$linklog(debug) == 1} {
         putlog "$linklog(debugstring) File $linklog(location) opened at $time"
      }
      puts $linklog(fileappend) "Linked to $linklog(url) @ [clock format $time]"
      close $linklog(fileappend)
      if {$linklog(debug) == 1} {
         putlog "$linklog(debugstring) File $linklog(location) closed"
      }
   } else {
      if {$linklog(debug) == 1} {
         putlog "$linklog(debugstring) This shouldnt really happen....."
         putlog "$linklog(debugstring) Channel set, user not ignored but no valid link!"
      }
}
}

###################
# Link searching
###################
proc linkcall {nick host hand chan arg} {
   global linklog
   ###################
   # Check for no arguments then spam help
   ###################
   if {[string length $arg] < 1} {
                puthelp "PRIVMSG $chan :usage: $linklog(call) <username>"
      puthelp "PRIVMSG $chan :usage: $linklog(stats) <username>"
      puthelp "PRIVMSG $chan :usage: $linklog(stats) for global stats"   
      return
   }
   if {$linklog(debug) == 1} {
      putlog "$linklog(debugstring) $linklog(call) triggered linkcall"
      putlog "$linklog(debugstring) The argument was $arg"
   }
   ###################
   # Check a file exists
   ###################
   set linklog(fileresult) [linkfilecheck $linklog(location)$arg]
   if {$linklog(fileresult) != 1} {
      puthelp "PRIVMSG $chan $linklog(out) No links found for $arg :("
      putlog "$linklog(debugstring) File $linklog(location)$arg doesnt exist??"
      return
   }
   ###################
   # Open and read the file line by line
   ###################
   set loop 0
   set linklog(fileopen) [open $linklog(location)$arg r]
   set lines [split [read -nonewline $linklog(fileopen)] "\n"]
   puthelp "PRIVMSG $chan $linklog(out) $arg's most recent links"
   if {$linklog(debug) == 1} {
      putlog "$linklog(debugstring) $linklog(location)$arg File open and split"
   }
   for {set i [llength $lines]} {$i} {incr i -1} {
      set line [lindex $lines $i-1]
      if {$loop > 2} {
         return
      }
      puthelp "PRIVMSG $chan $line"
           if {$linklog(debug) == 1} {
                        putlog "$linklog(debugstring) loop = $loop "
                }
      incr loop
   }
   close $linklog(fileopen)
   if {$linklog(debug) == 1} {
      putlog "$linklog(debugstring) File $linklog(location)$arg closed"
   }
}

###################
# Get some stats
###################
proc linkstats {nick host hand chan arg} {
   global linklog
   if {$linklog(debug) == 1} {
      putlog "$linklog(debugstring) link stats called with arg $arg"
   }
   if {[string length $arg] < 1} {
      if {$linklog(debug) == 1} {
         putlog "$linklog(debugstring) No arg given to $linklog(stats)"
      }
      set files [glob $linklog(location)*]
      if {$linklog(debug) == 1} {
         putlog "$linklog(debugstring) Files to be checked are $files"
      }
      if { [llength $files] > 0 } {
         foreach f [lsort $files] {
            set name [regsub -nocase {.*links\_} $f {}]
            set size [linklinecount $f]
            lappend thelist "$name $size"
          }
       } else {
         puthelp "PRIVMSG $chan $linklog(out) Nobody has linked to anything :o"
       }
            if {$linklog(debug) == 1} {
                        putlog "$linklog(debugstring) unsorted list is $thelist "
                 }
       lappend outputlist [lsort -index 1 -decreasing -integer $thelist]
       if {$linklog(debug) == 1} {
                         putlog "$linklog(debugstring) Sorted list is $outputlist"
                 }
                 set x "0"
       while {$x < 3} {
         set list [lindex $outputlist 0 $x]
         incr x
         lassign $list user count
         if {$count < 0} {
            return
         }
         if {$x == 1} {
            puthelp "PRIVMSG $chan $linklog(out) Top link spammers"
         }
         puthelp "PRIVMSG $chan $x. $user spammed $count links"
      }
      return
   }
   # Check the file exists first
   set linklog(fileresult) [linkfilecheck $linklog(location)$arg]
   if {$linklog(debug) == 1} {
      putlog "$linklog(debugstring) files we try to open will be $linklog(fileresult)"
   }
   if {$linklog(fileresult) != 1} {
      puthelp "PRIVMSG $chan $linklog(out) No links found for $arg :("
      putlog "$linklog(debugstring) File $linklog(location)$arg doesnt exist??"
   return
   }
   # Count the links
   set linkcount [linklinecount $linklog(location)$arg]
        puthelp "PRIVMSG $chan $arg has spammed $linkcount links"
}

###################
# Count the lines in a file
###################
proc linklinecount {FILENAME} {
   global linklog
   if {$linklog(debug) == 1} {
      putlog "$linklog(debugstring) Linklinecount called with arg $FILENAME"
   }
   # c
        set i 0
        set fid [open $FILENAME r]
        while {[gets $fid line] > -1} {incr i}
        close $fid
   if {$linklog(debug) == 1} {
                putlog "$linklog(debugstring) Linklinecount returning $i lines counted"
        }
        return $i
}

###################
# Check file exsists
###################
proc linkfilecheck {FILENAME} {
   global linklog
   if {$linklog(debug) == 1} {
      putlog "$linklog(debugstring) Linkfilecheck called with arg $FILENAME"
   }
   # checking the file exists
        if [file exists $FILENAME] then {
        # file exists
      return 1
        } else {
        # file not exists
      return "0"
   }
}
putlog "link logger v 1.1 by m00nie http://www.m00nie.com :)"

_________________
IRCwebNET
Back to top
View user's profile Send private message Visit poster's website AIM Address
CrazyCat
Revered One


Joined: 13 Jan 2002
Posts: 1032
Location: France

PostPosted: Mon Mar 01, 2021 7:11 pm    Post subject: Reply with quote

Wow, such a complex script for a simple feature.

I can correct it to work as you want, and I can modify it to use a sqlite DB. This second alternative will do a simplest script, and probably more secured Smile
_________________
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
View user's profile Send private message Visit poster's website
Suratka
Voice


Joined: 25 Jun 2016
Posts: 19

PostPosted: Mon Mar 01, 2021 8:14 pm    Post subject: sq lite ??? Reply with quote

sorry what do you mean by sqlite db?
I don't know how to get started with the sqlite db.

I only use tcl which creates simple db files inside the eggdrop.
Creating a tcl that needs sqlite would mean to me working on sqlite and I don't even know what it is.

I only know how to install an eggdrop and simple tcls, in fact many complex tcls that require other dependencies I avoid them like the plague. : D

I just want this script to be settable and that it can choose which channels to run in, and that each channel has its own folder where it puts the txt nicknames that have written links to that channel.
_________________
IRCwebNET
Back to top
View user's profile Send private message Visit poster's website AIM Address
CrazyCat
Revered One


Joined: 13 Jan 2002
Posts: 1032
Location: France

PostPosted: Tue Mar 02, 2021 4:54 am    Post subject: Reply with quote

Here is a short untested modification.
do a .chanset #chan +linklog to enable the script in your chan.

Beware that omd files must be renamed to add the chan name before the nick.
Exemple: links_lamer must become links_siamosolonoi_lamer

Code:
#####################################################
#    link logger v 1.1 by m00nie
#            www.m00nie.com
#
#   Mostly written as a way to practice TCL....
# V1.1 Added Global Stats
# V1.0 Original release
#####################################################
# Settings to edit below
#####################################################
# Debug? Enabling debug is very verbose!
set linklog(debug) 1

# Users to ignore? E.g other bots
set linklog(ignore) "some people"

# Command to search for link
set linklog(call) "!link"

# Command for stats
set linklog(stats) "!linkstats"

# Location of the file to store links
set linklog(location) "/home/server/arale/loglink/links_"

# output line start
set linklog(out) "\002\[\002Link\002\]\002 "


#####################################################
# No need to edit anything from below here
#####################################################

set linklog(debugstring) "Link Logger Debug: "

bind pub - $linklog(call) linkcall
bind pub - $linklog(stats) linkstats
bind pubm - "$linklog(chanset) *://*" linklogger
setudef flag linklog

###################
# Link logging process
###################
proc linklogger {nick host hand chan arg} {
   global linklog
   if {$linklog(debug) == 1} {
      putlog "$linklog(debugstring) nick = $nick"
      putlog "$linklog(debugstring) host = $host"
      putlog "$linklog(debugstring) hand = $hand"
      putlog "$linklog(debugstring) chan = $chan"
      putlog "$linklog(debugstring) arg = $arg"
   }
   ###################
   # Checking the channel has been set
   ###################

   if {[channel get $chan linklog]!=0} {
      set tchan [string tolower $chan]
      if {$linklog(debug) == 1} {
         putlog "$linklog(debugstring) $chan is not set to log links!"
         return
      }
      return
   }
   ###################
   # Check is user ignored
   ###################
   set linklog(ignoretest) [regexp -nocase $nick $linklog(ignore)]
   if {$linklog(ignoretest) == 1} {
      if {$linklog(debug) == 1} {
         puts "$linklog(debugstring) $nick is being ignored"
         puts "$linklog(debugstring) Ingnore variable is $linklog(ignore)"
         return
      }
      return
   }
   ###################
   # Check for a link
   ###################
   if {[regexp -- {(https?://[a-z0-9\-]+\.[a-z0-9\-\.]+(?:/|(?:/[a-zA-Z0-9!#\$%&'\*\+,\-\.:;=\?@\[\]_~]+)*))} $arg match linklog(url)]} {
      if {$linklog(debug) == 1} {
         putlog "$linklog(debugstring) Found link, chan set and not ignoring user!"
         putlog "Link is $linklog(url)"
      }
      ###################
      # Open the file append and close
      ###################
      set time [clock seconds]
      set linklog(fileappend) [open $linklog(location)${tchan}_$nick a]
      if {$linklog(debug) == 1} {
         putlog "$linklog(debugstring) File $linklog(location) opened at $time"
      }
      puts $linklog(fileappend) "Linked to $linklog(url) @ [clock format $time]"
      close $linklog(fileappend)
      if {$linklog(debug) == 1} {
         putlog "$linklog(debugstring) File $linklog(location) closed"
      }
   } else {
      if {$linklog(debug) == 1} {
         putlog "$linklog(debugstring) This shouldnt really happen....."
         putlog "$linklog(debugstring) Channel set, user not ignored but no valid link!"
      }
   }
}

###################
# Link searching
###################
proc linkcall {nick host hand chan arg} {
   global linklog
   if {[channel get $chan linklog]==0} {
      puthelp "PRIVMSG $chan :not activated here"
      return 0
   } else {
      set tchan [string tolower $chan]
   }
   ###################
   # Check for no arguments then spam help
   ###################
   if {[string length $arg] < 1} {
      puthelp "PRIVMSG $chan :usage: $linklog(call) <username>"
      puthelp "PRIVMSG $chan :usage: $linklog(stats) <username>"
      puthelp "PRIVMSG $chan :usage: $linklog(stats) for global stats"   
      return
   }
   if {$linklog(debug) == 1} {
      putlog "$linklog(debugstring) $linklog(call) triggered linkcall"
      putlog "$linklog(debugstring) The argument was $arg"
   }
   ###################
   # Check a file exists
   ###################
   set linklog(fileresult) [linkfilecheck $linklog(location)${tchan}_$arg]
   if {$linklog(fileresult) != 1} {
      puthelp "PRIVMSG $chan $linklog(out) No links found for $arg :("
      putlog "$linklog(debugstring) File $linklog(location)$arg doesnt exist??"
      return
   }
   ###################
   # Open and read the file line by line
   ###################
   set loop 0
   set linklog(fileopen) [open $linklog(location)$arg r]
   set lines [split [read -nonewline $linklog(fileopen)] "\n"]
   puthelp "PRIVMSG $chan $linklog(out) $arg's most recent links"
   if {$linklog(debug) == 1} {
      putlog "$linklog(debugstring) $linklog(location)$arg File open and split"
   }
   for {set i [llength $lines]} {$i} {incr i -1} {
      set line [lindex $lines $i-1]
      if {$loop > 2} {
         return
      }
      puthelp "PRIVMSG $chan $line"
      if {$linklog(debug) == 1} {
         putlog "$linklog(debugstring) loop = $loop "
      }
      incr loop
   }
   close $linklog(fileopen)
   if {$linklog(debug) == 1} {
      putlog "$linklog(debugstring) File $linklog(location)$arg closed"
   }
}

###################
# Get some stats
###################
proc linkstats {nick host hand chan arg} {
   global linklog
   if {[channel get $chan linklog]==0} {
      puthelp "PRIVMSG $chan :not activated here"
      return 0
   } else {
      set tchan [string tolower $chan]
   }
   if {$linklog(debug) == 1} {
      putlog "$linklog(debugstring) link stats called with arg $arg"
   }
   if {[string length $arg] < 1} {
      if {$linklog(debug) == 1} {
         putlog "$linklog(debugstring) No arg given to $linklog(stats)"
      }
      set files [glob $linklog(location)${tchan}_*]
      if {$linklog(debug) == 1} {
         putlog "$linklog(debugstring) Files to be checked are $files"
      }
      if { [llength $files] > 0 } {
         foreach f [lsort $files] {
            set name [lindex [split $f "_"] end]
            set size [linklinecount $f]
            lappend thelist "$name $size"
         }
      } else {
         puthelp "PRIVMSG $chan $linklog(out) Nobody has linked to anything :o"
      }
      if {$linklog(debug) == 1} {
         putlog "$linklog(debugstring) unsorted list is $thelist "
      }
      lappend outputlist [lsort -index 1 -decreasing -integer $thelist]
      if {$linklog(debug) == 1} {
         putlog "$linklog(debugstring) Sorted list is $outputlist"
      }
      set x "0"
      while {$x < 3} {
         set list [lindex $outputlist 0 $x]
         incr x
         lassign $list user count
         if {$count < 0} {
            return
         }
         if {$x == 1} {
            puthelp "PRIVMSG $chan $linklog(out) Top link spammers"
         }
         puthelp "PRIVMSG $chan $x. $user spammed $count links"
      }
      return
   }
   # Check the file exists first
   set linklog(fileresult) [linkfilecheck $linklog(location)$arg]
   if {$linklog(debug) == 1} {
      putlog "$linklog(debugstring) files we try to open will be $linklog(fileresult)"
   }
   if {$linklog(fileresult) != 1} {
      puthelp "PRIVMSG $chan $linklog(out) No links found for $arg :("
      putlog "$linklog(debugstring) File $linklog(location)$arg doesnt exist??"
      return
   }
   # Count the links
   set linkcount [linklinecount $linklog(location)$arg]
   puthelp "PRIVMSG $chan $arg has spammed $linkcount links"
}

###################
# Count the lines in a file
###################
proc linklinecount {FILENAME} {
   global linklog
   if {$linklog(debug) == 1} {
      putlog "$linklog(debugstring) Linklinecount called with arg $FILENAME"
   }
   # c
   set i 0
   set fid [open $FILENAME r]
   while {[gets $fid line] > -1} {incr i}
   close $fid
   if {$linklog(debug) == 1} {
      putlog "$linklog(debugstring) Linklinecount returning $i lines counted"
   }
   return $i
}

###################
# Check file exsists
###################
proc linkfilecheck {FILENAME} {
   global linklog
   if {$linklog(debug) == 1} {
      putlog "$linklog(debugstring) Linkfilecheck called with arg $FILENAME"
   }
   # checking the file exists
   if [file exists $FILENAME] then {
      # file exists
      return 1
   } else {
      # file not exists
      return "0"
   }
}
putlog "link logger v 1.1 by m00nie http://www.m00nie.com :)"


I'll do a sqlite version, you'll see how it' simplest and it only requires one package.
If you don't want to use this evolution, some could be interested in it.
_________________
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
View user's profile Send private message Visit poster's website
Suratka
Voice


Joined: 25 Jun 2016
Posts: 19

PostPosted: Tue Mar 02, 2021 11:55 am    Post subject: Reply with quote

Hi. i just tested the tc you edited.

Now I can enable it in the channels where I want via .chanset
The rest doesn't work.

when in the set channel a user types a link it is not registered, the tcl does not create any log file.
I tried to create it by hand example:
links_ # channel_nick
and when that nick spams a link in the channel here is the response of the bot in partyline:

Code:
[15:41:08] Link Logger Debug:  nick = UNKNOWN
[15:41:08] Link Logger Debug:  host = SMCV@8780DF14.233F274D.EC498D0F.IP
[15:41:08] Link Logger Debug:  hand = *
[15:41:08] Link Logger Debug:  chan = #siamosolonoi
[15:41:08] Link Logger Debug:  arg = https://www.iol.it
[15:41:08] Link Logger Debug:  #siamosolonoi is not set to log links!


after which I try to type in channel:! link nick and I get this:



Code:
[15:48:19] Link Logger Debug:  !link triggered linkcall
[15:48:19] Link Logger Debug:  The argument was UNKNOWN
[15:48:19] Link Logger Debug:  Linkfilecheck called with arg /home/server/arale/                                                                                                                     loglink/links_#siamosolonoi_UNKNOWN
[15:48:19] Tcl error [linkcall]: couldn't open "/home/server/arale/loglink/links                                                                                                                     _UNKNOWN": no such file or directory


and even if it worked, it would have been impractical. Because from what I understand, you have to create the files by hand. The original tcl created a file for each user who wrote a links, which could then be called up via the public command! Link nick.

So it doesn't make sense.
I thought once it became multichan, tcl would create a directory for each channel. instead it puts everyone in the same directory, but that's not the point. The fact is that the system does not create the log files.
I think I will keep it as it was and at most I will only use the modification you made to enable it via chanset. so there is no danger that it will work in other channels.
Thanks: D
_________________
IRCwebNET
Back to top
View user's profile Send private message Visit poster's website AIM Address
CrazyCat
Revered One


Joined: 13 Jan 2002
Posts: 1032
Location: France

PostPosted: Tue Mar 02, 2021 6:48 pm    Post subject: Reply with quote

As I said, my changes weren't tested, I'll look further tomorrow.

But you haven't to create the files by the hand, it's just the old files which cannot be used and that you have to rename if you want to keep the old datas.
_________________
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
View user's profile Send private message Visit poster's website
CrazyCat
Revered One


Joined: 13 Jan 2002
Posts: 1032
Location: France

PostPosted: Wed Mar 03, 2021 4:14 am    Post subject: Reply with quote

So... I just made 2 errors in my previous script.
Here is the working one:
Code:
#####################################################
#    link logger v 1.1 by m00nie
#            www.m00nie.com
#
#   Mostly written as a way to practice TCL....
# V1.1 Added Global Stats
# V1.0 Original release
#####################################################
# Settings to edit below
#####################################################
# Debug? Enabling debug is very verbose!
set linklog(debug) 1

# Users to ignore? E.g other bots
set linklog(ignore) "some people"

# Command to search for link
set linklog(call) "!link"

# Command for stats
set linklog(stats) "!linkstats"

# Location of the file to store links
set linklog(location) "databases/links_"

# output line start
set linklog(out) "\002\[\002Link\002\]\002 "


#####################################################
# No need to edit anything from below here
#####################################################

set linklog(debugstring) "Link Logger Debug: "

bind pub - $linklog(call) linkcall
bind pub - $linklog(stats) linkstats
bind pubm - "*://*" linklogger
setudef flag linklog

###################
# Link logging process
###################
proc linklogger {nick host hand chan arg} {
   global linklog
   if {$linklog(debug) == 1} {
      putlog "$linklog(debugstring) nick = $nick"
      putlog "$linklog(debugstring) host = $host"
      putlog "$linklog(debugstring) hand = $hand"
      putlog "$linklog(debugstring) chan = $chan"
      putlog "$linklog(debugstring) arg = $arg"
   }
   ###################
   # Checking the channel has been set
   ###################

   if {[channel get $chan linklog]==0} {
      puthelp "PRIVMSG $chan :not activated here"
      return 0
   } else {
      set tchan [string tolower $chan]
   }
   ###################
   # Check is user ignored
   ###################
   set linklog(ignoretest) [regexp -nocase $nick $linklog(ignore)]
   if {$linklog(ignoretest) == 1} {
      if {$linklog(debug) == 1} {
         puts "$linklog(debugstring) $nick is being ignored"
         puts "$linklog(debugstring) Ingnore variable is $linklog(ignore)"
         return
      }
      return
   }
   ###################
   # Check for a link
   ###################
   if {[regexp -- {(https?://[a-z0-9\-]+\.[a-z0-9\-\.]+(?:/|(?:/[a-zA-Z0-9!#\$%&'\*\+,\-\.:;=\?@\[\]_~]+)*))} $arg match linklog(url)]} {
      if {$linklog(debug) == 1} {
         putlog "$linklog(debugstring) Found link, chan set and not ignoring user!"
         putlog "Link is $linklog(url)"
      }
      ###################
      # Open the file append and close
      ###################
      set time [clock seconds]
      set linklog(fileappend) [open $linklog(location)${tchan}_$nick a]
      if {$linklog(debug) == 1} {
         putlog "$linklog(debugstring) File $linklog(location) opened at $time"
      }
      puts $linklog(fileappend) "Linked to $linklog(url) @ [clock format $time]"
      close $linklog(fileappend)
      if {$linklog(debug) == 1} {
         putlog "$linklog(debugstring) File $linklog(location) closed"
      }
   } else {
      if {$linklog(debug) == 1} {
         putlog "$linklog(debugstring) This shouldnt really happen....."
         putlog "$linklog(debugstring) Channel set, user not ignored but no valid link!"
      }
   }
}

###################
# Link searching
###################
proc linkcall {nick host hand chan arg} {
   global linklog
   if {[channel get $chan linklog]==0} {
      puthelp "PRIVMSG $chan :not activated here"
      return 0
   } else {
      set tchan [string tolower $chan]
   }
   ###################
   # Check for no arguments then spam help
   ###################
   if {[string length $arg] < 1} {
      puthelp "PRIVMSG $chan :usage: $linklog(call) <username>"
      puthelp "PRIVMSG $chan :usage: $linklog(stats) <username>"
      puthelp "PRIVMSG $chan :usage: $linklog(stats) for global stats"   
      return
   }
   if {$linklog(debug) == 1} {
      putlog "$linklog(debugstring) $linklog(call) triggered linkcall"
      putlog "$linklog(debugstring) The argument was $arg"
   }
   ###################
   # Check a file exists
   ###################
   set linklog(fileresult) [linkfilecheck $linklog(location)${tchan}_$arg]
   if {$linklog(fileresult) != 1} {
      puthelp "PRIVMSG $chan $linklog(out) No links found for $arg :("
      putlog "$linklog(debugstring) File $linklog(location)$arg doesnt exist??"
      return
   }
   ###################
   # Open and read the file line by line
   ###################
   set loop 0
   set linklog(fileopen) [open $linklog(location)${tchan}_$arg r]
   set lines [split [read -nonewline $linklog(fileopen)] "\n"]
   puthelp "PRIVMSG $chan $linklog(out) $arg's most recent links"
   if {$linklog(debug) == 1} {
      putlog "$linklog(debugstring) $linklog(location)$arg File open and split"
   }
   for {set i [llength $lines]} {$i} {incr i -1} {
      set line [lindex $lines $i-1]
      if {$loop > 2} {
         return
      }
      puthelp "PRIVMSG $chan $line"
      if {$linklog(debug) == 1} {
         putlog "$linklog(debugstring) loop = $loop "
      }
      incr loop
   }
   close $linklog(fileopen)
   if {$linklog(debug) == 1} {
      putlog "$linklog(debugstring) File $linklog(location)$arg closed"
   }
}

###################
# Get some stats
###################
proc linkstats {nick host hand chan arg} {
   global linklog
   if {[channel get $chan linklog]==0} {
      puthelp "PRIVMSG $chan :not activated here"
      return 0
   } else {
      set tchan [string tolower $chan]
   }
   if {$linklog(debug) == 1} {
      putlog "$linklog(debugstring) link stats called with arg $arg"
   }
   if {[string length $arg] < 1} {
      if {$linklog(debug) == 1} {
         putlog "$linklog(debugstring) No arg given to $linklog(stats)"
      }
      set files [glob $linklog(location)${tchan}_*]
      if {$linklog(debug) == 1} {
         putlog "$linklog(debugstring) Files to be checked are $files"
      }
      if { [llength $files] > 0 } {
         foreach f [lsort $files] {
            set name [lindex [split $f "_"] end]
            set size [linklinecount $f]
            lappend thelist "$name $size"
         }
      } else {
         puthelp "PRIVMSG $chan $linklog(out) Nobody has linked to anything :o"
      }
      if {$linklog(debug) == 1} {
         putlog "$linklog(debugstring) unsorted list is $thelist "
      }
      lappend outputlist [lsort -index 1 -decreasing -integer $thelist]
      if {$linklog(debug) == 1} {
         putlog "$linklog(debugstring) Sorted list is $outputlist"
      }
      set x "0"
      while {$x < 3} {
         set list [lindex $outputlist 0 $x]
         incr x
         lassign $list user count
         if {$count < 0} {
            return
         }
         if {$x == 1} {
            puthelp "PRIVMSG $chan $linklog(out) Top link spammers"
         }
         puthelp "PRIVMSG $chan $x. $user spammed $count links"
      }
      return
   }
   # Check the file exists first
   set linklog(fileresult) [linkfilecheck $linklog(location)$arg]
   if {$linklog(debug) == 1} {
      putlog "$linklog(debugstring) files we try to open will be $linklog(fileresult)"
   }
   if {$linklog(fileresult) != 1} {
      puthelp "PRIVMSG $chan $linklog(out) No links found for $arg :("
      putlog "$linklog(debugstring) File $linklog(location)$arg doesnt exist??"
      return
   }
   # Count the links
   set linkcount [linklinecount $linklog(location)$arg]
   puthelp "PRIVMSG $chan $arg has spammed $linkcount links"
}

###################
# Count the lines in a file
###################
proc linklinecount {FILENAME} {
   global linklog
   if {$linklog(debug) == 1} {
      putlog "$linklog(debugstring) Linklinecount called with arg $FILENAME"
   }
   # c
   set i 0
   set fid [open $FILENAME r]
   while {[gets $fid line] > -1} {incr i}
   close $fid
   if {$linklog(debug) == 1} {
      putlog "$linklog(debugstring) Linklinecount returning $i lines counted"
   }
   return $i
}

###################
# Check file exsists
###################
proc linkfilecheck {FILENAME} {
   global linklog
   if {$linklog(debug) == 1} {
      putlog "$linklog(debugstring) Linkfilecheck called with arg $FILENAME"
   }
   # checking the file exists
   if [file exists $FILENAME] then {
      # file exists
      return 1
   } else {
      # file not exists
      return "0"
   }
}
putlog "link logger v 1.1 by m00nie http://www.m00nie.com :)"

_________________
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
View user's profile Send private message Visit poster's website
CrazyCat
Revered One


Joined: 13 Jan 2002
Posts: 1032
Location: France

PostPosted: Wed Mar 03, 2021 6:00 am    Post subject: Reply with quote

The sqlite version:
Code:
# sqlink logger

namespace eval sqlink {

   # path to the database (the directory must exists)
   variable dbpath "databases/"
   
   # list of ignored users
   variable ignore {john roger guru}

   # Command to search for link
   variable call "!link"
   # Command for stats
   variable stats "!linkstats"

   # output line start
   variable out "\002\[\002Link\002\]\002 "
   
   variable debug 1

   if { [catch { package require sqlite3 }] } { putloglev o * "Error : you need sqlite3 package" ; return }

   variable db
   
   proc opendb {} {
      sqlite3 ::sqlink::db ${::sqlink::dbpath}/linklogger.sqlite
   }

   proc closedb {} {
      ::sqlink::db close
   }

   proc init {} {
      ::sqlink::opendb
      ::sqlink::db eval {CREATE TABLE IF NOT EXISTS links (id integer primary key, chan text, nick text, url text, seentime datetime)}
      ::sqlink::db eval {CREATE INDEX IF NOT EXISTS id ON links(id)}
      ::sqlink::db eval {CREATE INDEX IF NOT EXISTS chan ON links(chan)}
      ::sqlink::db eval {CREATE INDEX IF NOT EXISTS nick ON links(nick)}
      ::sqlink::closedb
   }
   
   variable debugstring "Link Logger Debug: "

   bind pub - $::sqlink::call ::sqlink::linkcall
   bind pub - $::sqlink::stats ::sqlink::linkstats
   bind pubm - "*://*" ::sqlink::linklogger
   setudef flag linklog

   proc linklogger {nick host hand chan arg} {
      if {$::sqlink::debug == 1} {
         putlog "$::sqlink::debugstring nick = $nick"
         putlog "$::sqlink::debugstring host = $host"
         putlog "$::sqlink::debugstring hand = $hand"
         putlog "$::sqlink::debugstring chan = $chan"
         putlog "$::sqlink::debugstring arg = $arg"
      }
      if {[channel get $chan linklog]==0} {
         puthelp "PRIVMSG $chan :not activated here"
         return 0
      }
      if {[lsearch -nocase $::::sqlink::ignore $nick] != -1} {
         if {$::sqlink::debug == 1} {
            puts "$::sqlink::debugstring $nick is being ignored"
            return
         }
         return
      }
      if {[regexp -- {(https?://[a-z0-9\-]+\.[a-z0-9\-\.]+(?:/|(?:/[a-zA-Z0-9!#\$%&'\*\+,\-\.:;=\?@\[\]_~]+)*))} $arg match url]} {
         if {$::sqlink::debug == 1} {
            putlog "$::sqlink::debugstring Found link, chan set and not ignoring user!"
            putlog "Link is $url"
         }
         ::sqlink::opendb
         ::sqlink::db eval {INSERT INTO links (chan, nick, url, seentime) VALUES (LOWER($chan), LOWER($nick), $url, strftime('%s','now'))}
         ::sqlink::closedb
      }
   }
   
   proc linkcall {nick host hand chan arg} {
      if {[channel get $chan linklog]==0} {
         puthelp "PRIVMSG $chan :not activated here"
         return 0
      }
      if {[string length $arg] < 1} {
         puthelp "PRIVMSG $chan :usage: $::sqlink::call <username>"
         puthelp "PRIVMSG $chan :usage: $::sqlink::stats <username>"
         puthelp "PRIVMSG $chan :usage: $::sqlink::stats for global stats"   
         return
      }
      if {$::sqlink::debug == 1} {
         putlog "$::sqlink::debugstring $::sqlink::call triggered linkcall"
         putlog "$::sqlink::debugstring The argument was $arg"
      }
      ::sqlink::opendb
      set ulinks [::sqlink::db eval {SELECT * FROM links WHERE LOWER(nick)=LOWER($arg) AND chan=LOWER($chan) ORDER BY seentime desc}]
      if {[llength $ulinks]==0} {
         puthelp "PRIVMSG $chan $::sqlink::out No links found for $arg :("
         return 0
      }
      puthelp "PRIVMSG $chan $::sqlink::out $arg's most recent links"
      for {set i 0} {$i < [llength $ulinks]} {incr i 5} {
         puthelp "PRIVMSG $chan :Linked [lindex $ulinks $i+3] on [clock format [lindex $ulinks $i+4] -format %d/%m/%Y\ \@\ %H:%M:%S]"
      }
      ::sqlink::closedb
   }
   
   proc linkstats {nick host hand chan text} {
      if {[channel get $chan linklog]==0} {
         puthelp "PRIVMSG $chan :not activated here"
         return 0
      }
      if {[llength [split $text]] == 1} {
         set where " AND LOWER(nick)=LOWER($nick)"
      } else {
         set where ""
      }
      ::sqlink::opendb
      set top [::sqlink::db eval {SELECT COUNT(*) AS top, nick FROM links WHERE chan=LOWER($chan)$where GROUP BY nick ORDER BY top DESC LIMIT 3}]
      if {[llength $top]==0} {
         putserv "PRIVMSG $chan :No links where posted here"
         return 0
      }
      putserv "PRIVMSG $chan :Top spammers for $chan"
      for {set i 0} {$i < [llength $top]} {incr i 2} {
         putserv "PRIVMSG $chan :[lindex $top $i+1] with [lindex $top $i] links"
      }
      ::sqlink::closedb
   }
}

::sqlink::init

_________________
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
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber