.NET mIRC search script
From The Unofficial Google Wiki
Here is a really basic and not particularly good script that demonstrates one way of querying Google from mIRC using the Google Web API. It consists of a VB.NET component with COM bindings that is called from a mIRC script, and was made by GreenReaper. You may use the code below as you desire, as long as you don't blame him for it. :-)
[edit] mIRC side
Enter this in the Remote scripting section. Making the COM call asynchronous so that it does not freeze up mIRC while googling is left as an exercise to the reader. :-)
;This line detects anyone saying "google *" in a channel. It then passes
;everything after "google" to the google alias. "$2-" means the second word and
;everything after it.
;on 1:TEXT:google *:#:/google $chan $2-
;Later, you might want to change that command to make it call the
;"google" alias, i.e., "/google $2-"
alias google {
comopen ircgoogle IRCGoogle.IRCGoogle
if ($comerr) {
echo comopen failed - $com(ircgoogle).errortext
halt
}
if ($com(ircgoogle,GetSite,1,bstr,$2-) == 0) {
echo com failed - $com(ircgoogle).errortext
echo com argerror - $com(ircgoogle).argerr
echo com error - $com(ircgoogle).error
goto cleanup
}
var %result = $com(ircgoogle).result
msg $1 %result
echo com result - $com(ircgoogle).result
:cleanup
comclose ircgoogle
}
[edit] .NET side
- Create a Class Library project called "IRCGoogle", and tick the "Register for COM Interop" option on the project build configuration properties section
- Add a web reference to http://api.google.com/GoogleSearch.wsdl
- Put this code in an IRCGoogle.vb file (or change the class name and project name it whatever you want, but you'll need to change the mIRC script likewise)
- Replace the license string with your own license string, and enjoy!
Public Interface IGetSite
Function GetSite(ByVal name As String) As String
End Interface
<ComClass()> _
Public Class IRCGoogle
Implements IGetSite
Private license As String = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
Public Sub New()
End Sub
Public Function GetSite(ByVal query As String) As String Implements IGetSite.GetSite
' Create a Google Search object
Dim s As New Google.GoogleSearchService
Try
Dim result As String
' Invoke the search method
Dim r As Google.GoogleSearchResult = s.doGoogleSearch(license, query, 0, 1, False, "", False, "", "", "")
If r.resultElements.Length > 0 Then
result = r.resultElements(0).URL
Else
result = "No results found"
End If
Dim spelling As String = s.doSpellingSuggestion(license, query)
If Not spelling Is Nothing Then
result += " (did you mean: " & spelling & "?)"
End If
Return result
Catch ex As System.Web.Services.Protocols.SoapException
Return "Error: " & ex.Message
End Try
End Function
End Class
