Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 5th, 2012  |  syntax: None  |  size: 4.96 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. ###############################################################################
  2. #  Name:                                        Ping
  3. #  Author:                                      kriptik@fieldsofnoise.org
  4. #  Eggdrop Version:     1.6.x
  5.  
  6. ###############################################################################
  7. #  Description
  8.  
  9. #  Gives an eggdrop the ability to respond to the public command:
  10. #  ping [target]
  11. #  If target is not specified the person triggering the script
  12. #  will be targeted.  The script also allows you to customise the result of the
  13. #  ping request by using the tokens described below.
  14.  
  15. ###############################################################################
  16. #  Version History
  17.  
  18. #  0.1 First Release
  19. #  0.2 Complete re-write
  20.  
  21. ###############################################################################
  22. #  Getting Started
  23.  
  24. #  1) Put this script in your scripts directory.
  25. #  2) Edit your eggdrop configuration file to include this file
  26. #     Something like: source scripts/ping.tcl
  27. #  3) Customise gPingFormat below, if you wish.
  28.  
  29. ###############################################################################
  30. #  User Configuration
  31.  
  32. #  Avalible tokens:
  33. #  %botnick%          Nickname of the bot
  34. #  %requester%        Person who requested the ping
  35. #  %target%           Target nickname
  36. #  %period%           Ping time as a string
  37. #  %period_numeric%   Ping time as an integer
  38. #  %b%                Bold styled text
  39. #  %u%                Underline styled text
  40. #  %isare%            If the period is plural this is 'are' otherwise 'is'
  41.  
  42. # gPingFormat <string>
  43. # Defines how the ping result is displayed
  44. # Historically the format has been:
  45. #  set gPingFormatString "%b%%botnick%%b%  <-- %period% -->  %b%%target%%b%"
  46.  
  47. set gPingFormatString "12Пинг от 4%botnick% 12до 4%target% 12составляет : %period%"
  48.  
  49. # gRoundTrip <boolean>
  50. # If set to 1 pings are reported as roundtrips (Normal IRC behavior)
  51. set gRoundTrip 1
  52.  
  53. ###############################################################################
  54. #  You shouldn't need to edit below here.
  55.  
  56. bind pub   -  ping doPing
  57. bind ctcr  -  PING onPingReply
  58. bind raw   -  401  noSuchNick
  59.  
  60. set gTheScriptVersion "0.2"
  61.  
  62. if {[array exists gNickRecord]} { unset gNickRecord }
  63. array set gNickRecord ""
  64.  
  65. proc note {msg} {
  66.   putlog "% $msg"
  67. }
  68.  
  69. proc noSuchNick {from keyword text} {
  70.   global gNickRecord
  71.   set theNick [string tolower [lindex $text 1]]
  72.   if {[info exists gNickRecord($theNick)]} {
  73.     set theChannel [lindex $gNickRecord($theNick) 1]
  74.     putserv "PRIVMSG $theChannel :$theNick does not exist."
  75.     unset gNickRecord($theNick)
  76.   }
  77. }
  78.  
  79. proc doPing {nick uhost hand chan arg} {
  80.   global gNickRecord
  81.   if {[llength $arg] > 0} {
  82.     set theNick [string tolower [lindex [split $arg] 0]]
  83.   } else {
  84.     set theNick [string tolower $nick]
  85.   }
  86.   note "Pinging $theNick (Requested by $nick on $chan)"
  87.   set gNickRecord($theNick) [subst {[unixtime] $chan $nick}]
  88.   putserv "PRIVMSG $theNick :\001PING [unixtime]\001"
  89. }
  90.  
  91. proc onPingReply {nick uhost hand dest key arg} {
  92.   global botnick gNickRecord gRoundTrip
  93.   set theNick [string tolower $nick]
  94.   if {[info exists gNickRecord($theNick)]} {
  95.     set theTimeStamp [lindex $gNickRecord($theNick) 0]
  96.     set thePeriod [expr ([unixtime] - $theTimeStamp)]
  97.     if {$gRoundTrip != 1} {
  98.       set thePeriod [expr $thePeroid/2]
  99.     }
  100.     set theChannel [lindex $gNickRecord($theNick) 1]
  101.     set theRequester [lindex $gNickRecord($theNick) 2]
  102.     set theMessage [formatPingString $thePeriod $botnick $theRequester $theNick]
  103.     putserv "PRIVMSG $theChannel :$theMessage"
  104.     unset gNickRecord($theNick)
  105.   }
  106. }
  107.  
  108. proc formatPingString {thePeriod theBotNick theRequester theTarget} {
  109.   global gPingFormatString
  110.   if {$thePeriod == 0} {
  111.     set thePeriodString "меньше секунды!"
  112.     set theIsAre "is"
  113.   } elseif {$thePeriod == 1} {
  114.     set thePeriodString "1 секунда"
  115.     set theIsAre "is"
  116.   } else {
  117.     set thePeriodString "$thePeriod секунд(ы)"
  118.     set theIsAre "are"
  119.   }
  120.   set resultString $gPingFormatString
  121.   regsub -all "%botnick%" $resultString $theBotNick resultString
  122.   regsub -all "%requester%" $resultString $theRequester resultString
  123.   regsub -all "%target%" $resultString $theTarget resultString
  124.   regsub -all "%period%" $resultString $thePeriodString resultString
  125.   regsub -all "%period_numeric%" $resultString $thePeriod resultString
  126.   regsub -all "%isare%" $resultString $theIsAre resultString
  127.   regsub -all "%b%" $resultString "\002" resultString
  128.   regsub -all "%u%" $resultString "\037" resultString
  129.   return $resultString
  130.   # :-( map is sexy but doesn't work with older tcl
  131.   # set theTokens [subst {%botnick% $theBotNick %requester% $theRequester %target% $theTarget %period% $thePeriodString %period_numeric% $thePeriod %isare% $theIsAre %b% \002 %u% \037}]
  132.   # return [string map $theTokens $gPingFormatString]
  133. }
  134.  
  135. ###############################################################################
  136.  
  137. note "ping$gTheScriptVersion: loaded";