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 

A Simple play file script

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


Joined: 30 Dec 2010
Posts: 99

PostPosted: Mon Apr 16, 2012 6:25 am    Post subject: A Simple play file script Reply with quote

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
Back to top
View user's profile Send private message
BigToe
Halfop


Joined: 30 Dec 2010
Posts: 99

PostPosted: Mon Apr 30, 2012 1:22 pm    Post subject: Reply with quote

Anyone, please?
Back to top
View user's profile Send private message
caesar
Mint Rubber


Joined: 14 Oct 2001
Posts: 3741
Location: Mint Factory

PostPosted: Tue May 01, 2012 12:46 am    Post subject: Reply with quote

Code:

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.
_________________
Once the game is over, the king and the pawn go back in the same box.


Last edited by caesar on Fri May 04, 2012 2:00 am; edited 7 times in total
Back to top
View user's profile Send private message
BigToe
Halfop


Joined: 30 Dec 2010
Posts: 99

PostPosted: Wed May 02, 2012 3:47 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
speechles
Revered One


Joined: 26 Aug 2006
Posts: 1398
Location: emerald triangle, california (coastal redwoods)

PostPosted: Wed May 02, 2012 12:56 pm    Post subject: Reply with quote

Code:
if {[validchan $channel]} {

Change that to...
Code:
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:
      pushmode $channel +m
      foreach line $lines {
         puthelp "PRIVMSG $channel :$line"
      }
      pushmode $channel -m


To this....

Code:
      pushmode $channel +m
      flushmode $channel
      foreach line $lines {
         puthelp "PRIVMSG $channel :$line"
      }
      pushmode $channel -m
      flushmode $channel

_________________
speechles' eggdrop tcl archive
Back to top
View user's profile Send private message
caesar
Mint Rubber


Joined: 14 Oct 2001
Posts: 3741
Location: Mint Factory

PostPosted: Wed May 02, 2012 1:00 pm    Post subject: Reply with quote

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


Joined: 30 Dec 2010
Posts: 99

PostPosted: Thu May 03, 2012 12:34 pm    Post subject: Reply with quote

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..
Back to top
View user's profile Send private message
caesar
Mint Rubber


Joined: 14 Oct 2001
Posts: 3741
Location: Mint Factory

PostPosted: Fri May 04, 2012 1:21 am    Post subject: Reply with quote

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. Smile Also, changed the pushmode to puthelp as it didn't set the +m in time.
Quote:

[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:

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

with:
Code:

    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:

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

line add the following:
Code:

   scan $minute %d minute
   scan $hour %d hour

_________________
Once the game is over, the king and the pawn go back in the same box.
Back to top
View user's profile Send private message
caesar
Mint Rubber


Joined: 14 Oct 2001
Posts: 3741
Location: Mint Factory

PostPosted: Fri May 04, 2012 5:35 am    Post subject: Reply with quote

Here is a better version of the above code.
Code:

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


Joined: 30 Dec 2010
Posts: 99

PostPosted: Fri May 04, 2012 6:09 am    Post subject: Reply with quote

Thanks caesar and speechles

The script works perfectly now!
Back to top
View user's profile Send private message
BigToe
Halfop


Joined: 30 Dec 2010
Posts: 99

PostPosted: Wed May 09, 2012 11:08 am    Post subject: Reply with quote

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
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