Advertisement
outsider

story teller

Dec 9th, 2014
438
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TCL 5.30 KB | None | 0 0
  1.  
  2. # StoryTeller v1.0 by OUTsider <[email protected]>
  3. # Setup:
  4. #  Change below path to where the stories will rely named story.<2 letter language code>.txt
  5. set storydir "stories/"
  6. # To activate:
  7. #   .chanset <channel> +story (DCC)
  8. #
  9. # To use:
  10. #   !story <storyname> (PUB) (if paused @/+ to resume)
  11. #       will play the story, if language is ommitted the default (set below) is chosen
  12. #       channel will be +m, requester if not voiced, voiced temporary
  13. set storydefault "carol1"
  14. #
  15. #   !pause (PUB) @/+
  16. #       will pause the story, channel will be -m
  17. #
  18. #   !stop (PUB) @/+
  19. #       stops the story, channel will be -m, requester will loose voice if he didn't have it before play
  20. #
  21. #   !playspeed <interval in seconds>(PUB) @
  22. #       adjusts the playbackspeed in seconds
  23. #       can also be done using .chanset <channel> story_playspeed <interval in seconds> (DCC)
  24.  
  25. setudef flag story
  26. setudef int story_status
  27. setudef str story_requester
  28. setudef int story_playspeed
  29. setudef int story_line
  30. if {![info exists storyfile]} {
  31.     set storyfile(dummy) ""
  32. }
  33.  
  34. bind pub - !story story:play
  35. proc story:play {nick host hand chan args} {
  36.     global storydir storydefault
  37.     if {![channel get $chan story]} {
  38.         return
  39.     }
  40.     if {[channel get $chan story_playspeed] == 0} {
  41.         channel set $chan story_playspeed 6
  42.     }
  43.     set status [channel get $chan story_status]
  44.     switch -- $status {
  45.         0 {
  46.             set lang [lindex [lindex $args 0] 0]
  47.             if {$lang == ""} {
  48.                 set lang $storydefault
  49.             }
  50.             if {![file exists ${storydir}story.$lang.txt]} {
  51.                 putserv "NOTICE $nick :The story $lang is not present"
  52.                 return
  53.             }
  54.             story:initplay $nick $chan $lang
  55.             return
  56.         }
  57.  
  58.         1 {
  59.             putserv "NOTICE $nick :Story in $chan already running"
  60.             return
  61.         }
  62.  
  63.         2 {
  64.             if {![isop $nick $chan] && ![isvoice $nick $chan]} {
  65.                 return
  66.             }
  67.             pushmode $chan +m
  68.             flushmode $chan
  69.             channel set $chan story_status 1
  70.             story:player $chan
  71.             putserv "NOTICE $nick :Story in $chan resumed"
  72.             return
  73.         }
  74.     }
  75. }
  76.  
  77. bind pub - !pause story:pause
  78. proc story:pause {nick host hand chan args} {
  79.     if {![isop $nick $chan] && ![isvoice $nick $chan]} {
  80.         return
  81.     }
  82.     switch -- [channel get $chan story_status] {
  83.         0 {
  84.             putserv "NOTICE $nick :Story not running in $chan"
  85.             return
  86.         }
  87.  
  88.         1 {
  89.             channel set $chan story_status 2
  90.             pushmode $chan -m
  91.             flushmode $chan
  92.             putserv "NOTICE $nick :Story paused in $chan"
  93.             return
  94.         }
  95.  
  96.         2 {
  97.             putserv "NOTICE $nick :Story already paused in $chan"
  98.             return
  99.         }
  100.     }
  101. }
  102.  
  103. bind pub - !stop story:stop
  104. proc story:stop {nick host hand chan args} {
  105.     global storyfile
  106.     if {![isop $nick $chan] && ![isvoice $nick $chan]} {
  107.         return
  108.     }
  109.     if {[channel get $chan story_status] == 0} {
  110.         putserv "NOTICE $nick :Story not running in $chan"
  111.         return
  112.     }
  113.     story:end $chan
  114.     putserv "NOTICE $nick :Story stopped in $chan"
  115. }
  116.  
  117. bind pub - !playspeed story:playspeed
  118. proc story:playspeed {nick host hand chan args} {
  119.     if {![isop $nick $chan]} {
  120.         return
  121.     }
  122.     set args [lindex [lindex $args 0] 0]
  123.     if {![string is integer $args]} {
  124.         putserv "NOTICE $nick :Usage: !playspeed <interval in seconds> (Current: [channel get $chan story_playspeed])"
  125.         return
  126.     }
  127.     channel set $chan story_playspeed $args
  128.     putserv "NOTICE $nick :Playspeed changed to $args seconds"
  129.     return
  130. }
  131.  
  132. bind nick - * story:nickchange
  133. proc story:nickchange {nick host hand chan newnick} {
  134.     if {[channel get $chan story_requester] == $nick} {
  135.         channel set $chan story_requester $newnick
  136.     }
  137. }
  138.  
  139. bind sign - * story:signpart
  140. bind part - * story:signpart
  141. proc story:signpart {nick host hand chan reason} {
  142.     if {[channel get $chan story_requester] == $nick} {
  143.         channel set $chan story_requester ""
  144.         story:end $chan
  145.     }
  146. }
  147.  
  148. proc story:initplay {nick chan lang} {
  149.     global storyfile storydir
  150.     if {[catch {open ${storydir}story.$lang.txt "r"} fp] != 0} {
  151.                 putserv "NOTICE $nick :Unable to open ${storydir}story.$lang.txt"
  152.         return
  153.     }
  154.     set storyfile($chan) [split [read -nonewline $fp] "\n"]
  155.     channel set $chan story_status 1
  156.     channel set $chan story_line 0
  157.     pushmode $chan +m
  158.     if {![isvoice $nick $chan] && ![isop $nick $chan]} {
  159.         pushmode $chan +v $nick
  160.         channel set $chan story_requester $nick
  161.     }
  162.     flushmode $chan
  163.     putserv "NOTICE $nick :Enjoy the story"
  164.     story:player $chan
  165. }
  166.  
  167. proc story:player {chan} {
  168.     global storyfile
  169.     if {![channel get $chan story] || [channel get $chan story_status] != 1 || ![info exists storyfile($chan)]} {
  170.         return
  171.     }
  172.     set line [channel get $chan story_line]
  173.     if {[llength $storyfile($chan)] < $line} {
  174.         story:end $chan
  175.     }
  176.     set output [lindex $storyfile($chan) $line]
  177.     putserv "PRIVMSG $chan :$output"
  178.     incr line
  179.     channel set $chan story_line $line
  180.     dotimer [channel get $chan story_playspeed] "story:player $chan"
  181. }
  182.  
  183. proc story:end {chan} {
  184.     global storyfile
  185.     channel set $chan story_status 0
  186.     if {[info exists storyfile($chan)]} {
  187.         unset storyfile($chan)
  188.     }
  189.     if {[isvoice [channel get $chan story_requester] $chan]} {
  190.         pushmode $chan -v [channel get $chan story_requester]
  191.         channel set $chan story_requester ""
  192.     }
  193.     pushmode $chan -m
  194.     flushmode $chan
  195. }
  196.  
  197. proc dotimer {time command} {
  198.         foreach utime [utimers] {
  199.                 if {[lindex $utime 1] == $command} {
  200.                         killutimer [lindex $utime end]
  201.                 }
  202.         }
  203.         return [utimer $time $command]
  204. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement