diff options
author | Ben Harris <ben@tilde.team> | 2020-05-14 23:06:10 -0400 |
---|---|---|
committer | Ben Harris <ben@tilde.team> | 2020-05-14 23:17:47 -0400 |
commit | 21f1e95fb8e935134a969bc3d729964d8d2aadfa (patch) | |
tree | db2be27e9b5ac48e19f92b56cbad68ab59f7099e /IRCStates/ISupport.cs | |
parent | 304df7805b9925c2edd992fd4177eef80197f807 (diff) |
rename Irc to IRC
Diffstat (limited to 'IRCStates/ISupport.cs')
-rw-r--r-- | IRCStates/ISupport.cs | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/IRCStates/ISupport.cs b/IRCStates/ISupport.cs new file mode 100644 index 0000000..5fcd5b1 --- /dev/null +++ b/IRCStates/ISupport.cs @@ -0,0 +1,114 @@ +// ReSharper disable InconsistentNaming + +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; + +namespace IRCStates +{ + public class ISupport + { + public ISupport() + { + Raw = new Dictionary<string, string>(); + Modes = 3; + CaseMapping = Casemap.CaseMapping.Rfc1459; + Prefix = new ISupportPrefix("(ov)@+"); + ChanModes = new ISupportChanModes("b,k,l,imnpst"); + ChanTypes = new List<string> {"#"}; + StatusMsg = new List<string>(); + Whox = false; + } + + public Dictionary<string, string> Raw { get; set; } + public string Network { get; set; } + public ISupportChanModes ChanModes { get; set; } + public ISupportPrefix Prefix { get; set; } + public int? Modes { get; set; } + public Casemap.CaseMapping CaseMapping { get; set; } + public List<string> ChanTypes { get; set; } + public List<string> StatusMsg { get; set; } + public string CallerId { get; set; } + public string Excepts { get; set; } + public string Invex { get; set; } + public int? Monitor { get; set; } + public int? Watch { get; set; } + public bool Whox { get; set; } + + public void Parse(IEnumerable<string> tokens) + { + if (tokens == null) return; + + // remove first and last + tokens = tokens.Skip(1).SkipLast(1); + + foreach (var token in tokens) + { + var split = token.Split('=', 2); + var key = split[0]; + + var value = string.Empty; + if (split.Length > 1) + { + value = split[1]; + Raw[key] = value; + } + + switch (split[0]) + { + case "NETWORK": + Network = value; + break; + case "CHANMODES": + ChanModes = new ISupportChanModes(value); + break; + case "PREFIX": + Prefix = new ISupportPrefix(value); + break; + case "STATUSMSG": + StatusMsg = new List<string>(); + StatusMsg.AddRange(value.Select(c => c.ToString(CultureInfo.InvariantCulture))); + break; + case "MODES": + if (int.TryParse(value, NumberStyles.Integer, CultureInfo.InvariantCulture, out var modes)) + Modes = modes; + else + Modes = -1; + break; + case "MONITOR": + if (int.TryParse(value, NumberStyles.Integer, CultureInfo.InvariantCulture, out var monitor)) + Monitor = monitor; + else + Monitor = -1; + break; + case "WATCH": + if (int.TryParse(value, NumberStyles.Integer, CultureInfo.InvariantCulture, out var watch)) + Watch = watch; + else + Watch = -1; + break; + case "CASEMAPPING": + if (Enum.TryParse(value, true, out Casemap.CaseMapping caseMapping)) CaseMapping = caseMapping; + break; + case "CHANTYPES": + ChanTypes = new List<string>(); + ChanTypes.AddRange(value.Select(c => c.ToString(CultureInfo.InvariantCulture))); + break; + case "CALLERID": + CallerId = string.IsNullOrEmpty(value) ? "g" : value; + break; + case "EXCEPTS": + Excepts = string.IsNullOrEmpty(value) ? "e" : value; + break; + case "INVEX": + Invex = string.IsNullOrEmpty(value) ? "I" : value; + break; + case "WHOX": + Whox = true; + break; + } + } + } + } +} |