本文整理匯總了Golang中github.com/fluffle/sp0rkle/bot.Context.Me方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.Me方法的具體用法?Golang Context.Me怎麽用?Golang Context.Me使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/fluffle/sp0rkle/bot.Context
的用法示例。
在下文中一共展示了Context.Me方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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)
}
}
示例2: lookup
func lookup(ctx *bot.Context) {
// Only perform extra prefix removal if we weren't addressed directly
key := ToKey(ctx.Text(), !ctx.Addressed)
var fact *factoids.Factoid
if fact = fc.GetPseudoRand(key); fact == nil && ctx.Cmd == client.ACTION {
// Support sp0rkle's habit of stripping off it's own nick
// but only for actions, not privmsgs.
if strings.HasSuffix(key, ctx.Me()) {
key = strings.TrimSpace(key[:len(key)-len(ctx.Me())])
fact = fc.GetPseudoRand(key)
}
}
if fact == nil {
return
}
// Chance is used to limit the rate of factoid replies for things
// people say a lot, like smilies, or 'lol', or 'i love the peen'.
chance := fact.Chance
if key == "" {
// This is doing a "random" lookup, triggered by someone typing in
// something entirely composed of the chars stripped by ToKey().
// To avoid making this too spammy, forcibly limit the chance to 40%.
chance = 0.4
}
if rand.Float64() < chance {
// Store this as the last seen factoid
LastSeen(ctx.Target(), fact.Id)
// Update the Accessed field
// TODO(fluffle): fd should take care of updating Accessed internally
fact.Access(ctx.Storable())
// And store the new factoid data
if err := fc.Update(bson.M{"_id": fact.Id}, fact); err != nil {
ctx.ReplyN("I failed to update '%s' (%s): %s ",
fact.Key, fact.Id, err)
}
recurse(fact, map[string]bool{key: true})
switch fact.Type {
case factoids.F_ACTION:
ctx.Do("%s", fact.Value)
default:
ctx.Reply("%s", fact.Value)
}
}
}
示例3: insult
func insult(ctx *bot.Context) {
source := mc.Source("tag:insult")
whom, lc := ctx.Text(), strings.ToLower(ctx.Text())
if lc == strings.ToLower(ctx.Me()) || lc == "yourself" {
ctx.ReplyN("Ha, you're funny. No, wait. Retarded... I meant retarded.")
return
}
if lc == "me" {
whom = ctx.Nick
}
if out, err := chain.Sentence(source); err == nil {
if len(whom) > 0 {
ctx.Reply("%s: %s", whom, out)
} else {
ctx.Reply("%s", out)
}
} else {
ctx.ReplyN("markov error: %v", err)
}
}