97 lines
3.5 KiB
C#
97 lines
3.5 KiB
C#
// 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;
|
|
// TODO: add remaining defaults, change properties to normal members as needed
|
|
}
|
|
|
|
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 = split[1];
|
|
|
|
if (split.Length > 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> {value};
|
|
break;
|
|
case "MODES":
|
|
Modes = int.Parse(value, NumberStyles.Integer, CultureInfo.InvariantCulture);
|
|
break;
|
|
case "MONITOR":
|
|
Monitor = int.Parse(value, NumberStyles.Integer, CultureInfo.InvariantCulture);
|
|
break;
|
|
case "WATCH":
|
|
Watch = int.Parse(value, NumberStyles.Integer, CultureInfo.InvariantCulture);
|
|
break;
|
|
case "CASEMAPPING":
|
|
if (Enum.TryParse(value, true, out Casemap.CaseMapping caseMapping))
|
|
CaseMapping = caseMapping;
|
|
break;
|
|
case "CHANTYPES":
|
|
ChanTypes = new List<string> {value};
|
|
break;
|
|
case "CALLERID":
|
|
CallerId = string.IsNullOrEmpty(value) ? value : "g";
|
|
break;
|
|
case "EXCEPTS":
|
|
Excepts = string.IsNullOrEmpty(value) ? value : "e";
|
|
break;
|
|
case "INVEX":
|
|
Invex = string.IsNullOrEmpty(value) ? value : "I";
|
|
break;
|
|
case "WHOX":
|
|
Whox = true;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|