control-net / Miunie

Miunie is a community developed bot with an attitude.
Other
46 stars 31 forks source link

Simple yes no command #110

Closed petrspelos closed 4 years ago

petrspelos commented 5 years ago

💡 This issue is perfect for a Miunie beginner.

Feel free to ask about anything you might not understand. 😉

It would be fun to implement a command like this:

User: @Miunie what do you think?
Miunie: Sure
User: @Miunie what do you think?
Miunie: I don't know...
User: @Miunie what do you think?
Miunie: Nah

Point being it would be a random Yes/No/Maybe answer.


How this should be done

Thank you to @DraxCodes for helping with this this. ❤️

  1. Create MiscService.cs

This feature should be provided by a MiscService (standing for Miscellaneous service).

This new MiscService.cs fits in nicely to where all the other services are, that is:

Miunie/src/Miunie.Core/Services

ℹ️ For now if you create MiscService.cs it will generate namespace Miunie.Core.Services inside the file. You should change it to namespace Miunie.Core.

  1. Add IDiscordMessages dependency

In your MiscService create a constructor that will get IDiscordMessages messages passed into it as a parameter and store it in a local field. 💡 See this example for inspiration.

ℹ️ The IDiscordMessages gives your service the ability to send discord messages. You don't need to set anything up, it's kind of cool. 😊

  1. Add a language resource

Miunie needs to know what to say in response.

You should create a new language entry by editing the Miunie/src/Miunie.Core/Strings.resx file. (💡 you should open this file from Visual Studio for a better editting experience)

Ideally you would create a single key: YES_NO_MAYBE with the different output values being separated with {{OR}}

💡 Example: Image

This would in effect give it the randomness because we already pick a random value if your entry contains {{OR}} directives.

  1. Add your key into the phrases enum

In the previous step you defined YES_NO_MAYBE as the Key of your language entry. We now need to add it to the PhraseKeys.

All you need to do is add the entry into the src/Miunie.Core/Entities/PhraseKey.cs enum.

  1. Create a service method

In your MiscService.cs you should create a new method. Give it a descriptive name, something like SendRandomYesNoAnswer.

This method should have the following signature: public async Task SendRandomYesNoAnswer(MiunieChannel channel)

ℹ️ just like other service methods do, for example this one.

In this method, simply call await _messages.SendMessage( and pass in the MiunieChannel you got passed into this method and the PhraseKey you defined in the previous step.

ℹ️ The _messages comes from step 2

  1. Create a command module

The last step is to create a command module in src/Miunie.Discord/CommandModules. Something like MiscCommands.cs should be fine.

Create your module similar to this example.

The only difference between your implementation and the example is that instead of RemoteRepositoryService, you want to ask for MiscService you defined in step 1.

You only need to require it in the constructor, nothing else needs to be done for it to get injected, though you do want to store it in a private field _miscService or similar.

The command attribute should be "what do you think?"

Then you need to convert the channel into MiunieChannel like this inside your command.

The last this is to call await _miscService.SendRandomYesNoAnswer(channel);

  1. Profit

🎉 Congrats! You did it, it's time to test your code and submit your changes! If you need help with running the bot or submitting your changes, feel free to contact either me (@petrspelos or @DraxCodes on our discord server, we'll be more than happy to help you out). ❤️

lopezayl commented 5 years ago

Hello! I'm interested in helping with this feature. First time contributor here, eager to learn! Experience in C, hoping it transfers over to C#... Let me know if I can be assigned to this issue.

petrspelos commented 5 years ago

Hello, @lopezayl! Welcome! By all means, we're really glad you decided to help out. If you have any questions, feel free to ask. And of course this task is all yours. 😊

petrspelos commented 5 years ago

Also, if you'd like a more direct Q&A experience, we have a Discord server you can join. Once you read and accept the rules, there is a #miunie-dev channel just for this project. 🙂

petrspelos commented 5 years ago

Architecture got reworked, the issue is now applicable again. 🎉

DraxCodes commented 5 years ago

New Implementation

The Service implementation (MiscService) still applies the same as above.

We have moved our string resources (previously found in the Lang.json files) into Strings.resx This is where you can define new Keys & Values.

Ideally you would have a single key: YES_NO_MAYBE with the different output values being seperated with {{OR}} Example: Image This would in effect give it the randomness because we already pick a random value in the method: GetPhrase()

The rest of the implementation would still be the same: Inside the MiscService call SendMessage from IDiscordMessages and pass in the new Phrase. YES_NO_MAYBE.

DraxCodes commented 5 years ago

Due to this issue being open for nearly a month now and it being a nice easy beginer freindly one, It is now open again for someone else to take.

DannyKrendel commented 5 years ago

Since noone is interested in this one, I'm gonna grab it :)

Hantick commented 5 years ago

I'm interested in doimg this

DraxCodes commented 5 years ago

Sadly this issue is blocked while we implement some side features. If you want to keep up to date with the latest projects we are doing though, please feel free to join our Discord Server. You can find a link to it on the main page of this Repo :)

petrspelos commented 4 years ago

This is yet again up for grabs. 😊

bitmoji