本文整理匯總了Golang中github.com/fluffle/sp0rkle/bot.Context.Text方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.Text方法的具體用法?Golang Context.Text怎麽用?Golang Context.Text使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/fluffle/sp0rkle/bot.Context
的用法示例。
在下文中一共展示了Context.Text方法的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: 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())
}
示例3: 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())
}
}
示例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)
}
示例5: 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)
}
示例6: 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
}
}
}
示例7: githubWatcher
func githubWatcher(ctx *bot.Context) {
// Watch #sp0rklf for IRC messages about issues coming from github.
if ctx.Nick != "fluffle\\sp0rkle" || ctx.Target() != "#sp0rklf" ||
!strings.Contains(ctx.Text(), "issue #") {
return
}
text := util.RemoveColours(ctx.Text()) // srsly github why colours :(
l := &util.Lexer{Input: text}
l.Find(' ')
text = text[l.Pos()+1:]
l.Find('#')
l.Next()
issue := int(l.Number())
labels, _, err := gh.Issues.ListLabelsByIssue(
githubUser, githubRepo, issue, &github.ListOptions{})
if err != nil {
logging.Error("Error getting labels for issue %d: %v", issue, err)
return
}
for _, l := range labels {
kv := strings.Split(*l.Name, ":")
if len(kv) == 2 && kv[0] == "nick" {
logging.Debug("Recording tell for %s about issue %d.", kv[1], issue)
r := reminders.NewTell("that "+text, bot.Nick(kv[1]), "github", "")
if err := rc.Insert(r); err != nil {
logging.Error("Error inserting github tell: %v", err)
}
}
}
}
示例8: 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])
}
示例9: 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)
}
}
示例10: 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))
}
示例11: 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)
}
}
示例12: 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)
}
}
示例13: 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)
}
}
示例14: 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)
}
}
示例15: 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())
}
}