Fix indentation
This commit is contained in:
parent
1d1d4d5a87
commit
849494b1a7
140
ircbot.d
140
ircbot.d
|
@ -308,85 +308,85 @@ class TLSClient
|
||||||
|
|
||||||
struct Message
|
struct Message
|
||||||
{
|
{
|
||||||
string prefix;
|
string prefix;
|
||||||
string command;
|
string command;
|
||||||
string[] parameters;
|
string[] parameters;
|
||||||
bool prefixedParameter;
|
bool prefixedParameter;
|
||||||
|
|
||||||
//NOTE: The RFCs don't state what this is exactly, but common implementations use the byte count of the message parameters
|
//NOTE: The RFCs don't state what this is exactly, but common implementations use the byte count of the message parameters
|
||||||
ulong bytes;
|
ulong bytes;
|
||||||
|
|
||||||
static Message fromString(string line)
|
static Message fromString(string line)
|
||||||
{
|
{
|
||||||
string prefix = null;
|
string prefix = null;
|
||||||
if(line.startsWith(':'))
|
if(line.startsWith(':'))
|
||||||
{
|
{
|
||||||
line = line[1 .. $];
|
line = line[1 .. $];
|
||||||
prefix = line[0 .. line.indexOf(' ')];
|
prefix = line[0 .. line.indexOf(' ')];
|
||||||
line = line[prefix.length + 1 .. $];
|
line = line[prefix.length + 1 .. $];
|
||||||
}
|
}
|
||||||
|
|
||||||
//stop early when no space character can be found (message without parameters)
|
//stop early when no space character can be found (message without parameters)
|
||||||
if(!line.canFind(' '))
|
if(!line.canFind(' '))
|
||||||
{
|
{
|
||||||
return Message(prefix, line, [], false);
|
return Message(prefix, line, [], false);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto command = line[0 .. line.indexOf(' ')];
|
auto command = line[0 .. line.indexOf(' ')];
|
||||||
line = line[command.length + 1 .. $];
|
line = line[command.length + 1 .. $];
|
||||||
auto bytes = line.length;
|
auto bytes = line.length;
|
||||||
string[] params = [];
|
string[] params = [];
|
||||||
bool prefixedParam;
|
bool prefixedParam;
|
||||||
while(true)
|
while(true)
|
||||||
{
|
{
|
||||||
if(line.startsWith(':'))
|
if(line.startsWith(':'))
|
||||||
{
|
{
|
||||||
params ~= line[1 .. $];
|
params ~= line[1 .. $];
|
||||||
prefixedParam = true;
|
prefixedParam = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else if(line.canFind(' '))
|
else if(line.canFind(' '))
|
||||||
{
|
{
|
||||||
auto param = line[0 .. line.indexOf(' ')];
|
auto param = line[0 .. line.indexOf(' ')];
|
||||||
line = line[param.length + 1 .. $];
|
line = line[param.length + 1 .. $];
|
||||||
params ~= param;
|
params ~= param;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
params ~= line;
|
params ~= line;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Message(prefix, command, params, prefixedParam, bytes);
|
return Message(prefix, command, params, prefixedParam, bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
string toString()
|
string toString()
|
||||||
{
|
{
|
||||||
auto message = "";
|
auto message = "";
|
||||||
if(prefix != null)
|
if(prefix != null)
|
||||||
{
|
{
|
||||||
message = ":" ~ prefix ~ " ";
|
message = ":" ~ prefix ~ " ";
|
||||||
}
|
}
|
||||||
|
|
||||||
if(parameters.length == 0)
|
if(parameters.length == 0)
|
||||||
{
|
{
|
||||||
return message ~ command;
|
return message ~ command;
|
||||||
}
|
}
|
||||||
|
|
||||||
message ~= command ~ " ";
|
message ~= command ~ " ";
|
||||||
if(parameters.length > 1)
|
if(parameters.length > 1)
|
||||||
{
|
{
|
||||||
message ~= parameters[0 .. $-1].join(' ') ~ " ";
|
message ~= parameters[0 .. $-1].join(' ') ~ " ";
|
||||||
}
|
}
|
||||||
|
|
||||||
if(parameters[$-1].canFind(' ') || prefixedParameter)
|
if(parameters[$-1].canFind(' ') || prefixedParameter)
|
||||||
{
|
{
|
||||||
message ~= ":";
|
message ~= ":";
|
||||||
}
|
}
|
||||||
message ~= parameters[$-1];
|
message ~= parameters[$-1];
|
||||||
|
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue