當前位置: 首頁>>代碼示例>>Golang>>正文


Golang bot.Context類代碼示例

本文整理匯總了Golang中github.com/fluffle/sp0rkle/bot.Context的典型用法代碼示例。如果您正苦於以下問題:Golang Context類的具體用法?Golang Context怎麽用?Golang Context使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Context類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: 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)
	}
}
開發者ID:gundalow,項目名稱:sp0rkle,代碼行數:25,代碼來源:handlers.go

示例2: githubCreateIssue

func githubCreateIssue(ctx *bot.Context) {
	s := strings.SplitN(ctx.Text(), ". ", 2)
	if s[0] == "" {
		ctx.ReplyN("I'm not going to create an empty issue.")
		return
	}

	req := &github.IssueRequest{
		Title: &s[0],
		Labels: &[]string{
			"from:IRC",
			"nick:" + ctx.Nick,
			"chan:" + ctx.Target(),
		},
	}
	if len(s) == 2 {
		req.Body = &s[1]
	}
	issue, _, err := gh.Issues.Create(githubUser, githubRepo, req)
	if err != nil {
		ctx.ReplyN("Error creating issue: %v", err)
		return
	}

	ctx.ReplyN("Issue #%d created at %s/%d",
		*issue.Number, githubIssuesURL, *issue.Number)
}
開發者ID:gundalow,項目名稱:sp0rkle,代碼行數:27,代碼來源:github.go

示例3: Remind

func Remind(r *reminders.Reminder, ctx *bot.Context) {
	delta := r.RemindAt.Sub(time.Now())
	if delta < 0 {
		return
	}
	c := make(chan struct{})
	running[r.Id] = c
	go func() {
		select {
		case <-time.After(delta):
			ctx.Privmsg(string(r.Chan), r.Reply())
			// TODO(fluffle): Tie this into state tracking properly.
			ctx.Privmsg(string(r.Target), r.Reply())
			// This is used in snooze to reinstate reminders.
			finished[strings.ToLower(string(r.Target))] = r
			if pc != nil {
				if s := pc.GetByNick(string(r.Target)); s.CanPush() {
					push.Push(s, "Reminder from sp0rkle!", r.Reply())
				}
			}
			Forget(r.Id, false)
		case <-c:
			return
		}
	}()
}
開發者ID:fluffle,項目名稱:sp0rkle,代碼行數:26,代碼來源:reminddriver.go

示例4: 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)

}
開發者ID:gundalow,項目名稱:sp0rkle,代碼行數:25,代碼來源:commands.go

示例5: recordKick

func recordKick(ctx *bot.Context) {
	n, c := ctx.Storable()
	kn := bot.Nick(ctx.Text())
	// seenNickFromLine doesn't work with the hacks for KICKING and KICKED
	// First, handle KICKING
	kr := sc.LastSeenDoing(ctx.Nick, "KICKING")
	if kr == nil {
		kr = seen.SawNick(n, c, "KICKING", ctx.Args[2])
	} else {
		kr.Nick, kr.Chan = n, c
		kr.Timestamp, kr.Text = time.Now(), ctx.Args[2]
	}
	kr.OtherNick = kn
	_, err := sc.Upsert(kr.Id(), kr)
	if err != nil {
		ctx.Reply("Failed to store seen data: %v", err)
	}
	// Now, handle KICKED
	ke := sc.LastSeenDoing(ctx.Text(), "KICKED")
	if ke == nil {
		ke = seen.SawNick(kn, c, "KICKED", ctx.Args[2])
	} else {
		ke.Nick, ke.Chan = kn, c
		ke.Timestamp, ke.Text = time.Now(), ctx.Args[2]
	}
	ke.OtherNick = n
	_, err = sc.Upsert(ke.Id(), ke)
	if err != nil {
		ctx.Reply("Failed to store seen data: %v", err)
	}
}
開發者ID:gundalow,項目名稱:sp0rkle,代碼行數:31,代碼來源:handlers.go

示例6: topten

func topten(ctx *bot.Context) {
	top := sc.TopTen(ctx.Target())
	s := make([]string, 0, 10)
	for i, n := range top {
		s = append(s, fmt.Sprintf("#%d: %s - %d", i+1, n.Nick, n.Lines))
	}
	ctx.Reply("%s", strings.Join(s, ", "))
}
開發者ID:gundalow,項目名稱:sp0rkle,代碼行數:8,代碼來源:commands.go

示例7: recordNick

