- $f->finish;
-}
-
-sub setpnick
- : Help(Usage: .setpnick username pnick | Changes a user's pnick)
- : ACL(irc_setpnick)
-{
- my ($self,$c,$msg) = @_;
- my ($nick,$pnick) = $msg =~ /^(\S+) (\S+)$/ or die 'ARGS';
- my $dbh = $c->model;
-
- my $f = $dbh->prepare(q{SELECT uid,username FROM users WHERE username ILIKE ?});
- $f->execute($nick);
- my $user = $f->fetchrow_hashref;
- if ($f->rows == 1){
- my $hostname = "$pnick.users.netgamers.org";
- eval{
- $dbh->do(q{UPDATE users SET pnick = ?, hostmask = ? WHERE uid = ?}
- ,undef,$pnick,$hostname,$user->{uid});
- $c->reply("Updated <b>$user->{username}</b>'s pnick to: <b>$pnick</b> and hostname to <b>$hostname</b>");
- };
- if($@){
- if ($@ =~ /duplicate key value violates unique constraint/){
- my ($username, $hostname, $pnick) = $dbh->selectrow_array(q{
-SELECT username,hostmask,pnick FROM users WHERE hostmask ILIKE $1 OR pnick ILIKE $2
- },undef,$hostname, $pnick);
- $c->reply("<c04>Problem</c>, <b>$username</b> already uses host <b>$hostname</b> and pnick <b>$pnick</b>.");
- }else{
- die $@;
+};
+
+command setpnick => {
+ help => q(Usage: .setpnick username pnick | Changes a user's pnick),
+ acl => q(irc_setpnick)
+}, class extends NDIRC::Command {
+ method execute ($c,$msg) {
+ my ($nick,$pnick) = $msg =~ /^(\S+) (\S+)$/ or die 'ARGS';
+ my $dbh = $c->model;
+
+ my $f = $dbh->prepare(q{SELECT uid,username FROM users WHERE username ILIKE ?});
+ $f->execute($nick);
+ my $user = $f->fetchrow_hashref;
+ if ($f->rows == 1){
+ my $hostname = "$pnick.users.netgamers.org";
+ eval{
+ $dbh->do(q{UPDATE users SET pnick = ?, hostmask = ? WHERE uid = ?}
+ ,undef,$pnick,$hostname,$user->{uid});
+ $c->reply("Updated <b>$user->{username}</b>'s pnick to: <b>$pnick</b> and hostname to <b>$hostname</b>");
+ };
+ if($@){
+ if ($@ =~ /duplicate key value violates unique constraint/){
+ my ($username, $hostname, $pnick) = $dbh->selectrow_array(q{
+SELECT username,hostmask,pnick FROM users WHERE hostmask = $1 OR pnick = $2
+ },undef,$hostname, $pnick);
+ $c->reply("<c04>Problem</c>, <b>$username</b> already uses host <b>$hostname</b> and pnick <b>$pnick</b>.");
+ }else{
+ die $@;
+ }
+ }
+ }elsif ($f->rows == 0){
+ $c->reply("No hit, maybe spelling mistake, or add % as wildcard");
+ }else{
+ $c->reply("More than 1 user matched, please refine the search");
+ }
+ $f->finish;
+ }
+};
+
+command setdiscordid => {
+ help => q(Usage: .setdiscordid username discordid | Changes a user's discord id/tag Nick#id),
+ acl => q(bot_setdiscordid)
+}, class extends NDIRC::Command {
+ method execute ($c,$msg) {
+ my ($nick,$discordid) = $msg =~ /^(\S+) (\S+)$/ or die 'ARGS';
+ my $dbh = $c->model;
+
+ my $f = $dbh->prepare(q{SELECT uid,username FROM users WHERE username ILIKE ?});
+ $f->execute($nick);
+ my $user = $f->fetchrow_hashref;
+ if ($f->rows == 1){
+ eval{
+ $dbh->do(q{UPDATE users SET discord_id = NULLIF($1, 'NULL') WHERE uid = $2}
+ ,undef,$discordid,$user->{uid});
+ $c->reply("Updated <b>$user->{username}</b>'s discord id to: <b>$discordid</b>");
+ };
+ if($@){
+ if ($@ =~ /duplicate key value violates unique constraint/){
+ my ($username, $discordid) = $dbh->selectrow_array(q{
+SELECT username,discord_id FROM users WHERE discord_id = $1
+ },undef,$discordid);
+ $c->reply("<c04>Problem</c>, <b>$username</b> already uses discord id <b>$discordid</b>.");
+ }else{
+ die $@;
+ }