]> ruin.nu Git - NDIRC.git/blobdiff - Commands/Members.pm
Converted the .forum command
[NDIRC.git] / Commands / Members.pm
index dbfa1f416f6b01495dee17db37903bb7893b8b39..34ef7d605028efa790c8935fdf336a976019b3dc 100644 (file)
@@ -123,4 +123,28 @@ sub links
        $c->reply("https://nd.ruin.nu/");
 }
 
+sub forum
+       : Help(syntax: .forum [nick] | not everyone have access to check for others.)
+{
+       my ($self,$c,$msg) = @_;
+       my $dbh = $c->model;
+
+       my $user;
+       if ($msg =~ /(\S+)/ && $c->check_user_roles('irc_forum_others')){
+               $user = $dbh->selectrow_hashref(q{
+SELECT uid,username FROM users WHERE username ILIKE ?
+               }, undef, $1);
+       }else{
+               $user = $dbh->selectrow_hashref(q{
+SELECT uid,username FROM users WHERE hostmask ILIKE ?
+               }, undef, $c->host);
+       }
+       if ($user){
+               my $unread = $dbh->selectrow_hashref(q{SELECT * FROM unread_posts($1)},undef,$user->{uid});
+               if ($unread){
+                       $c->reply("$user->{username} has $unread->{new} posts since your last forum visit ($unread->{unread} unread posts in total) https://nd.ruin.nu/forum/allUnread");
+               }
+       }
+}
+
 1;