Skip to content
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

V4: Message builder #2250

Open
wants to merge 2 commits into
base: 4.0
Choose a base branch
from
Open

V4: Message builder #2250

wants to merge 2 commits into from

Conversation

quinchs
Copy link
Member

@quinchs quinchs commented Apr 18, 2022

Summary

This PR adds a new builder called MessageBuilder which can build a Message that is used in SendMessageAsync functions.
The upsides to this style is we can merge SendFile and SendMessage functions as the library can determine whether or not the message contains files.
The builder also makes building reusable message templates easier.

Todo

  • IMessageChannel.SendMessageAsync
  • Interaction responses
  • Module base methods

@d4n3436
Copy link
Contributor

d4n3436 commented Apr 18, 2022

There should be some abstraction layer for MessageBuilder and Message like interfaces, so people can create their own custom builders.

@quinchs
Copy link
Member Author

quinchs commented Apr 18, 2022

We could just make stuff protected and virtual?

@csmir
Copy link
Collaborator

csmir commented May 24, 2022

@quinchs thoughts on allowing message parameters to be provided with a string operator?

    public class Message
    {
        private Message(string input)
        {

        }
        
        public static implicit operator Message(string input)
            => new Message(input);
    }

    internal class Example
    {
        public void ExampleMethod()
        {
            Send("test");

            void Send(Message message)
            {

            }
        }
    }

@csmir
Copy link
Collaborator

csmir commented May 24, 2022

Also with the same design as above, an embed could serve as operator for message:

        private Message(Embed input)
        {

        }

        public static implicit operator Message(Embed embed)
            => new Message(embed);

@csmir
Copy link
Collaborator

csmir commented May 24, 2022

With the mention of 'format', another idea to consider is a Format method, much like string.Format which runs over all entries of the builder looking for {} format entries and params object[] values as part of the Format method in these places. If not enough values are provided, escape and leave other format entries sit, or allow a bool to clear other format notations out of the string.

@quinchs quinchs changed the base branch from dev to 4.0 May 31, 2022 14:24
@quinchs
Copy link
Member Author

quinchs commented May 31, 2022

@Rozen4334 lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Working on
Development

Successfully merging this pull request may close these issues.

3 participants