コード例 #1
0
ファイル: fortune.go プロジェクト: krautchan/gbt
func (self *FortuneModule) ExecuteCommand(cmd string, params []string, srvMsg *irc.PrivateMessage, c chan irc.ClientMessage) {
	switch cmd {
	case "fortune":
		quote := ""

		if len(params) == 0 {
			fi := rand.Intn(len(self.fortunes))
			qi := rand.Intn(len(self.fortunes[fi].quotes))

			quote = strings.TrimSpace(strings.Replace(self.fortunes[fi].quotes[qi], "\n", " ", -1))
			if strings.HasPrefix(self.fortunes[fi].category, "off/") {
				quote = crypto.Rot13(quote) //WHY WOULD YOU DO THIS???
			}

		} else {
			for i := range self.fortunes {
				if self.fortunes[i].category == params[0] {
					qi := rand.Intn(len(self.fortunes[i].quotes))
					quote = strings.TrimSpace(strings.Replace(self.fortunes[i].quotes[qi], "\n", " ", -1))
					if strings.HasPrefix(self.fortunes[i].category, "off/") {
						quote = crypto.Rot13(quote)
					}
					break
				}
			}
		}

		self.sendMessage(srvMsg, quote, c)

	case "fortune.list":
		msg := "Categories:"

		for i := range self.fortunes {
			msg += " " + self.fortunes[i].category
		}
		self.sendMessage(srvMsg, msg, c)
	}
}
コード例 #2
0
ファイル: game.go プロジェクト: krautchan/gbt
func (self *GameModule) ExecuteCommand(cmd string, params []string, srvMsg *irc.PrivateMessage, c chan irc.ClientMessage) {
	switch cmd {
	case "morse":
		if len(params) == 0 {
			return
		}

		c <- self.Reply(srvMsg, crypto.Morse(strings.Join(params, " ")))
	case "dice":
		c <- self.Reply(srvMsg, strconv.Itoa(rand.Intn(6)+1))
	case "rot13":
		if len(params) == 0 {
			return
		}
		msg := strings.Join(params, " ")
		c <- self.Reply(srvMsg, crypto.Rot13(msg))
	case "roulette":
		ch := srvMsg.Target

		r, ok := self.rdb[ch]
		if !ok {
			r = &roulette{pos: rand.Intn(6), num: 0}
			self.rdb[ch] = r
		}

		if r.num == r.pos {
			c <- self.Reply(srvMsg, "You are dead. As agreed on in the TOS all your money will be transfered to the server owner")
			c <- self.Ban(srvMsg.Target, strings.Split(srvMsg.From(), "!")[0])
			c <- self.Kick(srvMsg.Target, strings.Split(srvMsg.From(), "!")[0], "Bye Bye")

			go func() {
				time.Sleep(5 * time.Minute)
				c <- self.Unban(srvMsg.Target, strings.Split(srvMsg.From(), "!")[0])
			}()

			r.num = 0
			r.pos = rand.Intn(6)
		} else {
			c <- self.Reply(srvMsg, "Lucky Bastard")
			r.num++
		}
	case "yn":
		answer := []string{"Yes", "No"}

		if len(params) == 0 {
			return
		}

		c <- self.Reply(srvMsg, answer[rand.Intn(2)])
	case "choice":
		if len(params) == 0 {
			return
		}
		c <- self.Reply(srvMsg, params[rand.Intn(len(params))])
	case "8ball":
		if len(params) == 0 {
			return
		}

		answers := []string{
			"Signs point to yes",
			"Yes",
			"Without a doubt",
			"As I see it, yes",
			"Most likely",
			"You may rely on it",
			"Yes definitely",
			"It is decidedly so",
			"Outlook good",
			"It is certain",
			"My sources say no",
			"Very doubtful",
			"Don't count on it",
			"Outlook not so good",
			"My reply is no",
			"Reply hazy, try again",
			"Concentrate and ask again",
			"Better not tell you now",
			"Cannot predict now",
			"Ask again later"}

		c <- self.Reply(srvMsg, answers[rand.Intn(len(answers))])
	}
}