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.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. // Copyright (c) 2012-2014 Jeremy Latt
  2. // Copyright (c) 2014-2015 Edmund Huber
  3. // released under the MIT license
  4. package irc
  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 (m *TheaterIdentifyCommand) HandleServer(s *Server) {
  24. client := m.Client()
  25. if !m.channel.IsChannel() {
  26. client.ErrNoSuchChannel(m.channel)
  27. return
  28. }
  29. channel := s.channels.Get(m.channel)
  30. if channel == nil {
  31. client.ErrNoSuchChannel(m.channel)
  32. return
  33. }
  34. if (m.hash == nil) || (m.err != nil) {
  35. client.ErrPasswdMismatch()
  36. return
  37. }
  38. if channel.members.AnyHasMode(Theater) {
  39. client.Reply(RplNotice(s, client, "someone else is +T in this channel"))
  40. return
  41. }
  42. channel.members[client][Theater] = true
  43. }
  44. type TheaterPrivMsgCommand struct {
  45. BaseCommand
  46. channel Name
  47. asNick Name
  48. message Text
  49. }
  50. func (m *TheaterPrivMsgCommand) HandleServer(s *Server) {
  51. client := m.Client()
  52. if !m.channel.IsChannel() {
  53. client.ErrNoSuchChannel(m.channel)
  54. return
  55. }
  56. channel := s.channels.Get(m.channel)
  57. if channel == nil {
  58. client.ErrNoSuchChannel(m.channel)
  59. return
  60. }
  61. if !channel.members.HasMode(client, Theater) {
  62. client.Reply(RplNotice(s, client, "you are not +T"))
  63. return
  64. }
  65. reply := RplPrivMsg(TheaterClient(m.asNick), channel, m.message)
  66. for member := range channel.members {
  67. member.Reply(reply)
  68. }
  69. }
  70. type TheaterActionCommand struct {
  71. BaseCommand
  72. channel Name
  73. asNick Name
  74. action CTCPText
  75. }
  76. func (m *TheaterActionCommand) HandleServer(s *Server) {
  77. client := m.Client()
  78. if !m.channel.IsChannel() {
  79. client.ErrNoSuchChannel(m.channel)
  80. return
  81. }
  82. channel := s.channels.Get(m.channel)
  83. if channel == nil {
  84. client.ErrNoSuchChannel(m.channel)
  85. return
  86. }
  87. if !channel.members.HasMode(client, Theater) {
  88. client.Reply(RplNotice(s, client, "you are not +T"))
  89. return
  90. }
  91. reply := RplCTCPAction(TheaterClient(m.asNick), channel, m.action)
  92. for member := range channel.members {
  93. member.Reply(reply)
  94. }
  95. }