当前位置: 首页>>代码示例>>Golang>>正文


Golang Context.Public方法代码示例

本文整理汇总了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
		}
	}
}
开发者ID:gundalow,项目名称:sp0rkle,代码行数:29,代码来源:handlers.go

示例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)
	}
}
开发者ID:gundalow,项目名称:sp0rkle,代码行数:10,代码来源:handlers.go

示例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)
		}
	}
}
开发者ID:gundalow,项目名称:sp0rkle,代码行数:13,代码来源:handlers.go

示例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.")
	}
}
开发者ID:gundalow,项目名称:sp0rkle,代码行数:14,代码来源:commands.go

示例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
}
开发者ID:gundalow,项目名称:sp0rkle,代码行数:21,代码来源:commands.go

示例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 :-(")
	}
}
开发者ID:gundalow,项目名称:sp0rkle,代码行数:22,代码来源:commands.go


注:本文中的github.com/fluffle/sp0rkle/bot.Context.Public方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。