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.

[Request] Bot Report File Script - King

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
K
King
Voice
Posts: 5
Joined: Thu Feb 04, 2016 7:12 am
Location: America

[Request] Bot Report File Script - King

Post by King »

Hello world,

I'm requesting a simple script for bot reports, usually would be categorized as feedbacks or bug reports for the bot. Which will then saves the report to a .txt file along with the issuer. For example;

<~King> !reportbot Please add a spam protection to the bot, thank you.
[notice from bot] Your report was sent, thanks for your corporation King!

BotReports.txt example.

Nick: King Userhost: (King@Reporting/bot/example) Report: Please add a spam protection to the bot, thank you. Date: 2/12/2016.
Nick: Test Userhost: (test@test.test.test) Report: Testing bot report.

This is just an example, you can create it simpler than this without userhost and time, just log reports to a .txt file per lines and I'll try to take it from there.

If possible, I'd like to be notified that a new report was recieved. (As the bot owner).
w
willyw
Revered One
Posts: 1197
Joined: Thu Jan 15, 2009 12:55 am

Re: [Request] Bot Report File Script - King

Post by willyw »

King wrote:
... Which will then saves the report to a .txt file ...

...
... I'll try to take it from there.

Check out:

http://forum.egghelp.org/viewtopic.php?t=6885

That shows you not only how to write to a text file, but also how to read from one too.
For a fun (and popular) Trivia game, visit us at: irc.librairc.net #science-fiction . Over 300K Q & A to play in BogusTrivia !
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

ReportBot Ver 0.1 by SpiKe^^

Post by SpiKe^^ »

Script has not been tested, try it out and see what we have.

Some notes on this script:

This script only keeps a data file so it can retain all its current data through an Eggdrop start/restart.
Do Not edit this file except through the public !reportbot and private message !reportdel commands!

All script data is always stored and kept current in the global array variable reBot(-data). That variable is a tcl list, and each element of that list is a tcl list with 6 elements like this...
{unixtime nick uhost handle channel reporttext}

The script currently has just 3 commands:

1) Public command: !reportbot <something to report> :available to all channel users.

2) Private message command: !reportlist :available to all global owners, masters, and operators.
Use this command to see all current reports.
Use the report numbers from this list for the !reportdel command.

3) Private message command: !reportdel <report number(s) to delete> :available to all global owners, masters, and operators.
Use this command to delete reports that are closed out.
Use the report numbers from the current !reportlist command reply.
IMPORTANT: After a successful !reportdel command, all/some reports may be renumbered to reflect their now current numbering!!!
Make sure to get the current report numbering with the !reportlist command before doing another !reportdel command!!!

Code: Select all

###########################  ReportBot Version 0.1  ###########################

# author:  SpiKe^^ #
# e-mail:  spike<at>mytclscripts<dot>com #
# webpage: http://mytclscripts.com/ #

# This file is Copyrighted under the GNU Public License. #
# http://www.gnu.org/copyleft/gpl.html #

# Note: this script requires tcl 8.5 or higher! #
# Note: this script requires alltools.tcl! #


########################### General Script Settings ###########################

