Skip to content

Commit

Permalink
Minor fixes (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
NiJeTi authored Jan 2, 2025
1 parent f26510b commit 28b3093
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 262 deletions.
5 changes: 3 additions & 2 deletions internal/discord/commands/responses/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import (

func Activity() *discordgo.Activity {
return &discordgo.Activity{
Name: "Collecting movies and quotes",
Type: discordgo.ActivityTypeCustom,
Name: "Movies and Quotes",
Type: discordgo.ActivityTypeCustom,
State: "Collecting movies and quotes",
}
}

Expand Down
23 changes: 6 additions & 17 deletions internal/discord/commands/responses/lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,22 @@ import (
"github.com/bwmarrin/discordgo"
)

func LockSpecifyLimit(
channel *discordgo.Channel,
) *discordgo.InteractionResponse {
func LockSpecifyLimit() *discordgo.InteractionResponse {
return &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: fmt.Sprintf(
"Please specify a limit for the channel %s",
channel.Mention(),
),
Flags: discordgo.MessageFlagsEphemeral,
Content: "Please specify a user limit",
Flags: discordgo.MessageFlagsEphemeral,
},
}
}

func LockDone(
channel *discordgo.Channel,
limit int,
) *discordgo.InteractionResponse {
func LockDone(limit int) *discordgo.InteractionResponse {
return &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: fmt.Sprintf(
"Locked channel %s for **%d** user(s)",
channel.Mention(), limit,
),
Flags: discordgo.MessageFlagsEphemeral,
Content: fmt.Sprintf("Locked channel for **%d** user(s)", limit),
Flags: discordgo.MessageFlagsEphemeral,
},
}
}
8 changes: 2 additions & 6 deletions internal/discord/commands/responses/unlock.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
package responses

import (
"fmt"

"github.com/bwmarrin/discordgo"
)

func UnlockDone(
channel *discordgo.Channel,
) *discordgo.InteractionResponse {
func UnlockDone() *discordgo.InteractionResponse {
return &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: fmt.Sprintf("Unclocked %s", channel.Mention()),
Content: "Unlocked channel",
Flags: discordgo.MessageFlagsEphemeral,
},
}
Expand Down
59 changes: 0 additions & 59 deletions internal/generated/mocks/services/lockVoiceChan/discord.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 0 additions & 59 deletions internal/generated/mocks/services/unlockVoiceChan/discord.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions internal/services/lockVoiceChan/deps.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ type discord interface {
response *discordgo.InteractionResponse,
) error

Channel(
ctx context.Context, channelID models.ID,
) (*discordgo.Channel, error)

UserVoiceState(
ctx context.Context, guildID models.ID, userID models.ID,
) (*discordgo.VoiceState, error)
Expand Down
13 changes: 5 additions & 8 deletions internal/services/lockVoiceChan/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,8 @@ func (s *Service) Exec(
return err
}

channel, err := s.discord.Channel(ctx, models.ID(voiceState.ChannelID))
if err != nil {
return fmt.Errorf("failed to get voice channel: %w", err)
}

