The easy to use and full featured Irc Bot everyone is talking about!
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.

Channel.cs 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace Combot.IRCServices
  7. {
  8. public class Channel
  9. {
  10. public string Name { get; set; }
  11. public string Topic { get; set; }
  12. public string Key { get; set; }
  13. public bool AutoJoin { get; set; }
  14. public bool Joined { get; set; }
  15. public DateTime Registration { get; set; }
  16. public List<ChannelMode> Modes { get; set; }
  17. public List<Nick> Nicks { get; set; }
  18. private IRC _IRC;
  19. public Channel(IRC irc)
  20. {
  21. Name = string.Empty;
  22. Topic = string.Empty;
  23. Key = string.Empty;
  24. AutoJoin = false;
  25. Joined = false;
  26. Registration = DateTime.Now;
  27. Modes = new List<ChannelMode>();
  28. Nicks = new List<Nick>();
  29. _IRC = irc;
  30. }
  31. public void AddNick(Nick nick)
  32. {
  33. Nicks.Add(nick);
  34. }
  35. public void AddNicks(List<Nick> nicks)
  36. {
  37. Nicks.AddRange(nicks);
  38. }
  39. public void RemoveNick(Nick nick)
  40. {
  41. if (Nicks.Contains(nick))
  42. {
  43. Nicks.Remove(nick);
  44. }
  45. }
  46. public void RemoveNicks(List<Nick> nicks)
  47. {
  48. foreach (Nick nick in nicks)
  49. {
  50. RemoveNick(nick);
  51. }
  52. }
  53. public void AddMode(ChannelMode mode)
  54. {
  55. if (!Modes.Contains(mode))
  56. {
  57. ChannelModeInfo modeInfo = new ChannelModeInfo();
  58. modeInfo.Mode = mode;
  59. modeInfo.Set = true;
  60. _IRC.IRCSendMode(Name, modeInfo);
  61. Modes.Add(mode);
  62. }
  63. }
  64. public void AddModes(List<ChannelMode> modes)
  65. {
  66. if (!modes.TrueForAll(mode => Modes.Contains(mode)))
  67. {
  68. List<ChannelModeInfo> modeInfos = new List<ChannelModeInfo>();
  69. modes.ForEach(mode => modeInfos.Add(new ChannelModeInfo() { Mode = mode, Set = true }));
  70. _IRC.IRCSendMode(Name, modeInfos);
  71. Modes.AddRange(modes);
  72. }
  73. }
  74. public void RemoveMode(ChannelMode mode)
  75. {
  76. if (Modes.Contains(mode))
  77. {
  78. ChannelModeInfo modeInfo = new ChannelModeInfo();
  79. modeInfo.Mode = mode;
  80. modeInfo.Set = false;
  81. _IRC.IRCSendMode(Name, modeInfo);
  82. Modes.Remove(mode);
  83. }
  84. }
  85. public void RemoveModes(List<ChannelMode> modes)
  86. {
  87. List<ChannelMode> validModes = Modes.FindAll(mode => mode == modes.Find(m => m == mode));
  88. List<ChannelModeInfo> modeInfos = new List<ChannelModeInfo>();
  89. validModes.ForEach(mode => modeInfos.Add(new ChannelModeInfo() { Mode = mode, Set = true }));
  90. validModes.ForEach(mode => Modes.Remove(mode));
  91. _IRC.IRCSendMode(Name, modeInfos);
  92. }
  93. public void Join()
  94. {
  95. if (!Joined)
  96. {
  97. _IRC.IRCSendJoin(Name, Key);
  98. Joined = true;
  99. }
  100. }
  101. public void Part()
  102. {
  103. if (Joined)
  104. {
  105. _IRC.IRCSendPart(Name);
  106. Joined = false;
  107. }
  108. }
  109. public void SetTopic(string topic)
  110. {
  111. if (Joined)
  112. {
  113. _IRC.IRCSendTopic(Name, topic);
  114. }
  115. }
  116. public string GetTopic()
  117. {
  118. return string.Empty;
  119. }
  120. }
  121. }