Skip to content

Migrate WolframAlpha command #212

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 20, 2022
Merged

Conversation

Zabuzard
Copy link
Member

@Zabuzard Zabuzard commented Oct 21, 2021

This adds the WolframAlpha command (previously known as =wolf). Command example:

/wolfram-alpha query:solve x^2 = 10

and the bot will respond with rendered images and data by using the WolframAlpha API.

example

Details

The code is straightforward:

  1. We send the query to the API,
  2. the API returns a XML response, we parse it using Jackson
  3. we do some early-outs for all error cases
  4. we parse the response and extract all images (from pods and their sub-pods)
  5. we add headlines to each image and combine them together into "tiles" (one tile per embed)
  6. we create a list of embeds and send that to the user

The image fiddling can be a bit awkward but ultimately its quite simple. The reason why we do not just send one big picture is because Discord would otherwise scale it down and it would not provide a nice UX. So instead we send multiple smaller images, so that Discord doesnt make them smaller.

Discord has a limit of 10 embeds, so we will cut off the rest in case its too much. Also, there are other edge cases leading to only partial results (for example if pods timed out).

In general, the response always consists of a quick summary/explanation (also with error messages, if any) and then the embeds.

Embeds itself can display images if they have been added to the message as attachment.

Also note that Wolfram Alpha itself also provides some error messages with extra info, which we can display as well:

error example

Config

We have created a community account and created two application IDs:

  • one used for the actual main bot (master), details are in the moderator chat (do not share)
  • one used for any sort of local testing and development (possibly also for develop), which is 79J52T-6239TVXHR7.

The bot picks it up from the config.json file. Therefore, a new parameter has been added. Adjust your config file and add:

"wolframAlphaAppId": "79J52T-6239TVXHR7"

@Zabuzard Zabuzard added the new command Add a new command or group of commands to the bot label Oct 21, 2021
@Zabuzard Zabuzard added this to the Migrate existing commands milestone Oct 21, 2021
@java-coding-prodigy
Copy link
Contributor

image
This is the output for the query x² + 3x + 2

@java-coding-prodigy
Copy link
Contributor

We had to restrict it to 10 images, because of JDA.

Copy link
Member

@Tais993 Tais993 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion, you should add a lot more empty lines between the code.
It's really hard to read, especially with those if without brackets.

I added an example, of how it'd be more readable in my opinion.

@java-coding-prodigy java-coding-prodigy force-pushed the feature/migrate_wolfram_alpha_command branch from 9da377b to 9ca2785 Compare November 3, 2021 05:23
@java-coding-prodigy
Copy link
Contributor

We will fix the design issues later, now I feel we should move on to making the error POJOs

@java-coding-prodigy
Copy link
Contributor

Keep in mind that the API is quite buggy. Sometimes if you make a spelling error it will send a tip asking you to spell correctly, at other times it will just auto correct it and sometimes it will send a didyoumean message

@CLAassistant
Copy link

CLAassistant commented Nov 15, 2021

CLA assistant check
All committers have signed the CLA.

@Tais993 Tais993 self-requested a review February 6, 2022 08:38
@java-coding-prodigy java-coding-prodigy force-pushed the feature/migrate_wolfram_alpha_command branch from c328402 to d4dbe08 Compare February 16, 2022 11:40
@java-coding-prodigy java-coding-prodigy force-pushed the feature/migrate_wolfram_alpha_command branch from d4dbe08 to 2acb1c3 Compare February 24, 2022 12:57
@github-actions
Copy link

This pull request is stale because it has been open 30 days with no activity. Remove stale label, comment or add the valid label or this will be closed in 5 days.

@github-actions github-actions bot added the stale label Mar 27, 2022
@java-coding-prodigy
Copy link
Contributor

Hello I am just responding to the review comments.

@Zabuzard Zabuzard added valid This issue/PR is validated and ready to be picked. This auto adds items to TJ project board. and removed stale labels Mar 27, 2022
@Zabuzard Zabuzard force-pushed the feature/migrate_wolfram_alpha_command branch from 65d1e84 to 2141bdd Compare May 5, 2022 09:09
@Zabuzard
Copy link
Member Author

Zabuzard commented May 5, 2022

taking over

java-coding-prodigy and others added 2 commits May 11, 2022 09:35
Stuff

Created a class for the expression types tag.


`deferReply` at the start now.


Added Tips and Tip classes for the error POJOs


Some changes to POJO classes


Forgot to include this in the commit


used the Tips POJO


committing gitignore


Changed as per @Zabuzard 's review


Performed the changes requested


a small change.


Using Optionals instead of a try-catch


@NotNull added and spotless applied


Some changes


Added unit test and utility class


Some changes

tested a failing case which failed successfully and wrote the pixel by pixel check to compare the images.
Another test


Fixed `combineImages`


A different approach to send the images.


removed a single `.`


Logged stuff for debugging.


Some changes


Fixed some issues and removed some obsolete logs.


Fixed almost everything but might change entire design


Embeds


Working embeds


Alternative method using `WebhookMessageUpdateAction`


New Package


Did you means


Future topics, Language messages and Related Examples


Example Page


This did not get committed properly


Updating QueryResult


Sending the actual URI to the users now


Query result fix and displaying an error if it occurs


@JsonProperty


@JacksonXmlElementWrapper


POJOs fix


Added some examples


POJO fix0


POJO fix1



POJO fix2


POJO fix3


POJO fix4


POJO fix5


POJO fix6


POJO fix7


POJO fix8


Handling the unsuccessful result case


Added Error POJOS


Some refactoring


The result of some git forkery


Ready for review :thumbs_up


ENUM!!!!!!


Some more refactoring


Fixed overlapping "error" attribute conflict


Error unrapping


Refactoring...


Some more refactoring


remove import


Remove that method


I am back


Fix config issue


Put constants in seperate enum

Put constants in seperate enum

Some minor changes

Some more minor changes

even less major changes

Better UX

Fix mistake

Fix rebasing issues.


fix that issue

remove comment
@Zabuzard Zabuzard force-pushed the feature/migrate_wolfram_alpha_command branch from 095e2f0 to 7c6a7c0 Compare May 11, 2022 07:35
@Zabuzard Zabuzard force-pushed the feature/migrate_wolfram_alpha_command branch from 215f78b to 09a7e6c Compare May 11, 2022 14:04
@Zabuzard Zabuzard force-pushed the feature/migrate_wolfram_alpha_command branch from b616629 to c1da29b Compare May 11, 2022 14:40
@Zabuzard Zabuzard linked an issue May 11, 2022 that may be closed by this pull request
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

@Zabuzard Zabuzard requested a review from Tais993 May 16, 2022 19:00
@Zabuzard Zabuzard merged commit ff007a2 into develop May 20, 2022
@Zabuzard Zabuzard deleted the feature/migrate_wolfram_alpha_command branch May 20, 2022 16:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new command Add a new command or group of commands to the bot priority: normal valid This issue/PR is validated and ready to be picked. This auto adds items to TJ project board.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Migrate Math-Bot commands
4 participants