diff --git a/README.md b/README.md index f3f2d82..86767ad 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,8 @@ The following is a description of the commands enabled by each flag: - `a`: add remove - `o`: op halfop deop dehalfop kick|k ban|b unban|u kb -- `h`: halfop|hop dehalfop|dehop kick ban unban kb (hop and dehop can only be used on yourself and you cannot kick or kb people with o or h) +- `h`: halfop|hop dehalfop|dehop kick|k ban|b unban|u kb (hop and dehop can only be used on yourself and you cannot kick or kb people with o or h) +- `v`: voice, devoice - `t`: topic appendtopic - `s`: say @@ -55,6 +56,10 @@ Op commands: - `deop raylu john`: deop raylu and john - `dehalfop`: dehalfop yourself - `dehalfop|dehop raylu john`: dehalfop raylu and john +- `voice`: voice yourself +- `voice raylu john`: voice raylu and john +- `devoice`: devoice yourself +- `devoice raylu john`: devoice raylu and john - `kick|k raylu`: kick raylu - `ban|b raylu john!*@*`: ban raylu by hostname and john by nick - `unban|u raylu john!*@*`: unban raylu by hostname and john by nick diff --git a/cmd-op.go b/cmd-op.go index 8c992ae..4442acc 100644 --- a/cmd-op.go +++ b/cmd-op.go @@ -76,6 +76,38 @@ func dehalfop(conn *irc.Conn, nick *irc.Nick, args, target string) { } } +func voice(conn *irc.Conn, nick *irc.Nick, args, target string) { + channel, args := parseAccess(conn, nick, target, args, "v") + if channel == "" { + return + } + + if args == "" { + conn.Mode(channel, "+v " + nick.Nick) + } else { + voices := strings.TrimSpace(args) + count := strings.Count(voices, " ") + 1 + modestring := "+" + strings.Repeat("v", count) + " " + voices + conn.Mode(channel, modestring) + } +} + +func devoice(conn *irc.Conn, nick *irc.Nick, args, target string) { + channel, args := parseAccess(conn, nick, target, args, "v") + if channel == "" { + return + } + + if args == "" { + conn.Mode(channel, "-v " + nick.Nick) + } else { + voices := strings.TrimSpace(args) + count := strings.Count(voices, " ") + 1 + modestring := "-" + strings.Repeat("v", count) + " " + voices + conn.Mode(channel, modestring) + } +} + func kick(conn *irc.Conn, nick *irc.Nick, args, target string) { channel, args := parseAccess(conn, nick, target, args, "oh") if channel == "" || args == "" { diff --git a/handler.go b/handler.go index c69005d..286f8c7 100644 --- a/handler.go +++ b/handler.go @@ -23,6 +23,8 @@ var commands = map [string]func(*irc.Conn, *irc.Nick, string, string) { "deop": deop, "dehalfop": dehalfop, "dehop": dehalfop, + "voice": voice, + "devoice": devoice, "kick": kick, "k": kick, "b": ban, @@ -77,6 +79,30 @@ func handleMode(conn *irc.Conn, line *irc.Line) { } } +func handleJoin(conn *irc.Conn, line *irc.Line) { + // autovoice users with v flag + if line.Nick == conn.Me.Nick { + return + } + + channel := conn.GetChannel(line.Text) + if channel == nil || !channel.Modes.Moderated { + return + } + + privs := conn.Me.Channels[channel] + if !(privs.Op || privs.Admin || privs.HalfOp || privs.Owner) { + return + } + nick := conn.GetNick(line.Nick) + if nick == nil { + return + } + if hasAccess(conn, nick, line.Text, "v") { + conn.Mode(line.Text, "+v " + line.Nick) + } +} + func handleInvite(conn *irc.Conn, line *irc.Line) { if line.Args[0] != conn.Me.Nick { return diff --git a/rbot.go b/rbot.go index 1df8807..8c33341 100644 --- a/rbot.go +++ b/rbot.go @@ -53,6 +53,7 @@ func connect(network string) { }) c.AddHandler("privmsg", handlePrivmsg) c.AddHandler("mode", handleMode) + c.AddHandler("join", handleJoin) c.AddHandler("invite", handleInvite) for {