package main import ( "fmt" "html" "strings" "text/tabwriter" tele "gopkg.in/telebot.v3" "git.gensokyo.cafe/kkyy/tgbot_misaka_5882f7/hostcmds" ) func handleDigCmd(c tele.Context) error { msg := c.Message() if msg == nil { return nil } req, err := hostcmds.NewDigRequest(msg.Payload) if err != nil { return c.Reply( "Invalid arguments.\nUsage: `/dig [type]`", &tele.SendOptions{ParseMode: tele.ModeMarkdown}, tele.Silent, ) } resp, err := hostcmds.Dig(req) if err != nil { _ = c.Reply(stickerFromID(stickerPanic), tele.Silent) return err } replyBuf := &strings.Builder{} tw := tabwriter.NewWriter(replyBuf, 0, 0, 2, ' ', 0) // Write header if len(resp.Records) > 0 { _, _ = tw.Write([]byte("Name\tTTL\tType\tData\n")) } // Write data for _, r := range resp.Records { _, _ = fmt.Fprintf(tw, "%s\t%d\t%s\t%s\n", r.Name, r.TTL, r.Type, r.Data) } _ = tw.Flush() replyText := []string{ fmt.Sprintf("Status: %s\n", resp.Status), fmt.Sprintf("Query Time: %s\n\n", resp.QueryTime), "
",
		html.EscapeString(replyBuf.String()),
		"
", } return c.Reply(strings.Join(replyText, ""), &tele.SendOptions{ParseMode: tele.ModeHTML}, tele.Silent) }