]> ruin.nu Git - NDIRC.git/commitdiff
Discord id in +user
authorMichael Andreen <harv@ruin.nu>
Wed, 6 Mar 2019 21:31:51 +0000 (22:31 +0100)
committerMichael Andreen <harv@ruin.nu>
Thu, 21 Mar 2019 15:47:50 +0000 (16:47 +0100)
Commands/Usermgm.pm

index 8dda53aaac5b3ac29c475a967a32b7ec397bf2f9..5866f9144886ecd829b6b91874988a0148c9a2c0 100644 (file)
@@ -25,29 +25,36 @@ use MooseX::Declare;
 use NDIRC::Dispatcher;
 
 command '+user' => {
 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) {
        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 $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){
 
                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{
                }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>");
                }
        }
 };
                }
        }
 };