-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v1.2.0, with dictionary option and better time formatting
- Loading branch information
Showing
4 changed files
with
62 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
module game | ||
|
||
import net.http | ||
import x.json2 | ||
|
||
pub fn get_definition(word string) { | ||
resp := http.get('https://api.dictionaryapi.dev/api/v2/entries/en/$word') or { http.Response{} } | ||
if resp.text != '' { | ||
json_resp := json2.raw_decode(resp.text) or { '' } | ||
resp_map := json_resp.as_map() | ||
// gotta love when they use arrays | ||
i := resp_map['0'] or { map[string]json2.Any{} }.as_map() // array index | ||
j := i['meanings'] or { map[string]json2.Any{} }.as_map() | ||
k := j['0'] or { map[string]json2.Any{} }.as_map() // array index | ||
l := k['definitions'] or { map[string]json2.Any{} }.as_map() | ||
m := l['0'] or { map[string]json2.Any{} }.as_map() // array index | ||
|
||
d := m['definition'] or {'!'}.str() | ||
e := m['example'] or {'!'}.str() | ||
if d != '!' { | ||
println('$d\nExample: $e') | ||
} | ||
} else { | ||
println('unable to get the definition of the word.') | ||
println('are you connected to the internet?') | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters