Skip to content

hashanCB/comment-moderator-ai

Repository files navigation

AI-Powered Comment Moderation React Hook 🤖

NPM Version License: MIT

A modern, AI-powered comment moderation system built with Next.js and OpenRouter AI. This project provides real-time comment validation with context awareness and detailed feedback.

✨ Features

  • 🔥 Real-time comment validation
  • 🤖 AI-powered content moderation
  • 💬 Context-aware responses
  • ⏱️ Debounced API calls for better performance
  • 📈 Detailed validation statistics
  • 💻 Modern React hooks for easy integration
  • 🎨 Beautiful UI with Tailwind CSS
  • 🚀 Next.js App Router support

🛠️ Installation

npm install @livehashan/comment-check

📖 Quick Start

  1. Set up your environment variables:
OPENROUTER_API_KEY=your_api_key_here
OPENROUTER_MODEL=deepseek/deepseek-chat-v3-0324:free
  1. Create your API route (Next.js):
import { CommentChecker } from '@livehashan/comment-check';

const checker = new CommentChecker(
  process.env.OPENROUTER_API_KEY,
  process.env.OPENROUTER_MODEL
);

export async function POST(req) {
  const body = await req.json();
  const result = await checker.checkComment(body);
  return new Response(JSON.stringify(result));
}
  1. Use the React hook in your component:
'use client'
import { useCommentCheck } from '@livehashan/comment-check'

export default function CommentForm() {
  const [comment, setComment] = useState('')
  const { isLoading, result, checkComment } = useCommentCheck()

  const handleSubmit = async (e) => {
    e.preventDefault()
    await checkComment(comment)
  }

  return (
    <form onSubmit={handleSubmit}>
      <textarea
        value={comment}
        onChange={(e) => setComment(e.target.value)}
        placeholder="Write your comment here..."
      />
      <button type="submit" disabled={isLoading}>
        {isLoading ? 'Checking...' : 'Submit'}
      </button>
      {result && (
        <div>
          {result.approved ? '✅ Approved!' : '❌ Not Approved'}
          <p>{result.reason}</p>
        </div>
      )}
    </form>
  )
}

💻 Tech Stack

  • Next.js 13+ (App Router)
  • React 18+
  • OpenRouter AI API
  • TypeScript
  • Tailwind CSS

📃 License

MIT © Hashan

❤️ Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

💬 Support

If you have any questions or need help, please:


Made with ❤️ by Hashan

About

AI-Powered Comment Moderation React Hook with real-time validation, context-aware feedback, and seamless integration for modern web apps.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors