community-bot icon indicating copy to clipboard operation
community-bot copied to clipboard

Centralized file for messages

Open NimperX opened this issue 5 years ago • 7 comments

Centralized file for messages #90

NimperX avatar Oct 03 '20 06:10 NimperX

We need a way to store messages with templates too, not sure how yet but this can be discussed.

We can just export functions instead of strings from the file

// template
export const templateMessage = (a: string) => `${a} is used here`;

// static
export const staticMessage = () => 'static message';

jellz avatar Oct 05 '20 03:10 jellz

We need a way to store messages with templates too, not sure how yet but this can be discussed.

We can just export functions instead of strings from the file

// template
export const templateMessage = (a: string) => `${a} is used here`;

// static
export const staticMessage = () => 'static message';

This won't allow us to use the Discord.js toString() overrides as TypeScript will be mad. Additionally, it will be quite big as we have to have that whole thing for each message.

p.s. haven't slept for a while, gonna write in more detail tomorrow.

ckiee avatar Oct 05 '20 03:10 ckiee

We need a way to store messages with templates too, not sure how yet but this can be discussed.

In that case I think using a message class would be a perfect solution.

export class Message {
	functionWithStaticMessage(): string { return 'some text'; }

	functionWithParameter(a: string): string { return 'value of a is' + a; }
}

NimperX avatar Oct 05 '20 07:10 NimperX

@robertt Thoughts?

Personally I don't really like this since you have to make an instance of the class and the static keyword on every method would probably just make this even longer. I'd like some Rust/Python-ey solution that lets us just have a object of strings and a function to call to populate stuff like %s but that seems quite far fetched for TS.

ckiee avatar Oct 05 '20 13:10 ckiee

Consider:

export const messages = {
    staticMessage: () => 'static message here',
    templateMessage: (a: string) => `this is a template, ${a}`
}

Short lines and simplicity.

jellz avatar Oct 06 '20 04:10 jellz

@jellz 👍, would probably be worth putting it in an object, so for example:

const messages = {
    commands: {
      rep: {
           toSelf: () => ':x: you cannot send rep to yourself',
           success: (member: string) => `:ok_hand: successfully sent rep to ${member}`
      }  
    },
};

robertt avatar Oct 06 '20 06:10 robertt

Anything blocking this from being merged?

cspotcode avatar Feb 12 '21 20:02 cspotcode