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 

Reports Users

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


Joined: 08 Jun 2020
Posts: 26

PostPosted: Wed Jul 28, 2021 4:51 pm    Post subject: Reports Users Reply with quote

Greetings friends ... I was testing this TCL to inform users ...

But I don't know how to end ...

As always I thank you for all your help.


public command

ORATEGOD: !report
Bot: ERROR! Enter a bot and info to report. Format: !report <user> <description>

ORATEGOD: !report <user> <description>
Bot: ORATEGOD: Your report has been received. (Thanks)..
Bot: ORATEGOD: Ihr Bericht wurde erhalten. (Vielen Dank)..
Bot: ORATEGOD: Se ha recibido su informe. (Gracias)..

command for bot owner

!report list (shows list of reports (if there are any)
Bot: 1. user1 description of the problem.
Bot: 2. user2 description of the problem.
Bot: 3. user3 description of the problem.
Bot: 4. user4 description of the problem.

!report del
Bot: Houston, we have a problem

!report del 3
Bot: report number 3 has been deleted
Quote:
set report(file) "report.txt"
set report(us.thanks) "Your report has been received. (Thanks)."
set report(de.thanks) "Ihr Bericht wurde erhalten. (Vielen Dank)."
set report(es.thanks) "Se ha recibido su reporte. (Gracias)."

bind pub -|- !report report:tofile

proc report:tofile {nk uh hn ch tx} {
global report
set date [strftime %d/%m/%y]
set open [open $report(file) a]
puts $open "- $nk reported: $tx"
close $open
puthelp "PRIVMSG $ch :${nk}: $report(us.thanks)."
puthelp "PRIVMSG $ch :${nk}: $report(de.thanks)."
puthelp "PRIVMSG $ch :${nk}: $report(es.thanks)."
}

putlog "************************************"
putlog "* REPORT ***** LOADED ***** REPORT *"
putlog "************************************"


Sorry my bad english (:
Back to top
View user's profile Send private message AIM Address
CrazyCat
Owner


Joined: 13 Jan 2002
Posts: 991
Location: France

PostPosted: Mon Aug 02, 2021 8:25 am    Post subject: Reply with quote

I did this little script:
Code:
set report(file) "report.txt"
set report(us.thanks) "Your report has been received. (Thanks)."
set report(de.thanks) "Ihr Bericht wurde erhalten. (Vielen Dank)."
set report(es.thanks) "Se ha recibido su reporte. (Gracias)."

bind pub -|- !report report

# main procedure: controler for actions
proc report {nick uhost handle chan text} {
   if {[llength [split $text]] == 0 } {
      report::error $nick $chan
      return 0
   }
   switch [join [lindex [split $text] 0]] {
      list {
         if {![report:hasrights $nick $chan $handle]} { return 0 }
         report:list $nick $uhost $handle $chan $text
      del {
         if {![report:hasrights $nick $chan $handle]} { return 0 }
         report:del $nick $uhost $handle $chan $text
      }
      default {
         report:save $nick $uhost $chan $text
      }
}

# Check if user can list/del
proc report:hasrights {nick chan handle} {
   if {($handle == "*") || ![matchattr $handle +n]} {
      report:error $nick $chan
      return 0
   } else {
      return 1
   }
}

# Send generic error message
proc report:error {nick chan} {
   putserv "PRIVMSG $chan :\002HOUSTON!\002 We've had a problem"
}

# Saves a report
proc report:save {nick uhost chan text} {
   if {[llength [split $text]] < 2 } {
      putserv "PRIVMSG $nick :\002ERROR!\002 Enter a bot and info to report. Format: \002!report <user> <description>\002"
      return 0
   }
   set date [strftime %d/%m/%y]
   set fo [open $::report(file) a]
   set vbot [join [lindex [split $text] 0]]
   set desc [join [lrange [split $text] 1 end]]
   report:save $nick $uhost $chan $vbot $desc
   puthelp "PRIVMSG $nick :$::report(us.thanks)"
   puthelp "PRIVMSG $nick :$::report(de.thanks)"
   puthelp "PRIVMSG $nick :$::report(es.thanks)"
   puts $fo "\[$date\] <$nick@$uhost> on $chan reported $vbot :$desc"
   close $fo
}

# Checks if report file exists and is not empty
proc report:getfile {nick} {
   if {![file exists $::report(file)]} {
      putserv "PRIVMSG $nick :No report"
      return 0
   }
   set fi [open $::report(file) r]
   set lines [read -nonewline $fi]
   if {$lines == ""} {
      putserv "PRIVMSG $nick :No report"
      return 0
   }
   close $fi
   return $lines
}

# list content of report file to user
proc report:list {nick uhost handle chan text} {
   if {![report:hasrights $nick $chan $handle]} { return 0 }
   set lines report:getfile $nick
   if {$lines == 0} { return 0 }
   set cpt 0
   foreach line [split $lines "\n"] {
      incr cpt
      putserv "PRIVMSG $nick :#$cpt $line"
   }
}

# delete a line in the report file
proc report:del {nick uhost handle chan text} {
   if {![report:hasrights $nick $chan $handle]} { return 0 }
   set args [split $text]
   if {[llength $args]!=2 || [join [lindex $args] 0]!="del"} {
      report:error $nick $chan
      return 0
   }
   set ln [join [lindex $args 1]]
   if {![string is integer -strict $ln]} {
      report:error $nick $chan
      return 0
   }
   set fo [open ${::report(file).tmp} w]
   set lines report:getfile $nick
   if {$lines == 0} { return 0 }
   set cpt 0
   foreach line [split $lines "\n"] {
      incr cpt
      if {$cpt == $ln} { continue }
      puts $fo $line
   }
   close $fo
   file rename -force -- ${::report(file).tmp} $::report(file)
}

putlog "************************************"
putlog "* REPORT ***** LOADED ***** REPORT *"
putlog "************************************"


It can seem complex because I separated functionalities to allow their reuse.

Note that I don't check if the reported user exists on chan, and I double-check if user is allowed to list/del reports (check in controler and in dedicated proc).
This is to allow to add binds to directly run proc, like bind pub n !rdel report:del

I didn't test the script, just made it on the fly 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
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