コード例 #1
0
ファイル: quotebot.py プロジェクト: andreybarsky/nevermore
async def loadmarkov(ctx, servername):
    serv = to_filename(servername)
    print('Loading corpus from %s' % serv)
    bot.markovchains[serv], bot.markovchains2[serv] = cm.server_chain(serv)
    print('Chain1: %s units long' % len(bot.markovchains[serv]))
    print('Chain2: %s units long' % len(bot.markovchains2[serv]))
    bot.corpus_last_read = time.time()
コード例 #2
0
ファイル: quotebot.py プロジェクト: andreybarsky/nevermore
async def markov_in(ctx):
    serv = to_filename(str(ctx.message.guild))
    if serv not in bot.markovchains or time.time() - bot.corpus_last_read > (
            60 * 60):
        print('Loading corpus from %s' % serv)
        bot.markovchains[serv], bot.markovchains2[serv] = cm.server_chain(serv)
        print('Chain1: %s units long' % len(bot.markovchains[serv]))
        print('Chain2: %s units long' % len(bot.markovchains2[serv]))
        bot.corpus_last_read = time.time()
    seed = ['*in']
    print("trying to make a markov chain, but with 'in'")
    valid = False
    attempts = 0
    while not valid and attempts < 30:
        msg = cm.generate_message2(bot.markovchains[serv],
                                   bot.markovchains2[serv],
                                   seed=seed)
        if 'voice*' in msg:
            valid = True
        else:
            attempts += 1
    print('made a 2nd order markov chain with in:\n%s' % msg)
    if msg is not None:
        # await bot.say(msg)
        await ctx.send(msg)
コード例 #3
0
ファイル: quotebot.py プロジェクト: andreybarsky/nevermore
async def markov(ctx, *seed: str):
    serv = to_filename(str(ctx.message.guild))
    print('server name: %s' % serv)

    if len(ctx.message.mentions) > 0:
        print('mention detected')
        mention = ctx.message.mentions[0]
        name = get_name(ctx.message.mentions[0])
        if len(seed) == 1:
            # we've been asked to make a markov from just a mention, so just convert it to string:
            seed = [name]

    # if we haven't loaded the chain for this server, or if we haven't loaded one in a while:
    if serv not in bot.markovchains or time.time() - bot.corpus_last_read > (
            60 * 60 * 8):  # not loaded in last 8 hours
        print('Loading corpus from %s' % serv)
        bot.markovchains[serv], bot.markovchains2[serv] = cm.server_chain(serv)
        print('Chain1: %s units long' % len(bot.markovchains[serv]))
        print('Chain2: %s units long' % len(bot.markovchains2[serv]))
        bot.corpus_last_read = time.time()

    if seed == ():
        seed = ['END']
    else:
        seed = [x.lower() for x in seed]  # lowercase the seed

    print('trying to make a markov chain...')
    msg = cm.generate_message2(bot.markovchains[serv],
                               bot.markovchains2[serv],
                               seed=seed)
    if msg is not None:
        # await bot.say(msg)
        await ctx.send(msg)
コード例 #4
0
ファイル: quotebot.py プロジェクト: andreybarsky/nevermore
async def servmarkov(ctx, servername):
    serv = to_filename(servername)
    seed = ['END']

    if serv not in bot.markovchains or time.time() - bot.corpus_last_read > (
            60 * 60):
        print('Loading corpus from %s' % serv)
        bot.markovchains[serv], bot.markovchains2[serv] = cm.server_chain(serv)
        print('Chain1: %s units long' % len(bot.markovchains[serv]))
        print('Chain2: %s units long' % len(bot.markovchains2[serv]))
        bot.corpus_last_read = time.time()
    else:
        print('Corpus is freshly loaded!')

    print('making a markov chain from server corpus: %s and seed: %s' %
          (serv, str(seed)))
    msg = cm.generate_message2(bot.markovchains[serv],
                               bot.markovchains2[serv],
                               seed=seed)
    print('made a 2nd order markov chain:\n%s' % msg)
    if msg is not None:
        await ctx.send(msg)
