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

Demonstrate how to properly adjust channel modes #281

Open
jottinger opened this issue Aug 2, 2019 · 0 comments
Open

Demonstrate how to properly adjust channel modes #281

jottinger opened this issue Aug 2, 2019 · 0 comments

Comments

@jottinger
Copy link

What is the feature or improvement?
Right now, the docs don't really cover channel modes well; the tests demonstrate modes but there's little documentation that directs users TO the tests, or documents what the options for the channel modes are clearly (the javadocs mention it but don't do so very clearly IMO.)

The code I use for a bot that de-ops on being opped looks like this right now - it bases the detection on nick and not hostmask, which is probably going to have to change at some point.

As a secondary point, it might be nice to have helper objects for the channel mode changes, as the tests have helper functions that instantiate local classes.

@Handler
fun onModeChange(event: ChannelModeEvent) {
    class LocalChannelMode(
            val c: Char,
            val cl: Client,
            val t: ChannelMode.Type
    ) : ChannelMode {
        override fun getType(): ChannelMode.Type = t
        override fun getChar(): Char = c
        override fun getClient(): Client = cl
    }
    // we need to determine if this is a +o on the bot

    with(event) {
        val mode = event
                .statusList
                .getByMode('o')
                .firstOrNull { status ->
                    status.mode.client.nick == event.client.nick
                            && status.action == ModeStatus.Action.ADD
                }
        if (mode != null) {
            val command = ChannelModeCommand(client, event.channel.name)
            command.add(
                    ModeStatus.Action.REMOVE,
                    LocalChannelMode(
                            'o',
                            client,
                            ChannelMode.Type.B_PARAMETER_ALWAYS
                    ),
                    client.nick
            )
            command.execute()
        }

        // should contain mode events applying to THIS NICK ONLY
        val modeEvent = ModeEvent(
                channel.name,
                convertActorToBotUser(actor),
                source.message
        )
        bot.handleModeEvent(modeEvent)
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants