Exemplo n.º 1
0
async def listen_to_chat():
    # TODO: split between adding chatter to db and the rest, right now it will wait for twitch to answer
    # before processing the next message
    while True:
        msg = await irc.get_msg()
        text = msg[0]
        username = msg[1]
        user_id = int(twitch_api.get_id_from_username(username))
        chatter = Chatter(twitch_id=user_id, name=username, points=0, guesses=0)
        db.add(db, chatter)
        if text[:1] == '!':  # if first char is !- than its a command
            command = parse_command(text)
            await exe_command(command, username, chatter)
        elif emote_guess.on_going is True:
            await emote_guess.check_answer(text, username, db, chatter)
        elif faction_game.on_going is True:
            loop.create_task(faction_game.faction_emote(all_msg_emotes(irc.channel, text), chatter))
Exemplo n.º 2
0
import re
from pymorphy2 import MorphAnalyzer
from chatter import Chatter
from dealer import Dealer


def makeRequest(msg, morph):
    words = list(filter(None, str.split(re.sub(r'[^\w\s:]', \
                 r' ', msg).lower())))
    for i in range(len(words)):
        words[i] = morph.normal_forms(words[i])[0]
    return ' '.join(words)


if __name__ == '__main__':
    chatter = Chatter()
    dealer = Dealer()
    morph = MorphAnalyzer()
    #True=chatter, False=dealer
    state = True
    ans = None
    msg = ''

    while True:
        if state: ans = chatter.getAnswer(ans, msg)
        else: ans = dealer.getAnswer(ans, msg)
        if ans != None: state = not state
        else: msg = makeRequest(input(), morph)
Exemplo n.º 3
0
        preprocessor = pickle.load(f)

ngram = Ngram(preprocessor.tokenizer.sequence)

if not LOAD_UNIGRAM:
    unigram_trie = ngram.build(1)
    with open('unigram.p', 'wb') as f:
        pickle.dump(unigram_trie, f)
else:
    with open('unigram.p', 'rb') as f:
        unigram_trie = pickle.load(f)

if not LOAD_BIGRAM:
    bigram_trie = ngram.build(2)
    with open('bigram.p', 'wb') as f:
        pickle.dump(bigram_trie, f)
else:
    with open('bigram.p', 'rb') as f:
        bigram_trie = pickle.load(f)

if not LOAD_TRIGRAM:
    trigram_trie = ngram.build(3)
    with open('trigram.p', 'wb') as f:
        pickle.dump(trigram_trie, f)
else:
    with open('trigram.p', 'rb') as f:
        trigram_trie = pickle.load(f)

chatter = Chatter([unigram_trie, bigram_trie, trigram_trie])
for _ in range(100):
    print(chatter.chat())