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.

A Simple play file script

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
B
BigToe
Halfop
Posts: 99
Joined: Thu Dec 30, 2010 4:49 pm

A Simple play file script

Post by BigToe »

hello

All I need is rather simple play file script
via public command you set the time and the file you want to be played in a channel, the bot will set +m before it plays it, and -m after it finishes to play it

example here:

<Me> !play 21:30 Script.txt #ChannelNameHere
<Bot> I will play script.txt to #ChannelNameHere at 21:30

* 21:30 *

#ChannelNameHere:

*** Bot sets mode +m
<Bot> 1st line from Script.txt
<Bot> 2nd line from Script.txt
....
*** Bot sets mode -m
B
BigToe
Halfop
Posts: 99
Joined: Thu Dec 30, 2010 4:49 pm

Post by BigToe »

Anyone, please?
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Code: Select all

namespace eval cronPlay {
  set play(info) ""
  bind pub * !play [namespace current]::create

  proc create {nick uhost hand chan text} {
    variable play
    if {[scan $text {%[^:]:%s%s%s} hour minute file channel] != 4} {
      puthelp "NOTICE $nick :Usage: !play <hour:minute> <file> <#channel>"
      return
    }
    if {![regexp {^[0-9]+$} $hour] || ![regexp {^[0-9]+$} $minute]} {
      puthelp "NOTICE $nick :Error, the hour or minute aren't valid."
      return
    }
    if {![file exists $file]} {
      puthelp "NOTICE $nick :Error, $file file doesn't exist."
      return
    }
    if {![validchan $channel]} {
      puthelp "NOTICE $nick :Error, $channel channel is not valid."
      return
    }
    set play(info) "$file $channel"
    bind cron - "$minute $hour * * *" [namespace current]::play
    puthelp "PRIVMSG $chan :I will play $file to $channel at $hour:$minute"
  }

  proc play {minute hour day month weekday} {
    variable play
    if {[catch {unbind cron - "$minute $hour * * *" [namespace current]::play} err]} {
      putlog "Error in cronPlay: $err"
    }
    if {[scan $play(info) {%s%s} file channel] != 2} return
    if {![file exists $file]} return
    set fo [open $file]
    set lines [split [read -nonewline $fo] \n]
    close $fo
    if {![llength $lines]} return
    if {[botisop $channel]} {
      puthelp "MODE $channel +m"
      foreach line $lines {
        puthelp "PRIVMSG $channel :$line"
      }
      puthelp "MODE $channel -m"
    }
  }
}

putlog "cronPlay.tcl loaded.."
Haven't tested so let me know if you get any errors.

Edit: fixed 3nd time.
Last edited by caesar on Fri May 04, 2012 2:00 am, edited 7 times in total.
Once the game is over, the king and the pawn go back in the same box.
B
BigToe
Halfop
Posts: 99
Joined: Thu Dec 30, 2010 4:49 pm

Post by BigToe »

Hey caesar,

Thanks for the script.

A couple of things:

I've tried:

[10:27:29] <@Nascimento> !play 07:30 preview.txt #taunt
[10:27:32] -MI6- Error, #taunt channel is not valid.

Even though it is a valid channel.

I tried playing it to myself:

[10:32:29] <@Nascimento> !play 07:35 preview.txt Nascimento

That didn't work either.

I've placed preview.txt in the 'eggdrop' folder
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

Code: Select all

