Skip to content

Commit

Permalink
docs gen by tlparser.
Browse files Browse the repository at this point in the history
  • Loading branch information
AmarnathCJD committed Sep 18, 2024
1 parent a016008 commit 3a888ac
Show file tree
Hide file tree
Showing 9 changed files with 2,861 additions and 2,414 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ If you'd like to support Gogram, you can consider:
<li><strong>up-to-date</strong>: 🔄 gogram is always in sync with the latest telegram api changes and additions (<code>tl-parser</code> is used to generate the api layer).</li>
</ul>

#### Current Layer - **187** (Updated on 2024-09-07)
#### Current Layer - **187** (Updated on 2024-09-18)

## doing stuff

Expand Down
19 changes: 18 additions & 1 deletion internal/cmd/tlgen/gen/tl_gen_interfaces.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package gen

import (
"regexp"
"sort"
"sync"

Expand Down Expand Up @@ -53,7 +54,23 @@ func (g *Generator) generateInterfaces(f *jen.File, d bool) {
wg.Add(1)
go func(_type tlparser.Object, i int) {
defer wg.Done()
structs[i].Comment = g.generateComment(_type.Name, "constructor")
comment, pComments := g.generateComment(_type.Name, "constructor")
structs[i].Comment = comment

if pComments != nil && len(pComments) == len(_type.Parameters) {
for j := range _type.Parameters {
pComments[j] = regexp.MustCompile(`(?i)<a\s+href="([^"]+)"\s*>([^<]+)</a>`).ReplaceAllString(pComments[j], "$2")
pComments[j] = regexp.MustCompile(`(?i)<strong>([^<]+)</strong>`).ReplaceAllString(pComments[j], "$1")
pComments[j] = regexp.MustCompile(`\[(.+)\]\(.+\)`).ReplaceAllString(pComments[j], "$1")
pComments[j] = regexp.MustCompile(`(?i)see here[^.]*`).ReplaceAllString(pComments[j], "")
pComments[j] = regexp.MustCompile(`(?i)<code>([^<]+)</code>`).ReplaceAllString(pComments[j], "'$1'")
pComments[j] = regexp.MustCompile(`(?i)<br>`).ReplaceAllString(pComments[j], "\n")
pComments[j] = regexp.MustCompile(`(?i)»`).ReplaceAllString(pComments[j], "")
pComments[j] = regexp.MustCompile(`(?i)\s+\.`).ReplaceAllString(pComments[j], ".")
pComments[j] = regexp.MustCompile(`(?i),\s*$`).ReplaceAllString(pComments[j], "")
structs[i].Parameters[j].Comment = pComments[j]
}
}
}(_type, i)
}

Expand Down
26 changes: 19 additions & 7 deletions internal/cmd/tlgen/gen/tl_gen_methods.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package gen

import (
"fmt"
"io"
"net/http"
"regexp"
Expand All @@ -26,7 +27,7 @@ func (g *Generator) generateMethods(f *jen.File, d bool) {
wg.Add(1)
go func(method tlparser.Method, i int) {
defer wg.Done()
g.schema.Methods[i].Comment = g.generateComment(method.Name, "method")
g.schema.Methods[i].Comment, _ = g.generateComment(method.Name, "method")
}(method, i)
}

Expand Down Expand Up @@ -65,25 +66,36 @@ func (g *Generator) generateMethods(f *jen.File, d bool) {
// }
}

func (g *Generator) generateComment(name, _type string) string {
func (g *Generator) generateComment(name, _type string) (string, []string) {
var base = "https://core.telegram.org/" + _type + "/"
fmt.Println(base + name)
req, _ := http.NewRequest("GET", base+name, http.NoBody)

resp, err := http.DefaultClient.Do(req)
if err != nil {
return ""
return "", nil
}

if resp.StatusCode != 200 {
return ""
return "", nil
}

body, err := io.ReadAll(resp.Body)
if err != nil {
return ""
return "", nil
}

ack := string(body)
re := regexp.MustCompile(`<td style="text-align: center;">.*?</td>\s*<td>(.*?)</td>`)

matches := re.FindAllStringSubmatch(ack, -1)

var descs []string

for _, match := range matches {
descs = append(descs, match[1])
}

ack = strings.Split(ack, "<div id=\"dev_page_content\">")[1]
ack = strings.Split(ack, "</p>")[0]
ack = strings.ReplaceAll(ack, "<p>", "")
Expand All @@ -97,10 +109,10 @@ func (g *Generator) generateComment(name, _type string) string {
ack = strings.TrimSpace(ack)

if strings.Contains(ack, "The page has not been saved") {
return ""
return "", nil
}

return ack
return ack, descs
}

func (g *Generator) generateMethodFunction(obj *tlparser.Method) jen.Code {
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/tlgen/gen/tl_gen_structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func (g *Generator) generateSpecificStructs(f *jen.File, d bool) {
wg.Add(1)
go func(_type tlparser.Object, i int) {
defer wg.Done()
g.schema.SingleInterfaceTypes[i].Comment = g.generateComment(_type.Name, "constructor")
g.schema.SingleInterfaceTypes[i].Comment, _ = g.generateComment(_type.Name, "constructor")
}(_type, i)
}

Expand Down
Loading

0 comments on commit 3a888ac

Please sign in to comment.