11package main
22
33import (
4+ "fmt"
45 "os"
56 "path/filepath"
67 "strconv"
@@ -24,7 +25,7 @@ type View struct {
2425
2526func main () {
2627 godotenv .Load ("config.env" )
27- //misskey
28+ // misskey
2829 client , err := mi .NewClientWithOptions (mi .WithSimpleConfig (os .Getenv ("MISSKEY_URL" ), os .Getenv ("MISSKEY_TOKEN" )))
2930 if err != nil {
3031 log .Fatal (err )
@@ -54,7 +55,7 @@ func main() {
5455 createFolder (client , os .Getenv ("UPLOAD_FOLDER" ))
5556 }
5657
57- //tgbot
58+ // tgbot
5859 bot , err := tgbotapi .NewBotAPI (os .Getenv ("TELEGRAM_BOT_TOKEN" ))
5960 if err != nil {
6061 log .Panic (err )
@@ -80,25 +81,31 @@ func main() {
8081 }
8182 }
8283 if len (updatesChannel ) == 0 {
84+ addFootInfo (& msg , update .Message )
8385 sendWithAttachment (client , v , & msg , & fileIDs )
8486 }
8587 } else if update .Message .Video != nil {
8688 fillMsgAndFileIDs (client , & fileIDs , & msg , update .Message .Caption , ignoreError (bot .GetFileDirectURL (update .Message .Video .FileID )).(string ))
8789 if len (updatesChannel ) == 0 {
90+ addFootInfo (& msg , update .Message )
8891 sendWithAttachment (client , v , & msg , & fileIDs )
8992 }
9093 } else if update .Message .Audio != nil {
9194 fillMsgAndFileIDs (client , & fileIDs , & msg , update .Message .Caption , ignoreError (bot .GetFileDirectURL (update .Message .Audio .FileID )).(string ))
9295 if len (updatesChannel ) == 0 {
96+ addFootInfo (& msg , update .Message )
9397 sendWithAttachment (client , v , & msg , & fileIDs )
9498 }
9599 } else if update .Message .Document != nil {
96100 fillMsgAndFileIDs (client , & fileIDs , & msg , update .Message .Caption , ignoreError (bot .GetFileDirectURL (update .Message .Document .FileID )).(string ))
97101 if len (updatesChannel ) == 0 {
102+ addFootInfo (& msg , update .Message )
98103 sendWithAttachment (client , v , & msg , & fileIDs )
99104 }
100105 } else {
101- sendMiNote (client , v , update .Message .Text , nil )
106+ msg = update .Message .Text
107+ addFootInfo (& msg , update .Message )
108+ sendMiNote (client , v , & msg , nil )
102109 }
103110 }
104111}
@@ -107,13 +114,17 @@ func ignoreError(val interface{}, err error) interface{} {
107114 return val
108115}
109116
110- func addFootInfo (msg string ) string {
111- return msg + "\n \n " + os .Getenv ("FOOT_INFO" )
117+ func addFootInfo (msg * string , tgMsg * tgbotapi.Message ) {
118+ * msg += "\n \n "
119+ if tgMsg .ForwardFromChat != nil {
120+ * msg += fmt .Sprintf ("Forwarded from Telegram Channel \" %s\" `@%s`\n " , tgMsg .ForwardFromChat .Title , tgMsg .ForwardFromChat .UserName )
121+ }
122+ * msg += os .Getenv ("FOOT_INFO" )
112123}
113124
114- func sendMiNote (client * mi.Client , v View , msg string , fileIDs []string ) {
125+ func sendMiNote (client * mi.Client , v View , msg * string , fileIDs []string ) {
115126 resp , err := client .Notes ().Create (notes.CreateRequest {
116- Text : core .NewString (addFootInfo ( msg ) ),
127+ Text : core .NewString (* msg ),
117128 Visibility : v .visibility ,
118129 LocalOnly : v .localOnly ,
119130 FileIDs : fileIDs ,
@@ -175,7 +186,7 @@ func fillMsgAndFileIDs(client *mi.Client, fileIDs *[]string, msg *string, captio
175186}
176187
177188func sendWithAttachment (client * mi.Client , v View , msg * string , fileIDs * []string ) {
178- sendMiNote (client , v , * msg , * fileIDs )
189+ sendMiNote (client , v , msg , * fileIDs )
179190 * fileIDs = nil
180191 * msg = ""
181192}
0 commit comments