help@rskworld.in +91 93305 39277
RSK World
  • Home
  • Development
    • Web Development
    • Mobile Apps
    • Software
    • Games
    • Project
  • Technologies
    • Data Science
    • AI Development
    • Cloud Development
    • Blockchain
    • Cyber Security
    • Dev Tools
    • Testing Tools
  • Blog
  • About
  • Contact

Theme Settings

Color Scheme
Display Options
Font Size
100%
Back to Project
RSK World
slack-bot-assistant
/
bot
RSK World
slack-bot-assistant
Slack Bot Assistant - Python + Slack API + SQLite + PHP Dashboard + Bot Commands + Automation
bot
  • __pycache__
  • app.py30.8 KB
  • config.py1.9 KB
  • helpers.py5.5 KB
  • models.py4.4 KB
  • scheduler.py3.1 KB
  • utils.py12.6 KB
FINAL_DATASET_SUMMARY.mdERROR_CHECK_REPORT.mdrequirements.txthelpers.py
requirements.txt
Raw Download
Find: Go to:
slack_bolt>=1.18.0
slack_sdk>=3.27.0
python-dotenv>=1.0.0
sqlalchemy>=2.0.0
schedule>=1.2.0
requests>=2.31.0
textblob>=0.17.1
vaderSentiment>=3.3.2
pytz>=2024.1
python-dateutil>=2.8.2

12 lines•196 B
text
bot/helpers.py
Raw Download
Find: Go to:
"""
Slack Bot Assistant - Helper Functions
Developer: Molla Samser (Founder, RSK World)
Design & Testing: Rima Khatun
Website: https://rskworld.in
Contact: hello@rskworld.in | +91 93305 39277
Year: 2026
"""

import random
import string
import hashlib
from datetime import datetime
from typing import List, Dict, Optional

def generate_random_string(length: int = 8) -> str:
    """Generate a random string for IDs or tokens"""
    return ''.join(random.choices(string.ascii_letters + string.digits, k=length))

def generate_hash(text: str) -> str:
    """Generate SHA256 hash of text"""
    return hashlib.sha256(text.encode()).hexdigest()[:16]

def format_timestamp(ts: str) -> str:
    """Format Slack timestamp to readable date"""
    try:
        timestamp = float(ts)
        dt = datetime.fromtimestamp(timestamp)
        return dt.strftime('%Y-%m-%d %H:%M:%S')
    except (ValueError, TypeError):
        return ts

def parse_user_mention(text: str) -> List[str]:
    """Extract user IDs from mentions in text"""
    import re
    pattern = r'<@([A-Z0-9]+)>'
    return re.findall(pattern, text)

def parse_channel_mention(text: str) -> List[str]:
    """Extract channel IDs from mentions in text"""
    import re
    pattern = r'<#([A-Z0-9]+)\|[^>]+>'
    return re.findall(pattern, text)

def truncate_text(text: str, max_length: int = 100, suffix: str = "...") -> str:
    """Truncate text to max length"""
    if len(text) <= max_length:
        return text
    return text[:max_length - len(suffix)] + suffix

def extract_urls(text: str) -> List[str]:
    """Extract URLs from text"""
    import re
    url_pattern = r'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\\(\\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+'
    return re.findall(url_pattern, text)

def format_file_size(size_bytes: int) -> str:
    """Format file size in human-readable format"""
    for unit in ['B', 'KB', 'MB', 'GB']:
        if size_bytes < 1024.0:
            return f"{size_bytes:.2f} {unit}"
        size_bytes /= 1024.0
    return f"{size_bytes:.2f} TB"

def calculate_time_difference(start_time: datetime, end_time: datetime = None) -> str:
    """Calculate and format time difference"""
    if end_time is None:
        end_time = datetime.utcnow()
    
    diff = end_time - start_time
    total_seconds = int(diff.total_seconds())
    
    if total_seconds < 60:
        return f"{total_seconds} seconds"
    elif total_seconds < 3600:
        minutes = total_seconds // 60
        return f"{minutes} minute{'s' if minutes != 1 else ''}"
    elif total_seconds < 86400:
        hours = total_seconds // 3600
        return f"{hours} hour{'s' if hours != 1 else ''}"
    else:
        days = total_seconds // 86400
        return f"{days} day{'s' if days != 1 else ''}"

def validate_email(email: str) -> bool:
    """Basic email validation"""
    import re
    pattern = r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$'
    return bool(re.match(pattern, email))

def format_list(items: List[str], max_items: int = 10, separator: str = ", ") -> str:
    """Format list of items with max limit"""
    if len(items) <= max_items:
        return separator.join(items)
    return separator.join(items[:max_items]) + f" and {len(items) - max_items} more"

def get_random_quote() -> str:
    """Get a random motivational quote"""
    quotes = [
        "The only way to do great work is to love what you do. - Steve Jobs",
        "Innovation distinguishes between a leader and a follower. - Steve Jobs",
        "Success is not final, failure is not fatal: it is the courage to continue that counts. - Winston Churchill",
        "The future belongs to those who believe in the beauty of their dreams. - Eleanor Roosevelt",
        "It is during our darkest moments that we must focus to see the light. - Aristotle",
        "The way to get started is to quit talking and begin doing. - Walt Disney",
        "Don't let yesterday take up too much of today. - Will Rogers",
        "You learn more from failure than from success. - Unknown",
        "If you are working on something exciting that you really care about, you don't have to be pushed. - Steve Jobs",
        "People who are crazy enough to think they can change the world, are the ones who do. - Rob Siltanen"
    ]
    return random.choice(quotes)

def create_progress_bar(progress: float, length: int = 20) -> str:
    """Create a text-based progress bar"""
    progress = max(0, min(1, progress))  # Clamp between 0 and 1
    filled = int(progress * length)
    bar = '█' * filled + '░' * (length - filled)
    percentage = int(progress * 100)
    return f"[{bar}] {percentage}%"

def mask_sensitive_data(text: str, visible_chars: int = 4) -> str:
    """Mask sensitive data like tokens or passwords"""
    if len(text) <= visible_chars:
        return '*' * len(text)
    return text[:visible_chars] + '*' * (len(text) - visible_chars)

def extract_hashtags(text: str) -> List[str]:
    """Extract hashtags from text"""
    import re
    pattern = r'#(\w+)'
    return re.findall(pattern, text)

def format_duration(seconds: float) -> str:
    """Format duration in seconds to human-readable format"""
    if seconds < 60:
        return f"{seconds:.1f}s"
    elif seconds < 3600:
        minutes = seconds / 60
        return f"{minutes:.1f}m"
    elif seconds < 86400:
        hours = seconds / 3600
        return f"{hours:.1f}h"
    else:
        days = seconds / 86400
        return f"{days:.1f}d"

147 lines•5.5 KB
python
🚀 Support RSK World

Subscribe to our YouTube channel for latest tutorials & updates!



Click subscribe & support our work ❤️

About RSK World

Founded by Molla Samser, with Designer & Tester Rima Khatun, RSK World is your one-stop destination for free programming resources, source code, and development tools.

Founder: Molla Samser
Designer & Tester: Rima Khatun

Development

  • Game Development
  • Web Development
  • Mobile Development
  • AI Development
  • Development Tools

Legal

  • Terms & Conditions
  • Privacy Policy
  • Disclaimer

Contact Info

Nutanhat, Mongolkote
Purba Burdwan, West Bengal
India, 713147

+91 93305 39277

hello@rskworld.in
support@rskworld.in

© 2026 RSK World. All rights reserved.

Content used for educational purposes only. View Disclaimer