New: handle RPL_CREATIONTIME

This commit is contained in:
kayos@tcp.direct 2021-11-26 00:53:20 -08:00
parent 1eacc3e108
commit 5ea3252b9b
5 changed files with 41 additions and 2 deletions

@ -51,6 +51,9 @@ func (c *Client) registerBuiltins() {
c.Handlers.register(true, false, MODE, HandlerFunc(handleMODE)) c.Handlers.register(true, false, MODE, HandlerFunc(handleMODE))
c.Handlers.register(true, false, RPL_CHANNELMODEIS, HandlerFunc(handleMODE)) c.Handlers.register(true, false, RPL_CHANNELMODEIS, HandlerFunc(handleMODE))
// Channel creation time.
c.Handlers.register(true, false, RPL_CREATIONTIME, HandlerFunc(handleCREATIONTIME))
// WHO/WHOX responses. // WHO/WHOX responses.
c.Handlers.register(true, false, RPL_WHOREPLY, HandlerFunc(handleWHO)) c.Handlers.register(true, false, RPL_WHOREPLY, HandlerFunc(handleWHO))
c.Handlers.register(true, false, RPL_WHOSPCRPL, HandlerFunc(handleWHO)) c.Handlers.register(true, false, RPL_WHOSPCRPL, HandlerFunc(handleWHO))
@ -230,6 +233,32 @@ func handlePART(c *Client, e Event) {
c.state.Unlock() c.state.Unlock()
} }
// handleCREATIONTIME handles incoming TOPIC events and keeps channel tracking info
// updated with the latest channel topic.
func handleCREATIONTIME(c *Client, e Event) {
var created string
var name string
switch len(e.Params) {
case 0, 1, 2:
return
default:
name = e.Params[1]
created = e.Params[2]
break
}
c.state.Lock()
defer c.state.Unlock()
channel := c.state.lookupChannel(name)
if channel == nil {
return
}
channel.Created = created
c.state.notify(c, UPDATE_STATE)
}
// handleTOPIC handles incoming TOPIC events and keeps channel tracking info // handleTOPIC handles incoming TOPIC events and keeps channel tracking info
// updated with the latest channel topic. // updated with the latest channel topic.
func handleTOPIC(c *Client, e Event) { func handleTOPIC(c *Client, e Event) {

@ -5,12 +5,17 @@ IRCNumToStr takes in a numeric IRC code and returns the relevant girc name.
IRCNumToStr accepts a string because that's how we tend to receive the codes. IRCNumToStr accepts a string because that's how we tend to receive the codes.
*/ */
func IRCNumToStr(code string) string { func IRCNumToStr(code string) string {
if _, ok := noTranslate[code]; ok {
return code
}
if result, ok := IRCCodes[code]; ok { if result, ok := IRCCodes[code]; ok {
return result return result
} }
return "" return ""
} }
var noTranslate = map[string]uint8{"JOIN":1, "INVITE":1, "NOTICE":1, "CAP":1, "MODE":1,"QUIT":1, "PRIVMSG":1}
// IRCCodes is just a map form of our constants for quick lookup purposes. // IRCCodes is just a map form of our constants for quick lookup purposes.
var IRCCodes = map[string]string { var IRCCodes = map[string]string {
"001":"RPL_WELCOME", "001":"RPL_WELCOME",
@ -36,6 +41,7 @@ var IRCCodes = map[string]string {
"323":"RPL_LISTEND", "323":"RPL_LISTEND",
"325":"RPL_UNIQOPIS", "325":"RPL_UNIQOPIS",
"324":"RPL_CHANNELMODEIS", "324":"RPL_CHANNELMODEIS",
"329":"RPL_CREATIONTIME",
"331":"RPL_NOTOPIC", "331":"RPL_NOTOPIC",
"332":"RPL_TOPIC", "332":"RPL_TOPIC",
"341":"RPL_INVITING", "341":"RPL_INVITING",

@ -152,6 +152,7 @@ const (
RPL_LISTEND = "323" RPL_LISTEND = "323"
RPL_UNIQOPIS = "325" RPL_UNIQOPIS = "325"
RPL_CHANNELMODEIS = "324" RPL_CHANNELMODEIS = "324"
RPL_CREATIONTIME = "329"
RPL_NOTOPIC = "331" RPL_NOTOPIC = "331"
RPL_TOPIC = "332" RPL_TOPIC = "332"
RPL_INVITING = "341" RPL_INVITING = "341"

@ -225,7 +225,10 @@ type Channel struct {
Name string `json:"name"` Name string `json:"name"`
// Topic of the channel. // Topic of the channel.
Topic string `json:"topic"` Topic string `json:"topic"`
// Created is the time/date the channel was created (if available).
// Created time.Time `json:"created"`
// TODO: Figure out if these are all unix timestamps, if so, convert it to time.Time
Created string `json:"created"`
// UserList is a sorted list of all users we are currently tracking within // UserList is a sorted list of all users we are currently tracking within
// the channel. Each is the nickname, and is rfc1459 compliant. // the channel. Each is the nickname, and is rfc1459 compliant.
UserList []string `json:"user_list"` UserList []string `json:"user_list"`

@ -7,5 +7,5 @@ import (
func randSleep() { func randSleep() {
rand.Seed(time.Now().UnixNano()) rand.Seed(time.Now().UnixNano())
time.Sleep(time.Duration(rand.Intn(25)) * time.Millisecond) time.Sleep(time.Duration(rand.Intn(5)) * time.Millisecond)
} }