Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add golangci lint #89

Merged
merged 8 commits into from
Aug 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: golangci-lint
on:
push:
tags:
- v*
branches:
- master
- main
pull_request:
permissions:
contents: read
# Optional: allow read access to pull request. Use with `only-new-issues` option.
# pull-requests: read
jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v3
with:
go-version: 1.17
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: v1.48.0
args: --timeout 3m

# Optional: working directory, useful for monorepos
# working-directory: somedir

# Optional: golangci-lint command line arguments.
# args: --issues-exit-code=0

# Optional: show only new issues if it's a pull request. The default value is `false`.
# only-new-issues: true

# Optional: if set to true then the all caching functionality will be complete disabled,
# takes precedence over all other caching options.
# skip-cache: true

# Optional: if set to true then the action don't cache or restore ~/go/pkg.
# skip-pkg-cache: true

# Optional: if set to true then the action don't cache or restore ~/.cache/go-build.
# skip-build-cache: true
16 changes: 11 additions & 5 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,12 @@ func main() {
dgSess.AddHandler(joinVc.VoiceStateUpdateHandler)
// dgSess.Debug = true
gTalker, closer := grpc.NewTalker(&conf.auth.CeviordConn, &conf.param.Parameters[0])
defer closer()
defer func() {
err = closer()
if err != nil {
panic(err)
}
}()
ceviord.SetNewTalker(gTalker)

var db *sql.DB
Expand Down Expand Up @@ -118,7 +123,10 @@ func main() {
slashCmds, err := slashCmd.NewCmds(dgSess, "", sg.Generate())
defer func() {
if slashCmds != nil {
slashCmds.DeleteCmds(dgSess, "")
err = slashCmds.DeleteCmds(dgSess, "")
if err != nil {
panic(err)
}
}
}()
if err != nil {
Expand All @@ -128,8 +136,6 @@ func main() {

// Wait here until CTRL-C or other term signal is received.
sc := make(chan os.Signal, 1)
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt, os.Kill)
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
<-sc

return
}
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ require (
github.com/k0kubun/pp v3.0.1+incompatible
github.com/mattn/go-sqlite3 v1.14.14
github.com/vrischmann/envconfig v1.3.0
golang.org/x/tools v0.1.12
google.golang.org/grpc v1.48.0
google.golang.org/protobuf v1.28.1
gopkg.in/yaml.v2 v2.4.0
Expand All @@ -21,7 +20,7 @@ require (
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/k0kubun/pp/v3 v3.1.0 // indirect
github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88 // indirect
github.com/lib/pq v1.10.4 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
Expand Down
18 changes: 2 additions & 16 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88 h1:uC1QfSlInpQF+M0ao65imhwqKnz3Q2z/d8PWZRMQvDM=
github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88/go.mod h1:3w7q1U84EfirKl04SVQ/s7nPm1ZPhiXd34z40TNz36k=
github.com/k0kubun/pp v3.0.1+incompatible h1:3tqvf7QgUnZ5tXO6pNAZlrvHgl6DvifjDrd9g2S9Z40=
github.com/k0kubun/pp v3.0.1+incompatible/go.mod h1:GWse8YhT0p8pT4ir3ZgBbfZild3tgzSScAn6HmfYukg=
github.com/k0kubun/pp/v3 v3.1.0 h1:ifxtqJkRZhw3h554/z/8zm6AAbyO4LLKDlA5eV+9O8Q=
github.com/k0kubun/pp/v3 v3.1.0/go.mod h1:vIrP5CF0n78pKHm2Ku6GVerpZBJvscg48WepUYEk2gw=
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
Expand All @@ -119,8 +119,6 @@ github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hd
github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE=
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/mattn/go-sqlite3 v1.14.13 h1:1tj15ngiFfcZzii7yd82foL+ks+ouQcj8j/TPq3fk1I=
github.com/mattn/go-sqlite3 v1.14.13/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
github.com/mattn/go-sqlite3 v1.14.14 h1:qZgc/Rwetq+MtyE18WhzjokPD93dNqLGNT3QJuLvBGw=
github.com/mattn/go-sqlite3 v1.14.14/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
Expand Down Expand Up @@ -209,8 +207,6 @@ golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81R
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/net v0.0.0-20220513224357-95641704303c h1:nF9mHSvoKBLkQNQhJZNsc66z2UzAMUbLGjC95CF3pU0=
golang.org/x/net v0.0.0-20220513224357-95641704303c/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b h1:PxfKdU9lEEDYjdIzOtC4qFWgkU2rGHdKlKowJSMN9h0=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
Expand All @@ -237,8 +233,6 @@ golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220513210249-45d2b4557a2a h1:N2T1jUrTQE9Re6TFF5PhvEHXHCguynGhKjWVsIUt5cY=
golang.org/x/sys v0.0.0-20220513210249-45d2b4557a2a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f h1:v4INt8xihDGvnrfjMDVXGxw9wrfxYyCjk0KbXjhR55s=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
Expand All @@ -255,10 +249,7 @@ golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200313205530-4303120df7d8 h1:gkI/wGGwpcG5W4hLCzZNGxA4wzWBGGDStRI1MrjDl2Q=
golang.org/x/tools v0.0.0-20200313205530-4303120df7d8/go.mod h1:Sl4aGygMT6LrqrWclx+PTx3U+LnKx/seiNR+3G19Ar8=
golang.org/x/tools v0.1.11/go.mod h1:SgwaegtQh8clINPpECJMqnxLv9I09HLqnW3RMqW0CA4=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand All @@ -280,10 +271,6 @@ google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8
google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0=
google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU=
google.golang.org/grpc v1.46.0/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk=
google.golang.org/grpc v1.46.2 h1:u+MLGgVf7vRdjEYZ8wDFhAVNmhkbJ5hmrA1LMWK1CAQ=
google.golang.org/grpc v1.46.2/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk=
google.golang.org/grpc v1.47.0 h1:9n77onPX5F3qfFCqjy9dhn8PbNQsIKeVU04J9G7umt8=
google.golang.org/grpc v1.47.0/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk=
google.golang.org/grpc v1.48.0 h1:rQOsyJ/8+ufEDJd/Gdsz7HG220Mh9HAhFHRGnIjda0w=
google.golang.org/grpc v1.48.0/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
Expand All @@ -298,7 +285,6 @@ google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlba
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw=
google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w=
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
Expand Down
15 changes: 13 additions & 2 deletions pkg/ceviord/handleMsg.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ceviord
import (
"crypto/rand"
"fmt"
"log"
"os"
"path/filepath"
"regexp"
Expand Down Expand Up @@ -36,7 +37,6 @@ func (c Channel) IsActorJoined(sess *discordgo.Session) (bool, error) {
}

type Channels map[string]*Channel

func (cs Channels) AddChannel(c Channel, guildId string) {
if _, ok := cs[guildId]; !ok {
c.CurrentParam = &Cache.Param.Parameters[0]
Expand Down Expand Up @@ -194,6 +194,8 @@ func MessageCreate(sess *discordgo.Session, msg *discordgo.MessageCreate) {
cev, err := Cache.Channels.GetChannel(msg.GuildID)
if err != nil || cev == nil {
//todo; チャンネルに入っていないときの挙動を定義
log.Println(err)
return
}
isJoined := false
if cev != nil {
Expand Down Expand Up @@ -244,7 +246,10 @@ func RawSpeak(text string, guildId string, sess *discordgo.Session) error {
if err != nil || !isJoined {
return err
}
Cache.cevioWav.ApplyEmotions(cev.CurrentParam)
err = Cache.cevioWav.ApplyEmotions(cev.CurrentParam)
if err != nil {
return err
}
Cache.mutex.Lock()
defer Cache.mutex.Unlock()
buf := make([]byte, 16)
Expand All @@ -269,6 +274,9 @@ func RawSpeak(text string, guildId string, sess *discordgo.Session) error {

func SendMsg(msg string, session *discordgo.Session, guildId string) error {
cev, err := Cache.Channels.GetChannel(guildId)
if err != nil {
return err
}
isJoined, err := cev.IsActorJoined(session)
if err != nil || !isJoined {
return err
Expand Down Expand Up @@ -318,6 +326,9 @@ func GetMsg(m *discordgo.MessageCreate, s *discordgo.Session) string {
msg := []rune(name + "。" + replace.ApplySysDict(cont))

cev, err := Cache.Channels.GetChannel(m.GuildID)
if err != nil {
return ""
}
cev.DictController.SetGuildId(m.GuildID)
rawMsg, err := cev.DictController.ApplyUserDict(string(msg))
if err != nil {
Expand Down
5 changes: 4 additions & 1 deletion pkg/ceviord/userCmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,16 @@ func (*byeOld) handle(sess *discordgo.Session, m *discordgo.MessageCreate) error
return fmt.Errorf("connection not found")
}
isJoin, err := cev.IsActorJoined(sess)
if err != nil {
return err
}
if !isJoin || cev.VoiceConn == nil {
return fmt.Errorf("ceviord is already disconnected\n")
}
defer func() {
if cev.VoiceConn != nil {
cev.VoiceConn.Close()
Cache.Channels.DeleteChannel(m.GuildID)
err = Cache.Channels.DeleteChannel(m.GuildID)
}
}()
err = cev.VoiceConn.Speaking(false)
Expand Down
14 changes: 6 additions & 8 deletions pkg/dgvoice/dgvoice.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"os"
"os/exec"
"strconv"
"sync"
"syscall"

"github.com/bwmarrin/discordgo"
Expand All @@ -38,7 +37,6 @@ const (
var (
speakers map[uint32]*gopus.Decoder
opusEncoder *gopus.Encoder
mu sync.Mutex
)

// OnError gets called by dgvoice when an error is encountered.
Expand Down Expand Up @@ -85,7 +83,7 @@ func SendPCM(v *discordgo.VoiceConnection, pcm <-chan []int16) {
return
}

if v.Ready == false || v.OpusSend == nil {
if !v.Ready || v.OpusSend == nil {
// OnError(fmt.Sprintf("Discordgo not ready for opus packets. %+v : %+v", v.Ready, v.OpusSend), nil)
// Sending errors here might not be suited
return
Expand All @@ -105,7 +103,7 @@ func ReceivePCM(v *discordgo.VoiceConnection, c chan *discordgo.Packet) {
var err error

for {
if v.Ready == false || v.OpusRecv == nil {
if !v.Ready || v.OpusRecv == nil {
OnError(fmt.Sprintf("Discordgo not to receive opus packets. %+v : %+v", v.Ready, v.OpusSend), nil)
return
}
Expand Down Expand Up @@ -164,13 +162,13 @@ func PlayAudioFile(v *discordgo.VoiceConnection, filename string, stop <-chan bo
return
}

// prevent memory leak from residual ffmpeg streams
defer killCmdSafely(run)

//when stop is sent, kill ffmpeg
go func() {
<-stop
killCmdSafely(run)
err := killCmdSafely(run)
if err != nil {
OnError("", err)
}
}()

// Send "speaking" packet over the voice websocket
Expand Down
10 changes: 7 additions & 3 deletions pkg/slashCmd/dict.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package slashCmd

import (
"fmt"
"log"

"github.com/azuki-bar/ceviord/pkg/ceviord"
"github.com/azuki-bar/ceviord/pkg/replace"
"github.com/bwmarrin/discordgo"
"github.com/k0kubun/pp"
"log"
)

type dict struct{}
Expand All @@ -30,10 +31,13 @@ func (*dict) handle(c chan<- bool, s *discordgo.Session, i *discordgo.Interactio
replySimpleMsg(fmt.Sprintf("dict sub cmd handler failed. err is `%s`", err.Error()), s, i.Interaction)
return
}
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
err = s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: d,
})
if err != nil {
log.Println(err)
}
c <- true
}

Expand Down Expand Up @@ -266,5 +270,5 @@ func (dd *dictDump) execute(guildId, authorId string) (*discordgo.InteractionRes
}

func (dd *dictDump) getOptStr() string {
return fmt.Sprintf("全てのレコードを表示します\n")
return "全てのレコードを表示します\n"
}
8 changes: 7 additions & 1 deletion pkg/slashCmd/leave.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,16 @@ func (*leave) rawHandle(s *discordgo.Session, i *discordgo.InteractionCreate) er
if !isJoin || cev.VoiceConn == nil {
return fmt.Errorf("voice actor is already disconnected")
}
if err != nil {
return err
}
defer func() {
if cev.VoiceConn != nil {
cev.VoiceConn.Close()
ceviord.Cache.Channels.DeleteChannel(i.GuildID)
err = ceviord.Cache.Channels.DeleteChannel(i.GuildID)
if err != nil {
ceviord.Logger.Log(logging.WARN, err)
}
}
}()
err = cev.VoiceConn.Speaking(false)
Expand Down
2 changes: 1 addition & 1 deletion pkg/slashCmd/slashCmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func InteractionHandler(s *discordgo.Session, i *discordgo.InteractionCreate) {
ceviord.Logger.Log(logging.INFO, fmt.Errorf("parse command failed err is `%w`", err))
return
}
finish := make(chan bool, 0)
finish := make(chan bool)
// TODO; タイムアウト時に handle内でメッセージを送信しないように変更。
go h.handle(finish, s, i)
select {
Expand Down