# Set the channel(s) for this script to run in.
#   Ex.  set reBot(chan) {#yourchannel}
#   Ex.  set reBot(chan) {#yourchannel #anotherchannel #someotherchan}
set reBot(chan) {#yourchannel}

# Set the file name or /fullRoute/fileName of the script data file.
#   Ex.  set reBot(file) {reBot_data.txt}
#   Ex.  set reBot(file) {/usr/home/spike/eggdrop/scripts/reBot_data.txt}
set reBot(file) {reBot_data.txt}

# Should this script message the perm owner(s) when a new report is received?
#  0 = no, do not message the owner(s)
#  1 = yes, message the owner(s) if they are online
set reBot(msgOwner) 1


############################ END OF SCRIPT SETINGS ############################

## edit command access flags and triggers here ##
bind pub -|- !reportbot reportBot:add
bind msg mno !reportlist reportBot:list
bind msg mno !reportdel reportBot:del
# END edit command access flags & triggers here #


set reBot(chan) [split $reBot(chan)]

proc reportBot:add {nick uhost hand chan text} {
  global reBot owner

  if {[lsearch -exact -nocase $reBot(chan) $chan] == -1} { return 0 }

  set text [string trim $text]
  if {$text eq ""} {
    putnotc $nick "Correct syntax is: !reportbot <something to report>"
    putnotc $nick "Example: !reportbot The bot is no longer opping me."
    return 0
  }

  if {![string match {[.!?]} [stridx $text end]]} { append text "." }

  lappend reBot(-data) [list [unixtime] $nick $uhost $hand $chan $text]
  reportBot:writeFile

  putnotc $nick "Your report has been received. Thanks for participating."

  if {$reBot(msgOwner) == 1} {
    set msg "\[ReportBot\] New report received from $nick $uhost"
    if {[llength $reBot(chan)] > 1} { append msg " on $chan" }

    foreach hnd [split $owner ", "] {
      if {$hnd eq ""} { continue }

      if {[handonchan $hnd] && [matchattr $hnd n]} {
        putmsg [hand2nick $hnd] "$msg \"$text\""
      }
    }
  }
  return 0
}

proc reportBot:list {nick uhost hand text} {
  global reBot

  if {![llength $reBot(-data)]} {
    putmsg $nick "Report list is currently empty."

  } else {
    set cnt 0

    foreach item $reBot(-data) {
      incr cnt
      foreach {ut nk uh hn ch tx} $item { break }

      set date [strftime %m/%d/%Y $ut]
      if {[llength $reBot(chan)] == 1} {  set ch ""
      } else { set ch " on $ch" }

      putmsg $nick "\[$cnt\] $nk $uh$ch Report: $tx Date: $date"
    }
  }

  return 0
}

proc reportBot:del {nick uhost hand text} {
  global reBot

  set text [split [string trim $text]]
  if {![string is digit -strict [lindex $text 0]]} {
    putmsg $nick "Correct syntax is: !reportdel <report number(s) to delete>"
    putmsg $nick "Example: !reportdel 3"
    putmsg $nick "Example: !reportdel 1 3 4"

    if {[llength $reBot(-data)]} { return 0 }
  }

  if {![llength $reBot(-data)]} {
    putmsg $nick "Report list is currently empty."

  } else {
    set del ""  ;  set err ""
    foreach item $text {
      if {$item eq ""} { continue }

      if {[string is digit $item] && $item <= [llength $reBot(-data)]} {
        lappend del $item
      } else {  set err $item  ;  break  }
    }

    if {[llength $del]} {
      set cnt 0
      set newdata ""
      foreach item $reBot(-data) {
        incr cnt
        if {[lsearch $del $cnt] == -1} { lappend newdata $item ; continue }

        foreach {ut nk uh hn ch tx} $item { break }
        putmsg $nick "Deleted report #$cnt: $nk $uh \"$tx\""
      }
      set reBot(-data) $newdata
      reportBot:writeFile
    }

    if {$err ne ""} {
      if {[string is digit $err]} {
        putmsg $nick "ReportBot Error: Report #$err does not exist!"
        putmsg $nick "Use: !reportlist :for a list of all current reports."
      } else {
        putmsg $nick "ReportBot Error: Invalid !reportdel command option: $err"
        putmsg $nick "Use: !reportdel :for correct syntax to delete reports."
      }
    }
  }

  return 0
}

# set global reBot(-data) variable to match script data file #
proc reportBot:readFile {} {
  global reBot

  if {![file exists $reBot(file)]} {
    set reBot(-data) ""

  } else {
    set id [open $reBot(file)]
    set data [read -nonewline $id]
    close $id

    set reBot(-data) [split $data \n]
  }
}

# set global reBot(-data) variable at script load #
reportBot:readFile


# write script data file to match global reBot(-data) variable #
proc reportBot:writeFile {} {
  global reBot

  if {![llength $reBot(-data)]} {
    file delete $reBot(file)

  } else {
    set id [open $reBot(file) w]
    foreach item $reBot(-data) {
      puts $id $item
    }
    close $id
  }
}

putlog "ReportBot Ver 0.1 by SpiKe^^ loaded."

Last edited by SpiKe^^ on Sat Feb 13, 2016 10:54 pm, edited 1 time in total.
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
K
King
Voice
Posts: 5
Joined: Thu Feb 04, 2016 7:12 am
Location: America

Post by King »

Nice, thanks Spike^^, that works perfectly, had to input the proc to get it working though since you forgot them :) works exactly as I wanted.

