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

PROOF OF CONCEPT; DO NOT MERGE: Implement else #152

Closed
wants to merge 2 commits into from

Conversation

KnorpelSenf
Copy link
Member

Explanation for #136 (comment)

@KnorpelSenf
Copy link
Member Author

KnorpelSenf commented Jan 3, 2022

Leaving this here in case someone is wondering how to do if-else statements.

let iff = bot.filter((ctx) => ctx.update.update_id % 4 === 0);
{
    iff.do((ctx) => ctx.reply("Div 4 has rem 0"));
}
let elsee = bot.else();
{
    iff = elsee.filter((ctx) => ctx.update.update_id % 4 === 1);
    {
        iff.do((ctx) => ctx.reply("Div 4 has rem 1"));
    }
    elsee = elsee.else();
    {
        iff = elsee.filter((ctx) => ctx.update.update_id % 4 === 2);
        {
            iff.do((ctx) => ctx.reply("Div 4 has rem 2"));
        }
        elsee = elsee.else();
        {
            elsee.do((ctx) => ctx.reply("Div 4 has rem 3"));
        }
    }
}
bot.do((ctx) => ctx.reply("Evaluation complete"));

Same thing but without brackets:

let iff = bot.filter((ctx) => ctx.update.update_id % 4 === 0);
    iff.do((ctx) => ctx.reply("Div 4 has rem 0"));
let elsee = bot.else();
    iff = elsee.filter((ctx) => ctx.update.update_id % 4 === 1);
        iff.do((ctx) => ctx.reply("Div 4 has rem 1"));
    elsee = elsee.else();
        iff = elsee.filter((ctx) => ctx.update.update_id % 4 === 2);
            iff.do((ctx) => ctx.reply("Div 4 has rem 2"));
        elsee = elsee.else();
            elsee.do((ctx) => ctx.reply("Div 4 has rem 3"));

Note that this is a pointless example because the if statements are all mutually exclusive but it still illustrates the point.

@KnorpelSenf
Copy link
Member Author

KnorpelSenf commented Jan 3, 2022

If we ever figure that we do indeed want to merge this, we would need to add a protection against doing

bot.filter()
bot.use()
bot.else()

because that will be super confusing, as the else call and the use call are actually going to be swapped. else will be executed before use in case filter does not trigger.

@KnorpelSenf
Copy link
Member Author

This only works with filter and on. It does not work with command or hears or any other composer method that uses multi-level filtering.

@KnorpelSenf KnorpelSenf closed this Jan 8, 2022
@KnorpelSenf KnorpelSenf deleted the composer-else branch January 8, 2022 09:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant