def privmsg(ctx, pline, signal, url_fetch_data): ctx.to_channel(pline.middle[0]) if url_fetch_data['locked']: return if not ctx.is_channel(pline.middle[0]): return if pline.trailing.startswith('+'): return if re.search(r'https?://', pline.trailing) is None: return if any( pattern.match(pline.prefix.raw) for pattern in url_fetch_data['ignore_list']): # weechat.prnt("", "Ignored {}".format(pline.prefix.mask)) return match = url_fetch_data['url_pattern'].search(pline.trailing) if match is None: return url = match.group('url') if '#' in url: url = url[:url.find('#')] url_fetch_data['locked'] = True # is it still cached? data = url_fetch_data['url_title_cache'].get(url, None) if data: ts, info_string = data if time.time() >= ts: del url_fetch_data['url_title_cache'][url] else: if info_string: ctx.command('/say \x02url_info |\x02 {}'.format(info_string)) hook_timer(2, url_requests_unlock, url_fetch_data) return url_fetch_data['proc_output'] = '' url_fetch_data['proc_errput'] = '' url_fetch_data['url'] = url url_fetch_data['priv_ctx'] = ctx hook_process(['fetch-url-title.py', url], process_cb, userdata=url_fetch_data)
def privmsg(ctx, pline, signal, url_fetch_data): ctx.to_channel(pline.middle[0]) if url_fetch_data['locked']: return if not ctx.is_channel(pline.middle[0]): return if pline.trailing.startswith('+'): return if re.search(r'https?://', pline.trailing) is None: return if any(pattern.match(pline.prefix.raw) for pattern in url_fetch_data['ignore_list']): # weechat.prnt("", "Ignored {}".format(pline.prefix.mask)) return match = url_fetch_data['url_pattern'].search(pline.trailing) if match is None: return url = match.group('url') if '#' in url: url = url[:url.find('#')] url_fetch_data['locked'] = True # is it still cached? data = url_fetch_data['url_title_cache'].get(url, None) if data: ts, info_string = data if time.time() >= ts: del url_fetch_data['url_title_cache'][url] else: if info_string: ctx.command('/say \x02url_info |\x02 {}'.format(info_string)) hook_timer(2, url_requests_unlock, url_fetch_data) return url_fetch_data['proc_output'] = '' url_fetch_data['proc_errput'] = '' url_fetch_data['url'] = url url_fetch_data['priv_ctx'] = ctx hook_process(['fetch-url-title.py', url], process_cb, userdata=url_fetch_data)
def jisho_hook(ctx, pline, userdata): if time.time() < userdata['locked_until']: return def _jisho_process_cb(returncode, stdout, stderr, _userdata): if returncode == 0: stdout = stdout.strip() if not stdout: return ctx.command('/say {}'.format(stdout)) args = pline.trailing.split() args.pop(0) if args: userdata['locked_until'] = time.time() + 3 param = ' '.join(args) hook_process(['jisho.py', param], _jisho_process_cb)
def google_hook(ctx, pline, userdata): if time.time() < userdata['locked_until']: return def _google_process_cb(returncode, stdout, stderr, _userdata): if returncode == 0: stdout = stdout.strip() if not stdout: return ctx.command( '/say \x02you\'re feeling lucky |\x02 {}'.format(stdout)) args = pline.trailing.split() args.pop(0) if args: userdata['locked_until'] = time.time() + 5 param = ' '.join(args) hook_process(['im-feeling-lucky.py', param], _google_process_cb)
def yuri_hook(ctx, pline, userdata): if time.time() < userdata['locked_until']: return def _yuri_process_cb(returncode, stdout, stderr, _userdata): if returncode == 0: stdout = stdout.strip() if not stdout: return dyn = json.loads(stdout) tag_string = u' '.join(u'[{}]'.format(tag) for tag in dyn[u'tags']) dyn[u'tag_string'] = tag_string ctx.command( '/say \x02Your random yuri chapter |\x02 {title} \x02by\x02' ' {authors} | {link} | \x02{tag_string}\x02'.format(**dyn)) userdata['locked_until'] = time.time() + 5 hook_process(['yuri.py'], _yuri_process_cb)
def yuri_hook(ctx, pline, userdata): if time.time() < userdata['locked_until']: return def _yuri_process_cb(returncode, stdout, stderr, _userdata): if returncode == 0: stdout = stdout.strip() if not stdout: return dyn = json.loads(stdout) tag_string = u' '.join(u'[{}]'.format(tag) for tag in dyn[u'tags']) dyn[u'tag_string'] = tag_string ctx.command( '/say \x02Your random yuri chapter |\x02 {title} \x02by\x02' ' {authors} | {link} | \x02{tag_string}\x02' .format(**dyn)) userdata['locked_until'] = time.time() + 5 hook_process(['yuri.py'], _yuri_process_cb)
def vision_hook(ctx, pline, userdata): if time.time() < userdata['locked_until']: return def _vision_process_cb(returncode, stdout, stderr, _userdata): if returncode == 0: stdout = stdout.strip() if not stdout: return ctx.command('/say {}'.format(stdout)) elif returncode in (1, 2, 3, 4): ctx.command('/say Error: {}'.format(stdout)) args = pline.trailing.split() args.pop(0) if args: userdata['locked_until'] = time.time() + 5 param = ' '.join(args) hook_process(['vision.py', param], _vision_process_cb)