You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

theater.go 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. package irc
  2. import (
  3. "fmt"
  4. )
  5. type TheaterClient Name
  6. func (c TheaterClient) Id() Name {
  7. return Name(c)
  8. }
  9. func (c TheaterClient) Nick() Name {
  10. return Name(c)
  11. }
  12. type TheaterSubCommand string
  13. type theaterSubCommand interface {
  14. String() string
  15. }
  16. type TheaterIdentifyCommand struct {
  17. PassCommand
  18. channel Name
  19. }
  20. func (m *TheaterIdentifyCommand) LoadPassword(s *Server) {
  21. m.hash = s.theaters[m.channel]
  22. }
  23. func (cmd *TheaterIdentifyCommand) String() string {
  24. return fmt.Sprintf("THEATER_IDENTIFY(channel=%s)", cmd.channel)
  25. }
  26. func (m *TheaterIdentifyCommand) HandleServer(s *Server) {
  27. client := m.Client()
  28. if !m.channel.IsChannel() {
  29. client.ErrNoSuchChannel(m.channel)
  30. return
  31. }
  32. channel := s.channels.Get(m.channel)
  33. if channel == nil {
  34. client.ErrNoSuchChannel(m.channel)
  35. return
  36. }
  37. if (m.hash == nil) || (m.err != nil) {
  38. client.ErrPasswdMismatch()
  39. return
  40. }
  41. if channel.members.AnyHasMode(Theater) {
  42. client.Reply(RplNotice(s, client, "someone else is +T in this channel"))
  43. return
  44. }
  45. channel.members[client][Theater] = true
  46. }
  47. type TheaterPrivMsgCommand struct {
  48. BaseCommand
  49. channel Name
  50. asNick Name
  51. message Text
  52. }
  53. func (cmd *TheaterPrivMsgCommand) String() string {
  54. return fmt.Sprintf("THEATER_PRIVMSG(channel=%s, asNick=%s, message=%s)", cmd.channel, cmd.asNick, cmd.message)
  55. }
  56. func (m *TheaterPrivMsgCommand) HandleServer(s *Server) {
  57. client := m.Client()
  58. if !m.channel.IsChannel() {
  59. client.ErrNoSuchChannel(m.channel)
  60. return
  61. }
  62. channel := s.channels.Get(m.channel)
  63. if channel == nil {
  64. client.ErrNoSuchChannel(m.channel)
  65. return
  66. }
  67. if !channel.members.HasMode(client, Theater) {
  68. client.Reply(RplNotice(s, client, "you are not +T"))
  69. return
  70. }
  71. for member := range channel.members {
  72. member.Reply(RplPrivMsg(TheaterClient(m.asNick), channel, m.message))
  73. }
  74. }
  75. type TheaterActionCommand struct {
  76. BaseCommand
  77. channel Name
  78. asNick Name
  79. action CTCPText
  80. }
  81. func (cmd *TheaterActionCommand) String() string {
  82. return fmt.Sprintf("THEATER_ACTION(channel=%s, asNick=%s, action=%s)", cmd.channel, cmd.asNick, cmd.action)
  83. }
  84. func (m *TheaterActionCommand) HandleServer(s *Server) {
  85. client := m.Client()
  86. if !m.channel.IsChannel() {
  87. client.ErrNoSuchChannel(m.channel)
  88. return
  89. }
  90. channel := s.channels.Get(m.channel)
  91. if channel == nil {
  92. client.ErrNoSuchChannel(m.channel)
  93. return
  94. }
  95. if !channel.members.HasMode(client, Theater) {
  96. client.Reply(RplNotice(s, client, "you are not +T"))
  97. return
  98. }
  99. for member := range channel.members {
  100. member.Reply(RplCTCPAction(TheaterClient(m.asNick), channel, m.action))
  101. }
  102. }