1 /++ 2 + 3 +/ 4 module virc.numerics.watch; 5 6 import std.algorithm.comparison : among; 7 8 import virc.numerics.definitions; 9 /++ 10 + Parses most of the WATCH numerics. Most of them have the same format, so the 11 + majority of the magic happens in this function. 12 + 13 + Formats are: 14 + 15 + `600 <client> <nickname> <username> <hostname> <signontime> :logged on` 16 + 17 + `601 <client> <nickname> <username> <hostname> <lastnickchange> :logged off` 18 + 19 + `602 <client> <nickname> <username> <hostname> <lastnickchange> :stopped watching` 20 + 21 + `604 <client> <nickname> <username> <hostname> <lastnickchange> :is online` 22 + 23 + `605 <client> <nickname> <username> <hostname> <lastnickchange> :is offline` 24 + 25 + `609 <client> <nickname> <username> <hostname> <awaysince> :is away` 26 + 27 + Standards: Conforms to https://raw.githubusercontent.com/grawity/irc-docs/master/client/draft-meglio-irc-watch-00.txt 28 +/ 29 auto parseNumeric(Numeric numeric, T)(T input) if (numeric.among(Numeric.RPL_LOGON, Numeric.RPL_LOGOFF, Numeric.RPL_WATCHOFF, Numeric.RPL_NOWOFF, Numeric.RPL_NOWON, Numeric.RPL_NOWISAWAY)) { 30 import std.conv : to; 31 import std.datetime : SysTime, UTC; 32 import std.typecons : tuple; 33 import virc.common : User; 34 input.popFront(); 35 auto user = User(); 36 user.mask.nickname = input.front; 37 input.popFront(); 38 user.mask.ident = input.front; 39 input.popFront(); 40 user.mask.host = input.front; 41 input.popFront(); 42 auto timeOccurred = SysTime.fromUnixTime(input.front.to!long, UTC()); 43 return tuple!("user", "timeOccurred")(user, timeOccurred); 44 } 45 /// 46 @safe pure /+nothrow @nogc+/ unittest { //Numeric.RPL_LOGON 47 import std.datetime : DateTime, SysTime, UTC; 48 import std.range : only; 49 { 50 immutable logon = parseNumeric!(Numeric.RPL_LOGON)(only("someone", "someoneElse", "someIdent", "example.net", "911248013", "logged on")); 51 assert(logon.user.mask.nickname == "someoneElse"); 52 assert(logon.user.mask.ident == "someIdent"); 53 assert(logon.user.mask.host == "example.net"); 54 static immutable date = SysTime(DateTime(1998, 11, 16, 20, 26, 53), UTC()); 55 assert(logon.timeOccurred == date); 56 } 57 }