Пример #1
0
def processCommand(conn, msg, msgText):
    parts = [normalize(x) for x in msgText.strip().split(" ")]
    if len(parts) != 3:
        return
    cmd, target, action = parts
    is_defend = sEq(action, u"защита")
    is_offend = sEq(action, u"атака")
    if sEq(cmd, "connect") and (is_offend or is_defend):
        person = registry[msg.getFrom().getResource()]
        if isValidTarget(person, target) and cooldown.canEnter(person):
            if is_offend and not cooldown.canAttack(person):
                answerPrivate(conn, msg, u"Передохни, выпей пивка")
                return
            conf = getConfByTarget(target)
            joinConference(conn, config.conference, conf.name, config.nickname)
            sendInvite(conn, person, conf.name)
            if is_offend:
                conf.newOffender(person)
                cooldown.startedAttack(person)
            else:
                conf.newDefender(person)
        else:
            answerPrivate(conn, msg, u"Тебе туда нельзя")
Пример #2
0
def onPrivateMessage(conn, msg):
    answerPrivate(conn, msg, u"Я не бот!")
Пример #3
0
def processCommand(conn, msg, msgText):
    if not msgText: return
    parts = [normalize(x) for x in msgText.strip().split(" ")]
    name = msg.getFrom().getResource()
    if not name:
        return
    if name not in registry:
        return
    logging.info("Command from %s: %s",name,msgText)
    person = registry[name]
    jid = person.getStripped()
    hackername = utils.jidStrip(jid)
    if len(parts) == 3:
        cmd, target, action = parts
        is_defend = sEq(action, u"defend")
        is_offend = sEq(action, u"attack")
        if sEq(cmd, "connect") and (is_offend or is_defend):
            hour = time.localtime().tm_hour
            if hour >= config.nightSleepHour and hour < config.morningStartHour:
                answerPrivate(conn, msg, u"Cool down, guy! Time to sleep for a while... Back to work at 9 a.m.")
                return
            if isValidTarget(name, target) and getConfsCount(person) < allowedChannelsCount(jid):
                if not cooldown.canEnter(person):
                    answerPrivate(conn, msg, u"Cool down, guy! Take a beer...")
                    logging.info( u"Cool down, guy! Take a beer... %s", hackername)
                    return
                if is_offend and (not cooldown.canAttack(target)):
                    answerPrivate(conn, msg, u"Target was broken recently. It's impossible to hack it for now.")
                    logging.info(u"Target was broken recently. It's impossible to hack it for now. %s", hackername)
                    return
                conf = getConfByTarget(target)
                if not conf.defeated():
                    joinConference(conn, config.conference, conf.name, config.nickname)
                    sendInvite(conn, person, conf.name)
                    if is_offend:
                        conf.newOffender(person)
#                        cooldown.startedAttack(person)
                        subs = subscribe.subscribersFor(target)
                        for p in subs:
                            if registry.containsHacker(p) and p != hackername:
#                                print "SUBS %s"%p
                                sendSubscription(conn, registry.getHacker(p), target)
                                    
                    else:
                        conf.newDefender(person)
                logging.info(u"CONF STARTED: %s" ,conf)
            else:
                answerPrivate(conn, msg, u"Access denied.")
    elif len(parts) == 2:
        cmd, target = parts
        if sEq(cmd, "subscribe"):
            if subscribe.canSubscribe(hackername, target):
                subscribe.add(hackername, target)
                answerPrivate(conn, msg, u"Target %s subscribed." % (target))
            else:
                answerPrivate(conn, msg, u"Too many subscriptions.")
        elif sEq(cmd, "unsubscribe"):
            if subscribe.remove(hackername, target):
                answerPrivate(conn, msg, u"Target %s unsubscribed." % (target))
            else:
                answerPrivate(conn, msg, u"Target %s isn't subscribed." % (target))
    elif len(parts) == 1:
        cmd = parts[0]
        if sEq(cmd, "subscriptions"):
            txt = u"List of subscriptions:\n"
            for s in subscribe.subscriptionsOf(hackername):
                txt += u"%s\n" % (s)
            answerPrivate(conn, msg, txt)
        elif sEq(cmd, "status"):
            txt = u"Current personal status: %d" % cooldown.getVitality(hackername)
            answerPrivate(conn, msg, txt)
