initial commit
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
Copyright © 2023 Jonas Möller <mail@jonasmoeller.de>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/spf13/viper"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// initConfigCmd represents the initConfig command
|
||||
var initConfigCmd = &cobra.Command{
|
||||
Use: "initConfig",
|
||||
Short: "Initialize config file",
|
||||
Long: `Creates the config file at default destination with default values.`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
viper.Set("spotify_callback_listen_port", ":8888")
|
||||
viper.Set("spotify_callback_redirect_url", "http://localhost:8888/callback")
|
||||
viper.Set("spotify_client_id", "")
|
||||
viper.Set("spotify_client_secret", "")
|
||||
viper.Set("spotify_playlist_id", "")
|
||||
viper.Set("telegram_api_token", "")
|
||||
viper.Set("telegram_debug", false)
|
||||
viper.Set("telegram_group_id", "")
|
||||
|
||||
if err := viper.SafeWriteConfig(); err != nil {
|
||||
cobra.CheckErr(err)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(initConfigCmd)
|
||||
|
||||
// Here you will define your flags and configuration settings.
|
||||
|
||||
// Cobra supports Persistent Flags which will work for this command
|
||||
// and all subcommands, e.g.:
|
||||
// initConfigCmd.PersistentFlags().String("foo", "", "A help for foo")
|
||||
|
||||
// Cobra supports local flags which will only run when this command
|
||||
// is called directly, e.g.:
|
||||
// initConfigCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
|
||||
}
|
||||
+90
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
Copyright © 2023 Jonas Möller <mail@jonasmoeller.de>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
var cfgFile string
|
||||
|
||||
// rootCmd represents the base command when called without any subcommands
|
||||
var rootCmd = &cobra.Command{
|
||||
Use: "spotigram",
|
||||
Short: "A Telegram to Spotify bridge",
|
||||
Long: `"spotigram" bridges a telegram group chat to Spotify.
|
||||
|
||||
The main functionality is to take messages addressed to a specific command of the telegram bot and add the
|
||||
first track of Spotify's search results to a specific playlist.
|
||||
This is a hobbyist program with no real world purpose other than fulfilling a very specific task.`,
|
||||
// Uncomment the following line if your bare application
|
||||
// has an action associated with it:
|
||||
// Run: func(cmd *cobra.Command, args []string) { },
|
||||
}
|
||||
|
||||
// Execute adds all child commands to the root command and sets flags appropriately.
|
||||
// This is called by main.main(). It only needs to happen once to the rootCmd.
|
||||
func Execute() {
|
||||
err := rootCmd.Execute()
|
||||
if err != nil {
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func init() {
|
||||
cobra.OnInitialize(initConfig)
|
||||
|
||||
// Here you will define your flags and configuration settings.
|
||||
// Cobra supports persistent flags, which, if defined here,
|
||||
// will be global for your application.
|
||||
|
||||
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.spotigram.yaml)")
|
||||
|
||||
}
|
||||
|
||||
// initConfig reads in config file and ENV variables if set.
|
||||
func initConfig() {
|
||||
if cfgFile != "" {
|
||||
// Use config file from the flag.
|
||||
viper.SetConfigFile(cfgFile)
|
||||
} else {
|
||||
// Find home directory.
|
||||
home, err := os.UserHomeDir()
|
||||
cobra.CheckErr(err)
|
||||
|
||||
// Search config in home directory with name ".spotigram" (without extension).
|
||||
viper.AddConfigPath(home)
|
||||
viper.SetConfigType("yaml")
|
||||
viper.SetConfigName(".spotigram")
|
||||
}
|
||||
|
||||
viper.AutomaticEnv() // read in environment variables that match
|
||||
|
||||
// If a config file is found, read it in.
|
||||
if err := viper.ReadInConfig(); err == nil {
|
||||
fmt.Fprintln(os.Stderr, "Using config file:", viper.ConfigFileUsed())
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
Copyright © 2023 Jonas Möller <mail@jonasmoeller.de>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/dchest/uniuri"
|
||||
"github.com/spf13/viper"
|
||||
"github.com/zmb3/spotify/v2"
|
||||
spotifyauth "github.com/zmb3/spotify/v2/auth"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// spotifyAuthCmd represents the spotifyAuth command
|
||||
var spotifyAuthCmd = &cobra.Command{
|
||||
Use: "spotifyAuth",
|
||||
Short: "Authenticate your Spotify account",
|
||||
Long: `Authenticate spotigram to access your Spotify account.
|
||||
|
||||
This will add the client configuration for Spotify to your config file.
|
||||
It is meant to run just once for initialization.
|
||||
|
||||
You can also use this command to recover your config with a new set of client credentials.
|
||||
|
||||
Client credentials for the Spotify application must be present as environment variables:
|
||||
"SPOTIFY_CLIENT_ID" and "SPOTIFY_CLIENT_SECRET".`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
spotifyLogin()
|
||||
},
|
||||
}
|
||||
var (
|
||||
auth = spotifyauth.New()
|
||||
ch = make(chan *spotify.Client)
|
||||
state = uniuri.New()
|
||||
)
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(spotifyAuthCmd)
|
||||
|
||||
// Here you will define your flags and configuration settings.
|
||||
|
||||
// Cobra supports Persistent Flags which will work for this command
|
||||
// and all subcommands, e.g.:
|
||||
// spotifyAuthCmd.PersistentFlags().String("foo", "", "A help for foo")
|
||||
|
||||
// Cobra supports local flags which will only run when this command
|
||||
// is called directly, e.g.:
|
||||
// spotifyAuthCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
|
||||
}
|
||||
|
||||
func spotifyLogin() {
|
||||
viper.SetDefault("spotify_callback_listen_port", ":8888")
|
||||
viper.SetDefault("spotify_callback_redirect_url", "http://localhost:8888/callback")
|
||||
|
||||
auth = spotifyauth.New(spotifyauth.WithRedirectURL(viper.GetString("spotify_callback_redirect_url")),
|
||||
spotifyauth.WithScopes(spotifyauth.ScopePlaylistModifyPublic),
|
||||
spotifyauth.WithClientID(viper.GetString("spotify_client_id")),
|
||||
spotifyauth.WithClientSecret(viper.GetString("spotify_client_secret")),
|
||||
)
|
||||
|
||||
http.HandleFunc("/callback", completeAuth)
|
||||
http.HandleFunc("/", func(writer http.ResponseWriter, request *http.Request) {
|
||||
log.Println("Got request for ", request.URL.String())
|
||||
})
|
||||
|
||||
go func() {
|
||||
err := http.ListenAndServe(viper.GetString("spotify_callback_listen_port"), nil)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}()
|
||||
|
||||
url := auth.AuthURL(state)
|
||||
fmt.Println("Visit this URL to authenticate Spotify: ", url)
|
||||
|
||||
client := <-ch
|
||||
|
||||
token, err := client.Token()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
viper.Set("spotify_access_token", token.AccessToken)
|
||||
viper.Set("spotify_refresh_token", token.RefreshToken)
|
||||
viper.Set("spotify_token_type", token.TokenType)
|
||||
viper.Set("spotify_token_expiry", token.Expiry)
|
||||
if err = viper.WriteConfig(); err != nil {
|
||||
cobra.CheckErr(err)
|
||||
}
|
||||
|
||||
fmt.Printf("\nLogin complete ✅\n\nSession: %s\n", state)
|
||||
}
|
||||
|
||||
func completeAuth(writer http.ResponseWriter, request *http.Request) {
|
||||
token, err := auth.Token(request.Context(), state, request)
|
||||
if err != nil {
|
||||
http.Error(writer, "Could not get token.", http.StatusForbidden)
|
||||
cobra.CheckErr(err)
|
||||
}
|
||||
if st := request.FormValue("state"); st != state {
|
||||
http.NotFound(writer, request)
|
||||
log.Fatalf("State mismatch: %s != %s\n", st, state)
|
||||
}
|
||||
|
||||
client := spotify.New(auth.Client(request.Context(), token))
|
||||
_, _ = fmt.Fprintf(writer, "Login complete ✅\n\nSession: %s", state)
|
||||
ch <- client
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
Copyright © 2023 Jonas Möller <mail@jonasmoeller.de>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/spf13/viper"
|
||||
"github.com/zmb3/spotify/v2"
|
||||
spotifyauth "github.com/zmb3/spotify/v2/auth"
|
||||
"golang.org/x/oauth2"
|
||||
"log"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// spotifyPlaylistsCmd represents the spotifyPlaylists command
|
||||
var spotifyPlaylistsCmd = &cobra.Command{
|
||||
Use: "spotifyPlaylists",
|
||||
Short: "Get a list of you playlists",
|
||||
Long: `Fetches a list of your playlists with the corresponding ID.
|
||||
Take note of the desired playlist ID and add it to your config file.`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
var (
|
||||
token = new(oauth2.Token)
|
||||
auth = spotifyauth.New()
|
||||
ctx = context.Background()
|
||||
)
|
||||
// Spotify client initialization
|
||||
token.AccessToken = viper.GetString("spotify_access_token")
|
||||
token.RefreshToken = viper.GetString("spotify_refresh_token")
|
||||
token.TokenType = viper.GetString("spotify_token_type")
|
||||
token.Expiry = viper.GetTime("spotify_token_expiry")
|
||||
client := spotify.New(auth.Client(ctx, token))
|
||||
|
||||
results, err := client.CurrentUsersPlaylists(ctx, spotify.Limit(50))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return
|
||||
}
|
||||
|
||||
for i := 0; i < results.Total; i++ {
|
||||
fmt.Printf("\n%s\nID: %s\n", results.Playlists[i].Name, results.Playlists[i].ID)
|
||||
}
|
||||
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(spotifyPlaylistsCmd)
|
||||
|
||||
// Here you will define your flags and configuration settings.
|
||||
|
||||
// Cobra supports Persistent Flags which will work for this command
|
||||
// and all subcommands, e.g.:
|
||||
// spotifyPlaylistsCmd.PersistentFlags().String("foo", "", "A help for foo")
|
||||
|
||||
// Cobra supports local flags which will only run when this command
|
||||
// is called directly, e.g.:
|
||||
// spotifyPlaylistsCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
/*
|
||||
Copyright © 2023 Jonas Möller <mail@jonasmoeller.de>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
"github.com/zmb3/spotify/v2"
|
||||
spotifyauth "github.com/zmb3/spotify/v2/auth"
|
||||
"golang.org/x/oauth2"
|
||||
"log"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// telegramBotCmd represents the telegramBot command
|
||||
var telegramBotCmd = &cobra.Command{
|
||||
Use: "telegramBot",
|
||||
Short: "Start the Telegram bot",
|
||||
Long: `Start the Telegram bot which listens for new messages in the configured group chat.
|
||||
|
||||
Currently spotigram only uses a single group ID to verify the origin of the message.
|
||||
It is not planned to extend this in the future.`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
var (
|
||||
cachedToken = new(oauth2.Token)
|
||||
auth = spotifyauth.New()
|
||||
ctx = context.Background()
|
||||
)
|
||||
viper.SetDefault("telegram_debug", false)
|
||||
viper.SetDefault("telegram_update_timeout", 60)
|
||||
|
||||
// Telegram Bot
|
||||
bot, err := tgbotapi.NewBotAPI(viper.GetString("telegram_api_token"))
|
||||
if err != nil {
|
||||
cobra.CheckErr(err)
|
||||
}
|
||||
|
||||
bot.Debug = viper.GetBool("telegram_debug")
|
||||
|
||||
log.Printf("Authorized account: %s", bot.Self.UserName)
|
||||
|
||||
u := tgbotapi.NewUpdate(0)
|
||||
u.Timeout = viper.GetInt("telegram_update_timeout")
|
||||
|
||||
updates := bot.GetUpdatesChan(u)
|
||||
|
||||
for update := range updates {
|
||||
if update.Message.Chat.IsGroup() && update.Message.Chat.ID == viper.GetInt64("telegram_group_id") {
|
||||
|
||||
if update.Message == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
if !update.Message.IsCommand() {
|
||||
continue
|
||||
}
|
||||
|
||||
msg := tgbotapi.NewMessage(update.Message.Chat.ID, "")
|
||||
msg.ReplyToMessageID = update.Message.MessageID
|
||||
|
||||
switch update.Message.Command() {
|
||||
case "spotigram":
|
||||
// Spotify client initialization
|
||||
cachedToken.AccessToken = viper.GetString("spotify_access_token")
|
||||
cachedToken.RefreshToken = viper.GetString("spotify_refresh_token")
|
||||
cachedToken.TokenType = viper.GetString("spotify_token_type")
|
||||
cachedToken.Expiry = viper.GetTime("spotify_token_expiry")
|
||||
client := spotify.New(auth.Client(ctx, cachedToken))
|
||||
newToken, err := client.Token()
|
||||
if err != nil {
|
||||
cobra.CheckErr(err)
|
||||
}
|
||||
if newToken != cachedToken {
|
||||
viper.Set("spotify_access_token", newToken.AccessToken)
|
||||
viper.Set("spotify_refresh_token", newToken.RefreshToken)
|
||||
viper.Set("spotify_token_type", newToken.TokenType)
|
||||
viper.Set("spotify_token_expiry", newToken.Expiry)
|
||||
if err = viper.WriteConfig(); err != nil {
|
||||
cobra.CheckErr(err)
|
||||
}
|
||||
}
|
||||
|
||||
results, err := client.Search(ctx, strings.TrimPrefix(update.Message.Text, "/spotigram "), spotify.SearchTypeTrack)
|
||||
if err != nil {
|
||||
cobra.CheckErr(err)
|
||||
}
|
||||
if results != nil {
|
||||
track := results.Tracks.Tracks[0]
|
||||
playlist, err := client.GetPlaylist(ctx, spotify.ID(viper.GetString("spotify_playlist_id")))
|
||||
if err != nil {
|
||||
cobra.CheckErr(err)
|
||||
}
|
||||
|
||||
addTrackResponse, err := client.AddTracksToPlaylist(ctx,
|
||||
playlist.ID,
|
||||
results.Tracks.Tracks[0].ID)
|
||||
if err != nil {
|
||||
cobra.CheckErr(err)
|
||||
}
|
||||
|
||||
msg.Text = fmt.Sprintf("Ich habe den Titel <pre>%s</pre> von <pre>%s</pre> zur Playlist <pre>%s</pre> hinzugefügt.",
|
||||
track.Name,
|
||||
track.Artists[0].Name,
|
||||
playlist.Name,
|
||||
)
|
||||
msg.ParseMode = "HTML"
|
||||
if _, err := bot.Send(msg); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
fmt.Printf("New track added to playlist, snapshot: %s\n", addTrackResponse)
|
||||
|
||||
}
|
||||
case "rofl":
|
||||
msg.Text = "🤣"
|
||||
if _, err := bot.Send(msg); err != nil {
|
||||
cobra.CheckErr(err)
|
||||
}
|
||||
default:
|
||||
msg.Text = "🖕"
|
||||
if _, err := bot.Send(msg); err != nil {
|
||||
cobra.CheckErr(err)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(telegramBotCmd)
|
||||
|
||||
// Here you will define your flags and configuration settings.
|
||||
|
||||
// Cobra supports Persistent Flags which will work for this command
|
||||
// and all subcommands, e.g.:
|
||||
// telegramBotCmd.PersistentFlags().String("foo", "", "A help for foo")
|
||||
|
||||
// Cobra supports local flags which will only run when this command
|
||||
// is called directly, e.g.:
|
||||
// telegramBotCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
|
||||
}
|
||||
Reference in New Issue
Block a user