本文整理匯總了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)
}
}
示例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])
}
}
示例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)
}
}
示例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))
}
示例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)))
}
示例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)
}
}
示例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])
}
}
示例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)
}
}
示例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.")
}
}
示例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
}
}
}
示例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)
}
}
示例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...")
}
示例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)
}
示例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, " "))
}
示例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.")
}
}