コード例 #1
0
async def givearai(message):
    if message.channel.is_private:
        return
    try:
        # One giveaway at a time
        if db.is_active_giveaway():
            await post_dm(message.author, GIVEAWAY_EXISTS)
            return
        split_content = message.content.split(' ')
        if len(split_content) > 2:
            amount = find_amount(split_content[1])
            fee = find_amount(split_content[2])
        else:
            raise util.TipBotException("usage_error")
        if amount < GIVEAWAY_MINIMUM:
            raise util.TipBotException("usage_error")
        max_fee = int(0.05 * amount)
        if fee > max_fee:
            await post_response(message, GIVEAWAY_MAX_FEE)
            return
        if 0 > fee:
            raise util.TipBotException("usage_error")
        user = db.get_user_by_id(message.author.id)
        if user is None:
            return
        balance = await wallet.get_balance(user)
        user_balance = balance['available']
        if user_balance < amount:
            await add_x_reaction(message)
            await post_dm(message.author, INSUFFICIENT_FUNDS_TEXT)
            return
        end_time = datetime.datetime.now() + datetime.timedelta(
            minutes=GIVEAWAY_DURATION)
        nano_amt = amount / 1000000
        giveaway = db.start_giveaway(message.author.id,
                                     message.author.name,
                                     nano_amt,
                                     end_time,
                                     message.channel.id,
                                     entry_fee=fee)
        uid = str(uuid.uuid4())
        await wallet.make_transaction_to_address(user,
                                                 amount,
                                                 None,
                                                 uid,
                                                 giveaway_id=giveaway.id)
        if fee > 0:
            await post_response(message, GIVEAWAY_STARTED_FEE,
                                message.author.name, nano_amt, fee, fee)
        else:
            await post_response(message, GIVEAWAY_STARTED, message.author.name,
                                nano_amt)
        asyncio.get_event_loop().create_task(start_giveaway_timer())
        db.update_tip_stats(user, amount)
        db.add_contestant(message.author.id, override_ban=True)
    except util.TipBotException as e:
        if e.error_type == "amount_not_found" or e.error_type == "usage_error":
            await post_dm(message.author, GIVEAWAY_USAGE)
コード例 #2
0
async def tipsplit(message):
    if message.channel.is_private:
        return
    try:
        amount = find_amount(message.content)
        # Make sure amount is valid and at least 1 user is mentioned
        if amount < 1 or len(message.mentions) < 1:
            raise util.TipBotException("usage_error")
        if int(amount / len(message.mentions)) < 1:
            raise util.TipBotException("invalid_tipsplit")
        # Create tip list
        users_to_tip = []
        for member in message.mentions:
            # Disregard mentions of self and exempt users
            if member.id not in settings.exempt_users and member.id != message.author.id and not db.is_banned(
                    member.id) and not member.bot:
                users_to_tip.append(member)
        if len(users_to_tip) < 1:
            raise util.TipBotException("no_valid_recipient")
        # Remove duplicates
        users_to_tip = list(set(users_to_tip))
        # Make sure user has enough in their balance
        user = db.get_user_by_id(message.author.id)
        if user is None:
            return
        balance = await wallet.get_balance(user)
        user_balance = balance['available']
        if user_balance < amount:
            await add_x_reaction(ctx.message)
            await post_dm(message.author, INSUFFICIENT_FUNDS_TEXT)
            return
        # Distribute tips
        tip_amount = int(amount / len(users_to_tip))
        # Recalculate amount as it may be different since truncating decimal
        real_amount = tip_amount * len(users_to_tip)
        for member in users_to_tip:
            uid = str(uuid.uuid4())
            actual_amt = await wallet.make_transaction_to_user(
                user, tip_amount, member.id, member.name, uid)
            # Tip didn't go through
            if actual_amt == 0:
                amount -= tip_amount
            else:
                await post_dm(member, TIP_RECEIVED_TEXT, tip_amount,
                              message.author.name)
        await react_to_message(message, amount)
        db.update_tip_stats(user, real_amount)
    except util.TipBotException as e:
        if e.error_type == "amount_not_found" or e.error_type == "usage_error":
            await post_dm(message.author, TIPSPLIT_USAGE)
        elif e.error_type == "invalid_tipsplit":
            await post_dm(message.author, TIPSPLIT_SMALL)
        elif e.error_type == "no_valid_recipient":
            await post_dm(message.author, TIP_SELF)
        else:
            await post_response(message, TIP_ERROR_TEXT)
