From bcce59cf9f1e7389a84efc7d1c0360963d5d56db Mon Sep 17 00:00:00 2001 From: sloppyjosh Date: Tue, 27 Feb 2024 01:39:51 -0500 Subject: [PATCH] Messages Handling --- src/db/services/databaseMaintenance.ts | 2 +- src/index.ts | 4 +-- src/messages/rdrama_messages.txt | 13 ++++++++ src/messages/reddit_messages.txt | 18 ++++++++++ src/rdrama/services/CommentProcessor.ts | 2 +- src/utils/MessageService.ts | 44 +++++++++++++++++++++++++ tsconfig.json | 32 ++++++++++-------- 7 files changed, 98 insertions(+), 17 deletions(-) create mode 100644 src/messages/rdrama_messages.txt create mode 100644 src/messages/reddit_messages.txt create mode 100644 src/utils/MessageService.ts diff --git a/src/db/services/databaseMaintenance.ts b/src/db/services/databaseMaintenance.ts index 13a8e3d..0298437 100644 --- a/src/db/services/databaseMaintenance.ts +++ b/src/db/services/databaseMaintenance.ts @@ -1,4 +1,4 @@ -import { DatabaseService } from './database'; +import { DatabaseService } from './Database'; /** * Manages and executes database maintenance tasks such as purging old comments. diff --git a/src/index.ts b/src/index.ts index e8c7a0e..e776d81 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,8 +5,8 @@ import WorkflowOrchestrator from './workflows/WorkflowOrchestrator'; import SessionManager from './rdrama/session/SessionManager'; import { CommentParser } from './rdrama/services/CommentParser'; import { DatabaseInitializer } from './db/initializeDatabase'; -import { DatabaseService } from './db/services/database'; -import { DatabaseMaintenanceService } from './db/services/databaseMaintenance'; +import { DatabaseService } from './db/services/Database'; +import { DatabaseMaintenanceService } from './db/services/DatabaseMaintenance'; import { CommentProcessor } from './rdrama/services/CommentProcessor'; // Import other necessary services or configurations diff --git a/src/messages/rdrama_messages.txt b/src/messages/rdrama_messages.txt new file mode 100644 index 0000000..4ec2021 --- /dev/null +++ b/src/messages/rdrama_messages.txt @@ -0,0 +1,13 @@ +Hi {rdramaUsername}, + +This is an automated message to address a recent comment you made mentioning a Reddit user. Our platform values respect and privacy for individuals across the internet. As part of our community standards, we urge you to consider the impact of publicly mentioning users from other platforms without their consent. + +Please be aware that we have notified the mentioned Reddit user about this instance. However, we strongly encourage you to reflect on this behavior and strive for positive interactions moving forward. Publicly mentioning users can lead to unwanted attention and discomfort, which contradicts our community's standards. + +Let's work together to maintain a respectful and welcoming environment for all users. Please consider this message a friendly reminder to uphold these values in your future posts and comments. + +Thank you for your understanding and cooperation. + +Best, +[Your Bot Name] - Automated Message (Unmonitored Account) +---END--- \ No newline at end of file diff --git a/src/messages/reddit_messages.txt b/src/messages/reddit_messages.txt new file mode 100644 index 0000000..a2e1b68 --- /dev/null +++ b/src/messages/reddit_messages.txt @@ -0,0 +1,18 @@ +Hello {username}, + +We hope this message finds you well. We're reaching out to inform you that there has been a mention of your Reddit username in a discussion on a different platform. This notification is part of our commitment to online privacy and community care. + +The mention was made in the context of a post or comment on rDrama. While we understand this might be of interest to you, we also recognize the importance of privacy and discretion. As such, we're not providing a direct link to the discussion to prevent any unintended traffic or attention. + +If you wish to view the mention, please note that some effort is required on your part to access it. The information needed to locate the discussion is as follows: + +- Platform: rDrama +- Partial URL: rdrama[dot]net/post/{postId} +- Mention context (optional placeholder if you have specific context information): {mentionContext} + +Please replace "[dot]" with "." to form the actual URL and consider your privacy and well-being before deciding to visit the site. + +We understand if this news is unwelcome or concerning. If you have any questions or need support regarding this matter, please don't hesitate to reach out to us. + +Take care, +[Your Platform Name or Team] \ No newline at end of file diff --git a/src/rdrama/services/CommentProcessor.ts b/src/rdrama/services/CommentProcessor.ts index 156d451..1c29a88 100644 --- a/src/rdrama/services/CommentProcessor.ts +++ b/src/rdrama/services/CommentProcessor.ts @@ -1,5 +1,5 @@ import { Comment } from '../models/Comment'; -import { DatabaseService } from '../../db/services/database'; +import { DatabaseService } from '../../db/services/Database'; import { CommentFetcher } from './CommentFetcher'; /** diff --git a/src/utils/MessageService.ts b/src/utils/MessageService.ts new file mode 100644 index 0000000..7172bc5 --- /dev/null +++ b/src/utils/MessageService.ts @@ -0,0 +1,44 @@ +import fs from 'fs'; +import path from 'path'; + +export class MessageService { + private redditMessages: string[] = []; + private rdramaMessages: string[] = []; + + constructor() { + this.loadMessages(); + } + + private loadMessages() { + try { + const redditMessagesPath = path.join(__dirname, 'messages', 'reddit_messages.txt'); + this.redditMessages = fs.readFileSync(redditMessagesPath, 'utf-8').split('---END---').filter(line => line.trim()); + } catch (error) { + console.error('Failed to load Reddit messages:', error); + } + + try { + const rdramaMessagesPath = path.join(__dirname, 'messages', 'rdrama_messages.txt'); + this.rdramaMessages = fs.readFileSync(rdramaMessagesPath, 'utf-8').split('---END---').filter(line => line.trim()); + } catch (error) { + console.error('Failed to load rDrama messages:', error); + } + } + + public getRandomRedditMessage(placeholders: { [key: string]: string }): string { + const message = this.redditMessages[Math.floor(Math.random() * this.redditMessages.length)]; + return this.replacePlaceholders(message, placeholders); + } + + public getRandomRdramaMessage(placeholders: { [key: string]: string }): string { + const message = this.rdramaMessages[Math.floor(Math.random() * this.rdramaMessages.length)]; + return this.replacePlaceholders(message, placeholders); + } + + private replacePlaceholders(message: string, placeholders: { [key: string]: string }): string { + return Object.keys(placeholders).reduce((acc, key) => { + const regex = new RegExp(`{${key}}`, 'g'); + return acc.replace(regex, placeholders[key]); + }, message); + } +} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index 661c0a2..411fd73 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,14 +1,20 @@ { - "compilerOptions": { - "target": "ES2022", - "module": "commonjs", - "lib": ["es2022"], - "outDir": "./dist", - "rootDir": "./src", - "strict": true, - "esModuleInterop": true, - "types": ["node"], - "moduleResolution": "node" - }, - "include": ["src/**/*"] - } \ No newline at end of file + "compilerOptions": { + "target": "ES2022", + "module": "commonjs", + "lib": [ + "es2022" + ], + "outDir": "./dist", + "rootDir": "./src", + "strict": true, + "esModuleInterop": true, + "types": [ + "node" + ], + "moduleResolution": "node" + }, + "include": [ + "src/**/*" + ] +} \ No newline at end of file