Пример #4
0
def onPrivateMessage(conn, msg):
    answerPrivate(conn, msg, u"I'm not a bot!")
Пример #5
0
def processCommand(conn, msg, msgText):
    if not msgText: return
    parts = [normalize(x) for x in msgText.strip().split(" ")]
    name = msg.getFrom().getResource()
    if not name:
        return
    if name not in registry:
        return
    logging.info("Command from %s: %s", name, msgText)
    person = registry[name]
    jid = person.getStripped()
    hackername = utils.jidStrip(jid)
    if len(parts) == 3:
        cmd, target, action = parts
        is_defend = sEq(action, u"defend")
        is_offend = sEq(action, u"attack")
        if sEq(cmd, "connect") and (is_offend or is_defend):
            hour = time.localtime().tm_hour
            if hour >= config.nightSleepHour and hour < config.morningStartHour:
                answerPrivate(
                    conn, msg,
                    u"Cool down, guy! Time to sleep for a while... Back to work at 9 a.m."
                )
                return
            if isValidTarget(name, target) and getConfsCount(
                    person) < allowedChannelsCount(jid):
                if not cooldown.canEnter(person):
                    answerPrivate(conn, msg, u"Cool down, guy! Take a beer...")
                    logging.info(u"Cool down, guy! Take a beer... %s",
                                 hackername)
                    return
                if is_offend and (not cooldown.canAttack(target)):
                    answerPrivate(
                        conn, msg,
                        u"Target was broken recently. It's impossible to hack it for now."
                    )
                    logging.info(
                        u"Target was broken recently. It's impossible to hack it for now. %s",
                        hackername)
                    return
                conf = getConfByTarget(target)
                if not conf.defeated():
                    joinConference(conn, config.conference, conf.name,
                                   config.nickname)
                    sendInvite(conn, person, conf.name)
                    if is_offend:
                        conf.newOffender(person)
                        #                        cooldown.startedAttack(person)
                        subs = subscribe.subscribersFor(target)
                        for p in subs:
                            if registry.containsHacker(p) and p != hackername:
                                #                                print "SUBS %s"%p
                                sendSubscription(conn, registry.getHacker(p),
                                                 target)

                    else:
                        conf.newDefender(person)
                logging.info(u"CONF STARTED: %s", conf)
            else:
                answerPrivate(conn, msg, u"Access denied.")
    elif len(parts) == 2:
        cmd, target = parts
        if sEq(cmd, "subscribe"):
            if subscribe.canSubscribe(hackername, target):
                subscribe.add(hackername, target)
                answerPrivate(conn, msg, u"Target %s subscribed." % (target))
            else:
                answerPrivate(conn, msg, u"Too many subscriptions.")
        elif sEq(cmd, "unsubscribe"):
            if subscribe.remove(hackername, target):
                answerPrivate(conn, msg, u"Target %s unsubscribed." % (target))
            else:
                answerPrivate(conn, msg,
                              u"Target %s isn't subscribed." % (target))
    elif len(parts) == 1:
        cmd = parts[0]
        if sEq(cmd, "subscriptions"):
            txt = u"List of subscriptions:\n"
            for s in subscribe.subscriptionsOf(hackername):
                txt += u"%s\n" % (s)
            answerPrivate(conn, msg, txt)
        elif sEq(cmd, "status"):
            txt = u"Current personal status: %d" % cooldown.getVitality(
                hackername)
            answerPrivate(conn, msg, txt)
Пример #6
0
def onPrivateMessage(conn, msg):
    answerPrivate(conn, msg, u"I'm not a bot!")