Renamed AI to AutomatedResponse

master
Sfan5 2013-02-23 21:54:05 +01:00
parent 994f79b7d5
commit 9a390d59ae
1 changed files with 69 additions and 38 deletions

View File

@ -1,32 +1,39 @@
#!/usr/bin/env python
"""
ai.py - Phenny AI Module (EXPERIMENTAL)
ai.py - Phenny AutomatedResponse Module
Copyright 2013, Sfan5
"""
import random
import random, time
ai = {}
ai["enable"] = False
ai["bn"] = "minetestbot" #lowercase bot name
ar["enable"] = True
ar["bn"] = "minetestbot" #lowercase bot name
def aictl(phenny, input):
def arctl(phenny, input):
if not input.admin or not input.owner: return
arg = input.group(2)
if not arg:
return
if arg == "enable":
ai["enable"] = True
phenny.say("AI enabled.")
ar["enable"] = True
phenny.say("AR enabled.")
elif arg == "disable":
ai["enable"] = False
phenny.say("AI disabled.")
ar["enable"] = False
phenny.say("AR disabled.")
aictl.commands = ['ai']
arctl.commands = ['ar']
aictl.priority = 'low'
def aip(phenny, input):
if not ai["enable"]:
def response(personal, nick, msg):
if personal:
return msg
else:
return nick + ": " + msg
def arp(phenny, input):
if not ar["enable"]:
return
ar["lm"] = [input.nick, input.bytes.strip(), time.time()]
for x in phenny.bot.commands["high"].values():
if x[0].__name__ == "aa_hook":
if x[0](phenny, input):
@ -36,7 +43,10 @@ def aip(phenny, input):
si = sia.__iter__()
try:
sn = si.next()
if sn.startswith("minetestbot"): sn = si.next()
personal = not input.sender.startswith("#")
if sn.startswith("minetestbot"):
sn = si.next()
personal = True
if sn == "hi" or sn == "hey" or sn == "hello":
try:
sn = si.next()
@ -48,33 +58,35 @@ def aip(phenny, input):
return phenny.reply("What are you wondering about?")
if sn == "thank":
if si.next() == "you":
if si.next().startswith(ai["bn"]):
return phenny.reply("Although i'm only a bot I appreciate your thanks.")
if si.next().startswith(ar["bn"]) or personal:
return phenny.say(response(personal, input.nick, "Although i'm only a bot I appreciate your thanks."))
if sn == "thanks":
if si.next().startswith(ai["bn"]):
return phenny.reply("Although i'm only a bot I appreciate your thanks.")
if si.next().startswith(ar["bn"]) or personal:
return phenny.say(response(personal, input.nick, "Although i'm only a bot I appreciate your thanks."))
if sn == "back":
return phenny.reply("Welcome back!")
return phenny.say("Welcome back " + input.nick + "!")
if sn == "should":
sn == si.next()
sn = si.next()
if sn == "i":
sn = si.next()
if sn == "eat" or sn == "drink":
sn = si.next()
if sn == "a" or sn == "an" or sn == "the": sn = si.next()
if sn == "kitty" or sn.startswith("kitten") or sn.startswith("cat"):
if sn == "kitty" or sn.startswith("kitte") or sn.startswith("cat"):
return phenny.reply("I don't recommend eating kittens")
elif sn == "air":
return phenny.reply("Eating air won't hurt you")
elif sn == "bot" or sn == ai["bn"] or sn == "you":
elif sn == "bot" or sn == ar["bn"] or (sn == "you" and personal):
return phenny.reply("Don't eat me D:")
elif sn == "acid":
return phenny.say(response(personal, input.nick, "Don't!!"))
else:
return phenny.reply("If it's acid, no, otherwise yes")
return phenny.reply("You decide")
if sn == "\x01action":
sn = si.next()
if sn == "hugs":
sn = si.next()
if sn != ai["bn"] and random.randint(0,3) == 0:
if sn != ar["bn"] and random.randint(0,3) == 0:
return phenny.say("Can I get a hug too? Please")
else:
return phenny.reply(" :D")
@ -83,12 +95,16 @@ def aip(phenny, input):
if sn == "a" or sn == "an" or sn == "the": sn = si.next()
r = sn
sn = si.next()
if sn == "on" or sn == "under" or sn == "behind":
if sn == "on" or sn == "under" or sn == "behind" or sn == "in" or sn == "above":
sn = si.next()
if sn.startswith(ai["bn"]):
if sn.startswith(ar["bn"]):
if r.startswith("kitt") or r.startswith("cat"):
return phenny.reply("I don't want it, talk to NekoGloop, he likes kittens")
elif r.startswith("pupp") or r.startswith("dog"):
return phenny.reply("Awwwww....")
elif r.startswith("bomb") or r.startswith("explosive") or r.startswith("dynamite"):
if random.randint(0,3) == 0:
return phenny.say("*shoots " + input.nick + " with an AK-74*")
return phenny.say("*runs away*")
elif r.startswith("cookie") or r.startswith("cake"):
return phenny.say("Ooh! thank you, nom nom nom...")
@ -106,21 +122,36 @@ def aip(phenny, input):
if sn == "compile":
sn = si.next()
if sn == "minetest":
return phenny.reply("There is a detailed guide at https://raw.github.com/celeron55/minetest/master/README.txt for compiling minetest on windows and linux, if you have a mac.. ..no luck")
return phenny.say(response(personal, input.nick, "There is a detailed guide at https://raw.github.com/celeron55/minetest/master/README.txt for compiling minetest on windows and linux, if you have a mac.. ..no luck"))
if sn == "install":
sn = si.next()
if sn == "a" or sn == "an": sn = si.next()
if sn.startswith("mod"):
return phenny.reply("You can usually find installation instruction in the mod topic, http://wiki.minetest.com/wiki/Mods also describes how to install mods")
return phenny.say(response(personal, input.nick, "You can usually find installation instruction in the mod topic, http://wiki.minetest.com/wiki/Mods also describes how to install mods"))
if sn == "texture":
if si.next().startswith("pack"):
return phenny.reply("http://wiki.minetest.com/wiki/Texture_Packs provides a good guide on how to install texture packs")
return phenny.say(response(personal, input.nick, "http://wiki.minetest.com/wiki/Texture_Packs provides a good guide on how to install texture packs"))
if sn == "craft":
sn = si.next()
if sn == "a" or sn == "an" or sn.endswith("s"):
return phenny.reply("Take a look at http://wiki.minetest.com/wiki/Crafting ,you should find it there")
return phenny.say(response(personal, input.nick, "Take a look at http://wiki.minetest.com/wiki/Crafting ,you should find it there"))
if sn == "where":
sn = si.next()
r = (False, 0)
if sn == "are" or sn == "is":
r = (True, 0)
if sn == "do" or sn == "did":
r = (True, 1)
if r[0]:
sn = si.next()
if (sn == "you" and personal) or (sn == ar["bn"] and not personal):
sn = si.next()
if sn == "come" and r[1] == 1: sn = si.next()
if sn == "from":
if random.randint(0,5) == 0:
return phenny.say(response(personal, input.nick, "I'm from the Bot Universe and i'm going to destroy you... BEEP BOOP BLEEP BOOP"))
else:
return phenny.say(response(personal, input.nick, "I come from https://github.com/sfan5/minetestbot-modules"))
if sn == "can" or sn == "could" or sn == "to":
sn = si.next()
if sn == "i": sn = si.next()
@ -135,24 +166,24 @@ def aip(phenny, input):
try:
sn = si.next()
except StopIteration:
return phenny.reply("http://www.minetest.net/download.php Please note that it is recommend to compile Minetest yourself if you use GNU/Linux")
return phenny.say(response(personal, input.nick, "http://www.minetest.net/download.php Please note that it is recommend to compile Minetest yourself if you use GNU/Linux"))
if sn.startswith("mod"):
return phenny.reply("http://forum.minetest.net/viewforum.php?id=11")
return phenny.say(response(personal, input.nick, "http://forum.minetest.net/viewforum.php?id=11"))
if sn.startswith("texture"):
if si.next().startswith("pack"):
return phenny.reply("http://forum.minetest.net/viewforum.php?id=4")
return phenny.say(response(personal, input.nick, "http://forum.minetest.net/viewforum.php?id=4"))
if sn.startswith("server") and r[1] == 1:
return phenny.reply("http://forum.minetest.net/viewforum.php?id=10 and http://servers.minetest.ru")
return phenny.say(response(personal, input.nick, "http://forum.minetest.net/viewforum.php?id=10 and http://servers.minetest.ru"))
elif sn.startswith("server") and r[1] == 0:
return phenny.reply("Download Minetest at http://www.minetest.net/download.php and run 'minetest.exe --server' to start a server instance")
return phenny.say(response(personal, input.nick, "Download Minetest at http://www.minetest.net/download.php and run 'minetest.exe --server' to start a server instance"))
if sn.startswith("map"):
return phenny.reply("http://forum.minetest.net/viewforum.php?id=12")
return phenny.say(response(personal, input.nick, "http://forum.minetest.net/viewforum.php?id=12"))
except:
return
aip.priority = 'medium'
aip.rule = r'.*'
aip.event = '*'
arp.priority = 'medium'
arp.rule = r'.*'
arp.event = '*'
if __name__ == '__main__':
print __doc__.strip()