-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathremoveEvent.go
125 lines (114 loc) · 2.48 KB
/
removeEvent.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
package main
import (
"context"
"errors"
"fmt"
"github.com/nbd-wtf/go-nostr"
)
/*
removeEvent {{{
[infomation for develop]
usage:
nostk removeEvent <event_id>
kind: 5
content: reason text (must)
tags [
"e": event id (hex)
]
*/
func removeEvent(args []string, cc confClass) error {
var event_id string
var kind string
content := ""
if len(args) < 4 || 5 < len(args) {
return errors.New("Wrong number of parameters")
}
for i := range args {
if i < 2 {
continue
}
switch i {
case 2: // event_id
event_id = args[i]
if 0 < len(event_id) && is64HexString(event_id) == false {
if pref, err := getPrefixInString(event_id); err == nil {
switch pref {
case "note":
if _, tmpEventId, err := toHex(event_id); err != nil {
return err
} else {
event_id = tmpEventId.(string)
}
case "nevent":
if _, tmpEventId, err := toHex(event_id); err != nil {
return err
} else {
event_id = tmpEventId.(nostr.EventPointer).ID
}
default:
return errors.New(fmt.Sprintf("Invalid id starting with %v", pref))
}
}
}
case 3: // kind
kind = args[i]
case 4: // content
content = args[i]
if containsNsec1(content) {
return errors.New(fmt.Sprintf("STRONGEST CAUTION!! : POSTS CONTAINING PRIVATE KEYS!! YOUR POST HAS BEEN REJECTED!!"))
}
}
}
sk, err := cc.load(cc.ConfData.Filename.Hsec)
if err != nil {
fmt.Println("Nothing key pair. Make key pair.")
return err
}
pk, err := nostr.GetPublicKey(sk)
if err != nil {
return err
}
var rl []string
if err := cc.getRelayList(&rl, writeFlag); err != nil {
fmt.Println("Nothing relay list. Make a relay list.")
return err
}
var t []string
tgs := nostr.Tags{}
if err := cc.setCustomEmoji(content, &tgs); err != nil {
return err
}
t = nil
t = append(t, "e")
t = append(t, event_id)
tgs = append(tgs, t)
t = append(t, "k")
t = append(t, kind)
tgs = append(tgs, t)
ev := nostr.Event{
PubKey: pk,
CreatedAt: nostr.Now(),
Kind: nostr.KindDeletion,
Tags: tgs,
Content: content,
}
// calling Sign sets the event ID field and the event Sig field
ev.Sign(sk)
// publish the event to two relays
ctx := context.Background()
for _, url := range rl {
relay, err := nostr.RelayConnect(ctx, url)
if err != nil {
fmt.Println(err)
continue
}
err = relay.Publish(ctx, ev)
if err != nil {
fmt.Println(err)
continue
}
fmt.Printf("published to %s\n", url)
}
return nil
}
// }}}