コード例 #1
0
ファイル: cmd-op.go プロジェクト: raylu/rbot
func unban(conn *irc.Conn, nick *irc.Nick, args, target string) {
	channel, args := parseAccess(conn, nick, target, args, "oh")
	if channel == "" || args == "" {
		return
	}

	ch := conn.GetChannel(channel)
	if ch == nil {
		say(conn, target, "%s: Unable to get channel information about %s", nick.Nick, channel)
		return
	}
	bans := strings.TrimSpace(args)
	split := strings.Fields(bans)
	for i, ban := range split {
		if strings.Index(ban, "@") != -1 {
			// it's already a host, do nothing
			continue
		}
		if b, ok := ch.Bans[ban]; ok {
			// we've seen this nick banned before
			split[i] = b
		} else if n := conn.GetNick(ban); n != nil {
			// the user is in one of our channels, here's our best guess
			split[i] = "*!*@" + n.Host
		}
	}
	bans = strings.Join(split, " ")
	modestring := "-" + strings.Repeat("b", len(bans)) + " " + bans
	conn.Mode(channel, modestring)
}
コード例 #2
0
ファイル: cmd-op.go プロジェクト: raylu/rbot
func ban(conn *irc.Conn, nick *irc.Nick, args, target string) {
	channel, args := parseAccess(conn, nick, target, args, "oh")
	if channel == "" || args == "" {
		return
	}

	bans := strings.TrimSpace(args)
	split := strings.Fields(bans)
	// turn nicks into *!*@host
	for i, ban := range split {
		if strings.Index(ban, "@") != -1 {
			// already a host
			continue
		}
		n := conn.GetNick(ban)
		if n == nil {
			//couldn't find the nick, so just cross our fingers
			continue
		}
		split[i] = "*!*@" + n.Host
	}
	bans = strings.Join(split, " ")
	modestring := "+" + strings.Repeat("b", len(bans)) + " " + bans
	conn.Mode(channel, modestring)
}
コード例 #3
0
ファイル: allbot2.go プロジェクト: antiartificial/allbot
// Called when incoming privmsg
// channel boolean evaluates true for channel privmsgs, false for bot privmsgs
func eventPrivmsg(conn *irc.Conn, line *irc.Line, channel bool) {
	if debug {
		fmt.Printf("Event PrivMSG fired: [%s] [%b]\n", line, channel)

	}

	// Determine what type of privmsg it is (channel||to bot)
	if channel {
		if debug {
			fmt.Printf("Line args: [%s]\n", line.Args[1])
		}

		var lastLine = strings.Split(line.Args[1], " ")

		if lastLine[0] == strings.ToLower("!say") {
			triggerSay(conn, lastLine, line.Args[0]) // why can't we pass line.Args?
		}

		if lastLine[0] == strings.ToLower("!ll") {
			var temp = findNickLastLine("testfile.txt", lastLine[1])
			fmt.Println("line:" + temp)
			conn.Privmsg(line.Args[0], temp)
		}

		// Silence Bot
		if lastLine[0] == strings.ToLower("!muzzle") {
			if muzzle == false {
				muzzle = true
				channelSay(conn, line.Args[0], "Muzzle enabled")
			} else {
				muzzle = false
				channelSay(conn, line.Args[0], "Muzzle disabled")
			}
			fmt.Printf("Muzzle set to: [%s]\n", muzzle)
		}

		if lastLine[0] == strings.ToLower("!op") {
			if line.Nick != botName && line.Nick == "arti" {
				//TODO do op
				conn.Mode(line.Args[0], "+o") // do we need to add a key arg?
			}
			//TODO do unauthorized message?
		}

		/*select {
		case strings.ToLower("!say"):
			triggerSay(conn, lastLine, line.Args[0]) // why can't we pass line.Args?
			fallthrough
		default:
			fmt.Println("No match.")
		}*/
	} else {
		// PrivMSG is to bot.
		if debug {
			fmt.Printf("Line args: [%s]\n", line.Args[1])
		}
		//TODO bot privmsg handling
	}
}
コード例 #4
0
ファイル: cmd-op.go プロジェクト: raylu/rbot
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)
	}
}
コード例 #5
0
ファイル: cmd-op.go プロジェクト: raylu/rbot
func op(conn *irc.Conn, nick *irc.Nick, args, target string) {
	channel, args := parseAccess(conn, nick, target, args, "o")
	if channel == "" {
		return
	}

	if args == "" {
		conn.Mode(channel, "+o "+nick.Nick)
	} else {
		ops := strings.TrimSpace(args)
		count := strings.Count(ops, " ") + 1
		modestring := "+" + strings.Repeat("o", count) + " " + ops
		conn.Mode(channel, modestring)
	}
}
コード例 #6
0
ファイル: cmd-op.go プロジェクト: raylu/rbot
func dehalfop(conn *irc.Conn, nick *irc.Nick, args, target string) {
	channel, args := parseAccess(conn, nick, target, args, "oh")
	if channel == "" {
		return
	}

	if args == "" {
		conn.Mode(channel, "-h "+nick.Nick)
	} else {
		if !hasAccess(conn, nick, channel, "o") {
			return
		}
		halfops := strings.TrimSpace(args)
		count := strings.Count(halfops, " ") + 1
		modestring := "-" + strings.Repeat("h", count) + " " + halfops
		conn.Mode(channel, modestring)
	}
}
コード例 #7
0
ファイル: cmd-op.go プロジェクト: raylu/rbot
func kickban(conn *irc.Conn, nick *irc.Nick, args, target string) {
	channel, args := parseAccess(conn, nick, target, args, "oh")
	if channel == "" || args == "" {
		return
	}

	split := strings.SplitN(args, " ", 2)

	n := conn.GetNick(split[0])
	if n == nil || (split[0] != nick.Nick &&
		(!hasAccess(conn, nick, channel, "o") && hasAccess(conn, n, channel, "oh"))) {
		return
	}
	conn.Mode(channel, "+b *!*@"+n.Host)

	reason := "(" + nick.Nick + ")"
	if len(split) == 2 {
		reason += " " + split[1]
	}
	conn.Kick(channel, split[0], reason)
}
コード例 #8
0
ファイル: rbot.go プロジェクト: thevermi/rbot
func BanManager(conn *irc.Conn) {
	for {
		time.Sleep(60000000000)
		c, err := config.ReadDefault("bans.list")
		if err != nil {
			panic(fmt.Sprintf("Config error: %s", err))
		}
		if !c.HasOption("timed", "count") {
			continue
		}
		count, err := c.Int("timed", "count")
		if err != nil || count == 0 {
			continue
		}
		banlist := make([]string, count)
		for i := 0; i < count; i++ {
			squid := strconv.Itoa(count - i)
			banlist[i], _ = c.String("timed", squid)
		}
		for e := count; e > 0; e-- {
			split := strings.SplitN(banlist[e-1], " ", 3)
			expiry, _ := strconv.Atoi64(split[2])
			if expiry <= time.Seconds() {
				c, _ = config.ReadDefault("bans.list")
				host, _ := c.String("#"+split[0], split[1]+".host")
				conn.Mode("#"+split[0], "-b "+host)
				banLogDel("#"+split[0], split[1])
				c.RemoveOption("timed", strconv.Itoa(count))
				count -= 1
				c.AddOption("timed", "count", strconv.Itoa(count))
				c.AddOption("#"+split[0], split[1]+".status", "EXPIRED")
				c.RemoveOption("#"+split[0], split[1]+".timer")
				c.WriteFile("bans.list", 0644, "Ban List")
			}
		}

	}
}
コード例 #9
0
ファイル: handler.go プロジェクト: thevermi/rbot
func handleJoin(conn *irc.Conn, line *irc.Line) {
	// autovoice users with v flag
	if line.Nick == conn.Me.Nick {
		return
	}

	channel := conn.GetChannel(line.Args[0])
	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.Nick, "v") {
		conn.Mode(line.Args[0], "+v "+line.Nick)
	}
}
コード例 #10
0
ファイル: cmd-op.go プロジェクト: thevermi/rbot
func tempban(conn *irc.Conn, nick *irc.Nick, args, target string) {
	channel, args := parseAccess(conn, nick, target, args, "oh")
	if channel == "" || args == "" {
		return
	}
	ch := conn.GetChannel(channel)
	if ch == nil {
		say(conn, target, "%s: Unable to get channel information about %s", nick.Nick, channel)
		return
	}
	args = strings.TrimSpace(args)
	split := strings.SplitN(args, " ", 3)
	dur, err := strconv.Atoi64(split[1])
	if dur < 5 {
		dur = 5
		split[1] = "5"
	}
	if err != nil {
		say(conn, channel, "Format: !tb <nick> <minutes> <reason>")
		return
	}
	n := conn.GetNick(split[0])
	if n == nil || (split[0] != nick.Nick &&
		(!hasAccess(conn, nick, channel, "o") && hasAccess(conn, n, channel, "oh"))) {
		return
	}
	conn.Mode(channel, "+b *!*@"+n.Host)

	reason := "(" + nick.Nick + ")"
	if len(split) == 3 {
		reason += " " + split[2]
	}
	reason += " (" + split[1] + " min.)"
	conn.Kick(channel, split[0], reason)
	expiry := time.Seconds() + dur*60
	banLogAdd("*!*@"+n.Host, split[0], reason, channel, expiry)
}