Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
2f1a9c9207 |
|||
|
dcf7728485 |
|||
|
999eea1919 |
|||
|
22e562d5be |
|||
|
34eaa9c298 |
|||
|
4dce56b104 |
|||
|
60dfec9b65 |
|||
|
a9c58cba45 |
|||
|
295ac3169d |
|||
|
f05cba0728 |
|||
|
4638688b6b |
|||
|
7af0d5ce1d |
|||
|
7afe1f94b0 |
|||
|
cb155c0334 |
|||
|
7604da1700 |
|||
|
a9cec81ee3 |
|||
|
7b6ab7444d |
|||
|
8d3ffc791b |
5 changed files with 59 additions and 44 deletions
|
|
@ -2,6 +2,9 @@ package main
|
|||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"os/signal"
|
||||
"slices"
|
||||
|
|
@ -55,6 +58,14 @@ type Bot struct {
|
|||
cancel context.CancelFunc
|
||||
}
|
||||
|
||||
type interceptor struct {
|
||||
mux *http.ServeMux
|
||||
}
|
||||
|
||||
func (i *interceptor) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Println(r.URL)
|
||||
}
|
||||
|
||||
func NewBot() (bot *Bot, errch chan error, err error) {
|
||||
bot = &Bot{}
|
||||
|
||||
|
|
@ -74,6 +85,21 @@ func NewBot() (bot *Bot, errch chan error, err error) {
|
|||
}
|
||||
bot.Bot = b
|
||||
|
||||
u, err := url.Parse(conf.Service.Webhook.URI)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("malformed URI: %s", conf.Service.Webhook.URI))
|
||||
}
|
||||
|
||||
err = b.SetWebhook(ctx, &telego.SetWebhookParams{
|
||||
URL: conf.Service.Webhook.URI,
|
||||
SecretToken: b.SecretToken(),
|
||||
})
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("failed setting up webhook: %w", err))
|
||||
}
|
||||
info, err := b.GetWebhookInfo(ctx)
|
||||
fmt.Println(info, err)
|
||||
|
||||
c := cron.New()
|
||||
c.AddFunc(fmt.Sprintf("TZ=%s %s",
|
||||
conf.System.TimeZone,
|
||||
|
|
@ -81,10 +107,23 @@ func NewBot() (bot *Bot, errch chan error, err error) {
|
|||
c.Start()
|
||||
bot.Cron = c
|
||||
|
||||
updates, err := b.UpdatesViaLongPolling(ctx, nil)
|
||||
/*updates, err := b.UpdatesViaLongPolling(ctx, nil)
|
||||
if err != nil {
|
||||
fmt.Errorf("failed receiving updates: %s", err)
|
||||
}*/
|
||||
|
||||
mux := http.NewServeMux()
|
||||
updates, err := b.UpdatesViaWebhook(ctx,
|
||||
telego.WebhookHTTPServeMux(mux, u.Path, b.SecretToken()))
|
||||
/*bot.Handler, err = th.NewBotHandler(b, updates)
|
||||
if err != nil {
|
||||
fmt.Errorf("failed configuring handlers: %s", err)
|
||||
}
|
||||
bot.AttachHandlers()*/
|
||||
go func() {
|
||||
_ = http.ListenAndServe(net.JoinHostPort(conf.Service.Webhook.Host, conf.Service.Webhook.Port), &interceptor{mux})
|
||||
}()
|
||||
|
||||
bot.Handler, err = th.NewBotHandler(b, updates)
|
||||
if err != nil {
|
||||
fmt.Errorf("failed configuring handlers: %s", err)
|
||||
|
|
@ -97,6 +136,7 @@ func NewBot() (bot *Bot, errch chan error, err error) {
|
|||
func (b *Bot) AttachHandlers() {
|
||||
fmt.Println("add handlers")
|
||||
b.Handler.HandleMessage(func(ctx *th.Context, message telego.Message) error {
|
||||
fmt.Println("handling message")
|
||||
if !slices.Contains(b.Settings.Chat.Channels, message.Chat.ID) {
|
||||
fmt.Println("adding chat:", message.Chat.ID)
|
||||
b.Settings.Chat.Channels = append(b.Settings.Chat.Channels, message.Chat.ID)
|
||||
|
|
|
|||
|
|
@ -27,8 +27,8 @@ type Scripture struct {
|
|||
}
|
||||
|
||||
type ScriptureStore struct {
|
||||
Verses []*Scripture
|
||||
Offset int `json:"offset"`
|
||||
Verses []*Scripture `json:"verses"`
|
||||
Offset int `json:"offset"`
|
||||
}
|
||||
|
||||
func (s *ScriptureStore) GetVerse() *Scripture {
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ type Service struct {
|
|||
|
||||
type Webhook struct {
|
||||
URI string `toml:"uri"`
|
||||
Port int `toml:"port"`
|
||||
Port string `toml:"port"`
|
||||
Host string `toml:"host"`
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,60 +1,35 @@
|
|||
{
|
||||
"verses": [
|
||||
{
|
||||
"verse": "Genesis 1:1",
|
||||
"verse": "Psalm 46:10",
|
||||
"translation": "BSB",
|
||||
"content": "In the beginning, God created the heavens and the earth."
|
||||
"content": "Be still and know that I am God; I will be exalted among the nations, I will be exalted over the earth."
|
||||
},
|
||||
{
|
||||
"verse": "John 6:36",
|
||||
"verse": "Romans 13:8",
|
||||
"translation": "BSB",
|
||||
"content": "Jesus answered, \"I am the bread of life. Whoever comes to Me will never hunger, and whoever believes in Me will never thirst.\""
|
||||
"content": "Be indebted to no one, except to one another in love. For he who loves his neighbor has fulfilled the law."
|
||||
},
|
||||
{
|
||||
"verse": "Psalm 62:1",
|
||||
"verse": "Philippians 4:4-5",
|
||||
"translation": "BSB",
|
||||
"content": "In God alone my soul finds rest; my salvation comes from Him."
|
||||
"content": "4Rejoice in the Lord always. I will say it again: Rejoice! 5Let your gentleness be apparent to all. The Lord is near."
|
||||
},
|
||||
{
|
||||
"verse": "Romans 12:12",
|
||||
"verse": "Micah 7:7",
|
||||
"translation": "BSB",
|
||||
"content": "Be joyful in hope, patient in affliction, persistent in prayer."
|
||||
"content": "But as for me, I will look to the LORD; I will wait for the God of my salvation. My God will hear me."
|
||||
},
|
||||
{
|
||||
"verse": "Psalm 45:6",
|
||||
"verse": "2 Corinthians 7:10",
|
||||
"translation": "BSB",
|
||||
"content": "Your throne, O God, endures forever and ever, and justice is the scepter of Your kingdom."
|
||||
"content": "Godly sorrow brings repentance that leads to salvation without regret, but worldly sorrow brings death."
|
||||
},
|
||||
{
|
||||
"verse": "Revelation 21:4",
|
||||
"verse": "Psalm 59:16",
|
||||
"translation": "BSB",
|
||||
"content": "'He will wipe away every tear from their eyes,' and there will be no more death or mourning or crying or pain, for the former things have passed away."
|
||||
},
|
||||
{
|
||||
"verse": "James 1:17",
|
||||
"translation": "BSB",
|
||||
"content": "Every good and perfect gift is from above, coming down from the Father of the heavenly lights, with whom there is no change or shifting shadow."
|
||||
},
|
||||
{
|
||||
"verse": "Job 42:2",
|
||||
"translation": "BSB",
|
||||
"content": "I know that You can do all things and that no plan of Yours can be thwarted."
|
||||
},
|
||||
{
|
||||
"verse": "Psalm 33:6",
|
||||
"translation": "BSB",
|
||||
"content": "By the word of the LORD the heavens were made, and all the stars by the breath of His mouth."
|
||||
},
|
||||
{
|
||||
"verse": "1 Corinthians 15:54",
|
||||
"translation": "BSB",
|
||||
"content": "When the perishable has been clothed with the imperishable and the mortal with immortality, then the saying that is written will come to pass: \"Death has been swallowed up in victory.\""
|
||||
},
|
||||
{
|
||||
"verse": "3 John 11",
|
||||
"translation": "BSB",
|
||||
"content": "Beloved, do not imitate what is evil, but what is good. The one who does good is of God; the one who does evil has not seen God."
|
||||
"content": "But I will sing of Your strength and proclaim Your loving devotion in the morning. For You are my fortress, my refuge in times of trouble."
|
||||
}
|
||||
],
|
||||
"offset": 2
|
||||
}
|
||||
"offset": 1
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ base_url = "https://bible.helloao.org/api/"
|
|||
|
||||
[daily_scripture]
|
||||
user_submitted = true
|
||||
schedule = "* 8 * * *"
|
||||
schedule = "0 8 * * *"
|
||||
rotation = "data/daily/rotation"
|
||||
user = "data/daily/user"
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue