Пример #1
0
    def execute(self,user,access,irc_msg):
        m=self.commandre.search(irc_msg.command)
        if not m:
            return 0

        if access < self.level:
            irc_msg.reply("You do not have enough access to use this command")
            return 0

        username = self.config.get("clickatell", "user")
        password = self.config.get("clickatell", "pass")
        api_id = self.config.get("clickatell", "api")

        ct = Clickatell(username, password, api_id)
        if not ct.auth():
            irc_msg.reply("Could not authenticate with server. Super secret message not sent.")
            return 1

        balance = ct.getbalance()

        if not balance:
            reply="Help me help you. I need the kwan. SHOW ME THE MONEY"
        else:
            reply="Current kwan balance: %d"%(float(balance),)

        irc_msg.reply(reply)
        return 1
Пример #2
0
    def execute(self,user,access,irc_msg):
        m=irc_msg.match_command(self.commandre)
        if not m:
            return 0

        if access < self.level:
            irc_msg.reply("You do not have enough access to use this command")
            return 0

        m=self.paramre.search(m.group(1))
        if not m:
            irc_msg.reply("Usage: %s" % (self.usage,))
            return 0

        u=self.load_user(user,irc_msg)
        if not u: return 1

        rec = m.group(1)
        public_text = m.group(2) + ' - %s' % (user,)
        text = public_text + '/%s' %(u.phone,)
        receiver=self.load_user_from_pnick(rec)
        if not receiver:
            irc_msg.reply("Who exactly is %s?" % (rec,))
            return 1
        if receiver.pnick.lower() == 'valle':
            irc_msg.reply("I refuse to talk to that Swedish clown. Use !phone show Valle and send it using your own phone.")
            return 

        results=self.phone_query_builder(receiver,"AND t1.friend_id=%s",(u.id,))

        if not (receiver.pubphone or len(results)>0):
            irc_msg.reply("%s's phone number is private or they have not chosen to share their number with you. Supersecret message not sent." % (receiver.pnick,))
            return 1

        phone = self.prepare_phone_number(receiver.phone)
        if not phone or len(phone) <= 6:
            irc_msg.reply("%s has no phone number or their phone number is too short to be valid (under 6 digits). Super secret message not sent." % (receiver.pnick,))
            return 1

        if len(text) >= 160:
            irc_msg.reply("Max length for a text is 160 characters. Your text was %i characters long. Super secret message not sent." % (len(text),))
            return 1

        username = self.config.get("clickatell", "user")
        password = self.config.get("clickatell", "pass")
        api_id = self.config.get("clickatell", "api")

        ct = Clickatell(username, password, api_id)

        if not ct.auth():
            irc_msg.reply("Could not authenticate with server. Super secret message not sent.")
            return 1

        hasher = md5()
        hasher.update(phone)
        hasher.update(text)
        msg_id = hasher.hexdigest()

        message = {
            'to': str(phone),
            'sender': "Munin",
            'text': str(text),
            'climsgid': str(msg_id),
            'msg_type': 'SMS_TEXT'
        }

        ret = ct.sendmsg(message)
        if not ret[0]:
            irc_msg.reply("That wasn't supposed to happen. I don't really know what wrong. Maybe your mother dropped you.")
            return 1
        reply="Successfully processed To: %s Message: %s"
        if irc_msg.chan_reply():
            irc_msg.reply(reply % (receiver.pnick,public_text))
        else:
            irc_msg.reply(reply % (receiver.pnick,text))
        self.log_message(u.id,receiver.id,phone, public_text)
        return 0