def payQuery(bot, update): sender = getOrCreateUser(update.callback_query.from_user) split = update.callback_query.data.split(" ") if len(split) != 3: print(split) raise Exception("invalid callback query") elif split[1] not in pays: print(split) raise Exception("invalid ID") pay = pays[split[1]] approved = pay.approved disapproved = pay.disapproved changed = False if sender == pay.creator: if split[2] == "disapprove": del pays[split[1]] pay.message.edit_text( "Pay canceled (the creator disapproves himself).") return elif split[2] == "approve": if sender not in approved: approved.append(sender) changed = True if sender in disapproved: disapproved.remove(sender) elif split[2] == "disapprove": if sender in approved: approved.remove(sender) if sender not in disapproved: disapproved.append(sender) changed = True def checkList(users): if len(users) < config['pay-min-users']: return False hasMember = False for user in users: if user['id'] in config['members']: hasMember = True break return hasMember if checkList(pay.disapproved): del pays[split[1]] pay.message.edit_text("DISAPPROVED\n" + str(pay)) elif checkList(pay.approved): del pays[split[1]] createTransaction(pay.creator, pay.amount, "pay for {}, approved by {}" \ .format(pay.reason, userListToString(pay.approved))) pay.message.edit_text("APPROVED\n" + str(pay)) elif changed: pay.message.edit_text(str(pay), reply_markup=pay.message_markup) else: update.callback_query.answer()
def communismQuery(bot, update): sender = getOrCreateUser(update.callback_query.from_user) split = update.callback_query.data.split(" ") if len(split) != 3: print(split) raise Exception("invalid callback query") elif split[1] not in communisms: print(split) raise Exception("invalid ID") communism = communisms[split[1]] members = communism.members isAdmin = sender == communism.creator if split[2] == "join/leave": if sender in members: members.remove(sender) else: members.append(sender) if len(members) == 0: del communisms[split[1]] communism.message.edit_text("Everyone left, the communism died") else: communism.updateText() elif isAdmin and split[2] == "ok": count = len(members) + communism.externs amount = communism.amount // count # if the amount can't be split equally eveyone pays 1 cent more if communism.amount % count != 0: amount = amount + 1 reason = "communism by " + communism.creator['name'] for member in members: createTransaction(member, -amount, reason) payout = communism.amount - communism.externs * amount createTransaction(communism.creator, payout, reason) del communisms[split[1]] creator = communism.creator['name'] amountf = amount / float(100) text = "Communism by {}\n{} paid {}\n{} received {}\n{} has to be collected from {} externs\nDescription: {}" \ .format(creator, userListToString(communism.members), amountf, creator, payout / float(100), amountf, communism.externs, communism.reason) communism.message.edit_text(text) elif isAdmin and split[2] == "cancel": del communisms[split[1]] communism.message.edit_text("Communism canceled") elif isAdmin and split[2] == "extern-": if communism.externs > 0: communism.externs -= 1 communism.updateText() else: update.message.reply_text("Cannot reduce externs below zero") elif isAdmin and split[2] == "extern+": communism.externs += 1 communism.updateText()
def __str__(self): return "Communism by {}\nAmount: {}€\nReason: {}\nExterns: {}\nCommunists: {}\n" \ .format(self.creator['name'], self.amountEuro(), self.reason, self.externs, userListToString(self.members))
def __str__(self): return "Pay by {}\nAmount: {:.2f}€\nReason: {}\nApprovers: {}\nDisapprovers: {}\n" \ .format(self.creator['name'], self.amountEuro(), self.reason, userListToString(self.approved), userListToString(self.disapproved))