Exemple #1
0
class CluBot(irc.IRCClient):
    """Main bot interface with IRC happenings

    This class hooks into various IRC actions and handles them appropriately.

    """

    @property
    def _get_nickname(self):
        return self.factory.nickname

    nickname = _get_nickname

    def __init__(self):
        self.nicks = []
        self.chat = Chatter()
        self.chat.load_bot("alice")

    def connectionMade(self):
        irc.IRCClient.connectionMade(self)

    def signedOn(self):
        for chan in self.factory.channels:
            self.join(chan)

    def joined(self, channel):
        """on channel join, clubot gets everyone's nicks"""
        self.sendLine("NAMES")

    def privmsg(self, user, channel, msg):
        """Handles user messages from channels

        This hooks every privmsg sent to the channel and sends the commands off
        to cmds.dispatch to process, then replies to the channel accordingly.

        The !reload command needs to be handled here though, as it allows edits
        to be made to clubot without disconnecting from IRC. It should get a
        list from cmds.dispatch if it needs to pm someone, otherwise it gets a
        string back and msgs the channel.

        """
        user = user.split("!", 1)[0]
        reply = self.chat.get_reply(msg)
        self.msg(channel, reply)
Exemple #2
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))
Exemple #3
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)
Exemple #4
0
 def __init__(self):
     self.nicks = []
     self.chat = Chatter()
     self.chat.load_bot("alice")
Exemple #5
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())
import re
from flask import Flask, request, abort
from simi_extract import CandReplyer
from chatter import Chatter
import os
from linebot import (LineBotApi, WebhookHandler)
from linebot.exceptions import (InvalidSignatureError)
from linebot.models import (
    MessageEvent,
    TextMessage,
    TextSendMessage,
)

app = Flask(__name__)
cand_replyer = CandReplyer()
chatter = Chatter()
mode = "promote"
mode_pattern = re.compile(r'.+\smode$')

is_prod = os.environ.get('IS_HEROKU', None)
if is_prod:
    line_bot_api = LineBotApi(os.environ.get('CHANNEL_ACCESS_TOKEN', ''))
    handler = WebhookHandler(os.environ.get('CHANNEL_SECRET', ''))


@app.route("/callback", methods=['POST'])
def callback():
    # get X-Line-Signature header value
    signature = request.headers['X-Line-Signature']

    # get request body as text