本文整理汇总了Golang中github.com/fluffle/sp0rkle/bot.Context.Target方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.Target方法的具体用法?Golang Context.Target怎么用?Golang Context.Target使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/fluffle/sp0rkle/bot.Context
的用法示例。
在下文中一共展示了Context.Target方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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())
}
示例2: 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)
}
}
}
}
示例3: 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)
}
}
示例4: 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)
}
示例5: 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
}
}
}
示例6: insert
// Factoid add: 'key := value' or 'key :is value'
func insert(ctx *bot.Context) {
if !ctx.Addressed || !util.IsFactoidAddition(ctx.Text()) {
return
}
var key, val string
if strings.Index(ctx.Text(), ":=") != -1 {
kv := strings.SplitN(ctx.Text(), ":=", 2)
key = ToKey(kv[0], false)
val = strings.TrimSpace(kv[1])
} else {
// we use :is to add val = "key is val"
kv := strings.SplitN(ctx.Text(), ":is", 2)
key = ToKey(kv[0], false)
val = strings.Join([]string{strings.TrimSpace(kv[0]),
"is", strings.TrimSpace(kv[1])}, " ")
}
n, c := ctx.Storable()
fact := factoids.NewFactoid(key, val, n, c)
// The "randomwoot" factoid contains random positive phrases for success.
joy := "Woo"
if rand := fc.GetPseudoRand("randomwoot"); rand != nil {
joy = rand.Value
}
if err := fc.Insert(fact); err == nil {
count := fc.GetCount(key)
LastSeen(ctx.Target(), fact.Id)
ctx.ReplyN("%s, I now know %d things about '%s'.", joy, count, key)
} else {
ctx.ReplyN("Error storing factoid: %s.", err)
}
}
示例7: 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, ", "))
}
示例8: 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)
}
}
示例9: 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
}
示例10: 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)
}
}
示例11: chance
// Factoid chance: 'chance of that is' => sets chance of lastSeen[chan]
func chance(ctx *bot.Context) {
str := ctx.Text()
var chance float64
if strings.HasSuffix(str, "%") {
// Handle 'chance of that is \d+%'
if i, err := strconv.Atoi(str[:len(str)-1]); err != nil {
ctx.ReplyN("'%s' didn't look like a % chance to me.", str)
return
} else {
chance = float64(i) / 100
}
} else {
// Assume the chance is a floating point number.
if c, err := strconv.ParseFloat(str, 64); err != nil {
ctx.ReplyN("'%s' didn't look like a chance to me.", str)
return
} else {
chance = c
}
}
// Make sure the chance we've parsed lies in (0.0,1.0]
if chance > 1.0 || chance <= 0.0 {
ctx.ReplyN("'%s' was outside possible chance ranges.", str)
return
}
// Retrieve last seen ObjectId, replace with ""
ls := LastSeen(ctx.Target(), "")
// ok, we're good to update the chance.
if fact := fc.GetById(ls); fact != nil {
// Store the old chance, update with the new
old := fact.Chance
fact.Chance = chance
// Update the Modified field
fact.Modify(ctx.Storable())
// And store the new factoid data
if err := fc.Update(bson.M{"_id": ls}, fact); err == nil {
ctx.ReplyN("'%s' was at %.0f%% chance, now is at %.0f%%.",
fact.Key, old*100, chance*100)
} else {
ctx.ReplyN("I failed to replace '%s': %s", fact.Key, err)
}
} else {
ctx.ReplyN("Whatever that was, I've already forgotten it.")
}
}
示例12: forget
// Factoid delete: 'forget|delete that' => deletes lastSeen[chan]
func forget(ctx *bot.Context) {
// Get fresh state on the last seen factoid.
ls := LastSeen(ctx.Target(), "")
if fact := fc.GetById(ls); fact != nil {
if err := fc.Remove(bson.M{"_id": ls}); err == nil {
ctx.ReplyN("I forgot that '%s' was '%s'.",
fact.Key, fact.Value)
} else {
ctx.ReplyN("I failed to forget '%s': %s", fact.Key, err)
}
} else {
ctx.ReplyN("Whatever that was, I've already forgotten it.")
}
}
示例13: 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)
}
}
示例14: 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)
}
}
}
示例15: cache
func cache(ctx *bot.Context) {
var u *urls.Url
if ctx.Text() == "" {
// assume we have been given "cache that"
if u = uc.GetById(lastseen[ctx.Target()]); u == nil {
ctx.ReplyN("I seem to have forgotten what to cache")
return
}
if u.CachedAs != "" {
ctx.ReplyN("That was already cached as %s%s%s at %s",
bot.HttpHost(), cachePath, u.CachedAs,
datetime.Format(u.CacheTime))
return
}
} else {
url := strings.TrimSpace(ctx.Text())
if idx := strings.Index(url, " "); idx != -1 {
url = url[:idx]
}
if !util.LooksURLish(url) {
ctx.ReplyN("'%s' doesn't look URLish", url)
return
}
if u = uc.GetByUrl(url); u == nil {
n, c := ctx.Storable()
u = urls.NewUrl(url, n, c)
} else if u.CachedAs != "" {
ctx.ReplyN("That was already cached as %s%s%s at %s",
bot.HttpHost(), cachePath, u.CachedAs,
datetime.Format(u.CacheTime))
return
}
}
if err := Cache(u); err != nil {
ctx.ReplyN("Failed to store cached url: %s", err)
return
}
ctx.ReplyN("%s cached as %s%s%s",
u.Url, bot.HttpHost(), cachePath, u.CachedAs)
}