本文整理汇总了Golang中github.com/fluffle/sp0rkle/bot.ReplyN函数的典型用法代码示例。如果您正苦于以下问题:Golang ReplyN函数的具体用法?Golang ReplyN怎么用?Golang ReplyN使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ReplyN函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: lines
func lines(line *base.Line) {
n := line.Nick
if len(line.Args[1]) > 0 {
n = line.Args[1]
}
sn := sc.LinesFor(n, line.Args[0])
if sn != nil {
bot.ReplyN(line, "%s has said %d lines in this channel",
sn.Nick, sn.Lines)
}
}
开发者ID:pzsz,项目名称:sp0rkle,代码行数:11,代码来源:commands.go
示例17: list
// remind list
func list(line *base.Line) {
r := rc.RemindersFor(line.Nick)
c := len(r)
if c == 0 {
bot.ReplyN(line, "You have no reminders set.")
return
}
if c > 5 && line.Args[0][0] == '#' {
bot.ReplyN(line, "You've got lots of reminders, ask me privately.")
return
}
// Save an ordered list of ObjectIds for easy reminder deletion
bot.ReplyN(line, "You have %d reminders set:", c)
list := make([]bson.ObjectId, c)
for i := range r {
bot.Reply(line, "%d: %s", i+1, r[i].List(line.Nick))
list[i] = r[i].Id
}
listed[line.Nick] = list
}
开发者ID:pzsz,项目名称:sp0rkle,代码行数:21,代码来源:commands.go
示例18: search
// Factoid search: 'fact search regexp' => list of possible key matches
func search(line *base.Line) {
keys := fc.GetKeysMatching(line.Args[1])
if keys == nil || len(keys) == 0 {
bot.ReplyN(line, "I couldn't think of anything matching '%s'.",
line.Args[1])
return
}
// RESULTS.
count := len(keys)
if count > 10 {
res := strings.Join(keys[:10], "', '")
bot.ReplyN(line,
"I found %d keys matching '%s', here's the first 10: '%s'.",
count, line.Args[1], res)
} else {
res := strings.Join(keys, "', '")
bot.ReplyN(line,
"%s: I found %d keys matching '%s', here they are: '%s'.",
count, line.Args[1], res)
}
}
开发者ID:pzsz,项目名称:sp0rkle,代码行数:22,代码来源:commands.go
示例19: set
// remind
func set(line *base.Line) {
// s == <target> <reminder> in|at|on <time>
s := strings.Fields(line.Args[1])
if len(s) < 4 {
bot.ReplyN(line, "Invalid remind syntax. Sucka.")
return
}
i := len(s) - 1
for i > 0 {
lc := strings.ToLower(s[i])
if lc == "in" || lc == "at" || lc == "on" {
break
}
i--
}
if i < 1 {
bot.ReplyN(line, "Invalid remind syntax. Sucka.")
return
}
reminder := strings.Join(s[1:i], " ")
timestr := strings.ToLower(strings.Join(s[i+1:], " "))
// TODO(fluffle): surface better errors from datetime.Parse
at, ok := datetime.Parse(timestr)
if !ok {
bot.ReplyN(line, "Couldn't parse time string '%s'", timestr)
return
}
now := time.Now()
start := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local)
if at.Before(now) && at.After(start) {
// Perform some basic hacky corrections before giving up
if strings.Contains(timestr, "am") || strings.Contains(timestr, "pm") {
at = at.Add(24 * time.Hour)
} else {
at = at.Add(12 * time.Hour)
}
}
if at.Before(now) {
bot.ReplyN(line, "Time '%s' is in the past.", timestr)
return
}
n, c := line.Storable()
// TODO(fluffle): Use state tracking! And do this better.
t := base.Nick(s[0])
if t.Lower() == strings.ToLower(line.Nick) ||
t.Lower() == "me" {
t = n
}
r := reminders.NewReminder(reminder, at, t, n, c)
if err := rc.Insert(r); err != nil {
bot.ReplyN(line, "Error saving reminder: %v", err)
return
}
// Any previously-generated list of reminders is now obsolete.
delete(listed, line.Nick)
bot.ReplyN(line, "%s", r.Acknowledge())
Remind(r)
}
开发者ID:pzsz,项目名称:sp0rkle,代码行数:59,代码来源:commands.go
示例20: convertBase
func convertBase(line *base.Line) {
s := strings.Split(line.Args[1], " ")
fromto := strings.Split(s[0], "to")
if len(fromto) != 2 {
bot.ReplyN(line, "Specify base as: <from base>to<to base>")
return
}
from, errf := strconv.Atoi(fromto[0])
to, errt := strconv.Atoi(fromto[1])
if errf != nil || errt != nil ||
from < 2 || from > 36 || to < 2 || to > 36 {
bot.ReplyN(line, "Either %s or %s is a bad base, must be in range 2-36",
fromto[0], fromto[1])
return
}
i, err := strconv.ParseInt(s[1], from, 64)
if err != nil {
bot.ReplyN(line, "Couldn't parse %s as a base %d integer", s[1], from)
return
}
bot.ReplyN(line, "%s in base %d is %s in base %d",
s[1], from, strconv.FormatInt(i, to), to)
}
开发者ID:pzsz,项目名称:sp0rkle,代码行数:23,代码来源:commands.go
注:本文中的github.com/fluffle/sp0rkle/bot.ReplyN函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论