Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;;--Simple google interface.
- ;;--
- ;;--Performs calculation, time, and weather checks on text triggers.
- ;;--
- ;;--Bugs: Google sometimes doesn't provide bits of weather data, in which case the bot will just not retrieve ANY.
- ;;--
- ;;--Enjoy. ~ataraxia_
- ;;-- This section self explanatory.
- ;;-- Aliases you can call, channel popups.
- alias no_wait {
- hadd -m commands except. $+ # true
- msg # * Command flood protection disabled in this channel.
- }
- alias cmd_wait {
- if ($hget(commands,except. $+ #)) hdel commands except. $+ #
- msg # * Command flood protection enabled in this channel.
- }
- menu channel {
- Google commands:
- .Disable flood protection:no_wait
- .Enable flood protection:cmd_wait
- .Disable in channel:hadd -m nocommands $chan true
- .Enable in channel:hdel nocommands $chan
- }
- ;--Main text command.
- on *:TEXT:*:*:{
- if ($hget(nocommands,$chan)) halt
- if ($left($1,1) = !) {
- ;--Get trigger.
- var %z $right($1,-1)
- if ($len(%z) > 1) halt
- if (%z = l) {
- if ($2) {
- writeini locations.ini people $nick $regsubex($2-,/([^\d\w])/ig,$chr(37) $+ $base($asc(\1),10,16,2))
- msg # * Stored location for $nick as: $2-
- halt
- }
- else {
- msg # * Currently stored location for $nick is: $regsubex($readini(locations.ini,n,people,$nick),/(\x25[0-9a-f]{2})/ig,$chr($base($remove(\A,$chr(37)),16,10)))
- halt
- }
- }
- ;--Open appropriate socket name.
- if (%z isin twc) {
- ;--Flood protections. (Basic - needs improvement.)
- if (!$hget(commands,except. $+ $chan)) {
- if ($hget(commands,$nick $+ . $+ $chan)) { .raw notice # $nick : $+ System usage disallowed. Try again in $hget(commands,$nick $+ . $+ $chan).unset seconds. | halt }
- hadd -mu30 commands $nick $+ . $+ $chan true
- }
- if (!$2) && (!$readini(locations.ini,n,people,$nick)) {
- raw notice # $nick : $+ Please input a valid location.
- halt
- }
- var %s g. $+ $replacex(%z,w,weather,t,time,c,calc) $+ . $+ $chan $+ . $+ $ticks
- sockopen %s google.com 80
- ;--Replace any non-alphanumerics with HTTP-compliant hex strings. (%20 etc.)
- sockmark %s $readini(locations.ini,n,people,$nick)
- if ($2) sockmark %s $regsubex($2-,/([^\d\w])/ig,$chr(37) $+ $base($asc(\1),10,16,2))
- .raw notice # $nick : $+ Fetching data for location: $regsubex($sock(%s).mark,/(\x25[0-9a-f]{2})/ig,$chr($base($remove(\1,$chr(37)),16,10))) $+ . This may take a moment..
- hadd -m commands %s $nick
- }
- }
- }
- on *:sockopen:g.*:{
- if ($sockerr) {
- msg $gettok($sockname,3,46) * Sorry $hget(commands,$sockname) $+ , there has been a problem communicating with the server. Please try again in a moment.
- halt
- }
- ;--Fetch correct page depending on sockname.
- if ($gettok($sockname,2,46) = weather) sockwrite -tn $sockname GET /search?hl=en&q=Weather%20in%20 $+ $sock($sockname).mark
- if ($gettok($sockname,2,46) = time) sockwrite -tn $sockname GET /search?hl=en&q=Time%20in%20 $+ $sock($sockname).mark
- if ($gettok($sockname,2,46) = calc) sockwrite -tn $sockname GET /search?hl=en&q= $+ $sock($sockname).mark
- ;--Requisite headers. Connection keep-alive to stop Google from killing the socket before mIRC finishes reading.
- sockwrite -tn $sockname HOST: www.google.com
- sockwrite -tn $sockname CONNECTION: Keep-alive
- sockwrite -tn $sockname $str($crlf,2)
- }
- on *:sockread:g.*:{
- ;--Sockread using a binvar - prevent the socket waiting forever for a CRLF by using -fn 4096
- sockread -fn 4096 &r
- while ($sockbr > 0) {
- var %r $bvar(&r, 1-).text
- ;--Return results.
- if ($window(@gout)) echo @gout %r
- if ($gettok($sockname,2,46) = calc) {
- if ($regex(%r,/<font size=\+1><b>(.+?)<.b>/ig)) {
- msg $gettok($sockname,3,46) * Calculation request by $hget(commands,$sockname) $+ : $remove($replace($utfencode($regsubex($regml(1),/(<\/?font.*?>)/ig,$null)),<sup>,^),</sup>)
- sockclose $sockname
- }
- }
- if ($gettok($sockname,2,46) = time) {
- if ($regex(%r,/<b>Time</b>\sin\s<b>(.+?)</b>(.+?)\x3C/ig)) set -u5 %l. [ $+ [ $sockname ] ] $regml(1) $+ $remove($regml(2),</td>)
- if ($regex(%r,/valign=.+?><b>(.+?)<.b>/ig)) {
- if (*Web* !iswm $regml(1)) {
- msg $gettok($sockname,3,46) * Time request by $hget(commands,$sockname) for: $utfencode(%l. [ $+ [ $sockname ] ] - $regsubex($regml(1),/(<\/?font.*?>)/ig,$null))
- sockclose $sockname
- }
- }
- }
- if ($gettok($sockname,2,46) = weather) {
- if ($regex(%r,/>Weather</b>\sfor\s<b>(.+?)</ig)) set -u5 %l. [ $+ [ $sockname ] ] $regml(1)
- if ($regex(%r,/font-size:140%.+>(.+?)</b>.+?Current.+?<b>(.+?)</b>.+?Wind:(.+?)<br>Humidity:(.+?)<.+/ig)) {
- msg $gettok($sockname,3,46) * Weather request by $hget(commands,$sockname) for: $utfencode(%l. [ $+ [ $sockname ] ] - Current Conditions: $regml(2) / Temperature: $regml(1) / Wind: $regml(3) / Humidity: $regml(4))
- sockclose $sockname
- }
- }
- ;--Continue loop reading.
- if ($sock($sockname)) sockread -fn 4096 &r
- }
- }
- ;--Only called if socket closes by itself, not if sockclose is triggered by information found.
- on *:sockclose:g.*:msg $gettok($sockname,3,46) * Sorry, $hget(commands,$sockname) $+ , no information was found for your $gettok($sockname,2,46) request.
Add Comment
Please, Sign In to add comment