コード例 #3
0
async def tip(message):
    if message.channel.is_private:
        return

    try:
        amount = find_amount(message.content)
        # Make sure amount is valid and at least 1 user is mentioned
        if amount < 1 or len(message.mentions) < 1:
            raise util.TipBotException("usage_error")
        # Create tip list
        users_to_tip = []
        for member in message.mentions:
            # Disregard mentions of exempt users and self
            if member.id not in settings.exempt_users and member.id != message.author.id and not db.is_banned(
                    member.id) and not member.bot:
                users_to_tip.append(member)
        if len(users_to_tip) < 1:
            raise util.TipBotException("no_valid_recipient")
        # Cut out duplicate mentions
        users_to_tip = list(set(users_to_tip))
        # Make sure this user has enough in their balance to complete this tip
        required_amt = amount * len(users_to_tip)
        user = db.get_user_by_id(message.author.id)
        balance = await wallet.get_balance(user)
        user_balance = balance['available']
        if user_balance < required_amt:
            await add_x_reaction(message)
            await post_dm(message.author, INSUFFICIENT_FUNDS_TEXT)
            return
        # Distribute tips
        for member in users_to_tip:
            uid = str(uuid.uuid4())
            actual_amt = await wallet.make_transaction_to_user(
                user, amount, member.id, member.name, uid)
            # Something went wrong, tip didn't go through
            if actual_amt == 0:
                required_amt -= amount
            else:
                await post_dm(member, TIP_RECEIVED_TEXT, actual_amt,
                              message.author.name)
        # Post message reactions
        await react_to_message(message, required_amt)
        # Update tip stats
        db.update_tip_stats(user, required_amt)
    except util.TipBotException as e:
        if e.error_type == "amount_not_found" or e.error_type == "usage_error":
            await post_dm(message.author, TIP_USAGE)
        elif e.error_type == "no_valid_recipient":
            await post_dm(message.author, TIP_SELF)
        else:
            await post_response(message, TIP_ERROR_TEXT)
コード例 #4
0
async def tipgiveaway(message, ticket=False):
    if message.channel.is_private:
        return
    try:
        giveaway = db.get_giveaway()
        amount = find_amount(message.content)
        user = db.get_user_by_id(message.author.id)
        if user is None:
            return
        balance = await wallet.get_balance(user)
        user_balance = balance['available']
        if user_balance < amount:
            await add_x_reaction(message)
            await post_dm(message.author, INSUFFICIENT_FUNDS_TEXT)
            return
        nano_amt = amount / 1000000
        if giveaway is not None:
            db.add_tip_to_giveaway(nano_amt)
            giveawayid = giveaway.id
            fee = giveaway.entry_fee
        else:
            giveawayid = -1
            fee = TIPGIVEAWAY_AUTO_ENTRY
        contributions = amount + db.get_tipgiveaway_contributions(
            message.author.id, giveawayid)
        if ticket:
            if fee > contributions:
                await post_dm(message.author,
                              "The fee to enter the giveaway is %d naneroo",
                              (fee - contributions))
                return
        uid = str(uuid.uuid4())
        await wallet.make_transaction_to_address(user,
                                                 amount,
                                                 None,
                                                 uid,
                                                 giveaway_id=giveawayid)
        if not ticket:
            await react_to_message(message, amount)
        # If eligible, add them to giveaway
        if contributions >= fee:
            entered = db.add_contestant(message.author.id, override_ban=True)
            if entered:
                if giveaway is None:
                    await post_response(message, TIPGIVEAWAY_ENTERED_FUTURE)
                else:
                    await post_dm(message.author, ENTER_ADDED)
            elif ticket:
                await post_dm(message.author, ENTER_DUP)
        # If tip sum is >= GIVEAWAY MINIMUM then start giveaway
        if giveaway is None:
            tipgiveaway_sum = db.get_tipgiveaway_sum()
            nano_amt = float(tipgiveaway_sum) / 1000000
            if tipgiveaway_sum >= GIVEAWAY_MINIMUM:
                duration = int(GIVEAWAY_DURATION / 2)
                end_time = datetime.datetime.now() + datetime.timedelta(
                    minutes=duration)
                db.start_giveaway(client.user.id,
                                  client.user.name,
                                  0,
                                  end_time,
                                  message.channel.id,
                                  entry_fee=fee)
                await post_response(message, GIVEAWAY_STARTED_FEE,
                                    client.user.name, nano_amt, fee, fee)
                asyncio.get_event_loop().create_task(start_giveaway_timer())
        # Update top tip
        db.update_tip_stats(user, amount)
    except util.TipBotException as e:
        if e.error_type == "amount_not_found" or e.error_type == "usage_error":
            if ticket:
                await post_dm(message.author, "Usage: `%sticket (fee)`",
                              COMMAND_PREFIX)
            else:
                await post_dm(message.author, TIPGIVEAWAY_USAGE)
