Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

theater.go 2.1KB

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