Example #1
0
File: bot.go Project: cosban/muggy
func registerConnect(s ircx.Sender, m *irc.Message) {
	log.Print("Identifying and joining channels...")
	if len(password) > 0 {
		messages.QueueMessages(s,
			&irc.Message{
				Command:  irc.PRIVMSG,
				Params:   []string{"NICKSERV"},
				Trailing: "identify " + name + " " + password,
			},
		)
	}

	messages.QueueMessages(s,
		&irc.Message{
			Command:  fmt.Sprintf("%s %s", irc.CAP, irc.CAP_REQ),
			Trailing: "account-notify extended-join",
		},
	)
	messages.QueueMessages(s,
		&irc.Message{
			Command: irc.JOIN,
			Params:  []string{channels},
		},
	)
}
Example #2
0
func SearchYoutube(s ircx.Sender, m *irc.Message, message string) {
	if len(message) < 1 {
		return
	}
	q := url.QueryEscape(message)
	request := fmt.Sprintf("https://www.googleapis.com/youtube/v3/search?&key=%s&part=id,snippet&maxResults=1&q=%s", key, q)

	r := &YoutubeData{}
	getJSON(request, r)

	response := fmt.Sprintf("\u200B%s: No results found :(", m.Prefix.Name)
	if len(r.Items) > 0 {
		response = fmt.Sprintf(
			"\u200B%s: https://youtube.com/watch?v=%s -- \u0002%s by %s\u0002: \"%s\" ",
			m.Prefix.Name,
			r.Items[0].Id.VideoID,
			r.Items[0].Snippet.Title,
			r.Items[0].Snippet.ChannelTitle,
			r.Items[0].Snippet.Description,
		)
	}

	messages.QueueMessages(s, &irc.Message{
		Command:  irc.PRIVMSG,
		Params:   m.Params,
		Trailing: response,
	})

}
Example #3
0
File: raw.go Project: cosban/muggy
func Raw(s ircx.Sender, m *irc.Message, message string) {
	if !isOwner(s, m.Name) {
		return
	}
	log.Printf("RAW: %s\n%+v", message, irc.ParseMessage(message))
	messages.QueueMessages(s, irc.ParseMessage(message))
}
Example #4
0
func Topic(s ircx.Sender, m *irc.Message, message string) {
	if !isTrusted(s, m.Name) {
		return
	}
	messages.QueueMessages(s, &irc.Message{
		Command:  irc.TOPIC,
		Params:   m.Params,
		Trailing: message,
	})
}
Example #5
0
func Leave(s ircx.Sender, m *irc.Message, message string) {
	if !isOwner(s, m.Name) {
		return
	}
	messages.QueueMessages(s, &irc.Message{
		Command:  irc.PART,
		Params:   m.Params,
		Trailing: "No one ever asks about Muggy!",
	})
}
Example #6
0
func Join(s ircx.Sender, m *irc.Message, message string) {
	if !isOwner(s, m.Name) {
		return
	}
	if strings.HasPrefix(message, "#") {
		channels := strings.Split(message, " ")
		for i := 0; i < len(channels); i++ {
			messages.QueueMessages(s, &irc.Message{
				Command:  irc.JOIN,
				Params:   []string{channels[i]},
				Trailing: "",
			})
		}
		messages.QueueMessages(s, &irc.Message{
			Command:  irc.NOTICE,
			Params:   []string{m.Name},
			Trailing: "I have now joined the following channels: " + message,
		})
	}
}
Example #7
0
File: quit.go Project: cosban/muggy
func Quit(s ircx.Sender, m *irc.Message, message string) {
	if !isOwner(s, m.Name) {
		return
	}
	messages.QueueMessages(s, &irc.Message{
		Command:  irc.QUIT,
		Params:   []string{" "},
		Trailing: "No one ever asks about Muggy!",
	})
	messages.StopLoop()
	os.Exit(1)
}
Example #8
0
func MagicBall(s ircx.Sender, m *irc.Message, message string) {
	if len(message) < 1 {
		return
	}
	r := rand.New(rand.NewSource(time.Now().UnixNano()))
	index := r.Int31n(int32(len(responses)))
	response := fmt.Sprintf("\u200B%s: %s", m.Name, responses[index])

	messages.QueueMessages(s, &irc.Message{
		Command:  irc.PRIVMSG,
		Params:   m.Params,
		Trailing: response,
	})
}
Example #9
0
func Doubt(s ircx.Sender, m *irc.Message, message string) {
	if !isOwner(s, m.Name) {
		return
	}
	args := strings.Split(message, " ")
	if _, ok := trusted[args[0]]; ok {
		delete(trusted, args[0])
		messages.QueueMessages(s, &irc.Message{
			Command:  irc.NOTICE,
			Params:   []string{m.Name},
			Trailing: "I no longer trust " + args[0],
		})
	}
}
Example #10
0
func Block(s ircx.Sender, m *irc.Message, message string) {
	if !isOwner(s, m.Name) {
		return
	}
	args := strings.Split(message, " ")
	if _, ok := trusted[args[0]]; ok {
		idents[args[0]] = false
		messages.QueueMessages(s, &irc.Message{
			Command:  irc.NOTICE,
			Params:   []string{m.Name},
			Trailing: args[0] + " is now blocked.",
		})
	}

}
Example #11
0
func Trust(s ircx.Sender, m *irc.Message, message string) {
	if !isOwner(s, m.Name) {
		return
	}
	args := strings.Split(message, " ")
	if len(args[0]) < 1 {
		Trusted(s, m, message)
		return
	}
	trusted[args[0]] = true
	messages.QueueMessages(s, &irc.Message{
		Command:  irc.NOTICE,
		Params:   []string{m.Name},
		Trailing: "I now trust " + args[0],
	})
}
Example #12
0
func Temperature(s ircx.Sender, m *irc.Message, message string) {
	r, err := unmarshalWeather(message)
	response := fmt.Sprintf("\u200B%s: 0.0 Kelvin. Seriously.", m.Prefix.Name)
	if err == nil && r != nil {
		response = fmt.Sprintf("\u200B%s- %s: %s H:%s L:%s ",
			m.Name,
			r.Name,
			tempString(r.Main.Temp),
			tempString(r.Main.Temp_max),
			tempString(r.Main.Temp_min))
	}
	messages.QueueMessages(s, &irc.Message{
		Command:  irc.PRIVMSG,
		Params:   m.Params,
		Trailing: response,
	})
}
Example #13
0
func Weather(s ircx.Sender, m *irc.Message, message string) {
	r, err := unmarshalWeather(message)
	response := fmt.Sprintf("\u200B%s: There is obviously no weather at that location, like, ever.", m.Prefix.Name)
	if err == nil && r != nil {
		response = fmt.Sprintf("\u200B%s %s: %s at %s wind at %s %s",
			m.Name,
			r.Name,
			r.Weather[0].Main,
			tempString(r.Main.Temp),
			speedString(r.Wind.Speed),
			directionString(r.Wind.Deg),
		)
	}
	messages.QueueMessages(s, &irc.Message{
		Command:  irc.PRIVMSG,
		Params:   m.Params,
		Trailing: response,
	})
}
Example #14
0
File: avwx.go Project: cosban/muggy
func callAVWX(s ircx.Sender, m *irc.Message, message, method string) {
	r := &AVWXData{}
	err := getJSON(fmt.Sprintf("https://avwx.rest/api/%s.php?station=%s&format=JSON", method, url.QueryEscape(message)), r)
	response := fmt.Sprintf("\u200B%s: There is obviously no weather at that location, like, ever.", m.Prefix.Name)
	if len(r.Error) > 0 {
		response = fmt.Sprintf("\u200B%s: %s",
			m.Name,
			r.Error,
		)
	} else if err == nil && len(r.RawReport) > 0 {
		response = fmt.Sprintf("\u200B%s: %s",
			m.Name,
			r.RawReport,
		)
	}

	messages.QueueMessages(s, &irc.Message{
		Command:  irc.PRIVMSG,
		Params:   m.Params,
		Trailing: response,
	})
}
Example #15
0
// Search performs a google search
func Search(s ircx.Sender, m *irc.Message, message string) {
	if len(message) < 1 {
		return
	}
	log.Print("im gay")
	site := parseSite(message)
	q := url.QueryEscape(message)

	request := fmt.Sprintf("https://www.googleapis.com/customsearch/v1?&key=%s&cx=%s&q=%s&siteSearch=%s&fields=items&num=1", key, cx, q, site)
	r := &SearchData{}
	getJSON(request, r)

	response := fmt.Sprintf("\u200B%s: No results found :(", m.Prefix.Name)
	if len(r.Items) > 0 {
		response = fmt.Sprintf("\u200B%s: %s -- \u0002%s\u0002: \"%s\" ", m.Prefix.Name, r.Items[0].Link, r.Items[0].Title, r.Items[0].Snippet)
	} else if len(r.Error.Message) > 0 {
		log.Print(r.Error.Message)
	}
	messages.QueueMessages(s, &irc.Message{
		Command:  irc.PRIVMSG,
		Params:   m.Params,
		Trailing: response,
	})
}
Example #16
0
func Trusted(s ircx.Sender, m *irc.Message, message string) {
	if !isTrusted(s, m.Name) {
		return
	}
	tlist := ""
	olist := ""
	for k, v := range trusted {
		if v {
			tlist += k + ", "
		}
	}
	if len(tlist) > 0 {
		tlist = tlist[:len(tlist)-2]
	}
	for k, v := range owners {
		if v {
			olist += k + ", "
		}
	}
	if len(olist) > 0 {
		olist = olist[:len(olist)-2]
	}
	messages.QueueMessages(s,
		&irc.Message{
			Command:  irc.NOTICE,
			Params:   []string{m.Name},
			Trailing: "I trust the following users: " + tlist,
		},
		&irc.Message{
			Command:  irc.NOTICE,
			Params:   []string{m.Name},
			Trailing: "I obey the following users: " + olist,
		},
	)
	log.Printf("I trust the following users: %s\nI obey the following users: %s\n", tlist, olist)
}