|
|
|
internal/community/query.go raw
| 1 | package community | | 2 | | | 3 | import ( | | 4 | "context" | | 5 | "database/sql" | | 6 | "errors" | | 7 | ) | | 8 | | | 9 | func (s *Service) IsMember(ctx context.Context, pubkey string) (bool, error) { | | 10 | var exists bool | | 11 | err := s.store.DB().QueryRowContext(ctx, `SELECT EXISTS(SELECT 1 FROM community_members WHERE pubkey=?)` , pubkey).Scan(&exists) | | 12 | return exists, err | | 13 | } | | 14 | | | 15 | func (s *Service) IsBanned(ctx context.Context, pubkey string) (bool, error) { | | 16 | var exists bool | | 17 | err := s.store.DB().QueryRowContext(ctx, `SELECT EXISTS(SELECT 1 FROM community_bans WHERE pubkey=?)` , pubkey).Scan(&exists) | | 18 | return exists, err | | 19 | } | | 20 | | | 21 | func (s *Service) IsEventBanned(ctx context.Context, id string) (bool, error) { | | 22 | var exists bool | | 23 | err := s.store.DB().QueryRowContext(ctx, `SELECT EXISTS(SELECT 1 FROM community_event_bans WHERE id=?)` , id).Scan(&exists) | | 24 | return exists, err | | 25 | } | | 26 | | | 27 | func (s *Service) IsIPBlocked(ctx context.Context, ip string) (bool, error) { | | 28 | var exists bool | | 29 | err := s.store.DB().QueryRowContext(ctx, `SELECT EXISTS(SELECT 1 FROM community_ip_blocks WHERE ip=?)` , ip).Scan(&exists) | | 30 | return exists, err | | 31 | } | | 32 | | | 33 | func (s *Service) MemberByName(ctx context.Context, name string) (Member, error) { | | 34 | var member Member | | 35 | err := s.store.DB().QueryRowContext(ctx, `SELECT pubkey,name,note,role,invited_by,via,created_at,keep_days FROM community_members WHERE name=?` , name).Scan(&member.PubKey, &member.Name, &member.Note, &member.Role, &member.InvitedBy, &member.Via, &member.CreatedAt, &member.KeepDays) | | 36 | if errors.Is(err, sql.ErrNoRows) { | | 37 | return Member{}, nil | | 38 | } | | 39 | return member, err | | 40 | } | | 41 | | | 42 | func (s *Service) NIP05(ctx context.Context, name string, relayURL string) (map[string]any, error) { | | 43 | member, err := s.MemberByName(ctx, name) | | 44 | if err != nil { | | 45 | return nil, err | | 46 | } | | 47 | if member.PubKey == "" { | | 48 | return map[string]any{"names" : map[string]string{}, "relays" : map[string][]string{}}, nil | | 49 | } | | 50 | return map[string]any{"names" : map[string]string{name: member.PubKey}, "relays" : map[string][]string{member.PubKey: {relayURL}}}, nil | | 51 | } |
|
|
About| owner | c01503e8035f |
|---|
| visibility | public |
|---|
| head | d730679639bf |
|---|
Maintainers- c01503e8035f owner
- ba1b5beed5b5 agent hermes
Clonehttps://012.run/npub1cq2s86qrtadf36eqq3epm38wmhdynrrcwxf84eldk3f94dkv7ttsrulrz5/tinyrelay.git
|