Skip to content

Commit

Permalink
Remove excessive whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
xoltia committed Oct 24, 2024
1 parent 77f93ff commit 4c2421b
Show file tree
Hide file tree
Showing 28 changed files with 1 addition and 146 deletions.
3 changes: 0 additions & 3 deletions cmd/aibmigration/activity.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,16 @@ func (activity *aibActivity) asNewFormatActivity() (a *activities.Activity) {
func populateVideoMetadata(ctx context.Context, a *activities.Activity, vidURL string) (err error) {
var u *url.URL
u, err = url.Parse(vidURL)

if err != nil {
return
}

var meta *videos.VideoInfo
meta, err = videos.GetVideoInfo(ctx, u, videos.Options{})

if err != nil {
return
}

a.Meta = meta

return
}
18 changes: 0 additions & 18 deletions cmd/botsu/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ func (c *Config) LoadEnv() error {

if ok {
token, err := os.ReadFile(tokenFile)

if err != nil {
return err
}
Expand All @@ -82,22 +81,18 @@ func (c *Config) LoadEnv() error {
}

token, ok := os.LookupEnv("BOTSU_TOKEN")

if ok {
c.Token = token
}

host, ok := os.LookupEnv("POSTGRES_HOST")

if ok {
c.Database.Host = host
}

port, ok := os.LookupEnv("POSTGRES_PORT")

if ok {
portInt, err := strconv.Atoi(port)

if err != nil {
return err
}
Expand All @@ -106,10 +101,8 @@ func (c *Config) LoadEnv() error {
}

userFile, ok := os.LookupEnv("POSTGRES_USER_FILE")

if ok {
user, err := os.ReadFile(userFile)

if err != nil {
return err
}
Expand All @@ -118,10 +111,8 @@ func (c *Config) LoadEnv() error {
}

passwordFile, ok := os.LookupEnv("POSTGRES_PASSWORD_FILE")

if ok {
password, err := os.ReadFile(passwordFile)

if err != nil {
return err
}
Expand All @@ -130,22 +121,18 @@ func (c *Config) LoadEnv() error {
}

database, ok := os.LookupEnv("POSTGRES_DB")

if ok {
c.Database.Database = database
}

sslMode, ok := os.LookupEnv("POSTGRES_SSL_MODE")

if ok {
c.Database.SSLMode = sslMode
}

connectionString, ok := os.LookupEnv("BOTSU_CONNECTION_STRING")

if ok {
connectionURL, err := url.Parse(connectionString)

if err != nil {
return err
}
Expand All @@ -154,30 +141,25 @@ func (c *Config) LoadEnv() error {
}

useMembersIntent, ok := os.LookupEnv("BOTSU_USE_MEMBERS_INTENT")

if ok {
c.UseMembersIntent = stringToTruthy(useMembersIntent)
}

logLevel, ok := os.LookupEnv("BOTSU_LOG_LEVEL")

if ok {
if err := c.LogLevel.UnmarshalText([]byte(logLevel)); err != nil {
return err
}
}

noPanic, ok := os.LookupEnv("BOTSU_NO_PANIC")

if ok {
c.NoPanic = stringToTruthy(noPanic)
}

dataUpdateInterval, ok := os.LookupEnv("BOTSU_DATA_UPDATE_INTERVAL")

if ok {
duration, err := time.ParseDuration(dataUpdateInterval)

if err != nil {
return err
}
Expand Down
5 changes: 0 additions & 5 deletions cmd/botsu/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,29 +145,25 @@ func main() {
}

migrationSource, err := iofs.New(migrations.MigrationFS, ".")

if err != nil {
logger.Error("Unable to create migration source", slog.String("err", err.Error()))
os.Exit(1)
}

m, err := migrate.NewWithSourceInstance("migrations.MigrationFS", migrationSource, migrationURL.String())

if err != nil {
logger.Error("Unable to create migration", slog.String("err", err.Error()))
os.Exit(1)
}

err = m.Up()
noChange := errors.Is(err, migrate.ErrNoChange)

if err != nil && !noChange {
logger.Error("Unable to run migrations", slog.String("err", err.Error()))
os.Exit(1)
}

ver, dirty, err := m.Version()

if err != nil {
logger.Warn("Failed to get database version")
}
Expand All @@ -186,7 +182,6 @@ func main() {
}

pool, err := pgxpool.New(context.Background(), config.Database.ConnectionString())

if err != nil {
logger.Error("Unable to connect to database", slog.String("err", err.Error()))
os.Exit(1)
Expand Down
4 changes: 0 additions & 4 deletions internal/activities/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ func (r *ActivityRepository) GetTotalByUserIDGroupByVideoChannel(
LIMIT $4
`
rows, err := r.pool.Query(ctx, query, userID, start, end, limit)

if err != nil {
return nil, err
}
Expand Down Expand Up @@ -299,7 +298,6 @@ func (r *ActivityRepository) GetTotalByUserIDGroupedByMonth(
`

rows, err := r.pool.Query(ctx, query, userID, guildID, start, end)

if err != nil {
return nil, err
}
Expand Down Expand Up @@ -356,7 +354,6 @@ func (r *ActivityRepository) GetTotalByUserIDGroupedByDay(
`

rows, err := r.pool.Query(ctx, query, userID, guildID, start, end)

if err != nil {
return nil, err
}
Expand Down Expand Up @@ -459,7 +456,6 @@ func (r *ActivityRepository) GetByID(ctx context.Context, id uint64, guildID str
&activity.ImportedAt,
&activity.Meta,
)

if err != nil {
return nil, err
}
Expand Down
4 changes: 0 additions & 4 deletions internal/bot/bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ func (b *Bot) onInteractionCreate(s *discordgo.Session, i *discordgo.Interaction
stack := debug.Stack()
ctx.Logger.Error("Panic occurred", slog.Any("panic", r), slog.Any("stack", string(stack)))
_, err := ctx.RespondOrFollowup(unexpectedErrorMessage, false)

if err != nil {
ctx.Logger.Error("Failed to send error message", slog.String("err", err.Error()))
}
Expand All @@ -94,7 +93,6 @@ func (b *Bot) onInteractionCreate(s *discordgo.Session, i *discordgo.Interaction

if ctx.IsCommand() {
_, err = ctx.RespondOrFollowup(unexpectedErrorMessage, false)

if err != nil {
ctx.Logger.Error("Failed to send error message", slog.String("err", err.Error()))
}
Expand Down Expand Up @@ -182,9 +180,7 @@ func (b *Bot) Close() {

if b.destroyOnClose {
b.logger.Debug("Destroying commands")

_, err := b.session.ApplicationCommandBulkOverwrite(b.session.State.User.ID, "", []*discordgo.ApplicationCommand{})

if err != nil {
b.logger.Error("Failed to destroy commands", slog.String("err", err.Error()))
}
Expand Down
5 changes: 0 additions & 5 deletions internal/bot/commands/chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,6 @@ func (c *ChartCommand) handleYoutubeChannel(ctx *bot.InteractionContext, user *u
}

resp, err := http.DefaultClient.Do(&req)

if err != nil {
return err
}
Expand Down Expand Up @@ -313,11 +312,9 @@ func (c *ChartCommand) Handle(ctx *bot.InteractionContext) error {
timezone = *user.Timezone
} else if guildID != "" {
guild, err := c.gr.FindByID(ctx.ResponseContext(), guildID)

if err != nil && !errors.Is(err, pgx.ErrNoRows) {
return err
}

if guild != nil && guild.Timezone != nil {
timezone = *guild.Timezone
}
Expand Down Expand Up @@ -422,7 +419,6 @@ func (c *ChartCommand) Handle(ctx *bot.InteractionContext) error {
}

reqBody, err := getQuickChartBarBody(dailyDurations.Keys(), values, goal)

if err != nil {
return err
}
Expand All @@ -437,7 +433,6 @@ func (c *ChartCommand) Handle(ctx *bot.InteractionContext) error {
}

resp, err := http.DefaultClient.Do(&req)

if err != nil {
return err
}
Expand Down
9 changes: 0 additions & 9 deletions internal/bot/commands/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ func (c *ConfigCommand) Handle(ctx *bot.InteractionContext) error {
switch options[0].Name {
case "timezone":
timezone, err := discordutil.GetRequiredStringOption(options, "timezone")

if err != nil {
return err
}
Expand All @@ -106,15 +105,13 @@ func (c *ConfigCommand) Handle(ctx *bot.InteractionContext) error {
}

err = c.userRepository.SetUserTimezone(ctx.Context(), discordutil.GetInteractionUser(i).ID, timezone)

if err != nil {
return err
}

embedBuilder.SetDescription("Your timezone has been updated.")
case "vn-speed":
vnSpeed, err := discordutil.GetRequiredFloatOption(options, "vn-speed")

if err != nil {
return err
}
Expand All @@ -127,41 +124,35 @@ func (c *ConfigCommand) Handle(ctx *bot.InteractionContext) error {
embedBuilder.SetDescription("Your visual novel reading speed has been updated.")
case "book-speed":
bookSpeed, err := discordutil.GetRequiredFloatOption(options, "book-speed")

if err != nil {
return err
}

err = c.userRepository.SetBookReadingSpeed(ctx.Context(), discordutil.GetInteractionUser(i).ID, float32(bookSpeed))

if err != nil {
return err
}

embedBuilder.SetDescription("Your book reading speed has been updated.")
case "manga-speed":
mangaSpeed, err := discordutil.GetRequiredFloatOption(options, "manga-speed")

if err != nil {
return err
}

err = c.userRepository.SetMangaReadingSpeed(ctx.Context(), discordutil.GetInteractionUser(i).ID, float32(mangaSpeed))

if err != nil {
return err
}

embedBuilder.SetDescription("Your manga reading speed has been updated.")
case "daily-goal":
dailyGoal, err := discordutil.GetRequiredUintOption(options, "daily-goal")

if err != nil {
return err
}

err = c.userRepository.SetDailyGoal(ctx.Context(), discordutil.GetInteractionUser(i).ID, int(dailyGoal))

if err != nil {
return err
}
Expand Down
1 change: 0 additions & 1 deletion internal/bot/commands/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ func (c *ExportCommand) Handle(ctx *bot.InteractionContext) error {

for _, activity := range activities {
err = jsonEncoder.Encode(activity)

if err != nil {
return err
}
Expand Down
2 changes: 0 additions & 2 deletions internal/bot/commands/goals.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ func (c *GoalCommand) handleDelete(cmd *bot.InteractionContext, subcommand *disc

func (c *GoalCommand) handleList(cmd *bot.InteractionContext, _ *discordgo.ApplicationCommandInteractionDataOption) error {
goals, err := c.goals.CheckAll(cmd.ResponseContext(), cmd.User().ID)

if err != nil {
return fmt.Errorf("failed to find goals: %w", err)
}
Expand All @@ -222,7 +221,6 @@ func (c *GoalCommand) handleList(cmd *bot.InteractionContext, _ *discordgo.Appli

for _, goal := range goals {
nextDueDate, err := c.goals.NextCron(cmd.Context(), goal)

if err != nil {
return fmt.Errorf("failed to calculate next due date: %w", err)
}
Expand Down
1 change: 0 additions & 1 deletion internal/bot/commands/guild_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ func (c *GuildConfigCommand) Handle(ctx *bot.InteractionContext) error {
switch options[0].Name {
case "timezone":
timezone, err := discordutil.GetRequiredStringOption(options, "timezone")

if err != nil {
return err
}
Expand Down
2 changes: 0 additions & 2 deletions internal/bot/commands/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ func (c *HistoryCommand) Handle(ctx *bot.InteractionContext) error {
}

page, err := c.r.PageByUserID(ctx.Context(), user.ID, ctx.Interaction().GuildID, pageSize, offset)

if err != nil {
return err
}
Expand Down Expand Up @@ -222,7 +221,6 @@ func (c *HistoryCommand) Handle(ctx *bot.InteractionContext) error {
}

page, err = c.r.PageByUserID(ciContext, user.ID, ctx.Interaction().GuildID, pageSize, offset)

if err != nil {
cancel()
return err
Expand Down
1 change: 0 additions & 1 deletion internal/bot/commands/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ func (c *ImportCommand) handleList(
cmd *bot.InteractionContext,
) error {
history, err := c.r.GetRecentImportsByUserID(ctx, cmd.User().ID, 10)

if err != nil {
return err
}
Expand Down
Loading

0 comments on commit 4c2421b

Please sign in to comment.