Fix nil compiled time and lint

This commit is contained in:
kayos@tcp.direct 2021-10-09 08:50:48 -07:00
parent c46e976ff3
commit d32dd5e8a0
10 changed files with 115 additions and 108 deletions

@ -1,13 +1,13 @@
language: go language: go
go: go:
- 1.11.x - 1.11.x
- tip - tip
before_install: before_install:
- go get -v golang.org/x/lint/golint - go get -v golang.org/x/lint/golint
script: script:
- $HOME/gopath/bin/golint -min_confidence 0.9 -set_exit_status - $HOME/gopath/bin/golint -min_confidence 0.9 -set_exit_status
- GORACE="exitcode=1 halt_on_error=1" go test -v -coverprofile=coverage.txt -race -timeout 3m -count 3 -cpu 1,4 - GORACE="exitcode=1 halt_on_error=1" go test -v -coverprofile=coverage.txt -race -timeout 3m -count 3 -cpu 1,4
- go vet -v . - go vet -v .
after_success: after_success:
- bash <(curl -s https://codecov.io/bash) - bash <(curl -s https://codecov.io/bash)
branches: branches:

@ -2,31 +2,24 @@
## Issue submission ## Issue submission
* When submitting an issue or bug report, please ensure to provide as much * When submitting an issue or bug report, please ensure to provide as much information as possible, please ensure that
information as possible, please ensure that you are running on the latest you are running on the latest stable version (tagged), or when using master, provide the specific commit being used.
stable version (tagged), or when using master, provide the specific commit * Provide the minimum needed viable source to replicate the problem.
being used.
* Provide the minimum needed viable source to replicate the problem.
## Pull requests ## Pull requests
To review what is currently being worked on, or looked into, feel free to head To review what is currently being worked on, or looked into, feel free to head over to the [issues list](../../issues).
over to the [issues list](../../issues).
Below are a few guidelines if you would like to contribute. Keep the code Below are a few guidelines if you would like to contribute. Keep the code clean, standardized, and much of the quality
clean, standardized, and much of the quality should match Golang's standard should match Golang's standard library and common idioms.
library and common idioms.
* Always test using the latest Go version. * Always test using the latest Go version.
* Always use `gofmt` before committing anything. * Always use `gofmt` before committing anything.
* Always have proper documentation before committing. * Always have proper documentation before committing.
* Keep the same whitespacing, documentation, and newline format as the * Keep the same whitespacing, documentation, and newline format as the rest of the project.
rest of the project. * Only use 3rd party libraries if necessary. If only a small portion of the library is needed, simply rewrite it within
* Only use 3rd party libraries if necessary. If only a small portion of the library to prevent useless imports.
the library is needed, simply rewrite it within the library to prevent * Also see [golang/go/wiki/CodeReviewComments](https://github.com/golang/go/wiki/CodeReviewComments)
useless imports.
* Also see [golang/go/wiki/CodeReviewComments](https://github.com/golang/go/wiki/CodeReviewComments)
If you would like to assist, and the pull request is quite large and/or it has If you would like to assist, and the pull request is quite large and/or it has the potential of being a breaking change,
the potential of being a breaking change, please open an issue first so it can please open an issue first so it can be discussed.
be discussed.

@ -13,33 +13,40 @@
## Status ## Status
### ₜₕₑ ₛₖy ᵢₛ 𝆑ₐₗₗᵢₙg ʇɥǝ sʞʎ ᴉs ⅎɐʅʅᴉuƃ ### ₜₕₑ ₛₖy ᵢₛ 𝆑ₐₗₗᵢₙg ʇɥǝ sʞʎ ᴉs ⅎɐʅʅᴉuƃ
### 𝚝𝚑𝚎𝚢 𝚜𝚑𝚘𝚞𝚕𝚍 𝚑𝚊𝚟𝚎 𝚕𝚒𝚜𝚝𝚎𝚗𝚎𝚍 ### 𝚝𝚑𝚎𝚢 𝚜𝚑𝚘𝚞𝚕𝚍 𝚑𝚊𝚟𝚎 𝚕𝚒𝚜𝚝𝚎𝚗𝚎𝚍
### ʇɥǝ sʞʎ ᴉs ⅎɐʅʅᴉuƃ ₜₕₑ ₛₖy ᵢₛ 𝆑ₐₗₗᵢₙg ### ʇɥǝ sʞʎ ᴉs ⅎɐʅʅᴉuƃ ₜₕₑ ₛₖy ᵢₛ 𝆑ₐₗₗᵢₙg
~~girc is fairly close to marking the 1.0.0 endpoint, which will be tagged as necessary, so you will be able to use this
~~girc is fairly close to marking the 1.0.0 endpoint, which will be tagged as with care knowing the specific tag you're using won't have breaking changes~~
necessary, so you will be able to use this with care knowing the specific tag
you're using won't have breaking changes~~
## Features ## Features
- Focuses on ~~simplicity~~ ʀᴀɪɴɪɴɢ ʜᴇʟʟғɪʀᴇ, yet tries to still be flexible. - Focuses on ~~simplicity~~ ʀᴀɪɴɪɴɢ ʜᴇʟʟғɪʀᴇ, yet tries to still be flexible.
- Only requires [standard library packages](https://godoc.org/github.com/yunginnanet/girc-atomic?imports) - Only requires [standard library packages](https://godoc.org/github.com/yunginnanet/girc-atomic?imports)
- Event based triggering/responses ([example](https://godoc.org/github.com/yunginnanet/girc-atomic#ex-package--Commands), and [CTCP too](https://godoc.org/github.com/yunginnanet/girc-atomic#Commands.SendCTCP)!) - Event based triggering/responses ([example](https://godoc.org/github.com/yunginnanet/girc-atomic#ex-package--Commands)
, and [CTCP too](https://godoc.org/github.com/yunginnanet/girc-atomic#Commands.SendCTCP)!)
- [Documentation](https://godoc.org/github.com/yunginnanet/girc-atomic) is _mostly_ complete. - [Documentation](https://godoc.org/github.com/yunginnanet/girc-atomic) is _mostly_ complete.
- Support for almost all of the [IRCv3 spec](http://ircv3.net/software/libraries.html). - Support for almost all of the [IRCv3 spec](http://ircv3.net/software/libraries.html).
- SASL Auth (currently only `PLAIN` and `EXTERNAL` is support by default, - SASL Auth (currently only `PLAIN` and `EXTERNAL` is support by default, however you can simply
however you can simply implement `SASLMech` yourself to support additional implement `SASLMech` yourself to support additional mechanisms.)
mechanisms.)
- Message tags (things like `account-tag` on by default) - Message tags (things like `account-tag` on by default)
- `account-notify`, `away-notify`, `chghost`, `extended-join`, etc -- all handled seemlessly ([cap.go](https://github.com/yunginnanet/girc-atomic/blob/master/cap.go) for more info). - `account-notify`, `away-notify`, `chghost`, `extended-join`, etc -- all handled
- Channel and user tracking. Easily find what users are in a channel, if a seemlessly ([cap.go](https://github.com/yunginnanet/girc-atomic/blob/master/cap.go) for more info).
user is away, or if they are authenticated (if the server supports it!) - Channel and user tracking. Easily find what users are in a channel, if a user is away, or if they are authenticated (
- Client state/capability tracking. Easy methods to access capability data ([LookupChannel](https://godoc.org/github.com/yunginnanet/girc-atomic#Client.LookupChannel), [LookupUser](https://godoc.org/github.com/yunginnanet/girc-atomic#Client.LookupUser), [GetServerOption (ISUPPORT)](https://godoc.org/github.com/yunginnanet/girc-atomic#Client.GetServerOption), etc.) if the server supports it!)
- Client state/capability tracking. Easy methods to access capability
data ([LookupChannel](https://godoc.org/github.com/yunginnanet/girc-atomic#Client.LookupChannel)
, [LookupUser](https://godoc.org/github.com/yunginnanet/girc-atomic#Client.LookupUser)
, [GetServerOption (ISUPPORT)](https://godoc.org/github.com/yunginnanet/girc-atomic#Client.GetServerOption), etc.)
- Built-in support for things you would commonly have to implement yourself. - Built-in support for things you would commonly have to implement yourself.
- Nick collision detection and prevention (also see [Config.HandleNickCollide](https://godoc.org/github.com/yunginnanet/girc-atomic#Config).) - Nick collision detection and prevention (also
see [Config.HandleNickCollide](https://godoc.org/github.com/yunginnanet/girc-atomic#Config).)
- Event/message rate limiting. - Event/message rate limiting.
- Channel, nick, and user validation methods ([IsValidChannel](https://godoc.org/github.com/yunginnanet/girc-atomic#IsValidChannel), [IsValidNick](https://godoc.org/github.com/yunginnanet/girc-atomic#IsValidNick), etc.) - Channel, nick, and user validation
methods ([IsValidChannel](https://godoc.org/github.com/yunginnanet/girc-atomic#IsValidChannel)
, [IsValidNick](https://godoc.org/github.com/yunginnanet/girc-atomic#IsValidNick), etc.)
- CTCP handling and auto-responses ([CTCP](https://godoc.org/github.com/yunginnanet/girc-atomic#CTCP)) - CTCP handling and auto-responses ([CTCP](https://godoc.org/github.com/yunginnanet/girc-atomic#CTCP))
- ~~And more!~~ - ~~And more!~~
- GOTTA GO FAST YOU GOTTA GO REALLY FAST - GOTTA GO FAST YOU GOTTA GO REALLY FAST
@ -47,14 +54,14 @@ you're using won't have breaking changes~~
## Installing ## Installing
~~$ go get -u github.com/yunginnanet/girc-atomic~~ ~~$ go get -u github.com/yunginnanet/girc-atomic~~
just use go modules probably just use go modules probably
## Examples ## Examples
See [the examples](https://godoc.org/github.com/yunginnanet/girc-atomic#example-package--Bare) See [the examples](https://godoc.org/github.com/yunginnanet/girc-atomic#example-package--Bare)
within the documentation for real-world usecases. Here are a few real-world within the documentation for real-world usecases. Here are a few real-world usecases/examples/projects which utilize the
usecases/examples/projects which utilize the real girc: real girc:
| Project | Description | | Project | Description |
| --- | --- | | --- | --- |
@ -66,12 +73,11 @@ Working on a project and want to add it to the list? Submit a pull request!
## Contributing ## Contributing
~~Please review the [CONTRIBUTING](CONTRIBUTING.md) doc for submitting issues/a guide ~~Please review the [CONTRIBUTING](CONTRIBUTING.md) doc for submitting issues/a guide on submitting pull requests and
on submitting pull requests and helping out.~~ helping out.~~
**OH GOD PLEASE MAKE IT STOP** **OH GOD PLEASE MAKE IT STOP**
## License ## License
Copyright (c) 2016 Liam Stanley <me@liamstanley.io> Copyright (c) 2016 Liam Stanley <me@liamstanley.io>
@ -94,23 +100,26 @@ on submitting pull requests and helping out.~~
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. SOFTWARE.
girc artwork licensed under [CC 3.0](http://creativecommons.org/licenses/by/3.0/) based on Renee French under Creative Commons 3.0 Attributions... girc artwork licensed under [CC 3.0](http://creativecommons.org/licenses/by/3.0/) based on Renee French under Creative
Commons 3.0 Attributions...
or so I'm told. Then it was defiled by [some idiot](https://github.com/yunginnanet). or so I'm told. Then it was defiled by [some idiot](https://github.com/yunginnanet).
## References ## References
* [IRCv3: Specification Docs](http://ircv3.net/irc/) * [IRCv3: Specification Docs](http://ircv3.net/irc/)
* [IRCv3: Specification Repo](https://github.com/ircv3/ircv3-specifications) * [IRCv3: Specification Repo](https://github.com/ircv3/ircv3-specifications)
* [IRCv3 Capability Registry](http://ircv3.net/registry.html) * [IRCv3 Capability Registry](http://ircv3.net/registry.html)
* [IRCv3: WEBIRC](https://ircv3.net/specs/extensions/webirc.html) * [IRCv3: WEBIRC](https://ircv3.net/specs/extensions/webirc.html)
* [KiwiIRC: WEBIRC](https://kiwiirc.com/docs/webirc) * [KiwiIRC: WEBIRC](https://kiwiirc.com/docs/webirc)
* [ISUPPORT Specification Docs](http://www.irc.org/tech_docs/005.html) ([alternative 1](http://defs.ircdocs.horse/defs/isupport.html), [alternative 2](https://github.com/grawity/irc-docs/blob/master/client/RPL_ISUPPORT/draft-hardy-irc-isupport-00.txt), [relevant draft](http://www.irc.org/tech_docs/draft-brocklesby-irc-isupport-03.txt)) * [ISUPPORT Specification Docs](http://www.irc.org/tech_docs/005.html) ([alternative 1](http://defs.ircdocs.horse/defs/isupport.html)
* [IRC Numerics List](http://defs.ircdocs.horse/defs/numerics.html) , [alternative 2](https://github.com/grawity/irc-docs/blob/master/client/RPL_ISUPPORT/draft-hardy-irc-isupport-00.txt)
* [Extended WHO (also known as WHOX)](https://github.com/quakenet/snircd/blob/master/doc/readme.who) , [relevant draft](http://www.irc.org/tech_docs/draft-brocklesby-irc-isupport-03.txt))
* [RFC1459: Internet Relay Chat Protocol](https://tools.ietf.org/html/rfc1459) * [IRC Numerics List](http://defs.ircdocs.horse/defs/numerics.html)
* [RFC2812: Internet Relay Chat: Client Protocol](https://tools.ietf.org/html/rfc2812) * [Extended WHO (also known as WHOX)](https://github.com/quakenet/snircd/blob/master/doc/readme.who)
* [RFC2813: Internet Relay Chat: Server Protocol](https://tools.ietf.org/html/rfc2813) * [RFC1459: Internet Relay Chat Protocol](https://tools.ietf.org/html/rfc1459)
* [RFC7194: Default Port for Internet Relay Chat (IRC) via TLS/SSL](https://tools.ietf.org/html/rfc7194) * [RFC2812: Internet Relay Chat: Client Protocol](https://tools.ietf.org/html/rfc2812)
* [RFC4422: Simple Authentication and Security Layer](https://tools.ietf.org/html/rfc4422) ([SASL EXTERNAL](https://tools.ietf.org/html/rfc4422#appendix-A)) * [RFC2813: Internet Relay Chat: Server Protocol](https://tools.ietf.org/html/rfc2813)
* [RFC4616: The PLAIN SASL Mechanism](https://tools.ietf.org/html/rfc4616) * [RFC7194: Default Port for Internet Relay Chat (IRC) via TLS/SSL](https://tools.ietf.org/html/rfc7194)
* [RFC4422: Simple Authentication and Security Layer](https://tools.ietf.org/html/rfc4422) ([SASL EXTERNAL](https://tools.ietf.org/html/rfc4422#appendix-A))
* [RFC4616: The PLAIN SASL Mechanism](https://tools.ietf.org/html/rfc4616)

@ -417,6 +417,7 @@ func handleCREATED(c *Client, e Event) {
split := strings.Split(e.String(), "created ") split := strings.Split(e.String(), "created ")
compiled, err := dateparse.ParseAny(split[0]) compiled, err := dateparse.ParseAny(split[0])
if err != nil { if err != nil {
c.IRCd.Compiled = time.Unix(0, 0)
return return
} }
c.state.Lock() c.state.Lock()
@ -523,7 +524,7 @@ func handleNAMES(c *Client, e Event) {
continue continue
} }
var s *Source = new(Source) var s = new(Source)
// If userhost-in-names. // If userhost-in-names.
if strings.Contains(nick, "@") { if strings.Contains(nick, "@") {
@ -570,14 +571,13 @@ func updateLastActive(c *Client, e Event) {
} }
c.state.Lock() c.state.Lock()
defer c.state.Unlock()
// Update the users last active time, if they exist. // Update the users last active time, if they exist.
user := c.state.lookupUser(e.Source.Name) user := c.state.lookupUser(e.Source.Name)
if user == nil { if user == nil {
c.state.Unlock()
return return
} }
user.LastActive = time.Now() user.LastActive = time.Now()
c.state.Unlock()
} }

12
cap.go

@ -123,9 +123,9 @@ func handleCAP(c *Client, e Event) {
if len(e.Params) >= 2 && e.Params[1] == CAP_DEL { if len(e.Params) >= 2 && e.Params[1] == CAP_DEL {
caps := parseCap(e.Last()) caps := parseCap(e.Last())
for cap := range caps { for capab := range caps {
// TODO: test the deletion. // TODO: test the deletion.
delete(c.state.enabledCap, cap) delete(c.state.enabledCap, capab)
} }
return return
} }
@ -194,11 +194,11 @@ func handleCAP(c *Client, e Event) {
if len(e.Params) == 3 && e.Params[1] == CAP_ACK { if len(e.Params) == 3 && e.Params[1] == CAP_ACK {
enabled := strings.Split(e.Last(), " ") enabled := strings.Split(e.Last(), " ")
for _, cap := range enabled { for _, capab := range enabled {
if val, ok := c.state.tmpCap[cap]; ok { if val, ok := c.state.tmpCap[capab]; ok {
c.state.enabledCap[cap] = val c.state.enabledCap[capab] = val
} else { } else {
c.state.enabledCap[cap] = nil c.state.enabledCap[capab] = nil
} }
} }

@ -317,7 +317,7 @@ func New(config Config) *Client {
c.debug.Print("initializing debugging") c.debug.Print("initializing debugging")
} }
envDisableSTS, _ := strconv.ParseBool((os.Getenv("GIRC_DISABLE_STS"))) envDisableSTS, _ := strconv.ParseBool(os.Getenv("GIRC_DISABLE_STS"))
if envDisableSTS { if envDisableSTS {
c.Config.DisableSTS = envDisableSTS c.Config.DisableSTS = envDisableSTS
} }

@ -146,12 +146,17 @@ func (cmd *Commands) ReplyKick(event Event, reason string) {
} }
} }
// ReplyBan kicks the source of the event from the channel where the event originated // ReplyBan kicks the source of the event from the channel where the event originated.
// Additionally, if a reason is provided, it will send a message to the channel.
func (cmd *Commands) ReplyBan(event Event, reason string) { func (cmd *Commands) ReplyBan(event Event, reason string) {
if event.Source == nil { if event.Source == nil {
panic(ErrInvalidSource) panic(ErrInvalidSource)
} }
if reason != "" {
cmd.Replyf(event, "{red}{b}[BAN] {r}%s", reason)
}
if len(event.Params) > 0 && IsValidChannel(event.Params[0]) { if len(event.Params) > 0 && IsValidChannel(event.Params[0]) {
cmd.Ban(event.Params[0], event.Source.Name) cmd.Ban(event.Params[0], event.Source.Name)
} }
@ -378,7 +383,7 @@ func (cmd *Commands) List(channels ...string) {
// Whowas sends a WHOWAS query to the server. amount is the amount of results // Whowas sends a WHOWAS query to the server. amount is the amount of results
// you want back. // you want back.
func (cmd *Commands) Whowas(user string, amount int) { func (cmd *Commands) Whowas(user string, amount int) {
cmd.c.Send(&Event{Command: WHOWAS, Params: []string{user, string(fmt.Sprintf("%d", amount))}}) cmd.c.Send(&Event{Command: WHOWAS, Params: []string{user, fmt.Sprintf("%d", amount)}})
} }
// Monitor sends a MONITOR query to the server. The results of the query // Monitor sends a MONITOR query to the server. The results of the query

@ -196,7 +196,7 @@ func (c *CTCP) Set(cmd string, handler func(client *Client, ctcp CTCPEvent)) {
c.mu.Lock() c.mu.Lock()
defer c.mu.Unlock() defer c.mu.Unlock()
c.handlers[cmd] = CTCPHandler(handler) c.handlers[cmd] = handler
} }
// SetBg is much like Set, however the handler is executed in the background, // SetBg is much like Set, however the handler is executed in the background,

@ -157,7 +157,7 @@ func (c *CModes) hasArg(set bool, mode byte) (hasArgs, isSetting bool) {
// For example, the latter would mean applying an incoming MODE with the modes // For example, the latter would mean applying an incoming MODE with the modes
// stored for a channel. // stored for a channel.
func (c *CModes) Apply(modes []CMode) { func (c *CModes) Apply(modes []CMode) {
var new []CMode var newcm []CMode
for j := 0; j < len(c.modes); j++ { for j := 0; j < len(c.modes); j++ {
isin := false isin := false
@ -166,14 +166,14 @@ func (c *CModes) Apply(modes []CMode) {
continue continue
} }
if c.modes[j].name == modes[i].name && modes[i].add { if c.modes[j].name == modes[i].name && modes[i].add {
new = append(new, modes[i]) newcm = append(newcm, modes[i])
isin = true isin = true
break break
} }
} }
if !isin { if !isin {
new = append(new, c.modes[j]) newcm = append(newcm, c.modes[j])
} }
} }
@ -183,19 +183,19 @@ func (c *CModes) Apply(modes []CMode) {
} }
isin := false isin := false
for j := 0; j < len(new); j++ { for j := 0; j < len(newcm); j++ {
if modes[i].name == new[j].name { if modes[i].name == newcm[j].name {
isin = true isin = true
break break
} }
} }
if !isin { if !isin {
new = append(new, modes[i]) newcm = append(newcm, modes[i])
} }
} }
c.modes = new c.modes = newcm
} }
// Parse parses a set of flags and args, returning the necessary list of // Parse parses a set of flags and args, returning the necessary list of

@ -123,7 +123,7 @@ func (u User) Channels(c *Client) []*Channel {
panic("nil Client provided") panic("nil Client provided")
} }
channels := []*Channel{} var channels []*Channel
c.state.RLock() c.state.RLock()
for i := 0; i < len(u.ChannelList); i++ { for i := 0; i < len(u.ChannelList); i++ {
@ -237,7 +237,7 @@ func (ch Channel) Users(c *Client) []*User {
panic("nil Client provided") panic("nil Client provided")
} }
users := []*User{} var users []*User
c.state.RLock() c.state.RLock()
for i := 0; i < len(ch.UserList); i++ { for i := 0; i < len(ch.UserList); i++ {
@ -258,7 +258,7 @@ func (ch Channel) Trusted(c *Client) []*User {
panic("nil Client provided") panic("nil Client provided")
} }
users := []*User{} var users []*User
c.state.RLock() c.state.RLock()
for i := 0; i < len(ch.UserList); i++ { for i := 0; i < len(ch.UserList); i++ {
@ -285,7 +285,7 @@ func (ch Channel) Admins(c *Client) []*User {
panic("nil Client provided") panic("nil Client provided")
} }
users := []*User{} var users []*User
c.state.RLock() c.state.RLock()
for i := 0; i < len(ch.UserList); i++ { for i := 0; i < len(ch.UserList); i++ {