Exemplo n.º 1
0
def ice(bot, update):
    num = getAmountHelper(update.message, "ice")
    if num > 0:
        user = getOrCreateUser(update.message.from_user)
        createTransaction(user, -50 * num, "ice x{}".format(num))
        update.message.reply_text("Have a sweet one! {}".format(num * '🚅'),
                                  disable_notification=True)
Exemplo n.º 2
0
def drink(bot, update):
    num = getAmountHelper(update.message, "drink")
    if num > 0:
        user = getOrCreateUser(update.message.from_user)
        createTransaction(user, -100 * num, "drink x{}".format(num))
        update.message.reply_text("OK, enjoy your {}!".format(num * '🍹'),
                                  disable_notification=True)
Exemplo n.º 3
0
def pizza(bot, update):
    num = getAmountHelper(update.message, "pizza")
    if num > 0:
        user = getOrCreateUser(update.message.from_user)
        createTransaction(user, -200 * num, "pizza x{}".format(num))
        update.message.reply_text("Buon appetito! {}".format(num * '🍕'),
                                  disable_notification=True)
Exemplo n.º 4
0
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()
Exemplo n.º 5
0
def water(bot, update):
    num = getAmountHelper(update.message, "water")
    if num > 0:
        user = getOrCreateUser(update.message.from_user)
        createTransaction(user, -50 * num, "water x{}".format(num))
        answer = random.choice(hydrationMessages)
        update.message.reply_text(answer[0].format(num * answer[1]),
                                  disable_notification=True)
Exemplo n.º 6
0
def send(bot, update):
    args = parseArgs(update.message, [ARG_AMOUNT, ARG_USER], [None, None],
                     "\nUsage: /send <amount> <user>")

    sender = getOrCreateUser(update.message.from_user)
    receiver = args[1]
    amount = args[0]

    if sender == receiver:
        update.message.reply_text("You cannot send money to yourself")
        return

    createTransaction(sender, -amount, "sent to {}".format(receiver['name']))
    createTransaction(receiver, amount,
                      "received from {}".format(sender['name']))
    update.message.reply_text("OK, you sent {}€ to {}" \
     .format(amount / float(100), receiver['name']))
Exemplo n.º 7
0
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()
Exemplo n.º 8
0
def drink(bot, update):
    user = getOrCreateUser(update.message.from_user)
    createTransaction(user, -100, "drink")
    update.message.reply_text("OK, enjoy your 🍹!", disable_notification=True)
Exemplo n.º 9
0
def ice(bot, update):
    user = getOrCreateUser(update.message.from_user)
    createTransaction(user, -50, "ice")
    update.message.reply_text("Have a sweet one! 🚅", disable_notification=True)
Exemplo n.º 10
0
def pizza(bot, update):
    user = getOrCreateUser(update.message.from_user)
    createTransaction(user, -200, "pizza")
    update.message.reply_text("Buon appetito! 🍕", disable_notification=True)
Exemplo n.º 11
0
def water(bot, update):
    user = getOrCreateUser(update.message.from_user)
    createTransaction(user, -50, "water")
    update.message.reply_text(random.choice(hydrationMessages),
                              disable_notification=True)