2013-02-19 22:29:43 +01:00
#!/usr/bin/env python
"""
2013-02-23 21:54:05 +01:00
ai . py - Phenny AutomatedResponse Module
2013-02-19 22:29:43 +01:00
Copyright 2013 , Sfan5
"""
2013-02-23 21:54:05 +01:00
import random , time
2013-02-23 21:55:32 +01:00
ar = { }
2013-02-19 22:29:43 +01:00
2013-02-23 21:54:05 +01:00
ar [ " enable " ] = True
ar [ " bn " ] = " minetestbot " #lowercase bot name
2013-02-19 22:29:43 +01:00
2013-02-23 21:54:05 +01:00
def arctl ( phenny , input ) :
2013-02-19 22:29:43 +01:00
if not input . admin or not input . owner : return
arg = input . group ( 2 )
if not arg :
return
if arg == " enable " :
2013-02-23 21:54:05 +01:00
ar [ " enable " ] = True
phenny . say ( " AR enabled. " )
2013-02-19 22:29:43 +01:00
elif arg == " disable " :
2013-02-23 21:54:05 +01:00
ar [ " enable " ] = False
phenny . say ( " AR disabled. " )
2013-02-19 22:29:43 +01:00
2013-02-23 21:54:05 +01:00
arctl . commands = [ ' ar ' ]
2013-02-23 23:07:12 +01:00
arctl . priority = ' low '
2013-02-19 22:29:43 +01:00
2013-02-23 21:54:05 +01:00
def response ( personal , nick , msg ) :
if personal :
return msg
else :
return nick + " : " + msg
def arp ( phenny , input ) :
if not ar [ " enable " ] :
2013-02-19 22:29:43 +01:00
return
2013-02-23 21:54:05 +01:00
ar [ " lm " ] = [ input . nick , input . bytes . strip ( ) , time . time ( ) ]
2013-02-19 22:29:43 +01:00
for x in phenny . bot . commands [ " high " ] . values ( ) :
if x [ 0 ] . __name__ == " aa_hook " :
if x [ 0 ] ( phenny , input ) :
return # Abort function
sia = input . bytes . strip ( ) . strip ( ' ?! ' ) . lower ( ) . split ( " " )
#print(sia)
si = sia . __iter__ ( )
try :
sn = si . next ( )
2013-02-23 21:54:05 +01:00
personal = not input . sender . startswith ( " # " )
if sn . startswith ( " minetestbot " ) :
sn = si . next ( )
personal = True
2013-02-19 22:29:43 +01:00
if sn == " hi " or sn == " hey " or sn == " hello " :
try :
sn = si . next ( )
except StopIteration :
return phenny . say ( " hi " + input . nick )
if sn == " guys " or sn == " folks " or sn == " people " or sn . startswith ( " every " ) or sn == " all " :
return phenny . say ( " hi " + input . nick )
if sn == " o.o " :
return phenny . reply ( " What are you wondering about? " )
if sn == " thank " :
if si . next ( ) == " you " :
2013-02-23 21:54:05 +01:00
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. " ) )
2013-02-19 22:29:43 +01:00
if sn == " thanks " :
2013-02-23 21:54:05 +01:00
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. " ) )
2013-02-19 22:29:43 +01:00
if sn == " back " :
2013-02-23 21:54:05 +01:00
return phenny . say ( " Welcome back " + input . nick + " ! " )
2013-02-19 22:29:43 +01:00
if sn == " should " :
2013-02-23 21:54:05 +01:00
sn = si . next ( )
2013-02-19 22:29:43 +01:00
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 ( )
2013-02-23 21:54:05 +01:00
if sn == " kitty " or sn . startswith ( " kitte " ) or sn . startswith ( " cat " ) :
2013-02-19 22:29:43 +01:00
return phenny . reply ( " I don ' t recommend eating kittens " )
elif sn == " air " :
return phenny . reply ( " Eating air won ' t hurt you " )
2013-02-23 21:54:05 +01:00
elif sn == " bot " or sn == ar [ " bn " ] or ( sn == " you " and personal ) :
2013-02-19 22:29:43 +01:00
return phenny . reply ( " Don ' t eat me D: " )
2013-02-23 21:54:05 +01:00
elif sn == " acid " :
return phenny . say ( response ( personal , input . nick , " Don ' t!! " ) )
2013-02-19 22:29:43 +01:00
else :
2013-02-23 21:54:05 +01:00
return phenny . reply ( " You decide " )
2013-02-19 22:29:43 +01:00
if sn == " \x01 action " :
sn = si . next ( )
if sn == " hugs " :
sn = si . next ( )
2013-02-23 21:54:05 +01:00
if sn != ar [ " bn " ] and random . randint ( 0 , 3 ) == 0 :
2013-02-19 22:29:43 +01:00
return phenny . say ( " Can I get a hug too? Please " )
else :
return phenny . reply ( " :D " )
if sn == " puts " :
sn = si . next ( )
if sn == " a " or sn == " an " or sn == " the " : sn = si . next ( )
r = sn
sn = si . next ( )
2013-02-23 21:54:05 +01:00
if sn == " on " or sn == " under " or sn == " behind " or sn == " in " or sn == " above " :
2013-02-19 22:29:43 +01:00
sn = si . next ( )
2013-02-23 21:54:05 +01:00
if sn . startswith ( ar [ " bn " ] ) :
2013-02-19 22:29:43 +01:00
if r . startswith ( " kitt " ) or r . startswith ( " cat " ) :
return phenny . reply ( " I don ' t want it, talk to NekoGloop, he likes kittens " )
2013-02-23 21:54:05 +01:00
elif r . startswith ( " pupp " ) or r . startswith ( " dog " ) :
return phenny . reply ( " Awwwww.... " )
2013-02-19 22:29:43 +01:00
elif r . startswith ( " bomb " ) or r . startswith ( " explosive " ) or r . startswith ( " dynamite " ) :
2013-02-23 21:54:05 +01:00
if random . randint ( 0 , 3 ) == 0 :
return phenny . say ( " *shoots " + input . nick + " with an AK-74* " )
2013-02-19 22:29:43 +01:00
return phenny . say ( " *runs away* " )
elif r . startswith ( " cookie " ) or r . startswith ( " cake " ) :
return phenny . say ( " Ooh! thank you, nom nom nom... " )
if sn == " how " :
sn = si . next ( )
r = False
if sn == " to " :
r = True
if sn == " do " or sn == " can " :
sn = si . next ( )
if sn == " i " or sn == " you " :
r = True
if r :
sn = si . next ( )
if sn == " compile " :
sn = si . next ( )
if sn == " minetest " :
2013-02-23 21:54:05 +01:00
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 " ) )
2013-02-19 22:29:43 +01:00
if sn == " install " :
sn = si . next ( )
if sn == " a " or sn == " an " : sn = si . next ( )
if sn . startswith ( " mod " ) :
2013-02-23 21:54:05 +01:00
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 " ) )
2013-02-19 22:29:43 +01:00
if sn == " texture " :
if si . next ( ) . startswith ( " pack " ) :
2013-02-23 21:54:05 +01:00
return phenny . say ( response ( personal , input . nick , " http://wiki.minetest.com/wiki/Texture_Packs provides a good guide on how to install texture packs " ) )
2013-02-19 22:29:43 +01:00
if sn == " craft " :
sn = si . next ( )
if sn == " a " or sn == " an " or sn . endswith ( " s " ) :
2013-02-23 21:54:05 +01:00
return phenny . say ( response ( personal , input . nick , " Take a look at http://wiki.minetest.com/wiki/Crafting ,you should find it there " ) )
2013-02-19 22:29:43 +01:00
if sn == " where " :
sn = si . next ( )
2013-02-23 21:54:05 +01:00
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 " ) )
2013-02-19 22:29:43 +01:00
if sn == " can " or sn == " could " or sn == " to " :
sn = si . next ( )
if sn == " i " : sn = si . next ( )
r = ( False , 0 )
if sn == " get " or sn == " download " :
r = ( True , 0 )
if sn == " find " :
r = ( True , 1 )
if r [ 0 ] :
sn = si . next ( )
if sn == " a " or sn == " an " or sn == " the " : sn = si . next ( )
try :
sn = si . next ( )
except StopIteration :
2013-02-23 21:54:05 +01:00
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 " ) )
2013-02-19 22:29:43 +01:00
if sn . startswith ( " mod " ) :
2013-02-23 21:54:05 +01:00
return phenny . say ( response ( personal , input . nick , " http://forum.minetest.net/viewforum.php?id=11 " ) )
2013-02-19 22:29:43 +01:00
if sn . startswith ( " texture " ) :
if si . next ( ) . startswith ( " pack " ) :
2013-02-23 21:54:05 +01:00
return phenny . say ( response ( personal , input . nick , " http://forum.minetest.net/viewforum.php?id=4 " ) )
2013-02-19 22:29:43 +01:00
if sn . startswith ( " server " ) and r [ 1 ] == 1 :
2013-02-23 21:54:05 +01:00
return phenny . say ( response ( personal , input . nick , " http://forum.minetest.net/viewforum.php?id=10 and http://servers.minetest.ru " ) )
2013-02-19 22:29:43 +01:00
elif sn . startswith ( " server " ) and r [ 1 ] == 0 :
2013-02-23 21:54:05 +01:00
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 " ) )
2013-02-19 22:29:43 +01:00
if sn . startswith ( " map " ) :
2013-02-23 21:54:05 +01:00
return phenny . say ( response ( personal , input . nick , " http://forum.minetest.net/viewforum.php?id=12 " ) )
2013-02-19 22:29:43 +01:00
except :
return
2013-02-23 21:54:05 +01:00
arp . priority = ' medium '
arp . rule = r ' .* '
arp . event = ' * '
2013-02-19 22:29:43 +01:00
if __name__ == ' __main__ ' :
print __doc__ . strip ( )