// Comprehensive moderation system
class ChannelModerator {
constructor(channelId, channelType) {
this.channelId = channelId;
this.channelType = channelType;
this.moderationRules = {
profanityFilter: true,
linkRestriction: true,
capsLockLimit: 0.7, // 70% caps lock threshold
mentionSpamLimit: 5
};
}
async moderateUser(userId, violations) {
const severity = this.calculateViolationSeverity(violations);
switch (severity) {
case 'low':
await this.issueWarning(userId, violations);
break;
case 'medium':
await this.temporaryRestriction(userId, violations);
break;
case 'high':
await this.addToBlacklist(userId, violations);
break;
}
}
calculateViolationSeverity(violations) {
const severityScores = {
'profanity': 2,
'spam': 3,
'harassment': 4,
'inappropriate_content': 3,
'link_spam': 2,
'caps_abuse': 1
};
const totalScore = violations.reduce((sum, violation) =>
sum + (severityScores[violation.type] || 1), 0
);
if (totalScore >= 6) return 'high';
if (totalScore >= 3) return 'medium';
return 'low';
}
async addToBlacklist(userId, violations) {
try {
await addToBlacklist({
channel_id: this.channelId,
channel_type: this.channelType,
uids: [userId]
});
// Create moderation record
await createModerationRecord({
channel_id: this.channelId,
user_id: userId,
action: 'blacklisted',
violations: violations,
moderator: 'system',
timestamp: new Date().toISOString(),
appeal_deadline: new Date(Date.now() + 7 * 24 * 60 * 60 * 1000).toISOString()
});
// Notify user
await notifyUser(userId, {
type: 'blacklisted',
channel_id: this.channelId,
violations: violations,
appeal_process: 'You can appeal this decision within 7 days'
});
console.log(`User ${userId} blacklisted for violations:`, violations);
} catch (error) {
console.error(`Failed to blacklist user ${userId}:`, error);
}
}
async issueWarning(userId, violations) {
await createModerationRecord({
channel_id: this.channelId,
user_id: userId,
action: 'warning',
violations: violations,
moderator: 'system',
timestamp: new Date().toISOString()
});
await notifyUser(userId, {
type: 'warning',
channel_id: this.channelId,
violations: violations,
message: 'Please follow channel guidelines'
});
}
async temporaryRestriction(userId, violations) {
// Implement temporary restriction logic
// This might involve a separate temporary blacklist system
console.log(`Temporary restriction for user ${userId}:`, violations);
}
}