func recordNick(ctx *bot.Context) {
	sn := seenNickFromLine(ctx)
	sn.Chan = ""
	sn.Text = ctx.Target()
	if _, err := sc.Upsert(sn.Id(), sn); err != nil {
		// We don't have anyone to reply to in this case, so log instead.
		logging.Warn("Failed to store seen data: %v", err)
	}
}
開發者ID:gundalow,項目名稱:sp0rkle,代碼行數:9,代碼來源:handlers.go

示例8: 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.")
}
開發者ID:gundalow,項目名稱:sp0rkle,代碼行數:9,代碼來源:commands.go

示例9: recordJoin

func recordJoin(ctx *bot.Context) {
	sn := seenNickFromLine(ctx)
	if len(ctx.Args) > 1 {
		// If we have a PART message
		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

示例10: id_replacer

// Split this out so we can inject a deterministic time for testing.
func id_replacer(val string, ctx *bot.Context, ts time.Time) string {
	val = strings.Replace(val, "$nick", ctx.Nick, -1)
	val = strings.Replace(val, "$chan", ctx.Target(), -1)
	val = strings.Replace(val, "$username", ctx.Ident, -1)
	val = strings.Replace(val, "$user", ctx.Ident, -1)
	val = strings.Replace(val, "$host", ctx.Host, -1)
	val = strings.Replace(val, "$date", datetime.Format(ts), -1)
	val = strings.Replace(val, "$time", datetime.Format(ts, "15:04:05"), -1)
	return val
}
開發者ID:gundalow,項目名稱:sp0rkle,代碼行數:11,代碼來源:plugins.go

示例11: seenNickFromLine

// Look up or create a "seen" entry for the line.
// Explicitly don't handle updating line.Text or line.OtherNick
func seenNickFromLine(ctx *bot.Context) *seen.Nick {
	sn := sc.LastSeenDoing(ctx.Nick, ctx.Cmd)
	n, c := ctx.Storable()
	if sn == nil {
		sn = seen.SawNick(n, c, ctx.Cmd, "")
	} else {
		sn.Nick, sn.Chan = n, c
		sn.Timestamp = time.Now()
	}
	return sn
}
開發者ID:gundalow,項目名稱:sp0rkle,代碼行數:13,代碼來源:seendriver.go

示例12: netmask

func netmask(ctx *bot.Context) {
	s := strings.Split(ctx.Text(), " ")
	if len(s) == 1 && strings.Index(s[0], "/") != -1 {
		// Assume we have netmask ip/cidr
		ctx.ReplyN("%s", parseCIDR(s[0]))
	} else if len(s) == 2 {
		// Assume we have netmask ip nm
		ctx.ReplyN("%s", parseMask(s[0], s[1]))
	} else {
		ctx.ReplyN("bad netmask args: %s", ctx.Text())
	}
}
開發者ID:gundalow,項目名稱:sp0rkle,代碼行數:12,代碼來源:commands.go

示例13: 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())
	}
}
開發者ID:gundalow,項目名稱:sp0rkle,代碼行數:7,代碼來源:commands.go

示例14: fetch

func fetch(ctx *bot.Context) {
	if RateLimit(ctx.Nick) {
		return
	}
	qid, err := strconv.Atoi(ctx.Text())
	if err != nil {
		ctx.ReplyN("'%s' doesn't look like a quote id.", ctx.Text())
		return
	}
	quote := qc.GetByQID(qid)
	if quote != nil {
		ctx.Reply("#%d: %s", quote.QID, quote.Quote)
	} else {
		ctx.ReplyN("No quote found for id %d", qid)
	}
}
開發者ID:gundalow,項目名稱:sp0rkle,代碼行數:16,代碼來源:commands.go

示例15: recordStats

func recordStats(ctx *bot.Context) {
	ns := sc.StatsFor(ctx.Nick, ctx.Target())
	if ns == nil {
		n, c := ctx.Storable()
		ns = stats.NewStat(n, c)
	}
	ns.Update(ctx.Text())
	if ns.Lines%10000 == 0 {
		ctx.Reply("%s has said %d lines in this channel and "+
			"should now shut the fuck up and do something useful",
			ctx.Nick, ns.Lines)

	}
	if _, err := sc.Upsert(ns.Id(), ns); err != nil {
		ctx.Reply("Failed to store stats data: %v", err)
	}
}
開發者ID:gundalow,項目名稱:sp0rkle,代碼行數:17,代碼來源:handlers.go


注:本文中的github.com/fluffle/sp0rkle/bot.Context類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。