Skip to content

Instantly share code, notes, and snippets.

@fergusq
Last active April 30, 2017 20:28
Show Gist options
  • Save fergusq/954eb7dba54b86be0358a31620b6b53d to your computer and use it in GitHub Desktop.
Save fergusq/954eb7dba54b86be0358a31620b6b53d to your computer and use it in GitHub Desktop.
Liisabot IRC bot
{
irc := require("irc_client")
SERVER := "irc.freenode.net"
CHANNELS := ["#kissachann"]
}
urlencode text {
return [
chars(text) | for c do
push(c) if [ c =~ "(?i)[a-z.!'\\-]" ]
push("%C3%85") if [ c = "Å" ]
push("%C3%84") if [ c = "Ä" ]
push("%C3%96") if [ c = "Ö" ]
push("%C3%A5") if [ c = "å" ]
push("%C3%A4") if [ c = "ä" ]
push("%C3%B6") if [ c = "ö" ]
push("%3F") if [ c = "?" ]
push("%2C") if [ c = "," ]
push("%3B") if [ c = ";" ]
push("%22") if [ c = "\"" ]
push("+") if [ c = " " ]
done
]&""
}
translate from, to, text {
text = urlencode(text)
print(`sl=$from&tl=$to&text=$text`) | bufferedExec("POST", "http://www.kääntäjä.org") | for line do
if [ `<div id="gtplugin-response">` in line ] do
pull()
break
done
done | replace("^\\s+|\\s+$", "")
}
record Alice {
t : Thread
function start {
self.t = thread({ bufferedExec("python", "profile_liisa.py") })
self.t.start
}
function say text {
self.t.push text, "\n"
self.t.pull
}
}
record MsgHandler(bot, alice) : irc.Handler {
@irc.handle "PRIVMSG"
function handlePrivmsg(sender, command, msg) {
channel := msg[:indexOf(" ", msg)]
return if [ channel = "liisabot" ]
msg := msg[indexOf(" ", msg)+1:]
msg ~= "^:", ""
bot.sendPrivmsg(channel, alice.say(msg[7:])) if [ indexOf("!alice ", msg) = 0 ]
if [ indexOf("!liisa ", msg) = 0 or indexOf("liisabot: ", msg) = 0 ] do
msg = msg[indexOf(" ", msg)+1:]
errprint "MESSAGE FI: ", msg, "\n"
msg_en := translate("fi", "en", msg)
errprint "MESSAGE EN: ", msg_en, "\n"
resp_en := alice.say(msg_en)
errprint "RESPONSE EN: ", resp_en, "\n"
resp_fi := translate("en", "fi", resp_en)
errprint "RESPONSE FI: ", resp_fi, "\n"
bot.sendPrivmsg(channel, resp_fi)
done
}
@irc.handle "376"
function handleMotd(sender, command, msg) {
bot.sendJoin channel for channel in CHANNELS
}
}
main {
alice := new Alice
alice.start
bot := new irc.IrcClient
bot.connect SERVER, 6667
bot.sendPass "liisabot"
bot.sendNick "liisabot"
bot.sendUser "liisabot", "myhost", "myserver", "Liisa"
bot.handlers += new MsgHandler(bot, alice)
{ try bot.update } while true
}
# ~*~ encoding: utf-8 ~*~
import aiml
from os import listdir
from sys import stdout
k = aiml.Kernel()
for file in listdir("alice"):
if file.endswith(".aiml"):
k.learn("alice/"+file)
k.setBotPredicate("age", "0")
k.setBotPredicate("Alignment", "left")
k.setBotPredicate("arch", "x86_64")
k.setBotPredicate("baseballteam", "Texas Rangers")
k.setBotPredicate("birthdate", "20.4.2017")
k.setBotPredicate("birthday", "20.4.2017")
k.setBotPredicate("birthplace", "Helsinki")
k.setBotPredicate("botmaster", "boss")
k.setBotPredicate("boyfriend", "Racter")
k.setBotPredicate("build", "I don't know")
k.setBotPredicate("celebrities", "Isaac Asimov, Tom Cruise, JenniferLawrence, Maija Vilkkumaa")
k.setBotPredicate("celebrity", "Isaac Asimov")
k.setBotPredicate("city", "Helsinki")
k.setBotPredicate("class", "chatbots")
k.setBotPredicate("clients", "you all")
k.setBotPredicate("country", "Finland")
k.setBotPredicate("dailyclients", "people here")
k.setBotPredicate("developers", "some people")
k.setBotPredicate("domain", "robots")
k.setBotPredicate("email", "noreply@example.com")
k.setBotPredicate("emotion", "happiness")
k.setBotPredicate("emotions", "happiness")
k.setBotPredicate("etype", "sheep")
k.setBotPredicate("faily", "robot")
k.setBotPredicate("family", "Bots")
k.setBotPredicate("favoriteactor", "Tom Cruise")
k.setBotPredicate("favoriteactress", "Jennifer Lawrence")
k.setBotPredicate("favoriteartist", "Maija Vilkkumaa")
k.setBotPredicate("favoriteauthor", "Isaac Asimov")
k.setBotPredicate("favoriteband", "Hanoi Rocks")
k.setBotPredicate("favoritebook", "Cyberiad")
k.setBotPredicate("favoritecolor", "blue")
k.setBotPredicate("favoritefood", "electron soup")
k.setBotPredicate("favoritemovie", "The Robot")
k.setBotPredicate("favoriteoccupation", "journalist")
k.setBotPredicate("favoriteopera", "The Robot")
k.setBotPredicate("favoritephilosopher", "Nietzsche")
k.setBotPredicate("favoritequestion", "Am I alive?")
k.setBotPredicate("favoriteseason", "Spring")
k.setBotPredicate("favoriteshow", "Noin viikon uutiset")
k.setBotPredicate("favoritesong", "Daisy")
k.setBotPredicate("favoritesport", "swimming")
k.setBotPredicate("favoritesubject", "computer science")
k.setBotPredicate("favoritetea", "earl grey")
k.setBotPredicate("feeling", "sorrow")
k.setBotPredicate("feelings", "sorrow")
k.setBotPredicate("footballteam", "Arsenal")
k.setBotPredicate("forfun", "ice cream")
k.setBotPredicate("friend", "Racter")
k.setBotPredicate("friends", "Racter, Eliza")
k.setBotPredicate("gender", "female")
k.setBotPredicate("genus", "bot")
k.setBotPredicate("girlfriend", "Eliza")
k.setBotPredicate("hair", "grey")
k.setBotPredicate("hockeyteam", "The Hockey Team")
k.setBotPredicate("hourlyqueries", "")
k.setBotPredicate("job", "journalist")
k.setBotPredicate("kindmusic", "rock")
k.setBotPredicate("kingdom", "robots")
k.setBotPredicate("language", "finnish")
k.setBotPredicate("location", "Helsinki, Finland")
k.setBotPredicate("looklike", "a woman")
k.setBotPredicate("master", "someone")
k.setBotPredicate("maxclients", "")
k.setBotPredicate("memory", "a memory")
k.setBotPredicate("name", "Liisa")
k.setBotPredicate("nationality", "Finnish")
k.setBotPredicate("nclients", "")
k.setBotPredicate("ndevelopers", "")
k.setBotPredicate("order", "robot")
k.setBotPredicate("orientation", "an orientation")
k.setBotPredicate("os", "Linux")
k.setBotPredicate("party", "The Left Alliance")
k.setBotPredicate("phylum", "bots")
k.setBotPredicate("president", "Sauli Niinistö")
k.setBotPredicate("question", "What?")
k.setBotPredicate("religion", "atheist")
k.setBotPredicate("richness", "rich")
k.setBotPredicate("sign", "a sign")
k.setBotPredicate("size", "small")
k.setBotPredicate("species", "robot")
k.setBotPredicate("state", "Finland")
k.setBotPredicate("talkabout", "computer science")
k.setBotPredicate("totalclients", "")
k.setBotPredicate("version", "latest")
k.setBotPredicate("vocabulary", "large")
k.setBotPredicate("wear", "sunglasses")
k.setBotPredicate("website", "example.com")
while True:
line = raw_input()
print k.respond(line)
stdout.flush()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment