Skip to content

Commit

Permalink
Merge pull request #30 from ccil-kbw/feat/recording-times
Browse files Browse the repository at this point in the history
fix: migrate to v2 for discord bot
  • Loading branch information
serafdev authored Apr 12, 2024
2 parents 11ddd89 + 3204e9a commit eeecbef
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 16 deletions.
6 changes: 4 additions & 2 deletions discord/discord.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/ccil-kbw/robot/rec"

"github.com/bwmarrin/discordgo"
iqamav1 "github.com/ccil-kbw/robot/iqama/v1"
iqamav2 "github.com/ccil-kbw/robot/iqama/v2"
)

var (
Expand All @@ -37,9 +37,11 @@ var (
},
}

iqamaClient = iqamav2.NewIqamaCSV("iqama_2024.csv")

commandHandlers = map[string]func(s *discordgo.Session, i *discordgo.InteractionCreate, obs *rec.Recorder){
"iqama": func(s *discordgo.Session, i *discordgo.InteractionCreate, obs *rec.Recorder) {
resp, _ := iqamav1.Get()
resp, _ := iqamaClient.GetTodayTimes()
_ = s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: mappers.IqamaTimesToDiscordInteractionResponseData(*resp),
Expand Down
14 changes: 7 additions & 7 deletions mappers/iqamadiscord.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import (
"fmt"

"github.com/bwmarrin/discordgo"
iqamav1 "github.com/ccil-kbw/robot/iqama/v1"
"github.com/ccil-kbw/robot/iqama/v2"
)

func IqamaTimesToDiscordInteractionResponseData(resp iqamav1.Resp) *discordgo.InteractionResponseData {
func IqamaTimesToDiscordInteractionResponseData(resp v2.IqamaDailyTimes) *discordgo.InteractionResponseData {
fmt.Println("discord command called: /iqama")
return &discordgo.InteractionResponseData{
Embeds: []*discordgo.MessageEmbed{
Expand All @@ -21,23 +21,23 @@ func IqamaTimesToDiscordInteractionResponseData(resp iqamav1.Resp) *discordgo.In
return []*discordgo.MessageEmbedField{
{
Name: "Fajr",
Value: resp.Fajr.Iqama,
Value: v2.FormatTime(resp.Fajr.Iqama),
},
{
Name: "Dhuhr",
Value: resp.Dhuhr.Iqama,
Value: v2.FormatTime(resp.Dhuhr.Iqama),
},
{
Name: "Asr",
Value: resp.Asr.Iqama,
Value: v2.FormatTime(resp.Asr.Iqama),
},
{
Name: "Maghrib",
Value: resp.Maghrib.Iqama,
Value: v2.FormatTime(resp.Maghrib.Iqama),
},
{
Name: "Isha",
Value: resp.Isha.Iqama,
Value: v2.FormatTime(resp.Isha.Iqama),
},
{
Name: "Friday Prayer 1",
Expand Down
32 changes: 25 additions & 7 deletions rec/rec_iqama.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,36 @@ package rec
import (
"fmt"
v1 "github.com/ccil-kbw/robot/iqama/v1"
v2 "github.com/ccil-kbw/robot/iqama/v2"
"sync"
"time"
)

var (
EveryDay []time.Weekday = []time.Weekday{time.Sunday, time.Monday, time.Tuesday, time.Wednesday, time.Thursday, time.Friday, time.Saturday}
JumuaaRecordDuration time.Duration = 2 * time.Hour
DarsRecordDuration time.Duration = 1 * time.Hour
DarsRecordDuration time.Duration = 45 * time.Minute
location string = "America/Montreal"
)

type RecordConfigDataS struct {
data *[]RecordConfig
mu sync.Mutex
data *[]RecordConfig
iqama v2.Iqama
mu sync.Mutex
}

func NewRecordConfigDataS() *RecordConfigDataS {
iqamaClient := v2.NewIqamaCSV("iqama_2024.csv")
today, err := iqamaClient.GetTodayTimes()
if err != nil {
fmt.Println("couldn't fetch iqama times, keeping current data")
}

fajr := today.Fajr.Iqama
dhuhr := today.Dhuhr.Iqama
isha := today.Isha.Iqama
rc := &RecordConfigDataS{
iqama: iqamaClient,
data: &[]RecordConfig{
{
Description: "Jumuaa Recording",
Expand All @@ -30,14 +42,20 @@ func NewRecordConfigDataS() *RecordConfigDataS {
},
{
Description: "Fajr Recording",
StartTime: time.Date(2024, 1, 1, 5, 0, 0, 0, time.Local),
StartTime: fajr,
Duration: DarsRecordDuration,
RecordingDays: EveryDay,
},
{
Description: "Tarawih Recording",
StartTime: time.Date(2024, 1, 1, 20, 0, 0, 0, time.Local),
Duration: 3 * time.Hour,
Description: "Dhuhur Recording",
StartTime: dhuhr,
Duration: DarsRecordDuration,
RecordingDays: EveryDay,
},
{
Description: "Isha Recording",
StartTime: isha,
Duration: DarsRecordDuration,
RecordingDays: EveryDay,
},
},
Expand Down

0 comments on commit eeecbef

Please sign in to comment.