Skip to content

Instantly share code, notes, and snippets.

@passcod
Created November 24, 2012 01:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save passcod/4137994 to your computer and use it in GitHub Desktop.
Save passcod/4137994 to your computer and use it in GitHub Desktop.
Personality mod for •AZ•BOT•
# coding: utf-8
"""
Personality mod
Scans all conversation and intervenes
when it picks up on specific patterns.
Responses are varied randomly, and most
have a mood index; mood is changed by
whetever you say to the bot.
Mood is two-dimensional:
^
|
Smooth
|
|
<--- Sad -----+---- Happy -->
|
|
Sharp
|
V
…and are partially modeled on myself.
I'm not looking to make the bot an auto-
portrait, though. That'd be awful.
Depends on:
core mods (azbot >= 1.4.0)
"""
import _util
import re
from pubsub import pub
mood = [0,0]
def hi(opts, message):
_util.answer(opts, "Hi there")
triggers = {
'h((e|u|a)(llo|y)|i(ya)?)\s+{name}': hi
}
def scanner(bot, user, channel, message, topic=pub.AUTO_TOPIC):
if bot.network['name'] == topic.getNameTuple()[-1]:
opts = {
'bot': bot,
'user': user,
'channel': channel
}
fields = {
'name': bot.nickname
}
print "Received message: “%s”" % message
for t in triggers:
trigger = t
for field in fields:
trigger = trigger.replace("{%s}" % field, fields[field])
if re.search(trigger, message, re.I | re.U) != None:
print "Matched: ‘%s’" % t
cont = triggers[t](opts, message)
if not cont:
break
pub.subscribe(scanner, 'irc.message')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment