├── LICENSE ├── github-link-bot ├── go.mod ├── go.sum └── main.go /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 hamidreza ghahremani 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /github-link-bot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hamidreza01/github-link-bot/966bfab757716a20d1eb2a37ed96182905df6f01/github-link-bot -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github-link-bot 2 | 3 | go 1.19 4 | 5 | require github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1 // indirect 6 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1 h1:wG8n/XJQ07TmjbITcGiUaOtXxdrINDz1b0J1w0SzqDc= 2 | github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1/go.mod h1:A2S0CWkNylc2phvKXWBBdD3K0iGnDBGbzRpISP2zBl8= 3 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "net/url" 6 | "os" 7 | "strings" 8 | 9 | telegram "github.com/go-telegram-bot-api/telegram-bot-api/v5" 10 | ) 11 | 12 | func main() { 13 | bot, err := telegram.NewBotAPI(os.Getenv("TOKEN")) 14 | e(1, err) 15 | u := telegram.NewUpdate(0) 16 | u.Timeout = 60 17 | updates := bot.GetUpdatesChan(u) 18 | for update := range updates { 19 | if update.Message != nil { 20 | if update.Message.Chat.ID != -1001765800269 { 21 | continue 22 | } 23 | go messageHandler(bot, update) 24 | } 25 | } 26 | } 27 | 28 | func messageHandler(bot *telegram.BotAPI, update telegram.Update) { 29 | if len(update.Message.Text) < 60 { 30 | u, err := url.ParseRequestURI(update.Message.Text) 31 | delete := false 32 | if err != nil { 33 | delete = true 34 | } else if u.Host = strings.ToLower(u.Host); u.Host != "github.com" && u.Host != "www.github.com" { 35 | delete = true 36 | } 37 | if delete { 38 | del := telegram.NewDeleteMessage(update.Message.Chat.ID, update.Message.MessageID) 39 | bot.Send(del) 40 | } 41 | } else { 42 | del := telegram.NewDeleteMessage(update.Message.Chat.ID, update.Message.MessageID) 43 | bot.Send(del) 44 | } 45 | 46 | } 47 | 48 | func e(id int, err error) { 49 | if err != nil { 50 | fmt.Println(id, ":", err) 51 | } 52 | } 53 | --------------------------------------------------------------------------------