コード例 #5
0
async def rain(message):
    if message.channel.is_private:
        return
    try:
        amount = find_amount(message.content)
        if amount < RAIN_MINIMUM:
            raise util.TipBotException("usage_error")
        # Create tip list
        users_to_tip = []
        active_user_ids = db.get_active_users(RAIN_DELTA)
        if len(active_user_ids) < 1:
            raise util.TipBotException("no_valid_recipient")
        for auid in active_user_ids:
            dmember = message.server.get_member(auid)
            if dmember is not None and (dmember.status == discord.Status.online
                                        or dmember.status
                                        == discord.Status.idle):
                if dmember.id not in settings.exempt_users and dmember.id != message.author.id and not db.is_banned(
                        dmember.id) and not dmember.bot:
                    users_to_tip.append(dmember)
        users_to_tip = list(set(users_to_tip))
        if len(users_to_tip) < 1:
            raise util.TipBotException("no_valid_recipient")
        if int(amount / len(users_to_tip)) < 1:
            raise util.TipBotException("invalid_tipsplit")
        user = db.get_user_by_id(message.author.id)
        if user is None:
            return
        balance = await wallet.get_balance(user)
        user_balance = balance['available']
        if user_balance < amount:
            await add_x_reaction(message)
            await post_dm(message.author, INSUFFICIENT_FUNDS_TEXT)
            return
        # Distribute Tips
        tip_amount = int(amount / len(users_to_tip))
        # Recalculate actual tip amount as it may be smaller now
        real_amount = tip_amount * len(users_to_tip)
        for member in users_to_tip:
            uid = str(uuid.uuid4())
            actual_amt = await wallet.make_transaction_to_user(
                user, tip_amount, member.id, member.name, uid)
            # Tip didn't go through for some reason
            if actual_amt == 0:
                amount -= tip_amount
            else:
                await post_dm(member, TIP_RECEIVED_TEXT, actual_amt,
                              message.author.name)

        # Message React
        await react_to_message(message, amount)
        await client.add_reaction(message, '\U0001F4A6')  # Sweat Drops
        db.update_tip_stats(user, real_amount)
    except util.TipBotException as e:
        if e.error_type == "amount_not_found" or e.error_type == "usage_error":
            await post_dm(message.author, RAIN_USAGE)
        elif e.error_type == "no_valid_recipient":
            await post_dm(message.author, RAIN_NOBODY)
        elif e.error_type == "invalid_tipsplit":
            await post_dm(message.author, TIPSPLIT_SMALL)
        else:
            await post_response(message, TIP_ERROR_TEXT)