├── README.md └── main.go /README.md: -------------------------------------------------------------------------------- 1 | # DisTee ( Discord Tee ) 2 | 3 |

4 | 5 | 6 | 7 |

8 | 9 | DisTee is a GO tool that works like tee command, Feed input to distee through the stdin. 10 | 11 | Crafted By : github.com/vsec7 12 | 13 | 14 | ## Installation 15 | ``` 16 | go install -v github.com/vsec7/distee@latest 17 | ``` 18 | 19 | ## Setup Configuration 20 | ``` 21 | distee -setup 22 | ``` 23 | 24 | ## Basic Usage : 25 | ``` 26 | ▶ echo "Hello Cath" | distee 27 | ▶ cat file.txt | distee -c 28 | ▶ cat file.txt | distee -c -t -code 29 | 30 | Options : 31 | -setup, --setup Setup Configuration 32 | -c, --c <channel_id> Send message to custom channel_id 33 | -t, --t <title> Send message with title 34 | -code, --code Send message with code markdown 35 | -config, --config <config.yaml> Set custom config.yaml location 36 | ``` 37 | 38 | ## General Questions 39 | 40 | [?] How to find the token ? <a href="https://www.writebots.com/discord-bot-token/"> READ HERE </a> 41 | 42 | [?] How to find the channel id ? 43 | 44 | https://discord.com/channels/8173952126616XXXXX/<8174070495026XXXXX> <= Channel ID 45 | 46 | ## Dependencies 47 | - github.com/bwmarrin/discordgo 48 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "gopkg.in/yaml.v2" 5 | "bufio" 6 | "os/user" 7 | "fmt" 8 | "io/ioutil" 9 | "os" 10 | "flag" 11 | "strings" 12 | "github.com/logrusorgru/aurora" 13 | "github.com/bwmarrin/discordgo" 14 | ) 15 | 16 | var ( 17 | Setup bool 18 | Code bool 19 | tok string 20 | chid string 21 | path string 22 | cfg string 23 | Channel_id string 24 | msgs string 25 | ConfigFile string 26 | Title string 27 | config Config 28 | ) 29 | 30 | type Config struct { 31 | Token string `yaml:"token"` 32 | DefChan string `yaml:"default_channel_id"` 33 | } 34 | 35 | func init() { 36 | flag.BoolVar(&Setup, "setup", false, "Setup Configuration") 37 | flag.StringVar(&Channel_id, "c", "", "Channel ID") 38 | flag.StringVar(&Title, "t", "", "Title") 39 | flag.BoolVar(&Code, "code", false, "Code") 40 | flag.StringVar(&ConfigFile, "config", "", "Configuration File") 41 | flag.Usage = func() { 42 | h := []string{ 43 | "", 44 | "DisTee (Discord Tee)", 45 | "", 46 | "Is a GO tool that works like tee command", 47 | "Feed input to Discord through the stdin", 48 | "", 49 | "Crafted By : github.com/vsec7", 50 | "", 51 | "Basic Usage :", 52 | " ▶ echo \"Hello Cath\" | distee", 53 | " ▶ cat file.txt | distee -c <channel_id>", 54 | " ▶ cat file.txt | distee -c <channel_id> -t <title> -code", 55 | "", 56 | "Options :", 57 | " -setup, --setup Setup Configuration", 58 | " -c, --c <channel_id> Send message to custom channel_id", 59 | " -t, --t <title> Send message with title", 60 | " -code, --code Send message with code markdown", 61 | " -config, --config <config.yaml> Set custom config.yaml location", 62 | "", 63 | "", 64 | } 65 | fmt.Fprintf(os.Stderr, strings.Join(h, "\n")) 66 | } 67 | flag.Parse() 68 | } 69 | 70 | func Chunks(s string, chunkSize int) []string { 71 | if chunkSize >= len(s) { 72 | return []string{s} 73 | } 74 | var chunks []string 75 | chunk := make([]rune, chunkSize) 76 | len := 0 77 | for _, r := range s { 78 | chunk[len] = r 79 | len++ 80 | if len == chunkSize { 81 | chunks = append(chunks, string(chunk)) 82 | len = 0 83 | } 84 | } 85 | if len > 0 { 86 | chunks = append(chunks, string(chunk[:len])) 87 | } 88 | return chunks 89 | } 90 | 91 | func main() { 92 | usr, err := user.Current() 93 | if err != nil { 94 | fmt.Println( err ) 95 | } 96 | 97 | path := usr.HomeDir+"/.distee" 98 | if _, err := os.Stat(path); os.IsNotExist(err) { 99 | os.Mkdir(path, 0755) 100 | } 101 | 102 | if Setup == true { 103 | fmt.Println("----------[ Setup Configuration ]----------") 104 | fmt.Println("[?] Enter Discord BOT Token: ") 105 | fmt.Scanln(&tok) 106 | fmt.Println("[?] Enter Default Channel ID : *Optional") 107 | fmt.Scanln(&chid) 108 | 109 | file, err := os.OpenFile(path+"/config.yaml", os.O_WRONLY|os.O_CREATE, 0644) 110 | if err != nil { 111 | fmt.Printf("Failed Creating File: %s", err) 112 | os.Exit(0) 113 | } 114 | buf := bufio.NewWriter(file) 115 | buf.WriteString("token: "+tok+"\ndefault_channel_id: "+chid+"\n" ) 116 | buf.Flush() 117 | file.Close() 118 | fmt.Println("----------[ Configuration Saved ]----------") 119 | os.Exit(0) 120 | } 121 | 122 | if len(ConfigFile) != 0 { 123 | cfg = ConfigFile 124 | }else{ 125 | cfg = path+"/config.yaml" 126 | } 127 | 128 | yamlFile, err := ioutil.ReadFile(cfg) 129 | if err != nil { 130 | fmt.Printf("[%s] File config.yaml not found!\n", aurora.Red("ERROR")) 131 | os.Exit(0) 132 | } 133 | 134 | err = yaml.Unmarshal(yamlFile, &config) 135 | if err != nil { 136 | fmt.Printf("[%s] Cannot parsing config.yaml!\n", aurora.Red("ERROR")) 137 | os.Exit(0) 138 | } 139 | 140 | if len(Channel_id) != 0 { 141 | Channel_id = Channel_id 142 | } else { 143 | Channel_id = config.DefChan 144 | } 145 | 146 | dg, _ := discordgo.New("Bot "+ config.Token ) 147 | fi, _ := os.Stdin.Stat() 148 | 149 | if (fi.Mode() & os.ModeCharDevice) == 0 { 150 | bytes, _ := ioutil.ReadAll(os.Stdin) 151 | str := string(bytes) 152 | 153 | cs := Chunks(str, 1900) 154 | for _, c := range cs { 155 | 156 | if Code == true { 157 | msgs = "```\n" + c + "\n```" 158 | } else { 159 | msgs = "" + c + "" 160 | } 161 | 162 | if len(Title) != 0 { 163 | msgs = "> " + Title + "\n" + msgs + "" 164 | } else { 165 | msgs = "" + msgs + "" 166 | } 167 | _, err := dg.ChannelMessageSend(Channel_id, msgs) 168 | if err != nil { 169 | fmt.Printf("[%s] Failed to send message !\n%s\n", aurora.Red("ERROR"), err) 170 | os.Exit(0) 171 | } 172 | } 173 | 174 | fmt.Printf(str) 175 | } 176 | } 177 | --------------------------------------------------------------------------------