示例#1
0
def process_mention(mention):
    """
    Handles username mentions and handles the formatting and posting of
    those calls as workable jobs to ToR.

    :param mention: the Comment object containing the username mention.
    :return: None.
    """
    i18n = translation()
    pm_subject = i18n['responses']['direct_message']['subject']
    pm_body = i18n['responses']['direct_message']['body']

    # message format is subject, then body
    mention.author.message(pm_subject, _(pm_body))
    logging.info(f'Message sent to {mention.author.name}!')
示例#2
0
文件: inbox.py 项目: GrafeasGroup/tor
    send_to_modchat,
    check_for_phrase,
)
from tor.core.posts import get_blossom_submission
from tor.core.user_interaction import (
    process_claim,
    process_coc,
    process_done,
    process_message,
    process_unclaim,
)
from tor.helpers.flair import flair_post
from tor.strings import translation
from tor.validation.transcription_validation import is_comment_transcription

i18n = translation()

log = logging.getLogger(__name__)


@beeline.traced(name="forward_to_slack")
def forward_to_slack(item: InboxableMixin, cfg: Config) -> None:
    username = str(item.author.name)

    send_to_modchat(
        f'<{i18n["urls"]["reddit_url"].format(item.context)}|Unhandled message>'
        f" by"
        f' <{i18n["urls"]["reddit_url"].format("/u/" + username)}|u/{username}> -- '
        f"*{item.subject}*:\n{item.body}",
        cfg,
    )
示例#3
0
import logging
from urllib.parse import parse_qs, urlparse

import requests
from tor.strings import translation

youtube_transcription_url = translation()['urls']['yt_transcript_url']


def get_yt_video_id(url):
    """
    Returns Video_ID extracting from the given url of Youtube

    Examples of URLs:
      Valid:
        'http://youtu.be/_lOT2p_FCvA',
        'www.youtube.com/watch?v=_lOT2p_FCvA&feature=feedu',
        'http://www.youtube.com/embed/_lOT2p_FCvA',
        'http://www.youtube.com/v/_lOT2p_FCvA?version=3&amp;hl=en_US',
        'https://www.youtube.com/watch?v=rTHlyTphWP0&index=6&list=PLjeDyYvG6-40qawYNR4juzvSOg-ezZ2a6',
        'youtube.com/watch?v=_lOT2p_FCvA',

      Invalid:
        'youtu.be/watch?v=_lOT2p_FCvA',
    """
    # initial version: http://stackoverflow.com/a/7936523/617185
    # by Mikhail Kashkin (http://stackoverflow.com/users/85739/mikhail-kashkin)

    if url.startswith(('youtu', 'www')):
        url = 'http://' + url