ircsharp/IRCStates/Channel.cs

62 lines
1.9 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.Linq;
2024-04-19 23:34:36 +00:00
// ReSharper disable AutoPropertyCanBeMadeGetOnly.Local
2020-05-15 03:06:10 +00:00
namespace IRCStates
{
public class Channel
{
2020-05-17 02:08:40 +00:00
public string Name { get; private set; }
public string NameLower { get; private set; }
2023-11-07 22:54:58 +00:00
public Dictionary<string, ChannelUser> Users { get; private set; } = new Dictionary<string, ChannelUser>();
public string Topic { get; set; }
public string TopicSetter { get; set; }
public DateTime TopicTime { get; set; }
public DateTime Created { get; set; }
2023-11-07 22:54:58 +00:00
public Dictionary<string, List<string>> ListModes { get; private set; } = new Dictionary<string, List<string>>();
public Dictionary<string, string> Modes { get; private set; } = new Dictionary<string, string>();
public override string ToString()
{
return $"Channel(name={Name})";
}
public void SetName(string name, string nameLower)
{
Name = name;
NameLower = nameLower;
}
public void AddMode(string ch, string param, bool listMode)
{
if (listMode)
{
if (!ListModes.ContainsKey(ch)) ListModes[ch] = new List<string>();
2020-05-14 21:13:46 +00:00
if (!ListModes[ch].Contains(param)) ListModes[ch].Add(param ?? string.Empty);
}
else
{
Modes[ch] = param;
}
}
public void RemoveMode(string ch, string param)
{
if (ListModes.ContainsKey(ch))
{
if (ListModes[ch].Contains(param))
{
ListModes[ch].Remove(param);
if (!ListModes[ch].Any()) ListModes.Remove(ch);
}
}
else if (Modes.ContainsKey(ch))
{
Modes.Remove(ch);
}
}
}
}