-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcount.go
More file actions
49 lines (39 loc) · 1.11 KB
/
count.go
File metadata and controls
49 lines (39 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main
import (
"strings"
"fmt"
tl "github.com/goTelegramBot/gogram"
"github.com/goTelegramBot/gogram/types"
)
func count(b tl.Bot,m *types.Message){
var message string
if m.ReplyToMessage != nil{
message = m.ReplyToMessage.Text
}else{
b.SendMessage(m.Chat.Id,"_Reply to any message with_ /count",&tl.Options{ParseMode:"Markdown"})
return
}
word_count := len(strings.Fields(message))
character := len(message)
var counts string
for index, element := range repetition(message) {
li := fmt.Sprintf("*%s* = _%d_\n",index, element)
counts = counts + li
}
text := fmt.Sprintf("*Words :* `%d`\n*Characters :* `%d`\n\n*Repeatation:*\n%s",word_count,character,counts)
b.SendMessage(m.Chat.Id, text,&tl.Options{ParseMode:"Markdown"})
}
func repetition(st string) map[string]int {
// using strings.Field Function
input := strings.Fields(st)
wc := make(map[string]int)
for _, word := range input {
_, matched := wc[word]
if matched {
wc[word] += 1
} else {
wc[word] = 1
}
}
return wc
}