当前位置: 首页>>代码示例>>Golang>>正文


Golang bot.ReplyN函数代码示例

本文整理汇总了Golang中github.com/fluffle/sp0rkle/bot.ReplyN函数的典型用法代码示例。如果您正苦于以下问题:Golang ReplyN函数的具体用法?Golang ReplyN怎么用?Golang ReplyN使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了ReplyN函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: insert

// Factoid add: 'key := value' or 'key :is value'
func insert(line *base.Line) {
	if !line.Addressed || !util.IsFactoidAddition(line.Args[1]) {
		return
	}

	var key, val string
	if strings.Index(line.Args[1], ":=") != -1 {
		kv := strings.SplitN(line.Args[1], ":=", 2)
		key = ToKey(kv[0], false)
		val = strings.TrimSpace(kv[1])
	} else {
		// we use :is to add val = "key is val"
		kv := strings.SplitN(line.Args[1], ":is", 2)
		key = ToKey(kv[0], false)
		val = strings.Join([]string{strings.TrimSpace(kv[0]),
			"is", strings.TrimSpace(kv[1])}, " ")
	}
	n, c := line.Storable()
	fact := factoids.NewFactoid(key, val, n, c)

	// The "randomwoot" factoid contains random positive phrases for success.
	joy := "Woo"
	if rand := fc.GetPseudoRand("randomwoot"); rand != nil {
		joy = rand.Value
	}

	if err := fc.Insert(fact); err == nil {
		count := fc.GetCount(key)
		bot.ReplyN(line, "%s, I now know %d things about '%s'.", joy, count, key)
	} else {
		bot.ReplyN(line, "Error storing factoid: %s.", err)
	}
}
开发者ID:pzsz,项目名称:sp0rkle,代码行数:34,代码来源:handlers.go

示例2: karmaCmd

func karmaCmd(line *base.Line) {
	if k := kc.KarmaFor(line.Args[1]); k != nil {
		bot.ReplyN(line, "%s", k)
	} else {
		bot.ReplyN(line, "No karma found for '%s'", line.Args[1])
	}
}
开发者ID:pzsz,项目名称:sp0rkle,代码行数:7,代码来源:commands.go

示例3: calculate

func calculate(line *base.Line) {
	maths := line.Args[1]
	if num, err := calc.Calc(maths); err == nil {
		bot.ReplyN(line, "%s = %g", maths, num)
	} else {
		bot.ReplyN(line, "%s error while parsing %s", err, maths)
	}
}
开发者ID:pzsz,项目名称:sp0rkle,代码行数:8,代码来源:commands.go

示例4: ord

func ord(line *base.Line) {
	ord := line.Args[1]
	r, _ := utf8.DecodeRuneInString(ord)
	if r == utf8.RuneError {
		bot.ReplyN(line, "Couldn't parse a utf8 rune from %s", ord)
		return
	}
	bot.ReplyN(line, "ord(%c) is %d, %U, '%s'", r, r, r, utf8repr(r))
}
开发者ID:pzsz,项目名称:sp0rkle,代码行数:9,代码来源:commands.go

示例5: chr

func chr(line *base.Line) {
	chr := line.Args[1]
	// handles decimal, hex, and octal \o/
	i, err := strconv.ParseInt(chr, 0, 0)
	if err != nil {
		bot.ReplyN(line, "Couldn't parse %s as an integer: %s", chr, err)
		return
	}
	bot.ReplyN(line, "chr(%s) is %c, %U, '%s'", chr, i, i, utf8repr(rune(i)))
}
开发者ID:pzsz,项目名称:sp0rkle,代码行数:10,代码来源:commands.go

示例6: add

func add(line *base.Line) {
	n, c := line.Storable()
	quote := quotes.NewQuote(line.Args[1], n, c)
	quote.QID = qc.NewQID()
	if err := qc.Insert(quote); err == nil {
		bot.ReplyN(line, "Quote added succesfully, id #%d.", quote.QID)
	} else {
		bot.ReplyN(line, "Error adding quote: %s.", err)
	}
}
开发者ID:pzsz,项目名称:sp0rkle,代码行数:10,代码来源:commands.go

