From 8b875882e988e1bf799ee9e17b5c43289cedc0b2 Mon Sep 17 00:00:00 2001 From: Andriy Cherniy Date: Thu, 4 Jan 2024 22:01:06 +0200 Subject: [PATCH] add send text to matrix when started --- main.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/main.go b/main.go index 1c78e45..7b6d8d1 100755 --- a/main.go +++ b/main.go @@ -55,6 +55,7 @@ func parseRegexFile(path string) ([]regexp.Regexp, error) { func main() { ctx := context.Background() err := godotenv.Load() + ROOM_ID := os.Getenv("MATRIX_ROOM_ID") if err != nil { log.Fatal(err) @@ -115,14 +116,15 @@ func main() { log.Fatal(err) } log.Info("starting...") + matrix_client.SendText(m_id.RoomID(ROOM_ID), "Бот запущений!") syncer.OnEventType(m_event.EventReaction, func(source mautrix.EventSource, ev *m_event.Event) { log.Info("reactions") - // if ev.RoomID == os.Getenv("MATRIX_ROOM_ID") && ev.Content != nil && + // if ev.RoomID == ROOM_ID && ev.Content != nil && content := ev.Content.AsReaction() key := []rune(content.RelatesTo.Key) log.Info(content.RelatesTo.Key) - if ev.RoomID.String() == os.Getenv("MATRIX_ROOM_ID") && (key[0] == '👍' || key[0] == '👎') { + if ev.RoomID.String() == ROOM_ID && (key[0] == '👍' || key[0] == '👎') { log.Info("reacted well") var post Post if err := db.First(&post, "message_id = ?", content.RelatesTo.EventID.String()).Error; err != nil { @@ -142,12 +144,12 @@ func main() { log.Error(err) return } - // matrix_client.SendMessageEvent(os.Getenv("MATRIX_ROOM_ID"), "m.room.message", interface{}) + // matrix_client.SendMessageEvent(ROOM_ID, "m.room.message", interface{}) body := fmt.Sprintf(`#%d: Схвалено %s `, post.ID, status.URL) - _, err := matrix_client.SendMessageEvent(m_id.RoomID(os.Getenv("MATRIX_ROOM_ID")), m_event.EventMessage, &m_event.MessageEventContent{ + _, err := matrix_client.SendMessageEvent(m_id.RoomID(ROOM_ID), m_event.EventMessage, &m_event.MessageEventContent{ Body: body, MsgType: m_event.MsgText, NewContent: &m_event.MessageEventContent{ @@ -167,7 +169,7 @@ func main() { body := fmt.Sprintf(`#%d: Відмовлено %s `, post.ID, status.URL) - _, err := matrix_client.SendMessageEvent(m_id.RoomID(os.Getenv("MATRIX_ROOM_ID")), m_event.EventMessage, &m_event.MessageEventContent{ + _, err := matrix_client.SendMessageEvent(m_id.RoomID(ROOM_ID), m_event.EventMessage, &m_event.MessageEventContent{ Body: body, MsgType: m_event.MsgText, NewContent: &m_event.MessageEventContent{ @@ -217,7 +219,7 @@ notif_loop: if len(acct_parsed) == 2 && regex.MatchString(acct_parsed[1]) { _, err := masto_client.AccountBlock(ctx, notif.Account.ID) if err == nil { - matrix_client.SendText(m_id.RoomID(os.Getenv("MATRIX_ROOM_ID")), fmt.Sprintf("%s заблокований автоматично регексом доменів: %s", notif.Account.Acct, regex.String())) + matrix_client.SendText(m_id.RoomID(ROOM_ID), fmt.Sprintf("%s заблокований автоматично регексом доменів: %s", notif.Account.Acct, regex.String())) } continue notif_loop } @@ -227,7 +229,7 @@ notif_loop: if regex.MatchString(acct_parsed[0]) { _, err := masto_client.AccountBlock(ctx, notif.Account.ID) if err == nil { - matrix_client.SendText(m_id.RoomID(os.Getenv("MATRIX_ROOM_ID")), fmt.Sprintf("%s заблокований автоматично регексом нікнеймів: %s", notif.Account.Acct, regex.String())) + matrix_client.SendText(m_id.RoomID(ROOM_ID), fmt.Sprintf("%s заблокований автоматично регексом нікнеймів: %s", notif.Account.Acct, regex.String())) } continue notif_loop } @@ -275,7 +277,7 @@ actor: %v`, notif.Status.ID, notif.Status.Content, notif.Account.Acct) log.Error(err) continue } - message, err := matrix_client.SendText(m_id.RoomID(os.Getenv("MATRIX_ROOM_ID")), fmt.Sprintf(`#%d: На модерації + message, err := matrix_client.SendText(m_id.RoomID(ROOM_ID), fmt.Sprintf(`#%d: На модерації %s 👍 - Так 👎 - Ні