if {[validchan $channel]} { 
Change that to...

Code: Select all

if {![validchan $channel]} { 
That.. Now it'll work and wont say a valid chan isn't valid. The logic of that statement was backwards...

and this part needs changing...

Code: Select all

      pushmode $channel +m
      foreach line $lines {
         puthelp "PRIVMSG $channel :$line"
      }
      pushmode $channel -m 
To this....

Code: Select all

      pushmode $channel +m
      flushmode $channel
      foreach line $lines {
         puthelp "PRIVMSG $channel :$line"
      }
      pushmode $channel -m
      flushmode $channel
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Oh snap.. Forgot a ! in the validchan check. It should work fine now. As for flushmode to be honest I would rather change the pushmode with a putserv or even a putquick if it's really necessarily. Just test it and let me know if the bot doesn't set +m before starting to play the file.
Once the game is over, the king and the pawn go back in the same box.
B
BigToe
Halfop
Posts: 99
Joined: Thu Dec 30, 2010 4:49 pm

Post by BigToe »

Hey guys,

Thanks for the reply.

I've tried this
[19:23:23] <@Nascimento> !play 16:30 preview.txt #moderators

Didn't get any errors - but it didn't set +m or -m and it didn't play the file either..
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

I have just noticed that I forgot to add a return after the channel validation check and corrected a few other things that where missing when initially wrote the code. All have been fixed now. :) Also, changed the pushmode to puthelp as it didn't set the +m in time.
[08:13] <caesar> !play 08:14 preview.txt #channel
[08:13] <@bot> I will play preview.txt to #channel at 08:14
[08:14] * bot sets mode: +m
[08:14] <@bot> line 1
[08:14] <@bot> line 2
[08:14] <@bot> line 3
[08:14] * bot sets mode: -m
The code as it is right now, the bot will play the file (only if it file exists and isn't empty) at the time you wanted if the bot has op on the channel.

Please do keep in mind that this isn't fool proof (yet) and the time has to be in two digits format, example: 09:12, 15:03.

Edit: To make it ignore the format you pick for time, meaning make it fool proof and accept 09:12 and 9:12 or 15:03 and 15:3 then do the following changes to the above code.

Replace:

Code: Select all

    if {![regexp {^[0-9]+$} $hour] || ![regexp {^[0-9]+$} $minute]} {
      puthelp "NOTICE $nick :Error, the hour or minute aren't valid."
      return
    }
with:

Code: Select all

    if {![regexp {^[0-9]+$} $hour] || ![regexp {^[0-9]+$} $minute]} {
      puthelp "NOTICE $nick :Error, the hour or minute aren't valid."
      return
    } else {
		scan $hour %d hour
		scan $minute %d minute
	}
and before the:

Code: Select all

if {[catch {unbind cron - "$minute $hour * * *" [namespace current]::play} err]} {
line add the following:

Code: Select all

	scan $minute %d minute
	scan $hour %d hour
Once the game is over, the king and the pawn go back in the same box.
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Here is a better version of the above code.

Code: Select all

namespace eval cronPlay {
  bind pub * !play [namespace current]::create

  proc create {nick uhost hand chan text} {
    variable play
    if {[scan $text {%[^:]:%s%s%s} hour minute file channel] != 4} {
      puthelp "NOTICE $nick :Usage: !play <hour:minute> <file> <#channel>"
      return
    }
    if {![regexp {^[0-9]+$} $hour] || ![regexp {^[0-9]+$} $minute]} {
      puthelp "NOTICE $nick :Error, the hour or minute aren't valid."
      return
    }
    if {![file exists $file]} {
      puthelp "NOTICE $nick :Error, $file file doesn't exist."
      return
    }
    switch -- [catch {botisop $channel} err] {
      "0" {
        if {!$err} {
          puthelp "NOTICE $nick :I won't be able to play the $file file in $channel channel if I'm not oped."
          		  return
        }
      }
      "1" {
        puthelp "NOTICE $nick :Error, $channel channel is not valid."
        return
      }
    }
    set play(info) "$file $channel"
    	scan $hour %d hour
    scan $minute %d minute
    bind cron - "$minute $hour * * *" [namespace current]::play
    puthelp "PRIVMSG $chan :I will play $file to $channel at $hour:$minute"
  }

  proc play {minute hour day month weekday} {
    variable play
    scan $minute %d minute
    scan $hour %d hour
    if {[catch {unbind cron - "$minute $hour * * *" [namespace current]::play} err]} {
      putlog "Error in cronPlay: $err"
    }
    if {[scan $play(info) {%s%s} file channel] != 2} return
    if {![file exists $file]} return
    set fo [open $file]
    set lines [split [read -nonewline $fo] \n]
    close $fo
    if {![llength $lines]} return
    if {![catch {botisop $channel} err] && $err eq 1} {
      puthelp "MODE $channel +m"
      foreach line $lines {
        puthelp "PRIVMSG $channel :$line"
      }
      puthelp "MODE $channel -m"
    }
  }
}
putlog "cronPlay.tcl loaded.."
The only issue I will try to solve later on is that you can trigger the same cron multiple times.
Once the game is over, the king and the pawn go back in the same box.
B
BigToe
Halfop
Posts: 99
Joined: Thu Dec 30, 2010 4:49 pm

Post by BigToe »

Thanks caesar and speechles

The script works perfectly now!
B
BigToe
Halfop
Posts: 99
Joined: Thu Dec 30, 2010 4:49 pm

Post by BigToe »

hey caesar I have another question if possible,

Would it be difficult for you to configure that script that from the time I write, the script will write every X mins the lines from the script one by one untill he's finishing?

<User> !play 21:30 2 Randomchat.txt #World

[21:30] <Bot> This is the randomchat file
[21:32] <Bot> this is line #2 from randomchat.txt
[21:34] <Bot> this is line #3 from randomchat.txt
Post Reply