示例7: netmask

func netmask(line *base.Line) {
	s := strings.Split(line.Args[1], " ")
	if strings.Index(s[1], "/") != -1 {
		// Assume we have netmask ip/cidr
		bot.ReplyN(line, "%s", parseCIDR(s[0]))
	} else if len(s) == 2 {
		// Assume we have netmask ip nm
		bot.ReplyN(line, "%s", parseMask(s[0], s[1]))
	} else {
		bot.ReplyN(line, "bad netmask args: %s", line.Args[1])
	}
}
开发者ID:pzsz,项目名称:sp0rkle,代码行数:12,代码来源:commands.go

示例8: randomCmd

func randomCmd(line *base.Line) {
	source := mc.CreateSourceForTag("user:" + line.Args[1])
	seed := time.Now().UTC().UnixNano()
	first_word := umarkov.SENTENCE_START

	out, err := umarkov.Generate(source, first_word, seed, 150)
	if err == nil {
		bot.ReplyN(line, "%s would say: %s", line.Args[1], out)
	} else {
		bot.ReplyN(line, "error: %v", err)
	}
}
开发者ID:pzsz,项目名称:sp0rkle,代码行数:12,代码来源:commands.go

示例9: forget

// Factoid delete: 'forget|delete that' => deletes lastSeen[chan]
func forget(line *base.Line) {
	// Get fresh state on the last seen factoid.
	ls := LastSeen(line.Args[0], "")
	if fact := fc.GetById(ls); fact != nil {
		if err := fc.Remove(bson.M{"_id": ls}); err == nil {
			bot.ReplyN(line, "I forgot that '%s' was '%s'.",
				fact.Key, fact.Value)
		} else {
			bot.ReplyN(line, "I failed to forget '%s': %s", fact.Key, err)
		}
	} else {
		bot.ReplyN(line, "Whatever that was, I've already forgotten it.")
	}
}
开发者ID:pzsz,项目名称:sp0rkle,代码行数:15,代码来源:commands.go

示例10: urlScan

func urlScan(line *base.Line) {
	words := strings.Split(line.Args[1], " ")
	n, c := line.Storable()
	for _, w := range words {
		if util.LooksURLish(w) {
			if u := uc.GetByUrl(w); u != nil {
				bot.Reply(line, "%s first mentioned by %s at %s",
					w, u.Nick, u.Timestamp.Format(time.RFC1123))
				continue
			}
			u := urls.NewUrl(w, n, c)
			if len(w) > autoShortenLimit {
				u.Shortened = Encode(w)
			}
			if err := uc.Insert(u); err != nil {
				bot.ReplyN(line, "Couldn't insert url '%s': %s", w, err)
				continue
			}
			if u.Shortened != "" {
				bot.Reply(line, "%s's URL shortened as %s%s%s",
					line.Nick, bot.HttpHost(), shortenPath, u.Shortened)
			}
			lastseen[line.Args[0]] = u.Id
		}
	}
}
开发者ID:pzsz,项目名称:sp0rkle,代码行数:26,代码来源:handlers.go

示例11: fetch

func fetch(line *base.Line) {
	if RateLimit(line.Nick) {
		return
	}
	qid, err := strconv.Atoi(line.Args[1])
	if err != nil {
		bot.ReplyN(line, "'%s' doesn't look like a quote id.", line.Args[1])
		return
	}
	quote := qc.GetByQID(qid)
	if quote != nil {
		bot.Reply(line, "#%d: %s", quote.QID, quote.Quote)
	} else {
		bot.ReplyN(line, "No quote found for id %d", qid)
	}
}
开发者ID:pzsz,项目名称:sp0rkle,代码行数:16,代码来源:commands.go

示例12: del

// remind del
func del(line *base.Line) {
	list, ok := listed[line.Nick]
	if !ok {
		bot.ReplyN(line, "Please use 'remind list' first, "+
			"to be sure of what you're deleting.")
		return
	}
	idx, err := strconv.Atoi(line.Args[1])
	if err != nil || idx > len(list) || idx <= 0 {
		bot.ReplyN(line, "Invalid reminder index '%s'", line.Args[1])
		return
	}
	idx--
	Forget(list[idx], true)
	delete(listed, line.Nick)
	bot.ReplyN(line, "I'll forget that one, then...")
}
开发者ID:pzsz,项目名称:sp0rkle,代码行数:18,代码来源:commands.go