if *limit > commands.LockOptionLimitMaxValue {
err = s.discord.Respond(ctx, i, responses.LockSpecifyLimit(channel))
err = s.discord.Respond(ctx, i, responses.LockSpecifyLimit())
if err != nil {
return fmt.Errorf("failed to respond: %w", err)
}
Expand All @@ -63,13 +58,15 @@ func (s *Service) Exec(
}

err = s.discord.EditChannel(
ctx, models.ID(channel.ID), &discordgo.ChannelEdit{UserLimit: *limit},
ctx,
models.ID(voiceState.ChannelID),
&discordgo.ChannelEdit{UserLimit: *limit},
)
if err != nil {
return fmt.Errorf("failed to edit channel user limit: %w", err)
}

err = s.discord.Respond(ctx, i, responses.LockDone(channel, *limit))
err = s.discord.Respond(ctx, i, responses.LockDone(*limit))
if err != nil {
return fmt.Errorf("failed to respond: %w", err)
}
Expand Down
75 changes: 9 additions & 66 deletions internal/services/lockVoiceChan/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,33 +99,6 @@ func TestService_Exec(t *testing.T) {
return lockVoiceChan.New(d)
},
},
"channel_error": {
args: args{
limit: nil,
},
err: errors.New("channel error"),
setup: func(
t *testing.T, _ args, err error,
) *lockVoiceChan.Service {
d := mocks.NewMockDiscord(t)

vs := &discordgo.VoiceState{ChannelID: "3"}
d.EXPECT().UserVoiceState(
ctx, models.ID(i.GuildID), models.ID(i.Member.User.ID),
).Return(vs, nil)

users := make([]*discordgo.Member, 1)
d.EXPECT().VoiceChannelUsers(
ctx, models.ID(i.GuildID), models.ID(vs.ChannelID),
).Return(users, nil)

d.EXPECT().Channel(
ctx, models.ID(vs.ChannelID),
).Return(nil, err)

return lockVoiceChan.New(d)
},
},
"too_many_users_response_error": {
args: args{
limit: nil,
Expand All @@ -148,13 +121,8 @@ func TestService_Exec(t *testing.T) {
ctx, models.ID(i.GuildID), models.ID(vs.ChannelID),
).Return(users, nil)

c := &discordgo.Channel{ID: vs.ChannelID}
d.EXPECT().Channel(
ctx, models.ID(vs.ChannelID),
).Return(c, nil)

d.EXPECT().Respond(
ctx, i, responses.LockSpecifyLimit(c),
ctx, i, responses.LockSpecifyLimit(),
).Return(err)

return lockVoiceChan.New(d)
Expand All @@ -180,14 +148,9 @@ func TestService_Exec(t *testing.T) {
ctx, models.ID(i.GuildID), models.ID(vs.ChannelID),
).Return(users, nil)

c := &discordgo.Channel{ID: vs.ChannelID}
d.EXPECT().Channel(
ctx, models.ID(vs.ChannelID),
).Return(c, nil)

d.EXPECT().EditChannel(
ctx,
models.ID(c.ID),
models.ID(vs.ChannelID),
&discordgo.ChannelEdit{UserLimit: len(users)},
).Return(err)

Expand All @@ -214,19 +177,14 @@ func TestService_Exec(t *testing.T) {
ctx, models.ID(i.GuildID), models.ID(vs.ChannelID),
).Return(users, nil)

c := &discordgo.Channel{ID: vs.ChannelID}
d.EXPECT().Channel(
ctx, models.ID(vs.ChannelID),
).Return(c, nil)

d.EXPECT().EditChannel(
ctx,
models.ID(c.ID),
models.ID(vs.ChannelID),
&discordgo.ChannelEdit{UserLimit: len(users)},
).Return(nil)

d.EXPECT().Respond(
ctx, i, responses.LockDone(c, len(users)),
ctx, i, responses.LockDone(len(users)),
).Return(err)

return lockVoiceChan.New(d)
Expand Down Expand Up @@ -275,13 +233,8 @@ func TestService_Exec(t *testing.T) {
ctx, models.ID(i.GuildID), models.ID(vs.ChannelID),
).Return(users, nil)

c := &discordgo.Channel{ID: vs.ChannelID}
d.EXPECT().Channel(
ctx, models.ID(vs.ChannelID),
).Return(c, nil)

d.EXPECT().Respond(
ctx, i, responses.LockSpecifyLimit(c),
ctx, i, responses.LockSpecifyLimit(),
).Return(nil)

return lockVoiceChan.New(d)
Expand All @@ -307,19 +260,14 @@ func TestService_Exec(t *testing.T) {
ctx, models.ID(i.GuildID), models.ID(vs.ChannelID),
).Return(users, nil)

c := &discordgo.Channel{ID: vs.ChannelID}
d.EXPECT().Channel(
ctx, models.ID(vs.ChannelID),
).Return(c, nil)

d.EXPECT().EditChannel(
ctx,
models.ID(c.ID),
models.ID(vs.ChannelID),
&discordgo.ChannelEdit{UserLimit: len(users)},
).Return(nil)

d.EXPECT().Respond(
ctx, i, responses.LockDone(c, len(users)),
ctx, i, responses.LockDone(len(users)),
).Return(nil)

return lockVoiceChan.New(d)
Expand All @@ -340,19 +288,14 @@ func TestService_Exec(t *testing.T) {
ctx, models.ID(i.GuildID), models.ID(i.Member.User.ID),
).Return(vs, nil)

c := &discordgo.Channel{ID: vs.ChannelID}
d.EXPECT().Channel(
ctx, models.ID(vs.ChannelID),
).Return(c, nil)

d.EXPECT().EditChannel(
ctx,
models.ID(c.ID),
models.ID(vs.ChannelID),
&discordgo.ChannelEdit{UserLimit: *args.limit},
).Return(nil)

d.EXPECT().Respond(
ctx, i, responses.LockDone(c, *args.limit),
ctx, i, responses.LockDone(*args.limit),
).Return(nil)

return lockVoiceChan.New(d)
Expand Down
Loading

0 comments on commit 28b3093

Please sign in to comment.