예제 #1
0
파일: bot.go 프로젝트: 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},
		},
	)
}
예제 #2
0
파일: youtube.go 프로젝트: cosban/muggy
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,
	})

}
예제 #3
0
파일: raw.go 프로젝트: 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))
}
예제 #4
0
파일: topic.go 프로젝트: cosban/muggy
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,
	})
}
예제 #5
0
파일: channels.go 프로젝트: cosban/muggy
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!",
	})
}
예제 #6
0
파일: channels.go 프로젝트: cosban/muggy
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,
		})
	}
}
예제 #7
0
파일: quit.go 프로젝트: 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)
}
예제 #8
0
파일: magicball.go 프로젝트: cosban/muggy
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,
	})
}
예제 #9
0
파일: trust.go 프로젝트: cosban/muggy
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],
		})
	}
}
예제 #10
0
파일: trust.go 프로젝트: cosban/muggy
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.",
		})
	}

}
예제 #11
0
파일: trust.go 프로젝트: cosban/muggy
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],
	})
}
예제 #12
0
파일: weather.go 프로젝트: cosban/muggy
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,
	})
}
예제 #13
0
파일: weather.go 프로젝트: cosban/muggy
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,
	})
}
예제 #14
0
파일: avwx.go 프로젝트: 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,
	})
}
예제 #15
0
파일: search.go 프로젝트: cosban/muggy
// 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,
	})
}
예제 #16
0
파일: trust.go 프로젝트: cosban/muggy
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)
}