use NDIRC::Dispatcher;
command '+user' => {
- help => q(syntax: .+user username [pnick] | username must be alphanum characters, if no pnick is given then it will be set to the same as username),
+ help => q(syntax: .+user username id | username must be alphanum characters, assumes discord id if it ends with #XXXX otherwise pnick),
type => q(usermgmt),
acl => 'irc_adduser'
}, class extends NDIRC::Command {
method execute ($c,$msg) {
- my ($nick,$pnick) = $msg =~ /^(\w+)(?: ([^.\s]+))?$/ or die 'ARGS';
- $pnick //= $nick;
+ my ($nick,$id) = $msg =~ /^(\w+) (.+)$/ or die 'ARGS';
my $dbh = $c->model;
-
- my $host = "$pnick.users.netgamers.org";
- my ($username,$hostname,$p_nick) = $dbh->selectrow_array(q{
-SELECT username, hostmask,pnick
-FROM users WHERE username = $1 OR hostmask = $2 OR pnick = $3
- },undef,$nick,$host,$pnick);
+ my $pnick = undef;
+ my $discordid = undef;
+ my $host = undef;
+
+ if ($id =~ /.+#\d+/) {
+ $discordid = $id;
+ } else {
+ $pnick = $id;
+ $host = "$pnick.users.netgamers.org";
+ }
+ my ($username,$hostname,$p_nick,$discord_id) = $dbh->selectrow_array(q{
+SELECT username, hostmask,pnick,discord_id
+FROM users WHERE username = $1 OR hostmask = $2 OR pnick = $3 OR discord_id = $4
+ },undef,$nick,$host,$pnick,$discordid);
if (defined $username){
- $c->reply("<b>$username ($p_nick)</b> already exists with host: <b>$hostname</b>");
+ $c->reply("<b>$username ($p_nick, $discord_id)</b> already exists with host: <b>$hostname</b>");
}else{
$dbh->do(q{
-INSERT INTO users (username,hostmask,pnick) VALUES($1,$2,$3)
- },undef,$nick,$host,$pnick);
- $c->reply("Added <b>$nick(/$pnick)</b> with host: <b>$host</b>");
+INSERT INTO users (username,hostmask,pnick,discord_id) VALUES($1,$2,$3,$4)
+ },undef,$nick,$host,$pnick,$discordid);
+ $c->reply("Added <b>$nick(/$id)</b>");
}
}
};