本文整理匯總了Golang中github.com/fluffle/sp0rkle/bot.Context.ReplyN方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.ReplyN方法的具體用法?Golang Context.ReplyN怎麽用?Golang Context.ReplyN使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/fluffle/sp0rkle/bot.Context
的用法示例。
在下文中一共展示了Context.ReplyN方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: snooze
// snooze
func snooze(ctx *bot.Context) {
r, ok := finished[strings.ToLower(ctx.Nick)]
if !ok {
ctx.ReplyN("No record of an expired reminder for you, sorry!")
return
}
now := time.Now()
at := now.Add(30 * time.Minute)
if ctx.Text() != "" {
at, ok = datetime.Parse(ctx.Text())
if !ok {
ctx.ReplyN("Couldn't parse time string '%s'.")
return
}
if at.Before(now) {
ctx.ReplyN("You can't snooze reminder into the past, fool.")
return
}
}
r.Created = now
r.RemindAt = at
if _, err := rc.UpsertId(r.Id, r); err != nil {
ctx.ReplyN("Error saving reminder: %v", err)
return
}
delete(listed, ctx.Nick)
ctx.ReplyN("%s", r.Acknowledge())
Remind(r, ctx)
}
示例2: randomCmd
func randomCmd(ctx *bot.Context) {
if len(ctx.Text()) == 0 {
ctx.ReplyN("Be who? Your mum?")
return
}
whom := strings.ToLower(strings.Fields(ctx.Text())[0])
if whom == strings.ToLower(ctx.Me()) {
ctx.ReplyN("Ha, you're funny. No, wait. Retarded... I meant retarded.")
return
}
if !shouldMarkov(whom) {
if whom == strings.ToLower(ctx.Nick) {
ctx.ReplyN("You're not recording markov data. " +
"Use 'markov me' to enable collection.")
} else {
ctx.ReplyN("Not recording markov data for %s.", ctx.Text())
}
return
}
source := mc.Source("user:" + whom)
if out, err := chain.Sentence(source); err == nil {
ctx.Reply("%s would say: %s", ctx.Text(), out)
} else {
ctx.ReplyN("markov error: %v", err)
}
}
示例3: tellCheck
func tellCheck(ctx *bot.Context) {
nick := ctx.Nick
if ctx.Cmd == client.NICK {
// We want the destination nick, not the source.
nick = ctx.Target()
}
r := rc.TellsFor(nick)
for i := range r {
if ctx.Cmd == client.NICK {
if r[i].Chan != "" {
ctx.Privmsg(string(r[i].Chan), nick+": "+r[i].Reply())
}
ctx.Reply("%s", r[i].Reply())
} else {
ctx.Privmsg(ctx.Nick, r[i].Reply())
if r[i].Chan != "" {
ctx.ReplyN("%s", r[i].Reply())
}
}
rc.RemoveId(r[i].Id)
}
if len(r) > 0 {
delete(listed, ctx.Nick)
}
}
示例4: insert
// Factoid add: 'key := value' or 'key :is value'
func insert(ctx *bot.Context) {
if !ctx.Addressed || !util.IsFactoidAddition(ctx.Text()) {
return
}
var key, val string
if strings.Index(ctx.Text(), ":=") != -1 {
kv := strings.SplitN(ctx.Text(), ":=", 2)
key = ToKey(kv[0], false)
val = strings.TrimSpace(kv[1])
} else {
// we use :is to add val = "key is val"
kv := strings.SplitN(ctx.Text(), ":is", 2)
key = ToKey(kv[0], false)
val = strings.Join([]string{strings.TrimSpace(kv[0]),
"is", strings.TrimSpace(kv[1])}, " ")
}
n, c := ctx.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)
LastSeen(ctx.Target(), fact.Id)
ctx.ReplyN("%s, I now know %d things about '%s'.", joy, count, key)
} else {
ctx.ReplyN("Error storing factoid: %s.", err)
}
}
示例5: urlScan
func urlScan(ctx *bot.Context) {
words := strings.Split(ctx.Text(), " ")
n, c := ctx.Storable()
for _, w := range words {
if util.LooksURLish(w) {
if u := uc.GetByUrl(w); u != nil {
if u.Nick != bot.Nick(ctx.Nick) &&
time.Since(u.Timestamp) > 2*time.Hour {
ctx.Reply("that URL first mentioned by %s %s ago",
u.Nick, util.TimeSince(u.Timestamp))
}
continue
}
u := urls.NewUrl(w, n, c)
if len(w) > autoShortenLimit && ctx.Public() {
u.Shortened = Encode(w)
}
if err := uc.Insert(u); err != nil {
ctx.ReplyN("Couldn't insert url '%s': %s", w, err)
continue
}
if u.Shortened != "" {
ctx.Reply("%s's URL shortened as %s%s%s",
ctx.Nick, bot.HttpHost(), shortenPath, u.Shortened)
}
lastseen[ctx.Target()] = u.Id
}
}
}
示例6: karmaCmd
func karmaCmd(ctx *bot.Context) {
if k := kc.KarmaFor(ctx.Text()); k != nil {
ctx.ReplyN("%s", k)
} else {
ctx.ReplyN("No karma found for '%s'", ctx.Text())
}
}
示例7: mcSet
func mcSet(ctx *bot.Context) {
kv := strings.Fields(ctx.Text())
if len(kv) < 2 {
ctx.ReplyN("I need a key and a value.")
return
}
switch kv[0] {
case mcServer:
mcConf.String(mcServer, kv[1])
case mcChan:
if !strings.HasPrefix(kv[1], "#") {
ctx.ReplyN("Channel '%s' doesn't start with #.", kv[1])
return
}
mcConf.String(mcChan, kv[1])
case mcFreq:
freq, err := strconv.Atoi(kv[1])
if err != nil {
ctx.ReplyN("Couldn't convert '%s' to an integer.", kv[1])
return
}
mcConf.Int(mcFreq, freq)
default:
ctx.ReplyN("Valid keys are: %s, %s, %s", mcServer, mcFreq, mcChan)
return
}
ctx.ReplyN("Set %s to '%s'", kv[0], kv[1])
}
示例8: ord
func ord(ctx *bot.Context) {
ord := ctx.Text()
r, _ := utf8.DecodeRuneInString(ord)
if r == utf8.RuneError {
ctx.ReplyN("Couldn't parse a utf8 rune from %s", ord)
return
}
ctx.ReplyN("ord(%c) is %d, %U, '%s'", r, r, r, utf8repr(r))
}
示例9: disableMarkov
func disableMarkov(ctx *bot.Context) {
key := strings.ToLower(ctx.Nick)
conf.Ns(markovNs).Delete(key)
if err := mc.ClearTag("user:" + key); err != nil {
ctx.ReplyN("Failed to clear tag: %s", err)
return
}
ctx.ReplyN("Sure, bro, I'll stop.")
}
示例10: add
func add(ctx *bot.Context) {
n, c := ctx.Storable()
quote := quotes.NewQuote(ctx.Text(), n, c)
quote.QID = qc.NewQID()
if err := qc.Insert(quote); err == nil {
ctx.ReplyN("Quote added succesfully, id #%d.", quote.QID)
} else {
ctx.ReplyN("Error adding quote: %s.", err)
}
}
示例11: statsCmd
func statsCmd(ctx *bot.Context) {
n := ctx.Nick
if len(ctx.Text()) > 0 {
n = ctx.Text()
}
ns := sc.StatsFor(n, ctx.Target())
if ns != nil {
ctx.ReplyN("%s", ns)
}
}
示例12: convertBase
func convertBase(ctx *bot.Context) {
s := strings.Split(ctx.Text(), " ")
fromto := strings.Split(s[0], "to")
if len(fromto) != 2 {
ctx.ReplyN("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 {
ctx.ReplyN("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 {
ctx.ReplyN("Couldn't parse %s as a base %d integer", s[1], from)
return
}
ctx.ReplyN("%s in base %d is %s in base %d",
s[1], from, strconv.FormatInt(i, to), to)
}
示例13: calculate
func calculate(ctx *bot.Context) {
nick := strings.ToLower(ctx.Nick)
maths := ctx.Text()
tm := calc.TokenMap{}
if res, ok := results[nick]; ok {
tm["result"] = res
}
if num, err := calc.Calc(maths, tm); err == nil {
ctx.ReplyN("%s = %g", maths, num)
tm[nick] = num
} else {
ctx.ReplyN("%s error while parsing %s", err, maths)
}
}
示例14: chr
func chr(ctx *bot.Context) {
chr := strings.ToLower(ctx.Text())
if strings.HasPrefix(chr, "u+") {
// Allow "unicode" syntax by translating it to 0x...
chr = "0x" + chr[2:]
}
// handles decimal, hex, and octal \o/
i, err := strconv.ParseInt(chr, 0, 0)
if err != nil {
ctx.ReplyN("Couldn't parse %s as an integer: %s", chr, err)
return
}
ctx.ReplyN("chr(%s) is %c, %U, '%s'", chr, i, i, utf8repr(rune(i)))
}
示例15: tell
// tell
func tell(ctx *bot.Context) {
// s == <target> <stuff>
txt := ctx.Text()
idx := strings.Index(txt, " ")
if idx == -1 {
ctx.ReplyN("Tell who what?")
return
}
tell := txt[idx+1:]
n, c := ctx.Storable()
t := bot.Nick(txt[:idx])
if t.Lower() == strings.ToLower(ctx.Nick) ||
t.Lower() == "me" {
ctx.ReplyN("You're a dick. Oh, wait, that wasn't *quite* it...")
return
}
r := reminders.NewTell(tell, t, n, c)
if err := rc.Insert(r); err != nil {
ctx.ReplyN("Error saving tell: %v", err)
return
}
if s := pc.GetByNick(txt[:idx]); s.CanPush() {
push.Push(s, fmt.Sprintf("%s in %s asked me to tell you:",
ctx.Nick, ctx.Target()), tell)
}
// Any previously-generated list of reminders is now obsolete.
delete(listed, ctx.Nick)
ctx.ReplyN("%s", r.Acknowledge())
}