Exemplo n.º 1
0
def cmd(send, msg, args):
    """Gets a random Reddit post.
    Syntax: {command} <subreddit>
    """
    if args['name'] == 'srepetsk':
        msg = 'nottheonion'
    if msg and not check_exists(msg):
        send("Non-existant subreddit.")
        return
    subreddit = '/r/%s' % msg if msg else ''
    url = get('http://reddit.com%s/random' % subreddit, headers={'User-Agent': 'CslBot/1.0'}).url
    send('** %s - %s' % (get_title(url), get_short(url)))
Exemplo n.º 2
0
def cmd(send, msg, args):
    """Gets a random Reddit post.
    Syntax: !reddit <subreddit>
    """
    if args["name"] == "srepetsk":
        msg = "nottheonion"
    if msg and not check_exists(msg):
        send("Non-existant subreddit.")
        return
    subreddit = "/r/%s" % msg if msg else ""
    url = get("http://reddit.com%s/random" % subreddit, headers={"User-Agent": "CslBot/1.0"}).url
    send("** %s - %s" % (get_title(url), get_short(url)))
Exemplo n.º 3
0
def cmd(send, msg, args):
    """Gets a random Reddit post.
    Syntax: !reddit <subreddit>
    """
    if args['name'] == 'srepetsk':
        msg = 'nottheonion'
    if msg and not check_exists(msg):
        send("Non-existant subreddit.")
        return
    subreddit = '/r/%s' % msg if msg else ''
    urlstr = 'http://reddit.com%s/random?%s' % (subreddit, time.time())
    url = get(urlstr, headers={'User-Agent': 'CslBot/1.0'}).url
    key = args['config']['api']['googleapikey']
    send('** %s - %s' % (get_title(url), get_short(url, key)))
Exemplo n.º 4
0
def handle(send, msg, args):
    match = re.search(r'(?:^|\s)/r/([\w|^/]*)\b', msg)
    if not match:
        return
    subreddit = match.group(1)
    if not check_exists(subreddit):
        return
    data = get('http://reddit.com/r/%s/about.json' % subreddit, headers={'User-Agent': 'CslBot/1.0'}).json()['data']
    output = ''
    if data['public_description']:
        for line in data['public_description'].splitlines():
            output += line + " "
    elif data['description']:
        output += data['description'].splitlines()[0]
    else:
        output += data['display_name']
    output = "%s -- %s" % (output.strip(), get_short('http://reddit.com/r/%s' % (subreddit)))
    send(output)
Exemplo n.º 5
0
def handle(send, msg, args):
    match = re.search(r'(?:^|\s)/r/([\w|^/]*)\b', msg)
    if not match:
        return
    subreddit = match.group(1)
    if not check_exists(subreddit):
        return
    data = get('http://reddit.com/r/%s/about.json' % subreddit, headers={'User-Agent': 'CslBot/1.0'}).json()['data']
    output = ''
    if data['public_description']:
        for line in data['public_description'].splitlines():
            output += line + " "
    elif data['description']:
        output += data['description'].splitlines()[0]
    else:
        output += data['display_name']
    output = output.strip()
    if len(output) > 256:
        output = output[:253] + "..."
    output = "%s -- %s" % (output, get_short('http://reddit.com/r/%s' % (subreddit)))
    send(output)