本文整理匯總了Golang中github.com/fluffle/sp0rkle/bot.Context.Public方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.Public方法的具體用法?Golang Context.Public怎麽用?Golang Context.Public使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/fluffle/sp0rkle/bot.Context
的用法示例。
在下文中一共展示了Context.Public方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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
}
}
}
示例2: recordPrivmsg
func recordPrivmsg(ctx *bot.Context) {
if !ctx.Public() {
return
}
sn := seenNickFromLine(ctx)
sn.Text = ctx.Text()
if _, err := sc.Upsert(sn.Id(), sn); err != nil {
ctx.Reply("Failed to store seen data: %v", err)
}
}
示例3: recordMarkov
func recordMarkov(ctx *bot.Context) {
whom := strings.ToLower(ctx.Nick)
if !ctx.Addressed && ctx.Public() && shouldMarkov(whom) {
// Only markov lines that are public, not addressed to us,
// and from markov-enabled nicks
switch ctx.Cmd {
case client.PRIVMSG:
mc.AddSentence(ctx.Text(), "user:"+whom)
case client.ACTION:
mc.AddAction(ctx.Text(), "user:"+whom)
}
}
}
示例4: learn
func learn(ctx *bot.Context) {
s := strings.SplitN(ctx.Text(), " ", 2)
if len(s) != 2 {
ctx.ReplyN("I can't learn from you, you're an idiot.")
return
}
// Prepending "tag:" prevents people from learning as "user:foo".
mc.AddSentence(s[1], "tag:"+s[0])
if ctx.Public() {
// Allow large-scale learning via privmsg by not replying there.
ctx.ReplyN("Ta. You're a fount of knowledge, you are.")
}
}
示例5: list
// remind list
func list(ctx *bot.Context) {
r := rc.RemindersFor(ctx.Nick)
c := len(r)
if c == 0 {
ctx.ReplyN("You have no reminders set.")
return
}
if c > 5 && ctx.Public() {
ctx.ReplyN("You've got lots of reminders, ask me privately.")
return
}
// Save an ordered list of ObjectIds for easy reminder deletion
ctx.ReplyN("You have %d reminders set:", c)
list := make([]bson.ObjectId, c)
for i := range r {
ctx.Reply("%d: %s", i+1, r[i].List(ctx.Nick))
list[i] = r[i].Id
}
listed[ctx.Nick] = list
}
示例6: literal
// Factoid literal: 'literal key' => info about factoid
func literal(ctx *bot.Context) {
key := ToKey(ctx.Text(), false)
if count := fc.GetCount(key); count == 0 {
ctx.ReplyN("I don't know anything about '%s'.", key)
return
} else if count > 10 && ctx.Public() {
ctx.ReplyN("I know too much about '%s', ask me privately.", key)
return
}
if facts := fc.GetAll(key); facts != nil {
for _, fact := range facts {
// Use Privmsg directly here so that the results aren't output
// via the plugin system and contain the literal data.
ctx.Privmsg(ctx.Target(), fmt.Sprintf(
"[%3.0f%%] %s", fact.Chance*100, fact.Value))
}
} else {
ctx.ReplyN("Something literally went wrong :-(")
}
}