Exemple #1
0
func parseChat(msg string, m *ircbot.Message) (reply string) {
	if config.Ignores[m.GetSender()] {
		return ""
	}

	if msg == "!help acm-bot" {
		return help(nil)
	}

	if matches := urlRegex.FindAllStringSubmatch(msg, -1); matches != nil {
		for _, m := range matches {

			response, finalURL, err := http.Get(m[0])

			if err != nil {
				errors.Printf("%s - Fetch failed: %s\n", m[0], err.String())
			} else if finalURL != m[0] || config.TitleWhitelist[m[1]] {
				if t := getTitle(response.Body); t != "" {
					info.Println("Fetched: " + m[0])
					reply += fmt.Sprintf("Title:%s\n", t)
				}
			}
		}
	}

	recordSighting(m)

	return
}
Exemple #2
0
func spam(c string, m *ircbot.Message) string {
	msgStart := strings.Index(c, ":")
	if msgStart == -1 {
		return "No message specified, try `?spam <recipients> :<message>`"
	}

	msg := strings.TrimSpace(c[msgStart+1:])

	if len(msg) == 0 {
		return "Empty message not sent"
	}

	recipients := strings.Split(c[:msgStart], " ", -1)[1:]

	if len(recipients) == 0 {
		return "No recipients specified, try `?spam <recipients> :<message>`"
	}

	for _, r := range recipients {
		_ = bot.Send(config.Server, &ircbot.Message{
			Command:  "PRIVMSG",
			Trailing: fmt.Sprintf("%s sez: %s", m.GetSender(), msg),
			Args:     []string{r},
		})
	}

	return "Ok, " + m.GetSender()
}
Exemple #3
0
func join(bot *ircbot.Bot, msg *ircbot.Message) *ircbot.Message {
	if config.Trusted[msg.GetSender()] {
		return &ircbot.Message{
			Command: "JOIN",
			Args:    []string{msg.Trailing},
		}
	}

	return nil
}
Exemple #4
0
func reconf(m *ircbot.Message) string {
	if config.Trusted[m.GetSender()] {
		if reparseConfig(bot) {
			return "Reparsed " + configPath + " successfully."
		} else {
			return "Failed to reparse " + configPath + "."
		}
	}
	return "I'm afraid I can't do that " + m.GetSender()
}
Exemple #5
0
func recordSighting(m *ircbot.Message) {
	s, ok := sightings[m.GetSender()]

	if !ok {
		s = make(map[string]*sighting)
		sightings[m.GetSender()] = s
	}

	s[m.Args[0]] = &sighting{time.LocalTime(), m.Trailing}
}
Exemple #6
0
func ignore(args []string, m *ircbot.Message) string {
	if config.Trusted[m.GetSender()] {
		for _, u := range args {
			if u[0] == '-' {
				config.Ignores[u[1:]] = false, false
			} else if u[0] == '+' {
				config.Ignores[u[1:]] = true
			} else {
				config.Ignores[u] = true
			}
		}
		return "Ok, " + m.GetSender()
	}
	return "I'm afraid I can't do that " + m.GetSender()
}