util.go 827 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package discord
  2. import (
  3. "strings"
  4. "github.com/ayntgl/astatine"
  5. )
  6. func ChannelToString(c *astatine.Channel) string {
  7. var repr string
  8. if c.Name != "" {
  9. repr = "#" + c.Name
  10. } else if len(c.Recipients) == 1 {
  11. rp := c.Recipients[0]
  12. repr = rp.Username + "#" + rp.Discriminator
  13. } else {
  14. rps := make([]string, len(c.Recipients))
  15. for i, r := range c.Recipients {
  16. rps[i] = r.Username + "#" + r.Discriminator
  17. }
  18. repr = strings.Join(rps, ", ")
  19. }
  20. return repr
  21. }
  22. func FindMessageByID(ms []*astatine.Message, mID string) (int, *astatine.Message) {
  23. for i, m := range ms {
  24. if m.ID == mID {
  25. return i, m
  26. }
  27. }
  28. return -1, nil
  29. }
  30. func HasPermission(s *astatine.State, cID string, p int64) bool {
  31. perm, err := s.UserChannelPermissions(s.User.ID, cID)
  32. if err != nil {
  33. return false
  34. }
  35. return perm&p == p
  36. }