Seems quiet easy to you considering the fact that you've done it with ease, though, I'd like to change the time to duration instead of date. But, it's fine otherwise, thanks again :)
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

Post by SpiKe^^ »

King wrote:had to input the proc to get it working though since you forgot them
Sorry 'bout that:)
All fixed in the above posted script.
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

ReportBot Ver 0.2 by SpiKe^^

Post by SpiKe^^ »

King wrote:though, I'd like to change the time to duration instead of date.
Here is a new version of the script with the option to choose date submitted or time ago...

Code: Select all

###########################  ReportBot Version 0.2  ###########################

# author:  SpiKe^^ #
# e-mail:  spike<at>mytclscripts<dot>com #
# webpage: http://mytclscripts.com/ #

# This file is Copyrighted under the GNU Public License. #
# http://www.gnu.org/copyleft/gpl.html #

# Note: this script requires tcl 8.5 or higher! #
# Note: this script requires alltools.tcl! #


########################### General Script Settings ###########################

# Set the channel(s) for this script to run in.
#   Ex.  set reBot(chan) {#yourchannel}
#   Ex.  set reBot(chan) {#yourchannel #anotherchannel #someotherchan}
set reBot(chan) {#yourchannel}

# Set the file name or /fullRoute/fileName of the script data file.
#   Ex.  set reBot(file) {reBot_data.txt}
#   Ex.  set reBot(file) {/usr/home/spike/eggdrop/scripts/reBot_data.txt}
set reBot(file) {reBot_data.txt}

# Should this script message the perm owner(s) when a new report is received?
#  0 = no, do not message the owner(s)
#  1 = yes, message the owner(s) if they are online
set reBot(msgOwner) 1

# In the return from !reportlist, use date submitted or time ago??
#  1 = use date submitted:   Example.  Date: 2/12/2016
#  2 = use time ago:  Example.  Time: about 1 hour & 15 minutes ago.
set reBot(addWhen) 2


############################ END OF SCRIPT SETINGS ############################

## edit command access flags and triggers here ##
bind pub -|- !reportbot reportBot:add
bind msg mno !reportlist reportBot:list
bind msg mno !reportdel reportBot:del
# END edit command access flags & triggers here #


set reBot(chan) [split $reBot(chan)]

proc reportBot:add {nick uhost hand chan text} {
  global reBot owner

  if {[lsearch -exact -nocase $reBot(chan) $chan] == -1} { return 0 }

  set text [string trim $text]
  if {$text eq ""} {
    putnotc $nick "Correct syntax is: !reportbot <something to report>"
    putnotc $nick "Example: !reportbot The bot is no longer opping me."
    return 0
  }

  if {![string match {[.!?]} [stridx $text end]]} { append text "." }

  lappend reBot(-data) [list [unixtime] $nick $uhost $hand $chan $text]
  reportBot:writeFile

  putnotc $nick "Your report has been received. Thanks for participating."

  if {$reBot(msgOwner) == 1} {
    set msg "\[ReportBot\] New report received from $nick $uhost"
    if {[llength $reBot(chan)] > 1} { append msg " on $chan" }

    foreach hnd [split $owner ", "] {
      if {$hnd eq ""} { continue }

      if {[handonchan $hnd] && [matchattr $hnd n]} {
        putmsg [hand2nick $hnd] "$msg "$text""
      }
    }
  }
  return 0
}

proc reportBot:list {nick uhost hand text} {
  global reBot

  if {![llength $reBot(-data)]} {
    putmsg $nick "Report list is currently empty."

  } else {
    set cnt 0

    foreach item $reBot(-data) {
      incr cnt
      foreach {ut nk uh hn ch tx} $item { break }

      if {[llength $reBot(chan)] == 1} {  set ch ""
      } else { set ch " on $ch" }

      if {$reBot(addWhen) == 2} {
        set when "Time: about "
        set dur [split [duration [expr {[unixtime] - $ut}]]]

        if {[llength $dur] == 2} {
          append when "[join $dur] ago."
        } else {
          if {[string match "sec*" [lindex $dur end]]} {
            set dur [lrange $dur 0 end-2]
          }
          if {[llength $dur] == 2} {
            append when "[string trimright [join $dur] ","] ago."
          } else {
            set dur [lrange $dur 0 3]
            set dur [lreplace $dur 1 1 [string trim [lindex $dur 1] ","] &]
            append when "[string trimright [join $dur] ","] ago."
          }
        }

      } else { set when "Date: [strftime %m/%d/%Y $ut]" }

      putmsg $nick "\[$cnt\] $nk $uh$ch Report: $tx $when"
    }
  }

  return 0
}

proc reportBot:del {nick uhost hand text} {
  global reBot

  set text [split [string trim $text]]
  if {![string is digit -strict [lindex $text 0]]} {
    putmsg $nick "Correct syntax is: !reportdel <report number(s) to delete>"
    putmsg $nick "Example: !reportdel 3"
    putmsg $nick "Example: !reportdel 1 3 4"

    if {[llength $reBot(-data)]} { return 0 }
  }

  if {![llength $reBot(-data)]} {
    putmsg $nick "Report list is currently empty."

  } else {
    set del ""  ;  set err ""
    foreach item $text {
      if {$item eq ""} { continue }

      if {[string is digit $item] && $item <= [llength $reBot(-data)]} {
        lappend del $item
      } else {  set err $item  ;  break  }
    }

    if {[llength $del]} {
      set cnt 0
      set newdata ""
      foreach item $reBot(-data) {
        incr cnt
        if {[lsearch $del $cnt] == -1} { lappend newdata $item ; continue }

        foreach {ut nk uh hn ch tx} $item { break }
        putmsg $nick "Deleted report #$cnt: $nk $uh "$tx""
      }
      set reBot(-data) $newdata
      reportBot:writeFile
    }

    if {$err ne ""} {
      if {[string is digit $err]} {
        putmsg $nick "ReportBot Error: Report #$err does not exist!"
        putmsg $nick "Use: !reportlist :for a list of all current reports."
      } else {
        putmsg $nick "ReportBot Error: Invalid !reportdel command option: $err"
        putmsg $nick "Use: !reportdel :for correct syntax to delete reports."
      }
    }
  }

  return 0
}

# set global reBot(-data) variable to match script data file #
proc reportBot:readFile {} {
  global reBot

  if {![file exists $reBot(file)]} {
    set reBot(-data) ""

  } else {
    set id [open $reBot(file)]
    set data [read -nonewline $id]
    close $id

    set reBot(-data) [split $data \n]
  }
}

# set global reBot(-data) variable at script load #
reportBot:readFile


# write script data file to match global reBot(-data) variable #
proc reportBot:writeFile {} {
  global reBot

  if {![llength $reBot(-data)]} {
    file delete $reBot(file)

  } else {
    set id [open $reBot(file) w]
    foreach item $reBot(-data) {
      puts $id $item
    }
    close $id
  }
}

putlog "ReportBot Ver 0.2 by SpiKe^^ loaded."

SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
K
King
Voice
Posts: 5
Joined: Thu Feb 04, 2016 7:12 am
Location: America

Post by King »

Thanks a lot Spike^^, does everything exactly as I wanted, actually learn some stuffs from this script :)
Best Regards,
- King
Post Reply