Skip to content

Commit fc74b1c

Browse files
committed
feat: add dynamic times
1 parent 3865a66 commit fc74b1c

File tree

4 files changed

+15
-63
lines changed

4 files changed

+15
-63
lines changed

cmd/darsrec/main.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ func main() {
2323
os.Exit(1)
2424
}
2525
}
26-
data := rec.NewRecordConfigDataS()
2726

28-
rec.StartRecServer(host, password, data)
27+
_, err := rec.StartRecServer(host, password)
28+
if err != nil {
29+
return
30+
}
2931

3032
}

cmd/monolith/main.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,8 @@ func main() {
7171
if config.Features.Record {
7272
host := os.Getenv("MDROID_OBS_WEBSOCKET_HOST")
7373
password := os.Getenv("MDROID_OBS_WEBSOCKET_PASSWORD")
74-
data := rec.NewRecordConfigDataS()
7574

76-
obsClient := startServerWithRetry(host, password, data)
75+
obsClient := startServerWithRetry(host, password)
7776

7877
// Calculate the duration until midnight
7978
now := time.Now()
@@ -94,7 +93,7 @@ func main() {
9493
if err != nil {
9594
return
9695
}
97-
obsClient = startServerWithRetry(host, password, data)
96+
obsClient = startServerWithRetry(host, password)
9897
}
9998
}()
10099

@@ -125,11 +124,6 @@ out:
125124

126125
}
127126

128-
// proxy, move to apis, maybe pkg/apis/proxyserver/proxyserver.go
129-
func proxy() {
130-
fmt.Println("implement me")
131-
}
132-
133127
func bot(obs *rec.Recorder, notifyChan chan string) {
134128
guildID := os.Getenv("MDROID_BOT_GUILD_ID")
135129
botToken := os.Getenv("MDROID_BOT_TOKEN")
@@ -175,9 +169,9 @@ func notifyPrayer(prayerName, prayerTime string, in time.Duration, notifyChan ch
175169
notifyChan <- msg
176170
}
177171

178-
func startServerWithRetry(host string, password string, data *rec.RecordConfigDataS) *rec.Recorder {
172+
func startServerWithRetry(host string, password string) *rec.Recorder {
179173
for {
180-
obs, err := rec.StartRecServer(host, password, data)
174+
obs, err := rec.StartRecServer(host, password)
181175
if err != nil {
182176
fmt.Printf("could not reach or authenticate to OBS, retrying in 1 minutes...\n")
183177
time.Sleep(1 * time.Minute)

rec/rec_iqama.go

Lines changed: 5 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package rec
22

33
import (
44
"fmt"
5-
v1 "github.com/ccil-kbw/robot/iqama/v1"
65
v2 "github.com/ccil-kbw/robot/iqama/v2"
76
"sync"
87
"time"
@@ -29,6 +28,10 @@ func NewRecordConfigDataS() *RecordConfigDataS {
2928
fmt.Println("couldn't fetch iqama times, keeping current data")
3029
}
3130

31+
if today == nil {
32+
33+
}
34+
3235
fajr := today.Fajr.Iqama
3336
dhuhr := today.Dhuhr.Iqama
3437
isha := today.Isha.Iqama
@@ -61,61 +64,15 @@ func NewRecordConfigDataS() *RecordConfigDataS {
6164
},
6265
},
6366
}
64-
//rc.Refresh()
6567
return rc
6668
}
69+
6770
func (rc *RecordConfigDataS) Get() *[]RecordConfig {
6871
defer rc.mu.Unlock()
6972
rc.mu.Lock()
7073
return rc.data
7174
}
7275

73-
func (rc *RecordConfigDataS) Refresh() {
74-
defer rc.mu.Unlock()
75-
rc.mu.Lock()
76-
timeLocation, err := time.LoadLocation("America/Montreal")
77-
if err != nil {
78-
fmt.Println("couldn't access remote iqama")
79-
}
80-
81-
iqamaTimes, err := v1.Get()
82-
if err != nil || iqamaTimes == nil {
83-
fmt.Println("couldn't fetch iqama times, keeping current data")
84-
if rc.Get() == nil {
85-
rc.data = &[]RecordConfig{
86-
{
87-
Description: "Jumuaa Recording",
88-
StartTime: time.Date(2023, 1, 1, 11, 55, 0, 0, timeLocation),
89-
Duration: JumuaaRecordDuration,
90-
RecordingDays: []time.Weekday{time.Friday},
91-
},
92-
}
93-
}
94-
return
95-
}
96-
97-
rc.data = &[]RecordConfig{
98-
{
99-
Description: "Fajr Recording",
100-
StartTime: toTime(iqamaTimes.Fajr.Iqama),
101-
Duration: DarsRecordDuration,
102-
RecordingDays: EveryDay,
103-
},
104-
{
105-
Description: "Dhuhur Recording",
106-
StartTime: toTime(iqamaTimes.Dhuhr.Iqama),
107-
Duration: DarsRecordDuration,
108-
RecordingDays: EveryDay,
109-
},
110-
{
111-
Description: "Jumuaa Recording",
112-
StartTime: time.Date(2023, 1, 1, 11, 55, 0, 0, timeLocation),
113-
Duration: JumuaaRecordDuration,
114-
RecordingDays: []time.Weekday{time.Friday},
115-
},
116-
}
117-
}
118-
11976
type RecordConfig struct {
12077
Description string
12178

rec/server.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"time"
66
)
77

8-
func StartRecServer(host, password string, data *RecordConfigDataS) (*Recorder, error) {
8+
func StartRecServer(host, password string) (*Recorder, error) {
99
client, err := New(host, password)
1010
if err != nil {
1111
fmt.Println("could not initiate client")
@@ -15,6 +15,7 @@ func StartRecServer(host, password string, data *RecordConfigDataS) (*Recorder,
1515
fmt.Println("Starting OBS recording control routine")
1616
go func() {
1717
for {
18+
data := NewRecordConfigDataS()
1819

1920
isRecording, err := client.IsRecording()
2021
if err != nil {
@@ -36,8 +37,6 @@ func StartRecServer(host, password string, data *RecordConfigDataS) (*Recorder,
3637
recordTimeLimit = 2 * 60 * 60 * 1000
3738
}
3839

39-
40-
4140
// Stop recording if not supposed to be recording but currently recording
4241
if !shouldRecord && isRecording && (client.RecordTime() > recordTimeLimit) {
4342
err := client.StopRecording()

0 commit comments

Comments
 (0)