示例#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)
}