コード例 #5
0
ファイル: quotebot.py プロジェクト: andreybarsky/nevermore
async def on_message(message):
    msg = None
    # we do not want the bot to reply to itself
    if message.author != bot.user:
        cmd = message.content.lower()
        serv = to_filename(str(message.guild))

        if cmd.lower() == 'same' or cmd.lower() == 'same.':
            bot.sames += 1
        else:
            bot.sames = 0

        if bot.sames >= 2:
            time.sleep(1)
            bot.sames = 0
            msg = 'same.'
        # respond to thanks, ignores the timer:
        elif 'ty bot' in cmd or 'thanks bot' in cmd or 'thanks nevermore' in cmd or 'ty nevermore' in cmd or 'thx bot' in cmd or 'thx nevermore' in cmd:
            requester = get_name(message.author,
                                 to_filename(str(message.guild)))
            responses = [
                "you're welcome, {}", "ur welcome, {}", "no problem, {}",
                "any time, {}", "my pleasure, {}"
            ]
            msg = (random.choice(responses).format(requester))

        # general banter with  timer:
        elif time.time() - bot.last_reply > 2:  # 60 sec cooldown

            # responds to praise or blame:
            if 'bad bot' in cmd:
                msg = ':('
            elif 'good bot' in cmd:
                msg = ':)'

            # responds to greetings:
            elif cmd in [
                    'hello bot', 'hi bot', 'hello nevermore', 'hi nevermore'
            ]:
                name = message.author.nick
                if name is None:
                    name = get_name(message.author, serv)
                greeting = random.choice(['hi', 'hello'])
                msg = '%s %s' % (greeting, name)

            # make the 'very carefully' joke:
            elif 'how do' in cmd and 'feel' not in cmd and len(
                    cmd
            ) < 100:  # we want "how do", but not "how do i/you feel"
                chance = 0.15
                roll = random.uniform(0, 1)
                if roll < chance:
                    time.sleep(3)  # for comedic effect
                    msg = 'very carefully.'

            # make fun of your wife:
            elif 'my wife' in cmd:
                msg = 'My Wife'

            # make the 'much like your posting' joke:
            elif 'so bad' in cmd or 'very bad' in cmd or 'really bad' in cmd or 'insanely bad' in cmd or 'incredibly bad' in cmd or 'unbelievably bad' in cmd:
                print('I smell something bad.')
                print('the server is: %s' % serv)
                if serv == 'very_official_discord_server' or serv == 'bot_testing_server':  # this is a dom goons injoke
                    print("so I'm considering making the joke")
                    if 'very bad' in cmd or 'so bad' in cmd or 'really bad' in cmd:
                        chance = 0.25
                    else:
                        chance = 0.5
                    roll = random.uniform(0, 1)
                    print('The roll is: %s' % roll)
                    if roll < chance:
                        time.sleep(5)  # for comedic effect
                        msg = 'much like your posting'

            # correct anime spelling:
            elif 'anime' in cmd:
                chance = 0.35
                roll = random.uniform(0, 1)
                if roll < chance:
                    msg = "I think you mean animé."

            # detect mentions (but does not currently do anything):
            elif len(message.mentions) > 0:
                print('mention detected')
                mention = message.mentions[0]
                name = get_name(message.mentions[0])
                if name == 'nevermore':
                    # someone is addressing us directly!
                    print("someone's talking about me")
                    # do something here

            else:
                # respond to 69:
                pattern = r"\b6 ?9\b"
                r = re.compile(pattern)
                if r.search(cmd) or 'sixty nine' in cmd:
                    print(cmd + '?\nnice')
                    chance = 0.25
                    roll = random.uniform(0, 1)
                    if roll < chance:
                        time.sleep(5)  # for comedic effect
                        msg = 'nice.'
                else:

                    # a random chance to spit out a markov chain
                    chance = MARKOV_PROC
                    roll = random.uniform(0, 1)
                    print('Random markov roll: %.2f' % roll)
                    if roll < chance and cmd[
                            0] != '.':  # don't do this for bot commands
                        # if we haven't loaded the chain for this server, or if we haven't loaded one in a while:
                        if serv not in bot.markovchains or time.time(
                        ) - bot.corpus_last_read > (60 * 60):
                            print('Loading corpus from %s' % serv)
                            bot.markovchains[serv], bot.markovchains2[
                                serv] = cm.server_chain(serv)
                            print('The result chain is %s units long' %
                                  len(bot.markovchains[serv]))
                            bot.corpus_last_read = time.time()
                        msg = cm.generate_message2(bot.markovchains[serv],
                                                   bot.markovchains2[serv],
                                                   seed=['END'])

        if msg is not None:
            bot.last_reply = time.time()
            # await bot.send_message(message.channel, msg)
            await message.channel.send(msg)

        # record raw messages to corpus:
        cm.write(cmd, serv)

    await bot.process_commands(message)