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 

[Request] Bot Report File Script - King

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


Joined: 04 Feb 2016
Posts: 5
Location: America

PostPosted: Fri Feb 12, 2016 11:32 pm    Post subject: [Request] Bot Report File Script - King Reply with quote

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).
Back to top
View user's profile Send private message
willyw
Owner


Joined: 15 Jan 2009
Posts: 925

PostPosted: Sat Feb 13, 2016 9:30 am    Post subject: Re: [Request] Bot Report File Script - King Reply with quote

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 !
Back to top
View user's profile Send private message
SpiKe^^
Owner


Joined: 12 May 2006
Posts: 505
Location: Tennessee, USA

PostPosted: Sat Feb 13, 2016 5:44 pm    Post subject: ReportBot Ver 0.1 by SpiKe^^ Reply with quote

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:

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


_________________
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com


Last edited by SpiKe^^ on Sat Feb 13, 2016 10:54 pm; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
King
Voice


Joined: 04 Feb 2016
Posts: 5
Location: America

PostPosted: Sat Feb 13, 2016 10:34 pm    Post subject: Reply with quote

Nice, thanks Spike^^, that works perfectly, had to input the proc to get it working though since you forgot them Smile 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 Smile
Back to top
View user's profile Send private message
SpiKe^^
Owner


Joined: 12 May 2006
Posts: 505
Location: Tennessee, USA

PostPosted: Sat Feb 13, 2016 10:57 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message Visit poster's website
SpiKe^^
Owner


Joined: 12 May 2006
Posts: 505
Location: Tennessee, USA

PostPosted: Sun Feb 14, 2016 2:24 pm    Post subject: ReportBot Ver 0.2 by SpiKe^^ Reply with quote

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:

###########################  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
Back to top
View user's profile Send private message Visit poster's website
King
Voice


Joined: 04 Feb 2016
Posts: 5
Location: America

PostPosted: Sun Feb 14, 2016 4:00 pm    Post subject: Reply with quote

Thanks a lot Spike^^, does everything exactly as I wanted, actually learn some stuffs from this script Smile
_________________
Best Regards,
- King
Back to top
View user's profile Send private message
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