Guest User

Untitled

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