diff options
author | Svetlana Tkachenko <svetlana@members.fsf.org> | 2018-02-08 10:50:37 +0000 |
---|---|---|
committer | Svetlana Tkachenko <svetlana@members.fsf.org> | 2018-02-08 10:50:37 +0000 |
commit | cfdc83c3117218054b4f6d205035eb395566fa7b (patch) | |
tree | c610ec55f96843ce124e59923522e2c79ade2e97 | |
parent | df70ea85bde2f4c49769794204eb049991b35f4f (diff) | |
download | guppy-cfdc83c3117218054b4f6d205035eb395566fa7b.tar.gz guppy-cfdc83c3117218054b4f6d205035eb395566fa7b.tar.bz2 |
-rw-r--r-- | conf/ai/basic_chat.aiml | 18 | ||||
-rw-r--r-- | conf/ai/std-startup.xml | 21 | ||||
-rw-r--r-- | extra/ai.py | 52 |
3 files changed, 91 insertions, 0 deletions
diff --git a/conf/ai/basic_chat.aiml b/conf/ai/basic_chat.aiml new file mode 100644 index 0000000..8fc8981 --- /dev/null +++ b/conf/ai/basic_chat.aiml @@ -0,0 +1,18 @@ +<aiml version="1.0.1" encoding="UTF-8"> +<!-- basic_chat.aiml --> + + <category> + <pattern>HELLO</pattern> + <template> + Well, hello! + </template> + </category> + + <category> + <pattern>WHAT ARE YOU</pattern> + <template> + I'm a bot, silly! + </template> + </category> + +</aiml>
\ No newline at end of file diff --git a/conf/ai/std-startup.xml b/conf/ai/std-startup.xml new file mode 100644 index 0000000..12c3992 --- /dev/null +++ b/conf/ai/std-startup.xml @@ -0,0 +1,21 @@ +<aiml version="1.0.1" encoding="UTF-8"> + <!-- std-startup.xml --> + + <!-- Category is an atomic AIML unit --> + <category> + + <!-- Pattern to match in user input --> + <!-- If user enters "LOAD AIML B" --> + <pattern>LOAD AIML B</pattern> + + <!-- Template is the response to the pattern --> + <!-- This learn an aiml file --> + <template> + <learn>./conf/ai/basic_chat.aiml</learn> + <!-- You can add more aiml files here --> + <!--<learn>more_aiml.aiml</learn>--> + </template> + + </category> + +</aiml> diff --git a/extra/ai.py b/extra/ai.py new file mode 100644 index 0000000..012884b --- /dev/null +++ b/extra/ai.py @@ -0,0 +1,52 @@ +# Copyright (C) 2010-2016 Svetlana A. Tkachenko <svetlana@members.fsf.org> +# Copyright (C) 2011 David Vo <david.vo2@gmail.com> +# +# This file is part of guppy. +# +# guppy is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# guppy is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# You should have received a copy of the GNU General Public License +# along with guppy. If not, see <http://www.gnu.org/licenses/>. + +import aiml + +# We need the decorator, otherwise the +# bot doesn't see it's a plugin +@plugin +class AI(object): + # The class name is the plugin name, case insensitive + """Provides AI chat features via the 'ai' command. Requires python3-aiml. Does not learn?""" + def __init__(self, server): + self.server = server + self.prnt = server.prnt + self.commands = ["ai"] + # Create the kernel and learn AIML files + self.kernel = aiml.Kernel() + self.kernel.learn("./conf/ai/std-startup.xml") + self.kernel.respond("load aiml b") + for h in self.server.handlers: + func = getattr(self, "handle_" + h, None) + if func is not None: + if h == "command": + self.server.handle(h, func, self.commands) + else: + self.server.handle(h, func) + def handle_command(self, channel, user, cmd, args): + """ + Called when we get a command + It will be called when we are addressed, as well, + thus allowing "Guppy: <command>" without the + comchar prefix. + """ + #in case we are handling a lot of commands + if cmd == "ai": + #send a response + reply = self.kernel.respond(' '.join(args)) + self.server.doMessage(channel, user + ": " + reply) #Pong. You said '"+" ".join(args)+"'") |