| 1 |
### This file is part of KoFooBot and is licensed under BSD-license according to the ### |
| 2 |
### LICENSE file in the base directory. ### |
| 3 |
### Code in this file is contributed by: ### |
| 4 |
### Krister Svanlund <krister.svanlund gmail.com> ### |
| 5 |
|
| 6 |
### MegaHAL implementation from http://megahal.alioth.debian.org/ ### |
| 7 |
|
| 8 |
import mh_python as megahal |
| 9 |
import re |
| 10 |
|
| 11 |
update_megahal_delay = 240 |
| 12 |
update_megahal_time_left = 0 |
| 13 |
|
| 14 |
def init_megahal(bot, server, sender = None): |
| 15 |
print " + Initiate MegaHAL module." |
| 16 |
megahal.initbrain() |
| 17 |
return True |
| 18 |
|
| 19 |
def unload_megahal(bot, server, sender): |
| 20 |
print " + Unload MegaHAL module." |
| 21 |
megahal.cleanup() |
| 22 |
return True |
| 23 |
|
| 24 |
def update_megahal(bot, server): |
| 25 |
print " + Clean up MegaHAL brain." |
| 26 |
megahal.cleanup() |
| 27 |
|
| 28 |
def megahal_public_msg_handler(bot, server, sender, target, msg, action = False): |
| 29 |
if not action: |
| 30 |
res = re.match("(\S+)[:;,] (.*)", msg) |
| 31 |
if res: |
| 32 |
nick = res.group(1) |
| 33 |
message = res.group(2) |
| 34 |
if nick == bot.settings.bot_nick_name: |
| 35 |
reply = megahal.doreply(message) |
| 36 |
bot.respond(server, sender, target, reply) |
| 37 |
return False |
| 38 |
else: |
| 39 |
megahal.learn(message) |
| 40 |
megahal.learn(msg) |
| 41 |
return False |
| 42 |
|
| 43 |
def megahal_private_msg_handler(bot, server, sender, msg, action = False): |
| 44 |
if not action: |
| 45 |
megahal.learn(msg) |
| 46 |
return False |