def info_command(self, message=None): jid = message.sender.split('/')[0] info = message.arg.strip().strip("#") if Roster.check_jid(jid) == False: return False info = info.replace("\r"," ") info = re.sub('\n',' ',info) if(len(info) <= 1): message.reply('Wpisz dłuższą wiadomość (minimum to 2 znaki).') return False if info in ['off','on']: infoCmd = False; if info == 'on': infoCmd = True r = Roster.findByJid(jid) if r <> None: r.infoCmd = infoCmd r.put() if infoCmd: message.reply('Od tej chwili będziesz otrzymywał informacje od użytkowników systemu. Zawsze możesz to zmienić wpisująć /info off') else: message.reply('Informacje od użytkowników systemu nie będą już więcej wysyłane do Ciebie. Zawsze możesz to zmienić wpisująć /info on') return True # Sprawdz na jakim pokoju pisze user currentRoom = DbSettings.get(jid,"currentRoom") if currentRoom != None and currentRoom != "global" and message.arg.strip()[0] != '#': self.send_to_room(message,currentRoom) return True r = Roster.all() r.filter("jid !=",jid) r.filter("infoCmd =",True) items = r.fetch(settings.BROADCAST_USERS_LIMIT) if len(items) == 0: message.reply('Brak osób które mogłyby odpowiedzieć na Twoją wiadomość (wszyscy wyłączyli sobie chęć odbierania tego typu powiadomień?).') return False jids = [] for item in items: jids.append(item.jid) xmpp.send_message(jids,u'%s: %s' % (re.sub(r'([\w\.-]+)@([\w\.-]+)', r'\1',jid),info)) try: mes = InfoMessages(jid=jid,message=info) mes.put() except: message.reply('Hurray! BOT exceeded quota limit. Thx You :) ');
def _get(self, params): # Default dt = date.today() page = 0 limit = 100 items = [] button_ac = 'dzis' frame = {} # Params in URL if len(params) > 0: dt = params[0].lower() page = int(params[1]) if (params[1] != None and int(params[1]) > 0) else 0 if (dt == 'wczoraj'): dt = date.today() - timedelta(1) button_ac = 'wczoraj' elif None != re.match('(\d{4}\-\d{2}\-\d{2})',dt): dt = parseDateTime(dt) button_ac = 'dzien' else: dt = date.today() startDate = parseDateTime(str(dt)+' 00:00:00') endDate = parseDateTime(str(dt)+' 23:59:59') chats = InfoMessages.all() chats.filter('created >=', startDate) chats.filter('created <=', endDate) chats.order("-created") chats = chats.fetch(limit, limit*page) for chat in chats: if len(frame) == 0: frame = {'author':chat.jid,'messages':[]} if frame['author'] == chat.jid: frame['messages'].append({'body':chat.message,'time':chat.created.strftime('%Y-%m-%d %H:%M')}) else: items.append(frame) frame = {'author':chat.jid,'messages':[]} frame['messages'].append({'body':chat.message,'time':chat.created.strftime('%Y-%m-%d %H:%M')}) if len(frame) > 0: items.append(frame) frame = {} if self.request.get('ajax',False): self.set_no_render(True) self.response.out.write(json.dumps(items)) else: self.view['chats'] = json.dumps(items) self.view['button_ac'] = button_ac