ACM-VIT / golly-bot

A general purpose discord bot, written in GO!
MIT License
4 stars 17 forks source link

Add: Command that accesses WolframAlpha API #35

Closed z404 closed 2 years ago

z404 commented 2 years ago

Add a command !math <math problem>. When the user executes this command, the bot must make a request to the WolframAlpha API using this package. The reply contains a set of "pods". Sort through these pods and return those that are useful for answering the question.

You may take a look at the website here

ankan792 commented 2 years ago

@z404 Please assign me this issue!

ankan792 commented 2 years ago

@z404 this somehow doesn't seem to work as in the bot doesn't respond with any result. Am I doing something wrong? The app id is functioning properly.


                var mathProb = strings.SplitN(m.Content, " ", 2)[1]

                c := &wolfram.Client{AppID: os.Getenv("WOLFRAM_API_KEY")}
                res, err := c.GetQueryResult(mathProb, nil)

        if err != nil {
            panic(err)
        }
        // Iterate through the pods and subpods
        // and print out their title attributes
        for i := range res.Pods {
            s.ChannelMessageSend(m.ChannelID, res.Pods[i].Title)

            for j := range res.Pods[i].SubPods {
                s.ChannelMessageSend(m.ChannelID, res.Pods[i].SubPods[j].Title)
            }
        }`
z404 commented 2 years ago

I'm assigning you to this issue!

z404 commented 2 years ago

I'm afk at the moment, I will test the API on my end and put up a post here when I have an update!

ankan792 commented 2 years ago

@z404 sure!

z404 commented 2 years ago

As is seen with most outdated APIs, this one is very broken.

image

I'm trying to get this to work directly using the API endpoint, as I did here: #31. I'll add a comment once that works.

ankan792 commented 2 years ago

@z404 I got the exact same output with this. Definitely broken. However I found another work around with the GetSpokentAnswerQuery function and this seems to work just fine. Screenshot 2022-10-14 214922


                        res, err := c.GetSpokentAnswerQuery(mathProb, wolfram.Metric, 1000)
            if err != nil {
                panic(err)
            }
            s.ChannelMessageSend(m.ChannelID, res)
z404 commented 2 years ago

Nice! This works perfectly, though the output seems a little odd (as it is meant to be spoken, not shown as text). We can work with this for now, and if need be, correct it later. Proceed with using this work-around. Good job :D

ankan792 commented 2 years ago

@z404 yeah the output is a bit weird but def works! Since the search applies for generic queries as well, should we name the call the command !math or something else maybe?

z404 commented 2 years ago

If you have a better name in mind, feel free to change it!

ankan792 commented 2 years ago

@z404 alright thanks!