dm.go 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. package model
  2. import (
  3. "hash/crc32"
  4. "strconv"
  5. "go-common/library/time"
  6. )
  7. // All const variable used in dm2
  8. const (
  9. AttrNo = int32(0) // 属性位为0
  10. AttrYes = int32(1) // 属性位为1
  11. AttrProtect = uint(0) // 保护弹幕
  12. StateNormal = int32(0) // 普通状态
  13. StateDelete = int32(1) // 删除状态
  14. StateHide = int32(2) // 隐藏状态
  15. StateBlock = int32(3) // 屏蔽状态
  16. StateFilter = int32(4) // 过滤状态
  17. StateMonitorBefore = int32(5) // 先审后发
  18. StateMonitorAfter = int32(6) // 先发后审
  19. StateSystemFilter = int32(7) // 敏感词过滤
  20. StateReportDelete = int32(8) // 举报删除
  21. StateAdminDelete = int32(9) // 弹幕管理删除
  22. StateUserDelete = int32(10) // 用户删除
  23. StateScriptDelete = int32(11) // 举报脚本删除
  24. PoolNormal = int32(0) // 普通弹幕池
  25. PoolSubtitle = int32(1) // 字幕弹幕池
  26. PoolSpecial = int32(2) // 特殊弹幕池
  27. NotFound = -1
  28. )
  29. // Hash 用户匿名弹幕uid hash
  30. func Hash(uid int64, ip uint32) string {
  31. var s uint32
  32. if uid != 0 {
  33. s = crc32.ChecksumIEEE([]byte(strconv.FormatInt(uid, 10)))
  34. return strconv.FormatInt(int64(s), 16)
  35. }
  36. s = crc32.ChecksumIEEE([]byte(strconv.FormatInt(int64(ip), 10)))
  37. return "D" + strconv.FormatInt(int64(s), 16)
  38. }
  39. // DM dm_index and dm_content
  40. type DM struct {
  41. ID int64 `json:"id"`
  42. Type int32 `json:"type"`
  43. Oid int64 `json:"oid"`
  44. Mid int64 `json:"mid"`
  45. Progress int32 `json:"progress"`
  46. Pool int32 `json:"pool"`
  47. Attr int32 `json:"attr"`
  48. State int32 `json:"state"`
  49. Ctime time.Time `json:"ctime"`
  50. Mtime time.Time `json:"mtime"`
  51. Content *Content `json:"content,omitempty"`
  52. ContentSpe *ContentSpecial `json:"content_special,omitempty"`
  53. }
  54. // AttrVal return val of index'attr
  55. func (d *DM) AttrVal(bit uint) int32 {
  56. return (d.Attr >> bit) & int32(1)
  57. }
  58. // AttrSet set val of index'attr
  59. func (d *DM) AttrSet(v int32, bit uint) {
  60. d.Attr = d.Attr&(^(1 << bit)) | (v << bit)
  61. }
  62. // NeedDisplay 判断该条弹幕是否需要展示
  63. func (d *DM) NeedDisplay() bool {
  64. return d.State == StateNormal || d.State == StateMonitorAfter
  65. }
  66. // Content dm_content
  67. type Content struct {
  68. ID int64 `json:"id"`
  69. FontSize int32 `json:"fontsize"`
  70. Color int64 `json:"color"`
  71. Mode int32 `json:"mode"`
  72. IP int64 `json:"ip"`
  73. Plat int32 `json:"plat"`
  74. Msg string `json:"msg"`
  75. Ctime time.Time `json:"ctime"`
  76. Mtime time.Time `json:"mtime"`
  77. }
  78. // ContentSpecial dm_content_special
  79. type ContentSpecial struct {
  80. ID int64 `json:"id"`
  81. Msg string `json:"msg"`
  82. Ctime time.Time `json:"ctime"`
  83. Mtime time.Time `json:"mtime"`
  84. }