Created
January 4, 2025 03:01
-
-
Save Madh93/f19bffaec6fd767fd690b01473f4fe65 to your computer and use it in GitHub Desktop.
Original implementation of https://github.com/Madh93/instaray
This file contains hidden or 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
package main | |
import ( | |
"log" | |
"os" | |
"strings" | |
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5" | |
) | |
func main() { | |
bot, err := tgbotapi.NewBotAPI(os.Getenv("TELEGRAM_BOT_TOKEN")) | |
if err != nil { | |
log.Panic(err) | |
} | |
log.Printf("%s is ready for the action", bot.Self.UserName) | |
bot.Debug = false | |
u := tgbotapi.NewUpdate(0) | |
u.Timeout = 60 | |
updates := bot.GetUpdatesChan(u) | |
for update := range updates { | |
if update.Message != nil { // If we got a message | |
text := update.Message.Text | |
log.Printf("[%s] New message", update.Message.From.UserName) | |
// Tokenize msg in words | |
for _, word := range strings.Fields(text) { | |
var fixed string | |
// Filter | |
switch { | |
case strings.Contains(word, "www.instagram.com"): | |
fixed = strings.ReplaceAll(word, "www.instagram.com", "www.ddinstagram.com") | |
case strings.Contains(word, "https://twitter.com"): | |
fixed = strings.ReplaceAll(word, "https://twitter.com", "https://fxtwitter.com") | |
case strings.Contains(word, "https://x.com"): | |
fixed = strings.ReplaceAll(word, "https://x.com", "https://fixupx.com") | |
} | |
// Send back | |
if fixed != "" { | |
msg := tgbotapi.NewMessage(update.Message.Chat.ID, fixed) | |
bot.Send(msg) | |
log.Printf("[%s] %s", bot.Self.UserName, fixed) | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment