| 1 | package telegramscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/ |
| 2 | |
| 3 | import ( |
| 4 | "errorsscip-go gomod github.com/golang/go/src . errors/" |
| 5 | "fmtscip-go gomod github.com/golang/go/src . fmt/" |
| 6 | "ioscip-go gomod github.com/golang/go/src . io/" |
| 7 | "osscip-go gomod github.com/golang/go/src . os/" |
| 8 | "os/signalscip-go gomod github.com/golang/go/src . `os/signal`/" |
| 9 | "slicesscip-go gomod github.com/golang/go/src . slices/" |
| 10 | "strconvscip-go gomod github.com/golang/go/src . strconv/" |
| 11 | |
| 12 | "github.com/nicholas-fedor/shoutrrr/pkg/formatscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/" |
| 13 | "github.com/nicholas-fedor/shoutrrr/pkg/typesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/" |
| 14 | "github.com/nicholas-fedor/shoutrrr/pkg/util/generatorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/generator`/" |
| 15 | ) |
| 16 | |
| 17 | // Generator facilitates Telegram-specific URL generation via user interaction. |
| 18 | type Generatorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Generator# struct { |
| 19 | userDialogscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Generator#userDialog. *generatorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/generator`/.UserDialogscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/generator`/UserDialog# |
| 20 | clientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Generator#client. *Clientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Client# |
| 21 | chatsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Generator#chats. []string |
| 22 | chatNamesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Generator#chatNames. []string |
| 23 | chatTypesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Generator#chatTypes. []string |
| 24 | donescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Generator#done. bool |
| 25 | botNamescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Generator#botName. string |
| 26 | Readerscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Generator#Reader. ioscip-go gomod github.com/golang/go/src . io/.Readerscip-go gomod github.com/golang/go/src . io/Reader# |
| 27 | Writerscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Generator#Writer. ioscip-go gomod github.com/golang/go/src . io/.Writerscip-go gomod github.com/golang/go/src . io/Writer# |
| 28 | } |
| 29 | |
| 30 | // UpdatesLimit defines the number of updates to retrieve per API call. |
| 31 | const ( |
| 32 | UpdatesLimitscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/UpdatesLimit. = 10 // Number of updates to retrieve per call |
| 33 | UpdatesTimeoutscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/UpdatesTimeout. = 120 // Timeout in seconds for long polling |
| 34 | ) |
| 35 | |
| 36 | // ErrNoChatsSelected indicates that no chats were selected during generation. |
| 37 | var ( |
| 38 | ErrNoChatsSelectedscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/ErrNoChatsSelected. = errorsscip-go gomod github.com/golang/go/src . errors/.Newscip-go gomod github.com/golang/go/src . errors/New().("no chats were selected") |
| 39 | ) |
| 40 | |
| 41 | // Generate creates a Telegram Shoutrrr configuration from user dialog input. |
| 42 | func (g *Generatorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Generator#) Generatescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Generator#Generate().( |
| 43 | _ typesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/.Servicescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/Service#, |
| 44 | props map[string]string, |
| 45 | _ []string, |
| 46 | ) (typesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/.ServiceConfigscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/ServiceConfig#, error) { |
| 47 | var config Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Config# |
| 48 | |
| 49 | if g.Readerscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Generator#Reader. == nil { |
| 50 | g.Readerscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Generator#Reader. = osscip-go gomod github.com/golang/go/src . os/.Stdinscip-go gomod github.com/golang/go/src . os/Stdin. |
| 51 | } |
| 52 | |
| 53 | if g.Writerscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Generator#Writer. == nil { |
| 54 | g.Writerscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Generator#Writer. = osscip-go gomod github.com/golang/go/src . os/.Stdoutscip-go gomod github.com/golang/go/src . os/Stdout. |
| 55 | } |
| 56 | |
| 57 | g.userDialogscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Generator#userDialog. = generatorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/generator`/.NewUserDialogscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/generator`/NewUserDialog().(g.Readerscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Generator#Reader., g.Writerscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Generator#Writer., props) |
| 58 | userDialog := g.userDialogscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Generator#userDialog. |
| 59 | |
| 60 | userDialog.Writelnfscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/generator`/UserDialog#Writelnf().( |
| 61 | "To start we need your bot token. If you haven't created a bot yet, you can use this link:", |
| 62 | ) |
| 63 | userDialog.Writelnfscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/generator`/UserDialog#Writelnf().(" %v", formatscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/.ColorizeLinkscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/ColorizeLink.("https://t.me/botfather?start")) |
| 64 | userDialog.Writelnfscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/generator`/UserDialog#Writelnf().("") |
| 65 | |
| 66 | token := userDialog.QueryStringscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/generator`/UserDialog#QueryString().( |
| 67 | "Enter your bot token:", |
| 68 | generatorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/generator`/.ValidateFormatscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/generator`/ValidateFormat().(IsTokenValidscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/IsTokenValid().), |
| 69 | "token", |
| 70 | ) |
| 71 | |
| 72 | userDialog.Writelnfscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/generator`/UserDialog#Writelnf().("Fetching bot info...") |
| 73 | |
| 74 | g.clientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Generator#client. = &Clientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Client#{ |
| 75 | tokenscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Client#token.: token, |
| 76 | httpClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Client#httpClient.: nil, |
| 77 | } |
| 78 | |
| 79 | botInfo, err := g.clientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Generator#client..GetBotInfoscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Client#GetBotInfo().() |
| 80 | if err != nil { |
| 81 | return &Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Config#{}, err |
| 82 | } |
| 83 | |
| 84 | g.botNamescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Generator#botName. = botInfo.Usernamescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/User#Username. |
| 85 | |
| 86 | userDialog.Writelnfscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/generator`/UserDialog#Writelnf().("") |
| 87 | userDialog.Writelnfscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/generator`/UserDialog#Writelnf().( |
| 88 | "Okay! %v will listen for any messages in PMs and group chats it is invited to.", |
| 89 | formatscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/.ColorizeStringscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/ColorizeString.("@", g.botNamescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Generator#botName.), |
| 90 | ) |
| 91 | |
| 92 | g.donescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Generator#done. = false |
| 93 | lastUpdate := 0 |
| 94 | |
| 95 | signals := make(chan osscip-go gomod github.com/golang/go/src . os/.Signalscip-go gomod github.com/golang/go/src . os/Signal#, 1) |
| 96 | |
| 97 | // Subscribe to system signals for graceful shutdown |
| 98 | signalscip-go gomod github.com/golang/go/src . `os/signal`/.Notifyscip-go gomod github.com/golang/go/src . `os/signal`/Notify().(signals, osscip-go gomod github.com/golang/go/src . os/.Interruptscip-go gomod github.com/golang/go/src . os/Interrupt.) |
| 99 | |
| 100 | for !g.donescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Generator#done. { |
| 101 | userDialog.Writelnfscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/generator`/UserDialog#Writelnf().("Waiting for messages to arrive...") |
| 102 | |
| 103 | updates, err := g.clientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Generator#client..GetUpdatesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Client#GetUpdates().( |
| 104 | lastUpdate, |
| 105 | UpdatesLimitscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/UpdatesLimit., |
| 106 | UpdatesTimeoutscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/UpdatesTimeout., |
| 107 | nil, |
| 108 | ) |
| 109 | if err != nil { |
| 110 | panic(err) |
| 111 | } |
| 112 | |
| 113 | // If no updates were retrieved, prompt user to continue |
| 114 | promptDone := len(updates) == 0 |
| 115 | |
| 116 | for _, update := range updates { |
| 117 | lastUpdate = update.UpdateIDscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Update#UpdateID. + 1 |
| 118 | |
| 119 | switch { |
| 120 | case update.Messagescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Update#Message. != nil || update.ChannelPostscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Update#ChannelPost. != nil: |
| 121 | message := update.Messagescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Update#Message. |
| 122 | if update.ChannelPostscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Update#ChannelPost. != nil { |
| 123 | message = update.ChannelPostscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Update#ChannelPost. |
| 124 | } |
| 125 | |
| 126 | chat := message.Chatscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Message#Chat. |
| 127 | |
| 128 | source := message.Chatscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Message#Chat..Namescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Chat#Name().() |
| 129 | if message.Fromscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Message#From. != nil { |
| 130 | source = "@" + message.Fromscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Message#From..Usernamescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/User#Username. |
| 131 | } |
| 132 | |
| 133 | userDialog.Writelnfscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/generator`/UserDialog#Writelnf().("Got Message '%v' from %v in %v chat %v", |
| 134 | formatscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/.ColorizeStringscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/ColorizeString.(message.Textscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Message#Text.), |
| 135 | formatscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/.ColorizePropscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/ColorizeProp.(source), |
| 136 | formatscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/.ColorizeEnumscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/ColorizeEnum.(chat.Typescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Chat#Type.), |
| 137 | formatscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/.ColorizeNumberscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/ColorizeNumber.(chat.IDscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Chat#ID.)) |
| 138 | userDialog.Writelnfscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/generator`/UserDialog#Writelnf().(g.addChatscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Generator#addChat().(chat)) |
| 139 | // Another chat was added, prompt user to continue |
| 140 | promptDone = true |
| 141 | |
| 142 | case update.ChatMemberUpdatescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Update#ChatMemberUpdate. != nil: |
| 143 | cmu := update.ChatMemberUpdatescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Update#ChatMemberUpdate. |
| 144 | oldStatus := cmu.OldChatMemberscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/ChatMemberUpdate#OldChatMember..Statusscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/ChatMember#Status. |
| 145 | newStatus := cmu.NewChatMemberscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/ChatMemberUpdate#NewChatMember..Statusscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/ChatMember#Status. |
| 146 | userDialog.Writelnfscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/generator`/UserDialog#Writelnf().( |
| 147 | "Got a bot chat member update for %v, status was changed from %v to %v", |
| 148 | formatscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/.ColorizePropscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/ColorizeProp.(cmu.Chatscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/ChatMemberUpdate#Chat..Namescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Chat#Name().()), |
| 149 | formatscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/.ColorizeEnumscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/ColorizeEnum.(oldStatus), |
| 150 | formatscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/.ColorizeEnumscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/ColorizeEnum.(newStatus), |
| 151 | ) |
| 152 | |
| 153 | default: |
| 154 | userDialog.Writelnfscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/generator`/UserDialog#Writelnf().("Got unknown Update. Ignored!") |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | if promptDone { |
| 159 | userDialog.Writelnfscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/generator`/UserDialog#Writelnf().("") |
| 160 | |
| 161 | g.donescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Generator#done. = !userDialog.QueryBoolscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/generator`/UserDialog#QueryBool().( |
| 162 | fmtscip-go gomod github.com/golang/go/src . fmt/.Sprintfscip-go gomod github.com/golang/go/src . fmt/Sprintf().("Got %v chat ID(s) so far. Want to add some more?", |
| 163 | formatscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/.ColorizeNumberscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/ColorizeNumber.(len(g.chatsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Generator#chats.))), |
| 164 | "", |
| 165 | ) |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | userDialog.Writelnfscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/generator`/UserDialog#Writelnf().("") |
| 170 | userDialog.Writelnfscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/generator`/UserDialog#Writelnf().("Cleaning up the bot session...") |
| 171 | |
| 172 | // Notify API that we got the updates |
| 173 | if _, err = g.clientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Generator#client..GetUpdatesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Client#GetUpdates().(lastUpdate, 0, 0, nil); err != nil { |
| 174 | g.userDialogscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Generator#userDialog..Writelnfscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/generator`/UserDialog#Writelnf().( |
| 175 | "Failed to mark last updates as received: %v", |
| 176 | formatscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/.ColorizeErrorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/ColorizeError.(err), |
| 177 | ) |
| 178 | } |
| 179 | |
| 180 | if len(g.chatsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Generator#chats.) < 1 { |
| 181 | return nil, ErrNoChatsSelectedscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/ErrNoChatsSelected. |
| 182 | } |
| 183 | |
| 184 | userDialog.Writelnfscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/generator`/UserDialog#Writelnf().("Selected chats:") |
| 185 | |
| 186 | for i, id := range g.chatsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Generator#chats. { |
| 187 | name := g.chatNamesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Generator#chatNames.[i] |
| 188 | chatType := g.chatTypesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Generator#chatTypes.[i] |
| 189 | userDialog.Writelnfscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/generator`/UserDialog#Writelnf().( |
| 190 | " %v (%v) %v", |
| 191 | formatscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/.ColorizeNumberscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/ColorizeNumber.(id), |
| 192 | formatscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/.ColorizeEnumscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/ColorizeEnum.(chatType), |
| 193 | formatscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/.ColorizeStringscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/ColorizeString.(name), |
| 194 | ) |
| 195 | } |
| 196 | |
| 197 | userDialog.Writelnfscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/generator`/UserDialog#Writelnf().("") |
| 198 | |
| 199 | config = Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Config#{ |
| 200 | Notificationscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Config#Notification.: true, |
| 201 | Tokenscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Config#Token.: token, |
| 202 | Chatsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Config#Chats.: g.chatsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Generator#chats., |
| 203 | } |
| 204 | |
| 205 | return &config, nil |
| 206 | } |
| 207 | |
| 208 | // addChat adds a chat to the generator's list if it’s not already present. |
| 209 | func (g *Generatorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Generator#) addChatscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Generator#addChat().(chat *Chatscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Chat#) string { |
| 210 | chatID := strconvscip-go gomod github.com/golang/go/src . strconv/.FormatIntscip-go gomod github.com/golang/go/src . strconv/FormatInt().(chat.IDscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Chat#ID., 10) |
| 211 | name := chat.Namescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Chat#Name().() |
| 212 | |
| 213 | if slicesscip-go gomod github.com/golang/go/src . slices/.Containsscip-go gomod github.com/golang/go/src . slices/Contains().(g.chatsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Generator#chats., chatID) { |
| 214 | return fmtscip-go gomod github.com/golang/go/src . fmt/.Sprintfscip-go gomod github.com/golang/go/src . fmt/Sprintf().("chat %v is already selected!", formatscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/.ColorizeStringscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/ColorizeString.(name)) |
| 215 | } |
| 216 | |
| 217 | g.chatsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Generator#chats. = append(g.chatsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Generator#chats., chatID) |
| 218 | g.chatNamesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Generator#chatNames. = append(g.chatNamesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Generator#chatNames., name) |
| 219 | g.chatTypesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Generator#chatTypes. = append(g.chatTypesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Generator#chatTypes., chat.Typescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/chat/telegram`/Chat#Type.) |
| 220 | |
| 221 | return fmtscip-go gomod github.com/golang/go/src . fmt/.Sprintfscip-go gomod github.com/golang/go/src . fmt/Sprintf().("Added new chat %v!", formatscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/.ColorizeStringscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/format`/ColorizeString.(name)) |
| 222 | } |