コード例 #1
0
ファイル: usercommands.py プロジェクト: MattTheRipper/DuelBot
        async def getStakeType():
            stakeType = ""
            arguments = args[0]
            itemLongName = ""
            itemId = None

            if len(arguments) == 0:
                return None
            # If there is only one argument
            if len(arguments) == 1:
                # Try to convert the argument into a number, because the stake should be GP
                value = RSMathHelpers.numify(self, arguments[0])
                try:
                    # If the number did not successfully convert to a number, this will throw an exception when int(value) is called
                    # If it is successful, it will return "gp" to indicate a monetary stake
                    intValue = int(value)
                    stakeType = "gp"
                    return [stakeType, arguments[0]]
                except:
                    return None

            # If there are two arguments (could be "[quantity] [text]" or "[text] [text]")
            if len(arguments) == 2 or len(arguments) == 3:
                try:
                    # Try to convert the arguments into a a [name, quantity] array
                    # This will fail if the
                    stakeVals = await convertArgsToItemString(arguments)
                    if stakeVals == None:
                        return

                    # Check to see if the name of the item is in either of the item dictionaries
                    if stakeVals[0] in Economy(self.bot).rareIDs.keys():
                        stakeType = "rares"
                        itemLongName = Economy(
                            self.bot).rareIDs[stakeVals[0]][2]
                        itemId = Economy(self.bot).rareIDs[stakeVals[0]][0]
                        return [stakeType, itemLongName, itemId]
                    elif stakeVals[0] in Economy(self.bot).itemList.values():
                        stakeType = "items"
                        itemId = get_key(stakeVals[0],
                                         Economy(self.bot).itemList)
                        itemLongName = Economy(self.bot).getItemName(itemId)
                        return [stakeType, itemLongName, itemId]
                    else:
                        await message.send(
                            "Couldn't find that item, please try again.")
                        return
                except:
                    await message.send(
                        "Couldn't find that item, please try again.")
                    return
            else:
                await message.send("Something went wrong.")
                return None
コード例 #2
0
ファイル: usercommands.py プロジェクト: MattTheRipper/DuelBot
    async def dice(self, message, *args):
        diceAmount = 0
        helper = RSMathHelpers(self.bot)
        winStatus = ""
        try:
            helper = RSMathHelpers(self.bot)
            diceAmount = helper.numify(args[0])

            if diceAmount <= 0:
                await message.send("You can't dice less than 1 GP.")
                return
            elif diceAmount > 2000000000:
                await message.send("You can only dice up to 2B at once.")
                return

            diceAmountString = helper.shortNumify(diceAmount, 1)

            hasMoney = await helper.removeGPFromUser(message,
                                                     message.author.id,
                                                     diceAmount)

            if hasMoney == False:
                return

            rand = randint(1, 100)
            diceDescription = ''

            if rand >= 55:
                await helper.giveGPToUser(message, message.author.id,
                                          diceAmount * 2)
                diceDescription = f'You rolled a **{rand}** and won {diceAmountString} GP'
                winStatus = "won"
            else:
                diceDescription = f'You rolled a **{rand}** and lost {diceAmountString} GP.'
                winStatus = "lost"

            embed = discord.Embed(title='**Dice Roll**',
                                  description=diceDescription,
                                  color=discord.Color.orange())
            embed.set_thumbnail(
                url=
                'https://vignette.wikia.nocookie.net/runescape2/images/f/f2/Dice_bag_detail.png/revision/latest?cb=20111120013858'
            )
            await message.send(embed=embed)
        except:
            await message.send('You must dice a valid amount.')

        # If over 100M is diced, send it to the global notifications channel
        if diceAmount >= 500000000:
            notifChannel = self.bot.get_channel(689313376286802026)
            await notifChannel.send(
                f"{ItemEmojis.Coins.coins} {message.author.nick} has just diced **{helper.shortNumify(diceAmount, 1)}** and **{winStatus}**."
            )
コード例 #3
0
ファイル: economy.py プロジェクト: MattTheRipper/DuelBot
    async def getItemValue(self, itemId):
        print("Trying to find price for", itemId)
        url = f'http://services.runescape.com/m=itemdb_oldschool/api/catalogue/detail.json?item={itemId}'

        try:
            response = requests.get(url)
            jsonResponse = response.json()
            itemPrice = jsonResponse['item']['current']['price']
            print("Price found", itemPrice)
            return RSMathHelpers.numify(self, itemPrice)
        except:
            print(f"Err fetching item {itemId} from Database.")
            return None
コード例 #4
0
ファイル: usercommands.py プロジェクト: MattTheRipper/DuelBot
        async def convertArgsToItemString(args):

            itemName = ""
            itemQuantity = 0
            try:
                try:
                    # Test if the argument is an integer
                    itemQuantity = int(args[0])
                except:
                    # Test if the argument is a string
                    try:
                        placeholderQuantity = int(
                            RSMathHelpers.numify(self, args[0]))
                        if type(placeholderQuantity) == int:
                            itemQuantity = placeholderQuantity
                    except:
                        itemQuantity = None
                #If the first argument is an integer,
                if type(itemQuantity) != int:
                    await message.send('Please enter a valid quantity.')
                    return None
            except:
                await message.send('Please enter a quantity to stake.')
                return None

            if len(
                    args
            ) == 1:  # If the user didn't include an item to purchase, but did include a quantity (is staking GP)
                itemName = "GP"
            elif len(
                    args
            ) == 2:  # If the args was two values long, including an integer
                itemName = args[1]
            else:  # If the args was more than two words long, concatenate
                for n in range(1, len(args)):
                    itemName += args[n]

            # Cast the itemName to its lowercase version
            itemName = itemName.lower()
            # Return [name of item, quantity to stake]
            return [itemName, itemQuantity]