-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from ccil-kbw/discord-iqama-notification
feat(iqama): add notification for iqamas v1
- Loading branch information
Showing
7 changed files
with
143 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package iqama | ||
|
||
import ( | ||
"fmt" | ||
v1 "github.com/ccil-kbw/robot/iqama/v1" | ||
"github.com/ccil-kbw/robot/rec" | ||
"sync" | ||
"time" | ||
) | ||
|
||
// RecordingsData (sync.Mutex) is used to handle the RecordConfig asynchronously as it's used in the main and some sub routines | ||
type RecordingsData struct { | ||
mu sync.Mutex | ||
confs []*rec.RecordConfig | ||
} | ||
|
||
// Refresh updates the scheduling configurations | ||
func (ac *RecordingsData) Refresh() { | ||
ac.mu.Lock() | ||
ac.confs = rec.GetIqamaRecordingConfigs() | ||
ac.mu.Unlock() | ||
} | ||
|
||
func (ac *RecordingsData) Confs() []*rec.RecordConfig { | ||
ac.mu.Lock() | ||
defer ac.mu.Unlock() | ||
return ac.confs | ||
} | ||
|
||
// PrayersData (sync.Mutex) is used to handle the Iqama times | ||
type PrayersData struct { | ||
mu sync.Mutex | ||
confs *v1.Resp | ||
} | ||
|
||
func (i *PrayersData) Refresh() { | ||
i.mu.Lock() | ||
defer i.mu.Unlock() | ||
resp := v1.Get() | ||
i.confs = &resp | ||
} | ||
|
||
func (i *PrayersData) Confs() *v1.Resp { | ||
i.mu.Lock() | ||
defer i.mu.Unlock() | ||
return i.confs | ||
} | ||
|
||
func StartRecordingScheduleServer() *RecordingsData { | ||
data := &RecordingsData{} | ||
data.Refresh() | ||
ticker := time.NewTicker(1 * time.Hour) | ||
go func() { | ||
for range ticker.C { | ||
fmt.Printf("%s: Updating Iqama time...\n", time.Now().Format(time.Kitchen)) | ||
data.Refresh() | ||
} | ||
}() | ||
return data | ||
} | ||
|
||
func StartIqamaServer() *PrayersData { | ||
data := &PrayersData{} | ||
data.Refresh() | ||
ticker := time.NewTicker(1 * time.Hour) | ||
go func() { | ||
for range ticker.C { | ||
fmt.Printf("%s: Updating Iqama time...\n", time.Now().Format(time.Kitchen)) | ||
data.Refresh() | ||
} | ||
}() | ||
return data | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters