MichaelAquilina / synapse-project

Powerful fuzzy search launcher for a multitude of tasks
GNU General Public License v3.0
51 stars 7 forks source link

Add Rolldice plugin #14

Closed andrenasturas closed 6 years ago

andrenasturas commented 6 years ago

Plugin for Rolldice.

Adds a plugin for the command-line program rolldice, allowing the user to throw dices and see results in synapse as easily as the calculator plugin. User only have to type a command in rolldice syntax like 6d10+5 and the result will be printed. Supports multiple dices rolls by returning as many results as rolls requested by the user.

Should be answering any string supported by rolldice :

Pseudo regex : [Ax]?[B]?dC[*D]?[+|-E]?[sF]? All parts between brackets are optional.

The command can be interpreted as : "Roll B C-sized dices, drop the lowest F, multiply the result by D and add or subtract E, and do it A times independently". A, B, C, D, E and F are all numbers.

C can also be the character %, which is here a shortcut for "100-sized dice". C cannot be 0 or 1, as these are not supported as number of faces by rolldice, and lead to unexpected results (rolldice use a default 6-sized dice instead).

Usage example :

MichaelAquilina commented 6 years ago

Thanks for this @andrenasturas ! The build passes so its pretty certain this works, but will test this out manually just in case.

Eventually my intention is to add some automated tests along with just building on the CI.

MichaelAquilina commented 6 years ago

Is rolldice part of any package manager? I cant seem t find it on ubuntu trusty or opensuse tumbleweed. Could you provide a link I can use to test with?

andrenasturas commented 6 years ago

rolldice is in Ubuntu Universe : https://packages.ubuntu.com/fr/trusty/rolldice I don't know if it is available in OpenSUSE.

MichaelAquilina commented 6 years ago

Seems pretty easy to compile: https://github.com/sstrickl/rolldice Will probably try add this myself to opensuse's build service and go from there

andrenasturas commented 6 years ago

As rolldice is a command-line program, it is not provided with any icon, so I chose an icon present on my system (Voyager Live 16.04, which is based on Xubuntu 16.04, with Faenza icon set) that made sense for this application : application-boardgames

applications-boardgames capture d ecran_2017-12-02_18-42-54

I will replace that with applications-games which, according to the specifications you provided, is a standard icon name.

About the "Send to" action, it seems to be the first default action when none are provided by the plugin : when you press Tab while selecting one of the plugin results, you have some actions available like "Copy to clipboard", "Send to pastebin" or "Search on internet", "Send message to" being the first one. It is the same with the calculator plugin which I was inspired by.

It is possible to convert the TextMatch object to an ActionMatch object so the ResultSet comes with a specific action, or to provide many specific actions by implementing ActionProvider interface (like in the Desktop File plugin) but I don't know if it can be more relevant than the default actions. All I am thinking about is an action to start a rolldice interactive console, and since it is not possible to start one already showing a result, it may not be very interesting.

andrenasturas commented 6 years ago

Fine, thanks :-)