kunt

golang IRC bot
git clone git://git.2f30.org/kunt.git
Log | Files | Refs | LICENSE

commit 9bc41991a84d7e5c9a0c3421504fad1db5cfdc32
parent 5f412947b403596f892cab799d2ff08cde35e2db
Author: sin <sin@2f30.org>
Date:   Thu May  2 12:14:23 +0100

rename irc functions

Diffstat:
src/games/games.go | 28++++++++++++++--------------
src/irc/irc.go | 6+++---
src/irc/message.go | 8++++----
src/kunt/kunt.go | 52++++++++++++++++++++++++++--------------------------
4 files changed, 47 insertions(+), 47 deletions(-)
diff --git a/src/games/games.go b/src/games/games.go @@ -63,14 +63,14 @@ func hangmanInit(cs *hangmanState) { //Second hangman state. It waits on a private query for the goal and then emits the next state (hangmanMainLoop) //to the state channel func hangmanWaitGoal(cs *hangmanState) { - cs.ictx.SendPrivmsg(cs.channame, "Hangman is waiting for goal. When ready use hangman <letter|possibleword>") + cs.ictx.Privmsg(cs.channame, "Hangman is waiting for goal. When ready use hangman <letter|possibleword>") for msg := range *cs.gchan { msg.Params[1] = strings.TrimSpace(msg.Params[1]) if msg.Params[0] == cs.botname { if strings.HasPrefix(msg.Params[1], ":setgoal ") { cs.goal = msg.Params[1][9:] who := msg.Prefix[:strings.Index(msg.Prefix, "!")] - cs.ictx.SendPrivmsg(who, "Goal is now set to: "+cs.goal) + cs.ictx.Privmsg(who, "Goal is now set to: "+cs.goal) runes := make([]rune, len(cs.goal)) for i := 0; i < len(runes); i++ { runes[i] = '_' @@ -79,11 +79,11 @@ func hangmanWaitGoal(cs *hangmanState) { break } else { who := msg.Prefix[:strings.Index(msg.Prefix, "!")] - cs.ictx.SendPrivmsg(who, "Now we are playing hangman. Use setgoal <WORD>") + cs.ictx.Privmsg(who, "Now we are playing hangman. Use setgoal <WORD>") } } else { if strings.HasPrefix(msg.Params[1], ":hangman ") { - cs.ictx.SendPrivmsg(msg.Params[0], "Still waiting for goal...") + cs.ictx.Privmsg(msg.Params[0], "Still waiting for goal...") } } } @@ -97,39 +97,39 @@ func hangmanWaitGoal(cs *hangmanState) { //and reprints the game state. At each loop if foundNow matches the goal the game is won. //Then it emits the final state (hangmanEnd) to the state channel func hangmanMainLoop(cs *hangmanState) { - cs.ictx.SendPrivmsg(cs.channame, cs.String()) + cs.ictx.Privmsg(cs.channame, cs.String()) for msg := range *cs.gchan { msg.Params[1] = strings.TrimSpace(msg.Params[1]) if msg.Params[0] != cs.botname { if cs.lives < 1 { - cs.ictx.SendPrivmsg(msg.Params[0], "You are hanged! Goal was ->"+cs.goal) + cs.ictx.Privmsg(msg.Params[0], "You are hanged! Goal was ->"+cs.goal) *cs.statchan <- hangmanEnd } if strings.HasPrefix(msg.Params[1], ":hangman ") { in := msg.Params[1][9:] if len(in) > 1 { if in == cs.goal { - cs.ictx.SendPrivmsg(msg.Params[0], "You won!") + cs.ictx.Privmsg(msg.Params[0], "You won!") *cs.statchan <- hangmanEnd } else { - cs.ictx.SendPrivmsg(msg.Params[0], "You lost a life punk...") + cs.ictx.Privmsg(msg.Params[0], "You lost a life punk...") cs.lives -= 1 - cs.ictx.SendPrivmsg(msg.Params[0], cs.String()) + cs.ictx.Privmsg(msg.Params[0], cs.String()) continue } } else { if strings.Index(cs.tried, string(in[0])) != -1 { - cs.ictx.SendPrivmsg(msg.Params[0], "I heard you the first time") + cs.ictx.Privmsg(msg.Params[0], "I heard you the first time") continue } hm := cs.checkLetter([]rune(in)[0]) - cs.ictx.SendPrivmsg(msg.Params[0], fmt.Sprintf("You got %d letters", hm)) + cs.ictx.Privmsg(msg.Params[0], fmt.Sprintf("You got %d letters", hm)) if hm == 0 { cs.lives -= 1 } - cs.ictx.SendPrivmsg(msg.Params[0], cs.String()) + cs.ictx.Privmsg(msg.Params[0], cs.String()) if cs.foundnow == cs.goal { - cs.ictx.SendPrivmsg(msg.Params[0], "You won!") + cs.ictx.Privmsg(msg.Params[0], "You won!") *cs.statchan <- hangmanEnd } } @@ -166,7 +166,7 @@ func cmdHangman(a *irc.IrcContext, gc *chan irc.IrcMessage) { for { select { case <-timeout: - a.SendPrivmsg(hc.channame, "Time is up! Goal was -> "+hc.goal) + a.Privmsg(hc.channame, "Time is up! Goal was -> "+hc.goal) a.DelIntercept(gc) close(stchan) return diff --git a/src/irc/irc.go b/src/irc/irc.go @@ -106,7 +106,7 @@ func (i *IrcContext) AddChannel(s string) int { func (i *IrcContext) JoinChannels() { for c := 0; c < i.network.channum; c++ { if !i.network.channels[c].joined { - i.SendJoin(i.network.channels[c].name) + i.Join(i.network.channels[c].name) i.network.channels[c].joined = true } } @@ -139,8 +139,8 @@ func (i *IrcContext) Connect() error { go i.outgoingMsgLoop() go i.rxLoop() - i.SendNick() - i.SendUser() + i.Nick() + i.User() return nil } diff --git a/src/irc/message.go b/src/irc/message.go @@ -7,7 +7,7 @@ type IrcMessage struct { } // Send the nickname -func (i *IrcContext) SendNick() { +func (i *IrcContext) Nick() { msg := IrcMessage{ Prefix: "", Cmd: "NICK", @@ -17,7 +17,7 @@ func (i *IrcContext) SendNick() { } // Send the username -func (i *IrcContext) SendUser() { +func (i *IrcContext) User() { msg := IrcMessage{ Prefix: "", Cmd: "USER", @@ -31,7 +31,7 @@ func (i *IrcContext) SendUser() { } // Join a channel -func (i *IrcContext) SendJoin(channel string) { +func (i *IrcContext) Join(channel string) { msg := IrcMessage{ Prefix: "", Cmd: "JOIN", @@ -41,7 +41,7 @@ func (i *IrcContext) SendJoin(channel string) { } // Send a PRIVMSG -func (i *IrcContext) SendPrivmsg(channel string, text string) { +func (i *IrcContext) Privmsg(channel string, text string) { msg := IrcMessage{ Prefix: "", Cmd: "PRIVMSG", diff --git a/src/kunt/kunt.go b/src/kunt/kunt.go @@ -51,7 +51,7 @@ func cmdKunt(msg irc.IrcMessage) { "no fucking way", } idx := rand.Intn(len(actions)) - kunt.ircCtx.SendPrivmsg(msg.Params[0], string(actions[idx])) + kunt.ircCtx.Privmsg(msg.Params[0], string(actions[idx])) } func cmdWisdom(msg irc.IrcMessage) { @@ -64,7 +64,7 @@ func cmdWisdom(msg irc.IrcMessage) { if i == "" { continue } - kunt.ircCtx.SendPrivmsg(msg.Params[0], i) + kunt.ircCtx.Privmsg(msg.Params[0], i) time.Sleep(512 * time.Millisecond) } } @@ -86,19 +86,19 @@ func cmdHelp(msg irc.IrcMessage) { "!version -> Show version", } for _, i := range help { - kunt.ircCtx.SendPrivmsg(msg.Params[0], i) + kunt.ircCtx.Privmsg(msg.Params[0], i) time.Sleep(512 * time.Millisecond) } } func cmdVersion(msg irc.IrcMessage) { ver := "v0.2.8" - kunt.ircCtx.SendPrivmsg(msg.Params[0], ver) + kunt.ircCtx.Privmsg(msg.Params[0], ver) } func cmdRandQuote(msg irc.IrcMessage) { if quoteDb.Empty() { - kunt.ircCtx.SendPrivmsg(msg.Params[0], "Empty quote database") + kunt.ircCtx.Privmsg(msg.Params[0], "Empty quote database") return } quote, idx := quoteDb.Rand() @@ -106,14 +106,14 @@ func cmdRandQuote(msg irc.IrcMessage) { // Print idx in red text := fmt.Sprintf("%s%02d[%d]%s %s", "\003", '5', idx, "\003", string(quote)) - kunt.ircCtx.SendPrivmsg(msg.Params[0], text) + kunt.ircCtx.Privmsg(msg.Params[0], text) } func cmdAddQuote(msg irc.IrcMessage) { s := msg.Params[1] hm := strings.Fields(s) if len(hm) < 2 { - kunt.ircCtx.SendPrivmsg(msg.Params[0], "Missing parameter for !addquote") + kunt.ircCtx.Privmsg(msg.Params[0], "Missing parameter for !addquote") return } s = s[11:] @@ -121,13 +121,13 @@ func cmdAddQuote(msg irc.IrcMessage) { s += "\n" buf := []byte(s) if quoteDb.CountMatches(buf) > 0 { - kunt.ircCtx.SendPrivmsg(msg.Params[0], + kunt.ircCtx.Privmsg(msg.Params[0], fmt.Errorf("Duplicate entry: %s", buf).Error()) return } _, err := quoteDb.Append(buf) if err != nil { - kunt.ircCtx.SendPrivmsg(msg.Params[0], err.Error()) + kunt.ircCtx.Privmsg(msg.Params[0], err.Error()) return } err = quoteDb.Sync() @@ -138,12 +138,12 @@ func cmdAddQuote(msg irc.IrcMessage) { func cmdCountQuotes(msg irc.IrcMessage) { text := fmt.Sprintf("The quote DB has %d quotes", quoteDb.Size()) - kunt.ircCtx.SendPrivmsg(msg.Params[0], text) + kunt.ircCtx.Privmsg(msg.Params[0], text) } func cmdRandUrl(msg irc.IrcMessage) { if urlDb.Empty() { - kunt.ircCtx.SendPrivmsg(msg.Params[0], "Empty url database") + kunt.ircCtx.Privmsg(msg.Params[0], "Empty url database") return } url, idx := urlDb.Rand() @@ -151,11 +151,11 @@ func cmdRandUrl(msg irc.IrcMessage) { // Print idx in red r := fmt.Sprintf("%s%02d[%d]%s %s", "\003", '5', idx, "\003", string(url)) - kunt.ircCtx.SendPrivmsg(msg.Params[0], r) + kunt.ircCtx.Privmsg(msg.Params[0], r) title, ok := resolveYoutubeTitle(string(url)) if ok { r = fmt.Sprintf("[YouTube] %s", title) - kunt.ircCtx.SendPrivmsg(msg.Params[0], r) + kunt.ircCtx.Privmsg(msg.Params[0], r) } } @@ -163,7 +163,7 @@ func cmdAddUrl(msg irc.IrcMessage) { s := msg.Params[1] as := strings.Fields(s) if len(as) < 2 { - kunt.ircCtx.SendPrivmsg(msg.Params[0], "Missing parameter for !addurl") + kunt.ircCtx.Privmsg(msg.Params[0], "Missing parameter for !addurl") return } s = s[9:] @@ -171,13 +171,13 @@ func cmdAddUrl(msg irc.IrcMessage) { s += "\n" buf := []byte(s) if urlDb.CountMatches(buf) > 0 { - kunt.ircCtx.SendPrivmsg(msg.Params[0], + kunt.ircCtx.Privmsg(msg.Params[0], fmt.Errorf("Duplicate entry: %s", buf).Error()) return } _, err := urlDb.Append(buf) if err != nil { - kunt.ircCtx.SendPrivmsg(msg.Params[0], err.Error()) + kunt.ircCtx.Privmsg(msg.Params[0], err.Error()) return } err = urlDb.Sync() @@ -188,38 +188,38 @@ func cmdAddUrl(msg irc.IrcMessage) { func cmdCountUrls(msg irc.IrcMessage) { r := fmt.Sprintf("The url DB has %d urls", urlDb.Size()) - kunt.ircCtx.SendPrivmsg(msg.Params[0], r) + kunt.ircCtx.Privmsg(msg.Params[0], r) } func cmdRadio(msg irc.IrcMessage) { np, e := http.Get("http://radio.2f30.org:8000/npsong.xsl") if e != nil { - kunt.ircCtx.SendPrivmsg(msg.Params[0], "Is radio broken?") + kunt.ircCtx.Privmsg(msg.Params[0], "Is radio broken?") } else { defer np.Body.Close() song, _ := ioutil.ReadAll(np.Body) r := fmt.Sprintf("[Radio] %s", song) - kunt.ircCtx.SendPrivmsg(msg.Params[0], r) + kunt.ircCtx.Privmsg(msg.Params[0], r) r = "[Radio] http://radio.2f30.org:8000/live.ogg" - kunt.ircCtx.SendPrivmsg(msg.Params[0], r) + kunt.ircCtx.Privmsg(msg.Params[0], r) } } func cmdUptime(msg irc.IrcMessage) { etime := time.Now() r := fmt.Sprintf("%v", etime.Sub(kunt.stime)) - kunt.ircCtx.SendPrivmsg(msg.Params[0], r) + kunt.ircCtx.Privmsg(msg.Params[0], r) } func cmdSrc(msg irc.IrcMessage) { src := "http://amnezia.2f30.org/tmp/kunt-latest.tgz" - kunt.ircCtx.SendPrivmsg(msg.Params[0], src) + kunt.ircCtx.Privmsg(msg.Params[0], src) } func cmdTodo(msg irc.IrcMessage) { todo, err := ioutil.ReadFile("TODO") if err != nil { - kunt.ircCtx.SendPrivmsg(msg.Params[0], "No TODO list available") + kunt.ircCtx.Privmsg(msg.Params[0], "No TODO list available") return } sf := strings.FieldsFunc(string(todo), func(r rune) bool { @@ -230,7 +230,7 @@ func cmdTodo(msg irc.IrcMessage) { return false }) for _, v := range sf { - kunt.ircCtx.SendPrivmsg(msg.Params[0], v) + kunt.ircCtx.Privmsg(msg.Params[0], v) time.Sleep(512 * time.Millisecond) } } @@ -239,7 +239,7 @@ func cmdGame(msg irc.IrcMessage) { s := msg.Params[1] as := strings.Fields(s) if len(as) < 2 { - kunt.ircCtx.SendPrivmsg(msg.Params[0], "Missing parameter for !game") + kunt.ircCtx.Privmsg(msg.Params[0], "Missing parameter for !game") return } s = s[6:] @@ -247,7 +247,7 @@ func cmdGame(msg irc.IrcMessage) { switch s { case "list": for _, str := range geng.List() { - kunt.ircCtx.SendPrivmsg(msg.Params[0], "[game] "+str) + kunt.ircCtx.Privmsg(msg.Params[0], "[game] "+str) } return }