def cancelmanger(self, data, user_data, for_user): session = DBSession() day = self.get_db_day(session) if not day: day = Day(date=datetime.date.today()) session.add(day) session.commit() outputs = [] if for_user: user = self.get_db_user(session, for_user) else: user = self.get_db_user(session, user_data['name']) if not user: send_error(data['channel'], 'Erreur zjaifnazgoizangoiazg', thread=data["ts"]) presence = session.query(Presence).filter( Presence.user_id == user.id, Presence.day_id == day.id).first() if not presence: if for_user: outputs.append( "@{0} n'étais pas inscrit, pas de soucis <@{1}> !".format( user.name, user_data['id'])) else: outputs.append( "Tu n'étais pas inscrit, pas de soucis <@{0}> !".format( user_data['id'])) else: session.query(Presence).filter_by(id=presence.id).delete() session.commit() if for_user: outputs.append("J'ai supprimé l'inscription de @{0}.".format( user.name)) else: outputs.append( "J'ai supprimé ta demande <@{0}>, dommage ça allait être trop bon !" .format(user_data['id'])) outputs.append("Si besoin tu !Manger à nouveau :)") send_info(data['channel'], text='\n'.join(outputs), markdown=True, ephemeral_user=user_data["id"]) data['text'] = '!QuiMange' self.quimange(data, user_data)
def achat(self, data, user_data, amount, description): session = DBSession() today = datetime.date.today() user = self.get_db_user(session, user_data['name']) expense = Expense(user_id=user.id, amount=amount, description=description) session.add(expense) session.commit() send_info(data['channel'], text='Achat enregistré !', markdown=True, thread=data["ts"])
def cancelcuisiner(self, data, user_data): session = DBSession() day = self.get_db_day(session) if not day: day = Day(date=datetime.date.today()) session.add(day) session.commit() outputs = [] user = self.get_db_user(session, user_data['name']) if not user: send_error(data['channel'], 'Erreur zjaifnazgoizangoiazg', thread=data["ts"]) presence = session.query(Presence).filter( Presence.user_id == user.id, Presence.day_id == day.id).first() if not presence: outputs.append( "Tu n'étais pas inscrit, pas de soucis <@{0}> !".format( user_data['id'])) else: presence.cook = 0 session.add(presence) session.commit() outputs.append("J'ai supprimé le fait que tu avais cuisiné") send_info(data['channel'], text='\n'.join(outputs), markdown=True, ephemeral_user=user_data["id"]) data['text'] = '!QuiMange' self.quimange(data, user_data)
def quimange(self, data, user_data): outputs = [] session = DBSession() day = self.get_db_day(session) if not day: day = Day(date=datetime.date.today()) session.add(day) session.commit() presences = session.query(Presence).filter( Presence.day_id == day.id).all() if not presences: outputs.append("Personne d'inscrit aujourd'hui, sniff :(") else: total = 0 for presence in presences: user = presence.user total += presence.meals guest = presence.meals - 1 if guest > 0: outputs.append("{0} avec {1} invités".format( user.name, guest)) else: outputs.append(user.name) if presence.cook == 1: outputs.append("C'est {0} qui cuisinera".format(user.name)) if total > 1: outputs.insert(0, "Ce midi, {0} personnes mangent:".format(total)) else: outputs.insert( 0, "Ce midi, {0} personne mange, bravo à elle !!".format( total)) send_info(data['channel'], text='\n'.join(outputs), markdown=True)
def cuisiner(self, data, user_data): session = DBSession() day = self.get_db_day(session) if not day: day = Day(date=datetime.date.today()) session.add(day) session.commit() outputs = [] user = self.get_db_user(session, user_data['name']) if not user: send_error(data['channel'], 'Erreur il faut ```python manage.py sync``` d\'abort !', thread=data["ts"]) presence = session.query(Presence).filter( Presence.user_id == user.id, Presence.day_id == day.id).first() if not presence: presence = Presence(user_id=user.id, day_id=day.id, cook=1) session.add(presence) session.commit() outputs.append( "J'ai pris en compte le fait que tu cuisinais aujourd'hui") else: presence.cook = 1 session.add(presence) session.commit() outputs.append( "J'ai pris en compte le fait que tu cuisinais aujourd'hui") send_info(data['channel'], text='\n'.join(outputs), markdown=True, ephemeral_user=user_data["id"]) data['text'] = '!QuiMange' self.quimange(data, user_data)
def manger(self, data, user_data, guest, for_user): session = DBSession() if guest < 0: send_error( data['channel'], "Touche à ton cul avec ton nombre négatif <@{0}> ;)".format( user_data['id']), markdown=True, thread=data["ts"]) return day = self.get_db_day(session) if not day: day = Day(date=datetime.date.today()) session.add(day) session.commit() outputs = [] if for_user: user = self.get_db_user(session, for_user) from_user = self.get_db_user(session, user_data['name']) else: user = self.get_db_user(session, user_data['name']) if not user: send_error(data['channel'], 'Erreur il faut ```python manage.py sync``` d\'abort !', thread=data["ts"]) presence = session.query(Presence).filter( Presence.user_id == user.id, Presence.day_id == day.id).first() if not presence: presence = Presence(user_id=user.id, day_id=day.id, meals=guest + 1) session.add(presence) session.commit() if for_user: outputs.append( "Demande enregistrée par <@{0}> pour <@{1}>".format( from_user.slackid, user.slackid)) if guest > 0: outputs.append("Je compterai {0} part(s)".format(guest + 1)) else: outputs.append("J'ai pris en compte ta demande <@{0}>".format( user_data['id'])) if guest > 0: outputs.append( "Je te compterai {0} part ce jour".format(guest + 1)) else: if presence.meals != guest + 1: presence.meals = guest + 1 session.add(presence) session.commit() if for_user: if guest > 0: outputs.append( "Demande modifiée par <@{0}> pour <@{1}>, {2} invité(s) rajoutés" .format(from_user.slackid, user.slackid, guest)) else: outputs.append( "Demande modifiée par <@{0}> pour <@{1}>, les invités ont été supprimés" .format(from_user.slackid, user.slackid, guest)) else: if guest > 0: outputs.append( "J'ai modifié ta demande, et rajouté {0} invité(s) <@{1}>" .format(guest, user.slackid)) else: outputs.append( "J'ai modifié ta demande, et enlevé les invités <@{1}>" .format(guest, user.slackid)) else: if for_user: outputs.append( "Rien n'a changé, <@{0}> était déjà inscrit <@{1}> :)". format(user.slackid, from_user.slackid)) else: outputs.append( "Rien n'a changé, tu étais déjà inscrit <@{0}> :)". format(user.slackid)) outputs.append( "Si besoin tu peux !CancelManger ou !Manger avec des invités :)") if for_user: send_info(data['channel'], text='\n'.join(outputs), markdown=True, ephemeral_user=user.slackid) send_info(data['channel'], text='\n'.join(outputs), markdown=True, ephemeral_user=from_user.slackid) else: send_info(data['channel'], text='\n'.join(outputs), markdown=True, ephemeral_user=user_data["id"]) data['text'] = '!QuiMange' self.quimange(data, user_data)