<commit_before>! Copyright (C) 2009 <NAME>
! See http://factorcode.org/license.txt for BSD license.
USING: accessors assocs concurrency.mailboxes io kernel namespaces
strings words.symbol irc.client.chats irc.messages ;
EXCLUDE: sequences => join ;
IN: irc.client.base

SYMBOL: current-irc-client

: irc> ( -- irc-client ) current-irc-client get ;
: stream> ( -- stream ) irc> stream>> ;
: irc-print ( s -- ) stream> [ stream-print ] [ stream-flush ] bi ;
: irc-send ( irc-message -- ) irc> out-messages>> mailbox-put ;
: chats> ( -- seq ) irc> chats>> values ;
: me? ( string -- ? ) irc> nick>> = ;

: with-irc ( ..a irc-client quot: ( ..a -- ..b ) -- ..b )
    \ current-irc-client swap with-variable ; inline

UNION: to-target privmsg notice ;
UNION: to-channel join part topic kick rpl-channel-modes
                  topic rpl-names rpl-names-end ;
UNION: to-one-chat to-target to-channel mode ;
UNION: to-many-chats nick quit ;
UNION: to-all-chats irc-end irc-disconnected irc-connected ;
PREDICATE: to-me < to-target target>> me? ;

GENERIC: chat-name ( irc-message -- name )
M: mode       chat-name name>> ;
M: to-target  chat-name target>> ;
M: to-me      chat-name sender>> ;
M: to-channel chat-name channel>> ;

GENERIC: chat> ( obj -- chat/f )
M: string      chat> irc> chats>> at ;
M: symbol      chat> irc> chats>> at ;
M: to-one-chat chat> chat-name +server-chat+ or chat> ;<commit_msg>client.base: paremeters was getting the channel name instead of the channel>> slot. try to fix it in chat-message.<commit_after>! Copyright (C) 2009 <NAME>
! See http://factorcode.org/license.txt for BSD license.
USING: accessors assocs concurrency.mailboxes io kernel namespaces
strings words.symbol irc.client.chats irc.messages ;
EXCLUDE: sequences => join ;
IN: irc.client.base

SYMBOL: current-irc-client

: irc> ( -- irc-client ) current-irc-client get ;
: stream> ( -- stream ) irc> stream>> ;
: irc-print ( s -- ) stream> [ stream-print ] [ stream-flush ] bi ;
: irc-send ( irc-message -- ) irc> out-messages>> mailbox-put ;
: chats> ( -- seq ) irc> chats>> values ;
: me? ( string -- ? ) irc> nick>> = ;

: with-irc ( ..a irc-client quot: ( ..a -- ..b ) -- ..b )
    \ current-irc-client swap with-variable ; inline

UNION: to-target privmsg notice ;
UNION: to-channel join part topic kick rpl-channel-modes
                  topic rpl-names rpl-names-end ;
UNION: to-one-chat to-target to-channel mode ;
UNION: to-many-chats nick quit ;
UNION: to-all-chats irc-end irc-disconnected irc-connected ;
PREDICATE: to-me < to-target target>> me? ;

GENERIC: chat-name ( irc-message -- name )
M: mode       chat-name name>> ;
M: to-target  chat-name target>> ;
M: to-me      chat-name sender>> ;

! to-channel messages are things like JOIN
! Freenode's join looks like:
! ":flogbot2_!~flogbot2@c-50-174-221-28.hsd1.ca.comcast.net JOIN #concatenative-bots"
! The channel>> field is empty and it's in parameters instead.
! This fixes chat> for these kinds of messages.
M: to-channel chat-name dup channel>> [ nip ] [ parameters>> ?first ] if* ;

GENERIC: chat> ( obj -- chat/f )
M: string      chat> irc> chats>> at ;
M: symbol      chat> irc> chats>> at ;
M: to-one-chat chat> chat-name +server-chat+ or chat> ;
{'fraction_non_alphanumeric': 0.1521468574984443, 'fraction_numerical': 0.006533914125700062, 'mean_word_length': 3.0799492385786804, 'pattern_counts': {'":': 1, '<': 7, '<?xml version=': 0, '>': 88, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, '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': '6698374', 'n_tokens_mistral': 1159, 'n_tokens_neox': 1123, 'n_words': 339}