1. Kirill Morarenko
  2. chatrug

Commits

Kirill Morarenko  committed 918814a Draft

+ private 'say' command

  • Participants
  • Parent commits 82fbd24
  • Branches default

Comments (0)

Files changed (2)

File tests/commands/say.py

View file
  • Ignore whitespace
+#coding=utf-8
+
+import crg
+
+def u(string):
+    return unicode(string, "utf-8")
+def s(un):
+    return un.encode("utf-8")
+
+def onSent2(*args, **kwargs):
+    pass
+
+def command(avatar, channel, msg, text, **kwargs):
+    if msg.sender() != "Predator0x309":
+        return crg.sendMessage(avatar, channel, crg.Message("Ты кто такой? Давай, до свидания!", msg.sender() if channel.isPrivate() else ""), onSent2)
+    parts = u(text).strip().split()
+    channel_name = s(parts[1])
+    c = [c for c in crg.g_channels if c.name() == channel_name][0]
+    text = s(u" ".join(parts[2:]))
+    crg.sendMessage(avatar, c, crg.Message(text, msg.sender() if channel.isPrivate() else ""), onSent2)
+
+
+class Command(object):
+    names = ["say"]
+    do = staticmethod(command)
+    help = None
+    onChannelUpdate = None

File tests/test.py

View file
  • Ignore whitespace
 import subprocess
 import os
 
-import commands.memo
-g_commands = [commands.memo.Command]
+import commands.memo, commands.say
+g_commands = [commands.memo.Command, commands.say.Command]
 
 def u(string):
     return unicode(string, "utf-8")
 log = Log("messages.db")
 
 def chatify(msg):
-    return msg.replace(u"\n", u" *n").replace(u" ", u" ")
+    return msg.replace(u"*n", u" ").replace(u"\n", u" *n").replace(u"  ", u"  ").replace(u"/", u" ")
 
 def onAuth(avatar, error):
     print "error '%s' on authing avatar %s with name %s" % (error, avatar, avatar.name())
         crg.receiveMessages(avatar, onMessage)
 
 g_channels = []
+crg.g_channels = g_channels #XXX
 def onJoin(avatar, channel, error):
     global g_channels
     if not error:
 
 def onChannelUpdate(avatar, channel):
     try:
-        [c.onChannelUpdate(avatar, channel) for c in g_commands]
+        [c.onChannelUpdate(avatar, channel) for c in g_commands if c.onChannelUpdate]
         #print "updated channel %s, users: %s" % (channel.name(), ", ".join(channel.users()))
         pass
     except:
     crg.sendMessage(avatar, channel, crg.Message("pong", msg.sender() if channel.isPrivate() else ""), onSent)
 
 def getHelpStr():
-    return "Команды: ping, stat, погода ГОРОД, sex ПОЛЬЗОВАТЕЛЬ, мальчики, девочки, " + ", ".join([", ".join(c.names) for c in g_commands])
+    return "Команды: ping, stat, погода ГОРОД, sex ПОЛЬЗОВАТЕЛЬ, мальчики, девочки, " + ", ".join([", ".join(c.names) for c in g_commands if c.help])
 
 def cmdHelp(avatar, channel, msg, **kwargs):
     crg.sendMessage(avatar, channel, crg.Message(getHelpStr(), msg.sender() if channel.isPrivate() else ""), onSent)
         except:
             #result = chatify(u"\n" + unicode(traceback.format_exc(), "utf-8"))
             result = u"не знаю такого города. С английскими версиями названий городов у меня обычно лучше."
-        return (u"%s - %s" % (unicode(city, "utf-8"), result)).encode("utf-8")
+        return chatify(u"%s - %s" % (unicode(city, "utf-8"), result)).encode("utf-8")
         
     parts = text.strip().split()
     if len(parts) == 1:
         city = "Москва"
     else:
         city = " ".join([x.strip() for x in parts[1:]])
-    print "weather for %s (%s)" % (city, text)
     crg.sendMessage(avatar, channel, crg.Message(getWeather(city), msg.sender() if channel.isPrivate() else ""), onSent)
 
 def cmdThanks(avatar, channel, msg, text, **kwargs):