-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
625 lines (553 loc) · 22.6 KB
/
main.go
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"math"
"math/rand"
"net/http"
"net/url"
"strconv"
"strings"
"time"
scraper "github.com/Fefefo/anime-themes-scraper"
cocwrapper "github.com/Fefefo/coc-wrapper"
"github.com/Knetic/govaluate"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api"
"gopkg.in/ini.v1"
)
type transBody struct {
Translations []translations `json:"translations,omitempty"`
}
type translations struct {
Text string `json:"text,omitempty"`
To string `json:"to,omitempty"`
}
type dict struct {
Word string `json:"word,omitempty"`
Phonetic string `json:"phonetic,omitempty"`
Origin string `json:"origin,omitempty"`
Meaning map[string][]definition `json:"meaning,omitempty"`
}
type definition struct {
Definition string `json:"definition,omitempty"`
Example string `json:"example,omitempty"`
Synonyms []string `json:"synonym,omitempty"`
}
type gattoLink struct {
Link string `json:"url"`
}
type caneLink struct {
Link string `json:"message"`
}
type film struct {
Results []struct {
//VoteAverage float64 `json:"vote_average"`
ReleaseDate string `json:"release_date"`
Title string `json:"title"`
Overview string `json:"overview"`
}
}
type urbanResponse struct {
List []struct {
Def string `json:"definition"`
Permalink string `json:"permalink"`
ThumbsUp int `json:"thumbs_up"`
SoundUrls []interface{} `json:"sound_urls"`
Author string `json:"author"`
Word string `json:"word"`
Defid int `json:"defid"`
CurrentVote string `json:"current_vote"`
WrittenOn time.Time `json:"written_on"`
Example string `json:"example"`
ThumbsDown int `json:"thumbs_down"`
} `json:"list"`
}
type redditResponse struct {
Data struct {
Children []struct {
Data struct {
File string `json:"url_overridden_by_dest"`
//Thumbnail string `json:"thumbnail"`
Title string `json:"title"`
Subreddit string `json:"subreddit_name_prefixed"`
} `json:"data"`
} `json:"children"`
} `json:"data"`
}
var tgapi, filmapi, catapi, transapi, cocapi string
var bot *tgbotapi.BotAPI
func getUrb(query string) urbanResponse {
link := "http://api.urbandictionary.com/v0/define?term=" + url.PathEscape(query)
req, _ := http.Get(link)
body, _ := ioutil.ReadAll(req.Body)
var res urbanResponse
json.Unmarshal(body, &res)
return res
}
func getReddit(query string) []redditResponse {
if strings.HasPrefix(query, "www") {
query = "https://" + query
}
if !strings.HasPrefix(query, "https://www.reddit.com/r/") && !strings.HasPrefix(query, "http://www.reddit.com/r/") {
return nil
}
client := &http.Client{}
var res []redditResponse
splitted := strings.Split(query, "/")
if len(splitted) < 8 {
return nil
}
query = strings.Join(splitted[:8], "/")
query += ".json"
req, err := http.NewRequest("GET", query, nil)
req.Header.Set("User-Agent", "Golang_FefegoBot")
if err != nil {
return nil
}
resp, err := client.Do(req)
if err != nil {
return nil
}
body, err := ioutil.ReadAll(resp.Body)
if fmt.Sprintf("%s", body) == "[]" || err != nil {
return nil
}
err = json.Unmarshal(body, &res)
if err != nil || len(res) == 0 || len(res[0].Data.Children) == 0 {
return nil
}
return res
}
func translate(text, to string) string {
link := "https://microsoft-translator-text.p.rapidapi.com/translate?profanityAction=NoAction&textType=plain&api-version=3.0&to=" + url.PathEscape(to)
txt := strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll(text, "\r", ""), "\n", ""), "\\", "/"), "\"", "'")
reqText := strings.NewReader(`[{"Text": "` + txt + `" }]`)
req, _ := http.NewRequest("POST", link, reqText)
req.Header.Add("x-rapidapi-host", "microsoft-translator-text.p.rapidapi.com")
req.Header.Add("x-rapidapi-key", transapi)
req.Header.Add("content-type", "application/json")
client, _ := http.DefaultClient.Do(req)
body, _ := ioutil.ReadAll(client.Body)
var res []transBody
json.Unmarshal(body, &res)
fmt.Println(client)
fmt.Println(string(body))
var out string
if len(res) > 0 {
out = res[0].Translations[0].Text
} else {
out = "Errore, utilizza la giusta sintassi del comando `.transto [lingua]` utilizzando il codice ISO della lingua in cui vuoi tradurre il messaggio (es: `it, en, es`)"
}
return out + "."
}
func getCat(api string) string {
resp, _ := http.Get("https://api.thecatapi.com/v1/images/search?api_key=" + api)
body, _ := ioutil.ReadAll(resp.Body)
var gattino []gattoLink
json.Unmarshal([]byte(body), &gattino)
return gattino[0].Link
}
func getDog() (string, string) {
respC, _ := http.Get("https://dog.ceo/api/breeds/image/random")
bodyC, _ := ioutil.ReadAll(respC.Body)
var cagnolino caneLink
json.Unmarshal([]byte(bodyC), &cagnolino)
return cagnolino.Link, "Cane di razza: " + strings.Split(strings.Replace(cagnolino.Link, "https://images.dog.ceo/breeds/", "", -1), "/")[0]
}
func getTime(start time.Time) string {
temp := time.Now()
diff := temp.Sub(start)
s := int(diff.Seconds())
d := s / (3600 * 24)
s = s % (3600 * 24)
h := s / 3600
s = s % 3600
m := s / 60
s = s % 60
out := ""
if m > 0 {
if h > 0 {
if d > 0 {
out += strconv.Itoa(d) + "d "
}
out += strconv.Itoa(h) + "h "
}
out += strconv.Itoa(m) + "m "
}
out += strconv.Itoa(s) + "s"
return out
}
func solver(mate string) string {
expression, er := govaluate.NewEvaluableExpression(mate)
testo := fmt.Sprintf(`Il risultato di <code>%s</code> è
<code>`, mate)
if er == nil {
parameters := make(map[string]interface{}, 8)
result, err := expression.Evaluate(parameters)
if err == nil {
if fmt.Sprintf("%T", result) == "float64" {
if math.Mod(result.(float64), 1) == 0 {
return fmt.Sprintf("%s%.0f</code>", testo, result)
} else {
return fmt.Sprintf("%s%0.3f</code>", testo, result)
}
}
return fmt.Sprintf("%s%v</code>", testo, result)
} else {
return fmt.Sprintf(`Espressione : <code>%s</code>
Non so come risolvere l'espressione`, mate)
}
} else {
return fmt.Sprintf(`Espressione : <code>%s</code>
Non riesco a capire la tua sintassi`, mate)
}
}
func getAnimeList() scraper.List {
animeList := scraper.GetAnimeList()
files := 0
for i := 0; i < len(animeList); i++ {
files += len(animeList[i].Songs)
}
msg := tgbotapi.NewMessage(146519367, fmt.Sprintf("Loaded %d anime (%d files)", len(animeList), files))
bot.Send(msg)
return animeList
}
func main() {
cfg, err := ini.Load("my.ini")
if err != nil {
fmt.Printf("Fail to read file: %v", err)
}
tgapi = cfg.Section("").Key("tgbot_api").String()
filmapi = cfg.Section("").Key("film_api").String()
catapi = cfg.Section("").Key("cat_api").String()
transapi = cfg.Section("").Key("translate_api").String()
myid, _ := cfg.Section("").Key("my_id").Int()
channelid, _ := cfg.Section("").Key("channel_id").Int64()
cocapi = cfg.Section("").Key("coc_api").String()
bot, err = tgbotapi.NewBotAPI(tgapi)
if err != nil {
log.Panic(err)
}
//bot.Debug = true
startTime := time.Now()
const helpText string = "*Il bot ha alcuni comandi utilizzabili con la seguente sintassi*\n" +
"`@fefegobot 'key' 'query'`\n\n" +
"*Key al momento disponibili:*\n" +
"`parola:` verrà cercata una parola italiana in un dizionario\n" +
" *es.* `@fefegobot parola ciao`\n\n" +
"`word:` verrà cercata una parola inglese in un dizionario\n" +
" *es.* `@fefegobot word hello`\n\n" +
"`film:` verranno cercati film con le parole inserite\n" +
" *es.* `@fefegobot film The Shape of Voice`\n\n" +
"`math:` verrà eseguita l'espressione immessa\n" +
" *es.* `@fefegobot math 5+6*7-2/(5-77)`\n\n" +
"`neko:` verrà cercata una foto di un gatto con le risoluzioni inserite\n" +
" *es.* `@fefegobot neko 1920 1080`\n\n" +
"`reddimg:` verrà mandata la foto di un post reddit\n" +
" *es.* `@fefegobot reddimg https://www.reddit.com/r/CatsAreAssholes/comments/kj6a90/we_dont_need_a_christmass_tree_topper_this_year/`\n\n" +
"`reddifile:` verrà mandata il file di un post reddit (non compresso)\n" +
" *es.* `@fefegobot reddfile https://www.reddit.com/r/CatsAreAssholes/comments/kj6a90/we_dont_need_a_christmass_tree_topper_this_year/`\n\n" +
"`theme:` verranno cercate tutte le opening e ending di anime che contengono i 5 caratteri inseriti nel nome\n" +
" *es.* `@fefegobot theme evang`\n\n\n" +
"*È inoltre possibile mandare le proprie foto del profilo scrivendo :*\n" +
"`@fefegobot mypics`\n\n" +
"*e il proprio id :*\n" +
"`@fefegobot myid`\n\n" +
"_Bot online da_ `"
log.Printf("Authorized on account %s", bot.Self.UserName)
animeList := getAnimeList()
cocwrapper.SetAPIToken(cocapi)
log.Println("Loaded", len(animeList), "anime")
u := tgbotapi.NewUpdate(0)
u.Timeout = 5
updates, err := bot.GetUpdatesChan(u)
for update := range updates {
if update.InlineQuery != nil {
rand.Seed(time.Now().UTC().UnixNano())
var array []interface{}
inlineText := update.InlineQuery.Query
splittedText := strings.Split(inlineText, " ")
if splittedText[0] == "parola" && len(splittedText) == 2 {
url := "https://api.dictionaryapi.dev/api/v1/entries/it/" + splittedText[1]
resp, _ := http.Get(url)
body, _ := ioutil.ReadAll(resp.Body)
var query []dict
json.Unmarshal([]byte(body), &query)
if len(query) != 0 {
i := 0
for j := range query {
for tipo, means := range query[j].Meaning {
//log.Println("Tipo:", tipo)
for _, def := range means {
text := "*Parola ricercata:* `" + query[j].Word + "`\n" +
"*Divisione in sillabe:* `" + query[j].Phonetic + "`\n" +
"*Significato:*\n" +
"`" + def.Definition + "`"
articolo := tgbotapi.NewInlineQueryResultArticleMarkdown("significato"+fmt.Sprintf("%d", i), query[j].Word, text)
articolo.Description = tipo
array = append(array, articolo)
i++
}
}
}
}
if len(array) == 0 {
articolo := tgbotapi.NewInlineQueryResultPhotoWithThumb("404", "https://http.cat/404", "https://http.cat/404")
articolo.Caption = "Nessun parola italiana trovata cercando " + splittedText[1]
articolo.Description = "NOPE"
array = append(array, articolo)
}
} else if splittedText[0] == "word" && len(splittedText) == 2 {
url := "https://api.dictionaryapi.dev/api/v1/entries/en/" + splittedText[1]
resp, _ := http.Get(url)
body, _ := ioutil.ReadAll(resp.Body)
var query []dict
json.Unmarshal([]byte(body), &query)
if len(query) != 0 {
i := 0
for tipo, means := range query[0].Meaning {
for _, def := range means {
sinonimi := ""
for i := 0; i < len(def.Synonyms); i++ {
if sinonimi != "" {
sinonimi += " " + def.Synonyms[i]
} else {
sinonimi = def.Synonyms[0]
}
}
text := "*Word:* `" + splittedText[1] + "`\n" +
"*Phonetic:* `" + query[0].Phonetic + "`\n" +
"*Synonyms:*\n" +
"`" + sinonimi + "`\n" +
"*Definition:*\n" +
"`" + def.Definition + "`"
articolo := tgbotapi.NewInlineQueryResultArticleMarkdown("mean"+fmt.Sprintf("%d", i), splittedText[1], text)
articolo.Description = tipo
array = append(array, articolo)
i++
}
}
}
if len(array) == 0 {
articolo := tgbotapi.NewInlineQueryResultPhotoWithThumb("404", "https://http.cat/404", "https://http.cat/404")
articolo.Caption = "Nessun parola inglese trovata cercando " + splittedText[1]
articolo.Description = "NOPE"
array = append(array, articolo)
}
} else if splittedText[0] == "film" && len(splittedText) >= 2 {
ricerca := url.QueryEscape(strings.Join(splittedText[1:], " "))
url := "https://api.themoviedb.org/3/search/movie?api_key=" + filmapi + "&language=it&query=" + ricerca + "&page=1&include_adult=true"
resp, _ := http.Get(url)
body, _ := ioutil.ReadAll(resp.Body)
var query film
json.Unmarshal([]byte(body), &query)
i := 0
for _, n := range query.Results {
articolo := tgbotapi.NewInlineQueryResultArticleMarkdown("film"+fmt.Sprintf("%d", i), n.Title, "***"+n.Title+"***" /*+" "+fmt.Sprintf("%.1f", n.VoteAverage)+" ⭐\n"*/ +"\n"+"`"+n.ReleaseDate+"`\n"+n.Overview)
articolo.Description = n.ReleaseDate
array = append(array, articolo)
i++
}
if len(array) == 0 {
articolo := tgbotapi.NewInlineQueryResultPhotoWithThumb("404", "https://http.cat/404", "https://http.cat/404")
articolo.Caption = "Nessun film trovato cercando " + ricerca
articolo.Description = "NOPE"
array = append(array, articolo)
}
} else if splittedText[0] == "math" && len(splittedText) >= 2 {
formula := strings.Join(splittedText[1:], " ")
if formula != "" {
sol := solver(formula)
articolo := tgbotapi.NewInlineQueryResultArticleHTML("soluzione", "Risolvi", sol)
articolo.Description = formula
array = append(array, articolo)
}
} else if splittedText[0] == "neko" && len(splittedText) == 3 {
url := "http://placekitten.com/" + splittedText[1] + "/" + splittedText[2]
resp, _ := http.Get(url)
if resp.StatusCode == 200 {
gattosize := tgbotapi.NewInlineQueryResultPhotoWithThumb("nekoSize", url, "http://image.thepaper.cn/www/image/28/100/499.jpg")
gattosize.Description = "Neko 猫"
gattosize.Caption = "Neko 猫\n" +
"Risoluzione : " + splittedText[1] + " x " + splittedText[2] + " px"
array = append(array, gattosize)
} else if len(array) == 0 {
articolo := tgbotapi.NewInlineQueryResultPhotoWithThumb("404", "https://http.cat/404", "https://http.cat/404")
articolo.Caption = "Non sono riuscito a trovare foto di gatti larghe " + splittedText[1] + " px e alte " + splittedText[2] + " px"
articolo.Description = "NOPE"
array = append(array, articolo)
}
} else if splittedText[0] == "theme" && len(splittedText) >= 2 {
query := strings.Join(splittedText[1:], " ")
if len(query) >= 3 {
lista := animeList.SelectByBothNames(query)
count := 0
for i := 0; i < len(lista) && count < 50; i++ {
for j := 0; j < len(lista[i].Songs) && count < 50; j++ {
esempio := tgbotapi.NewInlineQueryResultArticleHTML("animesong"+strconv.Itoa(i)+"id"+strconv.Itoa(j), lista[i].NameJap, lista[i].NameJap+"\n"+lista[i].NameEng+"\n"+"<a href='"+lista[i].Songs[j].Link+"'>"+lista[i].Songs[j].Version+" - "+lista[i].Songs[j].Title+"</a>")
esempio.Description = strings.Split(lista[i].NameEng, ",")[0] + " - " + lista[i].Songs[j].Version + " - " + lista[i].Songs[j].Title
array = append(array, esempio)
count++
}
}
if len(array) == 0 {
articolo := tgbotapi.NewInlineQueryResultPhotoWithThumb("404", "https://http.cat/404", "https://http.cat/404")
articolo.Caption = "Nessuna opening o ending trovata cercando " + query
articolo.Description = "NOPE"
array = append(array, articolo)
}
}
} else if splittedText[0] == "mypics" {
conf := tgbotapi.UserProfilePhotosConfig{
UserID: update.InlineQuery.From.ID,
}
foto, _ := bot.GetUserProfilePhotos(conf)
page := 0
if len(splittedText) == 2 {
if num, err := strconv.Atoi(splittedText[1]); err == nil && int(len(foto.Photos)/50) > (num-1) {
page = num - 1
}
}
for i := page * 50; i < len(foto.Photos); i++ {
if i < (page+1)*50 {
a := tgbotapi.NewInlineQueryResultPhotoWithThumb("pic"+strconv.Itoa(i), foto.Photos[i][2].FileID, foto.Photos[i][2].FileID)
a.Caption = "La tua pic numero " + strconv.Itoa(i+1)
array = append(array, a)
}
}
} else if splittedText[0] == "urban" && update.InlineQuery.From.ID == myid {
if len(splittedText) > 1 {
query := strings.Join(splittedText[1:], " ")
if strings.HasSuffix(query, ".") {
urb := getUrb(strings.ReplaceAll(query, ".", ""))
for i := 0; i < len(urb.List); i++ {
//a := tgbotapi.NewInlineQueryResultArticleHTML("urban"+strconv.Itoa(i), urb.List[i].Word, "Title: <a href='"+urb.List[i].Permalink+"'>"+urb.List[i].Word+"</a>\n\n"+strings.ReplaceAll(strings.ReplaceAll(urb.List[i].Def, "[", ""), "]", "")+"\n\nAuthor: "+urb.List[i].Author)
a := tgbotapi.NewInlineQueryResultArticle("urban"+strconv.Itoa(i), urb.List[i].Word, "Title: "+urb.List[i].Word+"\n\n"+strings.ReplaceAll(strings.ReplaceAll(urb.List[i].Def, "[", ""), "]", "")+"\n\nAuthor: "+urb.List[i].Author)
a.Description = urb.List[i].Author
array = append(array, a)
}
}
}
} else if splittedText[0] == "reddimg" {
if len(splittedText) == 2 {
query := splittedText[1]
img := getReddit(query)
if img != nil {
msg := tgbotapi.NewPhotoUpload(channelid, nil)
msg.FileID = img[0].Data.Children[0].Data.File
msg.UseExisting = true
msg.ParseMode = tgbotapi.ModeHTML
msg.Caption = "<a href='" + query + "'>Sauce</a>\nby@" + update.InlineQuery.From.UserName
m, err := bot.Send(msg)
if err == nil {
a := tgbotapi.NewInlineQueryResultCachedPhoto("img", (*m.Photo)[0].FileID)
a.Caption = img[0].Data.Children[0].Data.Title + "\n<a href='" + query + "'>Sauce</a> from <a href='reddit.com/" + img[0].Data.Children[0].Data.Subreddit + "'>" + img[0].Data.Children[0].Data.Subreddit + "</a>"
a.ParseMode = tgbotapi.ModeHTML
array = append(array, a)
} else {
a := tgbotapi.NewInlineQueryResultArticleHTML("sad", img[0].Data.Children[0].Data.Title, "Link al <a href='"+query+"'>POST</a>\nLink all'<a href='"+img[0].Data.Children[0].Data.File+"'>IMMAGINE</a>")
a.Description = "Immagine probabilmente troppo grande o file di altro tipo, puoi comunque mandare il link cliccando qui"
array = append(array, a)
}
} else {
articolo := tgbotapi.NewInlineQueryResultPhotoWithThumb("404", "https://http.cat/404", "https://http.cat/404")
articolo.Caption = "Hai mandato un link sbagliato"
articolo.Description = "NOPE"
array = append(array, articolo)
}
}
} else if splittedText[0] == "reddifile" {
if len(splittedText) == 2 {
query := splittedText[1]
img := getReddit(query)
if img != nil {
msg := tgbotapi.NewDocumentUpload(channelid, nil)
msg.FileID = img[0].Data.Children[0].Data.File
msg.UseExisting = true
msg.ParseMode = tgbotapi.ModeHTML
msg.Caption = "<a href='" + query + "'>Sauce</a>\nby@" + update.InlineQuery.From.UserName
m, err := bot.Send(msg)
if err == nil {
a := tgbotapi.NewInlineQueryResultCachedDocument("img", m.Document.FileID, img[0].Data.Children[0].Data.Title)
a.Caption = img[0].Data.Children[0].Data.Title + "\n<a href='" + query + "'>Sauce</a> from <a href='reddit.com/" + img[0].Data.Children[0].Data.Subreddit + "'>" + img[0].Data.Children[0].Data.Subreddit + "</a>"
a.ParseMode = tgbotapi.ModeHTML
array = append(array, a)
} else {
a := tgbotapi.NewInlineQueryResultArticleHTML("sad", img[0].Data.Children[0].Data.Title, "Link al <a href='"+query+"'>POST</a>\nLink al <a href='"+img[0].Data.Children[0].Data.File+"'>FILE</a>")
a.Description = "File probabilmente troppo grande, puoi comunque mandare il link cliccando qui"
array = append(array, a)
}
} else {
articolo := tgbotapi.NewInlineQueryResultPhotoWithThumb("404", "https://http.cat/404", "https://http.cat/404")
articolo.Caption = "Hai mandato un link sbagliato"
articolo.Description = "NOPE"
array = append(array, articolo)
}
}
} else if splittedText[0] == "cocclan" {
if len(splittedText) >= 2 {
var req cocwrapper.ReqClans
req.Name = strings.Join(splittedText[1:], " ")
fmt.Println(req.Name)
res := cocwrapper.GetClans(req)
if len(res.Clan) > 0 {
for i := 0; i < len(res.Clan) && i < 50; i++ {
a := tgbotapi.NewInlineQueryResultPhotoWithThumb("clan"+strconv.Itoa(i), res.Clan[i].Pic.Large, res.Clan[i].Pic.Small)
a.Caption = "*" + res.Clan[i].Name + "* `" + res.Clan[i].Tag + "`\nMembri : `" + strconv.Itoa(res.Clan[i].Members) + "/50` Trofei: `" + strconv.Itoa(res.Clan[i].Points) + "`\nGuerre Vinte: `" + strconv.Itoa(res.Clan[i].WarWins) + "`\nLega: `" + res.Clan[i].WarLeague.Name + "`\nLocalità: `" + res.Clan[i].Location.Name + "`"
a.ParseMode = tgbotapi.ModeMarkdown
array = append(array, a)
}
} else {
articolo := tgbotapi.NewInlineQueryResultPhotoWithThumb("404", "https://http.cat/404", "https://http.cat/404")
articolo.Caption = "Nessun clan trovato"
articolo.Description = "NOPE"
array = append(array, articolo)
}
}
} else if splittedText[0] == "myid" {
a := tgbotapi.NewInlineQueryResultArticleMarkdown("id", update.InlineQuery.From.FirstName+" ID", update.InlineQuery.From.FirstName+" id = `"+strconv.Itoa(update.InlineQuery.From.ID)+"`")
a.Description = strconv.Itoa(update.InlineQuery.From.ID)
array = append(array, a)
} else if splittedText[0] == "relThemes" && update.InlineQuery.From.ID == myid {
animeList = getAnimeList()
} else {
stats := tgbotapi.NewInlineQueryResultArticleMarkdown("help", "HELP", helpText+getTime(startTime)+"`")
stats.Description = "Comandi aggiuntivi e tempo online"
stats.ThumbURL = "https://pngimage.net/wp-content/uploads/2018/05/chiave-inglese-png-1.png"
ping := tgbotapi.NewInlineQueryResultArticle("ping", "PING", "PONG")
ping.Description = "Latenza? O FORSE NO"
ping.ThumbURL = "https://www.dictionary.com/e/wp-content/uploads/2018/03/eyes-1.jpg"
gatto := tgbotapi.NewInlineQueryResultPhotoWithThumb("neko", getCat(catapi), "http://image.thepaper.cn/www/image/28/100/499.jpg")
gatto.Description = "Neko 猫"
gatto.Caption = "Neko 猫"
caneLink, caneCaption := getDog()
cane := tgbotapi.NewInlineQueryResultPhotoWithThumb("inu", caneLink, "https://dog.ceo/img/dog-api-logo.svg")
cane.Description = "Inu 犬"
cane.Caption = caneCaption
array = append(array, stats, ping, gatto, cane)
}
risposta := tgbotapi.InlineConfig{
InlineQueryID: update.InlineQuery.ID,
IsPersonal: false,
CacheTime: 0,
Results: array,
SwitchPMText: "Bot di @Fedefio",
SwitchPMParameter: "255",
}
if _, err = bot.AnswerInlineQuery(risposta); err != nil {
log.Println(err)
}
bot.AnswerInlineQuery(risposta)
} else if update.Message != nil {
if strings.HasPrefix(update.Message.Text, ".transto") && update.Message.ReplyToMessage != nil {
to := strings.TrimSpace(strings.Replace(update.Message.Text, ".transto", "", 1))
out := translate(update.Message.ReplyToMessage.Text, to)
msg := tgbotapi.NewMessage(update.Message.Chat.ID, out)
msg.ReplyToMessageID = update.Message.ReplyToMessage.MessageID
bot.Send(msg)
}
}
}
}