示例13: lookup

func lookup(line *base.Line) {
	if RateLimit(line.Nick) {
		return
	}
	quote := qc.GetPseudoRand(line.Args[1])
	if quote == nil {
		bot.ReplyN(line, "No quotes matching '%s' found.", line.Args[1])
		return
	}

	// TODO(fluffle): qd should take care of updating Accessed internally
	quote.Accessed++
	if err := qc.Update(bson.M{"_id": quote.Id}, quote); err != nil {
		bot.ReplyN(line, "I failed to update quote #%d: %s", quote.QID, err)
	}
	bot.Reply(line, "#%d: %s", quote.QID, quote.Quote)
}
开发者ID:pzsz,项目名称:sp0rkle,代码行数:17,代码来源:commands.go

示例14: info

// Factoid info: 'fact info key' => some information about key
func info(line *base.Line) {
	key := ToKey(line.Args[1], false)
	count := fc.GetCount(key)
	if count == 0 {
		bot.ReplyN(line, "I don't know anything about '%s'.", key)
		return
	}
	msgs := make([]string, 0, 10)
	if key == "" {
		msgs = append(msgs, fmt.Sprintf("In total, I know %d things.", count))
	} else {
		msgs = append(msgs, fmt.Sprintf("I know %d things about '%s'.",
			count, key))
	}
	if created := fc.GetLast("created", key); created != nil {
		c := created.Created
		msgs = append(msgs, "A factoid")
		if key != "" {
			msgs = append(msgs, fmt.Sprintf("for '%s'", key))
		}
		msgs = append(msgs, fmt.Sprintf("was last created on %s by %s,",
			c.Timestamp.Format(time.ANSIC), c.Nick))
	}
	if modified := fc.GetLast("modified", key); modified != nil {
		m := modified.Modified
		msgs = append(msgs, fmt.Sprintf("modified on %s by %s,",
			m.Timestamp.Format(time.ANSIC), m.Nick))
	}
	if accessed := fc.GetLast("accessed", key); accessed != nil {
		a := accessed.Accessed
		msgs = append(msgs, fmt.Sprintf("and accessed on %s by %s.",
			a.Timestamp.Format(time.ANSIC), a.Nick))
	}
	if info := fc.InfoMR(key); info != nil {
		if key == "" {
			msgs = append(msgs, "These factoids have")
		} else {
			msgs = append(msgs, fmt.Sprintf("'%s' has", key))
		}
		msgs = append(msgs, fmt.Sprintf(
			"been modified %d times and accessed %d times.",
			info.Modified, info.Accessed))
	}
	bot.ReplyN(line, "%s", strings.Join(msgs, " "))
}
开发者ID:pzsz,项目名称:sp0rkle,代码行数:46,代码来源:commands.go

示例15: replace

// Factoid replace: 'replace that with' => updates lastSeen[chan]
func replace(line *base.Line) {
	ls := LastSeen(line.Args[0], "")
	if fact := fc.GetById(ls); fact != nil {
		// Store the old factoid value
		old := fact.Value
		// Replace the value with the new one
		fact.Value = line.Args[1]
		// Update the Modified field
		fact.Modify(line.Storable())
		// And store the new factoid data
		if err := fc.Update(bson.M{"_id": ls}, fact); err == nil {
			bot.ReplyN(line, "'%s' was '%s', now is '%s'.",
				fact.Key, old, fact.Value)
		} else {
			bot.ReplyN(line, "I failed to replace '%s': %s", fact.Key, err)
		}
	} else {
		bot.ReplyN(line, "Whatever that was, I've already forgotten it.")
	}
}
开发者ID:pzsz,项目名称:sp0rkle,代码行数:21,代码来源:commands.go


注:本文中的github.com/fluffle/sp0rkle/bot.ReplyN函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。