Permalink
Browse files

code cleaning, added a reply for non admins and some docs

  • Loading branch information...
1 parent f0fb42c commit 2837094568eb2bebefef8d3aaf909d8aac7cf0d2 @fs111 committed Oct 4, 2009
Showing with 32 additions and 6 deletions.
  1. +18 −0 phenny.diff
  2. +14 −6 src/silentguy.py
View
@@ -0,0 +1,18 @@
+81c81
+< #print priority, regexp.pattern.encode('utf-8'), func
+---
+> print priority, regexp.pattern.encode('utf-8'), func
+188,192d187
+< def callWithOrigin(self, func, origin, phenny, input):
+< try: func(phenny, input, origin)
+< except Exception, e:
+< self.error(origin)
+<
+219,221d213
+< target = self.call
+< if hasattr(func, "with_origin"):
+< target = self.callWithOrigin
+223c215
+< t = threading.Thread(target=target, args=targs)
+---
+> t = threading.Thread(target=self.call, args=targs)
View
@@ -1,36 +1,44 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from subprocess import Popen, PIPE
+
COMMAND = ".talk"
+ESPEAK_COMMAND = "espeak -s 40 -p 99 -v en"
+
class Speaker:
+ """Class that wraps the espeak subprocess"""
def __init__(self):
- self.process = Popen(["espeak -s 40 -p 99 -v en "], shell=True,
- stdin=PIPE, stdout=PIPE, close_fds=True)
+ self.process = Popen([ESPEAK_COMMAND], shell=True,
+ stdin=PIPE, stdout=PIPE, close_fds=True)
def sayitoutloud(self, what):
+ """I'm geek and proud! :-)"""
self.process.stdin.write(what + "\n")
+# poor mans singleton
speaker = Speaker()
def announce(phenny, input, origin):
- """Callback that phenny calls when somone issues the .talk command"""
+ """Callback that phenny calls when somone choins the channel"""
speaker.sayitoutloud("Dudes, %s has joined the channel" % origin.nick)
-
# tell phenny what to do
announce.rule = "(.*)"
announce.event = "JOIN"
announce.with_origin = True
+
def talk(phenny, input, origin):
"""Callback that phenny calls when somone issues the .talk command"""
+ # only admins are allowed to use the .talk command
if origin.nick in phenny.config.admins:
- input = input.replace(COMMAND, "")
+ input = input.replace(COMMAND, "")
speaker.sayitoutloud(input)
-
+ else:
+ phenny.reply("only admins can use .talk")
# tell phenny what to do
talk.commands = ["talk"]
talk.example = ".talk what"

0 comments on commit 2837094

Please sign in to comment.