def predict_cut(self): if not self._cost: if self._provider == 'ovh': time_to_cut = ((59 - random.randint(0,4))*60.0)-random.randint(0,30) self.log("ovh call, CUT IN %sm" %(time_to_cut/60.0)) self._callID = reactor.callLater(int(time_to_cut), self.cut_call, self._channel, "time limit reached on provider") return self.log("free call, will not be cut") return mana = accounting.get_credit(self._from_exten) if not mana or mana < 0.0: self.cut_call(self._channel, "not enough credit for call") else: time_to_cut = (float(mana) / float(self._cost)) * 60.0 self.log("CUT IN %sm" %(time_to_cut/60.0)) self._callID = reactor.callLater(int(time_to_cut), self.cut_call, self._channel, "out of credit while calling")
def on_app_start(self, event): self._starttime = 0 provider = event['appdata'].split("/") if len(provider) > 2: provider = provider[1] elif "@" in provider[1]: dest = provider[1].split(",")[0] provider = 'sip' self._real_to = dest else: provider = 'direct' if not self._real_to: # incoming calls from other providers self._real_to = event['exten'] notify_sse({'cost': float(self._cost), 'from': self._from, 'to': self._real_to, 'event': 'start'}, 'call_monitor', self._user) self._provider = provider self.log("call from %s to %s with %s mana remaining (%s)" % (self._from, self._real_to, accounting.get_credit(self._from_exten), self._provider))
def on_chan_start(self, args): channel = args['channel'] # precut call if user can't pay it mana = float(accounting.get_credit(self._from_exten)) if self._cost and (not mana or mana < self._cost): self.cut_call(channel, "not enough credit")