<commit_before>
:- module(isup, [isup/1]).

:- use_module(library(http/http_json)).
:- use_module(library(http/http_open)).
:- use_module(dispatch).
:- use_module(submodules/web).
:- use_module(submodules/html).


chan("##prolog").
api(`http://isitup.org/`).

isup(Msg) :-
  thread_create(ignore(isup_(Msg)), _Id, [detached(true)]).


isup_(Msg) :-
  chan(Chan),
  Msg = msg(_Prefix, "PRIVMSG", [Chan], Rest),
  append(`?isup `, Q, Rest),
  atom_codes(Query, Q),
  normalize_space(codes(Qcodes), Query),
  api(Fst),
  append(Qcodes, Diff, Snd),
  append(Fst, Snd, Thrd),
  Diff = `.json`,
  string_codes(Site, Thrd),
  setup_call_cleanup(
    http_open(Site, Stream, []),		     
    json:json_read(Stream, json(List)),
    close(Stream)    
  ),
  memberchk(response_code=Resp, List),
  memberchk(status_code=Status, List),
  memberchk(response_time=Time, List),
  decode(Status, Resp, Time).


decode(Status, Resp, Time) :-
  chan(Chan),
  (
     Status = 1,
     send_msg(priv_msg, "Website is alive.", Chan)
  ;
     Status = 2,
     send_msg(priv_msg, "Website appears down.", Chan)
  ;
     Status = 3,
     send_msg(priv_msg, "Domain was not valid.", Chan)
  ),
  format(string(Report), 'Response code: ~a, Response time: ~a s', [Resp, Time]),
  send_msg(priv_msg, Report, Chan).

<commit_msg>Allowing private queries for isup extension.  Changes to be committed: 	modified:   extensions/isup.pl<commit_after>
:- module(isup, [isup/1]).

:- use_module(library(http/http_json)).
:- use_module(library(http/http_open)).
:- use_module(dispatch).
:- use_module(parser).
:- use_module(submodules/web).
:- use_module(submodules/html).


target("##prolog", "yesbot").
api(`http://isitup.org/`).

isup(Msg) :-
  thread_create(ignore(isup_(Msg)), _Id, [detached(true)]).


isup_(Msg) :-
  target(Chan, Bot),
  Msg = msg(Prefix, "PRIVMSG", [Target], Rest),
  (
     Target = Chan
  ;
     Target = Bot
  ),
  append(`?isup `, Q, Rest),
  atom_codes(Query, Q),
  normalize_space(codes(Qcodes), Query),
  api(Fst),
  append(Qcodes, Diff, Snd),
  append(Fst, Snd, Thrd),
  Diff = `.json`,
  string_codes(Site, Thrd),
  setup_call_cleanup(
    http_open(Site, Stream, []),		     
    json:json_read(Stream, json(List)),
    close(Stream)    
  ),
  memberchk(response_code=Resp, List),
  memberchk(status_code=Status, List),
  memberchk(response_time=Time, List),
  decode(Prefix, Target, Status, Resp, Time).


decode(Prefix, Target, Status, Resp, Time) :-
  (
     target(Target, _),
     Sender = Target, !
  ;
     target(_, Target),
     prefix_id(Prefix, Sender, _, _)
  ),
  (
     Status = 1,
     send_msg(priv_msg, "Website is alive.", Sender)
  ;
     Status = 2,
     send_msg(priv_msg, "Website appears down.", Sender)
  ;
     Status = 3,
     send_msg(priv_msg, "Domain was not valid.", Sender)
  ),
  format(string(Report), 'Response code: ~a, Response time: ~a s', [Resp, Time]),
  send_msg(priv_msg, Report, Sender).


{'fraction_non_alphanumeric': 0.17725409836065573, 'fraction_numerical': 0.00273224043715847, 'mean_word_length': 3.8333333333333335, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4181867', 'n_tokens_mistral': 1132, 'n_tokens_neox': 1092, 'n_words': 214}