92 lines
2.4 KiB
D
92 lines
2.4 KiB
D
module commands.util;
|
|
|
|
struct Command {
|
|
string description = "No description provided";
|
|
string name;
|
|
}
|
|
|
|
static enum Time: int {
|
|
@('s') second = 1,
|
|
@('m') minute = 60 * second,
|
|
@('h') hour = 60 * minute,
|
|
@('d') day = 24 * hour,
|
|
@('w') week = 7 * day,
|
|
@('M') month = 30 * day,
|
|
@('y') year = 12 * month
|
|
}
|
|
|
|
struct Arguments {
|
|
string raw;
|
|
string command;
|
|
string[] parsed;
|
|
char[] options;
|
|
string getArg(string arg) @nogc {
|
|
int prev, splt;
|
|
for (int i; i < options.length; ++i) {
|
|
if (options[i] == '\0') splt = i;
|
|
else if (options[i] == '\1') {
|
|
if (arg == options[prev..splt])
|
|
return cast(string)options[splt+1..i];
|
|
prev = i + 1;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
|
|
auto parseMsg(string cmd) {
|
|
import std.stdio;
|
|
Arguments argz = Arguments(cmd);
|
|
if (argz.raw[0] == '#') {
|
|
string buf;
|
|
for (ulong i = 1; i < argz.raw.length; ++i)
|
|
if (argz.raw[i] != ' ' && argz.raw[i] != '=') {
|
|
buf ~= argz.raw[i];
|
|
if (i+1 == argz.raw.length || (argz.raw[i+1] == ' ' || argz.raw[i+1] == '=')) {
|
|
argz.parsed ~= buf;
|
|
buf = null;
|
|
}
|
|
}
|
|
argz.command = argz.parsed[0]; argz.parsed = argz.parsed[1..$];
|
|
|
|
for (ulong i; i < argz.parsed.length; ++i)
|
|
if (argz.parsed[i][0] == '-') {
|
|
string key = argz.parsed[i];
|
|
auto val = (i+1 < argz.parsed.length && argz.parsed[i+1][0] != '-')
|
|
? argz.parsed[i+1] : null;
|
|
if (key[1] == '-')
|
|
argz.options ~= key[2..$] ~ '\0' ~ val ~ '\1';
|
|
else for (ulong x = 1; x < key.length; ++x)
|
|
argz.options ~= key[x..x+1] ~ '\0' ~ val ~ '\1';
|
|
|
|
auto x = (val) ? i + 2 : i + 1;
|
|
argz.parsed = argz.parsed[0..i] ~ argz.parsed[x..$];
|
|
i = i - (x - i);
|
|
}
|
|
}
|
|
return argz;
|
|
}
|
|
|
|
int getUsrPL(string room, string user) {
|
|
import main: db;
|
|
auto q = db.query("select pl from room_pls where room = ? and user = ?", room, user);
|
|
if (q.step) return q.get!int;
|
|
return 0;
|
|
}
|
|
|
|
short[string] getUsrsPLs(string room) {
|
|
struct hz {
|
|
string user;
|
|
short pl;
|
|
}
|
|
|
|
import main: db;
|
|
short[string] buf;
|
|
auto q = db.query("select user, pl from room_pls where room = ?", room);
|
|
while (q.step) {
|
|
auto x = q.get!hz;
|
|
buf[x.user] = x.pl;
|
|
}
|
|
|
|
return buf;
|
|
} |