-
Notifications
You must be signed in to change notification settings - Fork 1
/
modWolframAlpha.vb
49 lines (45 loc) · 2.18 KB
/
modWolframAlpha.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
Module modWolframAlpha
Function Disable() As String
Unload()
My.Settings.WolframAlpha_Enable = False
My.Application.Log.WriteEntry("WolframAlpha module is disabled")
Return "WolframAlpha module disabled"
End Function
Function Enable() As String
My.Settings.WolframAlpha_Enable = True
My.Application.Log.WriteEntry("WolframAlpha module is enabled")
Load()
Return "WolframAlpha module enabled"
End Function
Function Load() As String
If My.Settings.WolframAlpha_Enable = True Then
My.Application.Log.WriteEntry("Loading WolframAlpha module")
If My.Settings.WolframAlpha_APIKey = "" Then
My.Application.Log.WriteEntry("No WolframAlpha API key, asking for it")
My.Settings.WolframAlpha_APIKey = InputBox("Enter WolframAlpha API Key. You can get an API key at https://developer.wolframalpha.com by signing up for a free account.", "WolframAlpha API")
End If
Return "WolframAlpha module loaded"
Else
My.Application.Log.WriteEntry("WolframAlpha module is disabled, module not loaded")
Return "WolframAlpha module is disabled, module not loaded"
End If
End Function
Function SpokenQuery(ByVal strQuestion As String) As String
If My.Settings.WolframAlpha_Enable = True Then
Dim RequestClient As System.Net.WebClient = New System.Net.WebClient
Try
Dim strQuestionResult As String = RequestClient.DownloadString("http://api.wolframalpha.com/v1/spoken?appid=" & My.Settings.WolframAlpha_APIKey & "&i=" & System.Net.WebUtility.UrlEncode(strQuestion))
Return strQuestionResult
Catch NetExcep As System.Net.WebException
My.Application.Log.WriteException(NetExcep)
Return "Unable to query WolframAlpha"
End Try
Else
Return "WolframAlpha module is disabled, query not sent"
End If
End Function
Function Unload() As String
My.Application.Log.WriteEntry("Unloading WolframAlpha module")
Return "WolframAlpha module unloaded"
End Function
End Module