예제 #1
0
    async def on_message(self, message):

        # Determine if using the `.user++ amount` syntax
        if not search(self.additionRegex, message.content):
            return

        # They are - check permissions
        if message.author.server_permissions.manage_channels or message.author.id in getFileJson(
                'Configs.json'
        )['Owner IDs'] or message.author.server_permissions.administrator:
            pass
        else:
            await self.bot.send_message(
                message.channel,
                'You are missing the permissions required to run that command.'
            )
            return

        # Wew that was a long line; change the user
        user = message.channel.server.get_member(''.join(
            i for i in message.content.split(' ')[0] if i.isdigit()))
        amount = int(message.content.split(' ')[-1])

        # Copy paste from the other command
        userData = getFileJson('userMoney.json')
        userMoney = userData.get(user.id, 0)
        userMoney += amount
        userData[user.id] = userMoney
        saveFileJson('userMoney.json', userData)
        await self.bot.send_message(
            message.channel,
            'This user\'s account has now been modified by a factor of `{}`.'.
            format(amount))
예제 #2
0
    async def setwarns(self, ctx, user: Member, amount: int = 0):
        '''
        Sets the amount of warnings that a user has
        '''

        if amount >= 3:
            await self.bot.say(
                'You can only *set* a maximum of 2 warnings on a user.')
            return
        elif amount < 0 and user.id != '141231597155385344':
            await self.bot.say(
                'You can\'t... you can\'t give someone *negative* warnings. That\'s dumb. Stop that. Don\'t be dumb.'
            )
            return

        # Get the current warnings for the user
        warningData = getFileJson('userWarns.json')

        # Save the new warning data
        if amount == 0:
            try:
                del warningData[user.id]
            except Exception:
                pass
        else:
            warningData[user.id] = amount
        saveFileJson('userWarns.json', warningData)

        # Send a message back to the user
        await self.bot.say(
            '👌 This user has had their warnings set to `{}`.'.format(amount)
        )
예제 #3
0
    async def remove(self, ctx, *, tagName: str = None):
        '''
        Remove a custom command from the bot
        '''

        # Get the tag name
        if not tagName:
            await self.bot.say(
                'What is the name of the command that you want to delete?')
            mes = await self.bot.wait_for_message(author=ctx.message.author)
            tagName = mes.content
            if not tagName:
                await self.bot.say(
                    'You can\'t send an image or an embed as a tag name.')
                return

        tagName = tagName.lower()

        # Get the current commands
        if not self.cc.get(tagName):
            await self.bot.say(
                'That currently isn\'t a custom command that\'s in my system.')
            return

        commands = self.cc
        del self.cc[tagName]
        self.cc = commands
        saveFileJson('customCommands.json', commands)
        await self.bot.say('Done!')
예제 #4
0
    def changeAmount(self, authorID):
        jsonData = getFileJson('userMoney.json')
        changeInt = randint(5, 10)
        currentMoney = jsonData.get(authorID, 0)

        # Change stored data
        currentMoney += changeInt
        jsonData[authorID] = currentMoney
        saveFileJson('userMoney.json', jsonData)
예제 #5
0
    async def buyrole(self, ctx, *, roleName: str):
        '''
        Lets you buy a role
        '''

        roleData = getFileJson('buyableRoles.json')
        roleIDs = list(roleData.keys())
        serverRoles = list(ctx.message.server.roles)
        availableRoles = [i for i in serverRoles if i.id in roleIDs]

        # Determine what role they were trying to search for
        wantedRole = [
            i for i in availableRoles
            if roleName.lower() in i.name.lower() or roleName == i.id
        ]

        # Determine if that role exists
        if len(wantedRole) == 0:
            await self.bot.say(
                'There were no roles that matched the hitstring `{}`.'.format(
                    roleName))
            return
        elif len(wantedRole) > 1:
            v = 'There were multiple roles that matched the hitstring `{}`; \n* {}'.format(
                roleName,
                '\n* '.join(['`{}`'.format(i.name) for i in wantedRole]))
            await self.bot.say(v)
            return
        else:
            # There was only one role that matched that hitstring
            pass

        # Determine whether the user already has the role or not
        userRoles = list(ctx.message.author.roles)
        if wantedRole[0] in userRoles:
            await self.bot.say('You already have that role!')
            return

        # Determine whether or not they have enough money for it
        userData = getFileJson('userMoney.json')
        userMoney = userData.get(ctx.message.author.id, 0)
        roleCost = roleData.get(str(wantedRole[0].id))
        if userMoney < roleCost:
            await self.bot.say(
                'You don\'t have enough money to purchase that role.')
            return

        # They have enough money - add the role and deduct money from their account
        await self.bot.add_roles(ctx.message.author, wantedRole[0])
        userMoney -= roleCost
        userData[ctx.message.author.id] = userMoney
        saveFileJson('userMoney.json', userData)
        await self.bot.say(
            'The role `{}` has been sucessfully added to you for `{}` credits.'
            .format(wantedRole[0].name, roleCost))
예제 #6
0
    async def removemoney(self, ctx, amount, user):
        '''
        Removes money from a user's account
        '''

        try:
            int(amount)
        except ValueError:
            user, amount = amount, user

        userData = getFileJson('userMoney.json')
        userMoney = userData.get(user.id, 0)
        amount = -amount
        userMoney += amount
        userData[user.id] = userMoney
        saveFileJson('userMoney.json', userData)
        await self.bot.say(
            'This user\'s account has now been modified by a factor of `{}`.'.
            format(amount))
예제 #7
0
    async def add(self, ctx):
        '''
        Add a custom command to the bot
        '''

        # Get the name of the command
        await self.bot.say('What will the name of the command be?')
        mes = await self.bot.wait_for_message(author=ctx.message.author)
        commandName = mes.content

        # Validate it
        while commandName[0] == '!':
            commandName = commandName[1:]
        if not commandName:
            await self.bot.say(
                'You can\'t just set the name of the command as a string of `!`s -.-'
            )
            return
        commandName = f'!{commandName}'.lower()

        # Get the content of the command
        await self.bot.say(
            f'What will the content of the command `{commandName}` be?')
        mes = await self.bot.wait_for_message(author=ctx.message.author)
        commandContent = mes.content

        # Validate it
        if not commandContent:
            await self.bot.say(
                'You need to have content in the message - you can\'t send images or embeds.'
            )
            return

        # Save it
        commands = self.cc
        commands[commandName] = commandContent
        saveFileJson('customCommands.json', commands)
        self.cc = commands

        # Return to user
        await self.bot.say(
            'The command `{}` has been added.'.format(commandName))
예제 #8
0
    async def add(self, price: int, *, roleName: str):
        '''
        Add a role that users can buy
        '''

        if price < 0:
            await self.bot.say(
                'Nice try, buddy. Making the price below 0? Despicable. You make me sick.'
            )
            return

        roleData = getFileJson('buyableRoles.json')
        serverRoles = list(ctx.message.roles)

        # Determine what role they were trying to search for
        wantedRole = [
            i for i in serverRoles
            if roleName.lower() in i.name.lower() or roleName == i.id
        ]

        # Determine if that role exists
        if len(wantedRole) == 0:
            await self.bot.say(
                'There were no roles that matched the hitstring `{}`.'.format(
                    roleName))
            return
        elif len(wantedRole) > 1:
            v = 'There were multiple roles that matched the hitstring `{}`; \n* {}'.format(
                roleName, '\n* '.join(wantedRole))
            await self.bot.say(v)
            return
        else:
            # There was only one role that matched that hitstring
            pass

        r = wantedRole[0]
        roleData[r.id] = price
        saveFileJson('buyableRoles.json', roleData)
        await self.bot.say(
            f'The role `{r.name}` (`{r.id}`) has been added as a buyable role for `{price}` credits.'
        )
예제 #9
0
    async def addmoney(self, ctx, amount, user):
        '''
        Adds money to a user's account
        '''

        try:
            amount = int(amount)
            userMention = user
        except ValueError:
            userMention, amount = amount, int(user)

        user = ctx.message.server.get_member(''.join(i for i in userMention
                                                     if i.isdigit()))

        userData = getFileJson('userMoney.json')
        userMoney = userData.get(user.id, 0)
        userMoney += amount
        userData[user.id] = userMoney
        saveFileJson('userMoney.json', userData)
        await self.bot.say(
            'This user\'s account has now been modified by a factor of `{}`.'.
            format(amount))
예제 #10
0
    async def warn(self, ctx, user: Member, *, reason: str = None):
        '''
        Gives a warning to the user.
        '''

        # Require a reason
        if reason == None:
            await self.bot.say('You need to provide a reason for your warning.'
                               )
            return

        # Set up local variable
        moderator = ctx.message.author

        # Get the current warnings for the user
        warningData = getFileJson('userWarns.json')
        warnAmounts = warningData.get(user.id, 0)

        # Increment their warns by one
        warnAmounts += 1

        # Check if they're over three warnings
        warnType = None
        v = False
        if warnAmounts >= 3:

            # This is the point at which we kick the user
            warnType = 'Warn Kick'
            f = self.privateMessages['Warn Kick'].format(
                server=ctx.message.server, reason=reason)
            try:
                await self.bot.send_message(user, f)
            except Exception:
                pass
            await self.bot.kick(user)
            await self.bot.say(
                '👌 This user has been kicked for having 3 warnings.')
            v = True

        else:

            # Just a warning
            warnType = 'Warn'

        # Save the new warning data
        if warnAmounts >= 3:
            del warningData[user.id]
        else:
            warningData[user.id] = warnAmounts
        saveFileJson('userWarns.json', warningData)

        # Send a message back to the user
        if not v:
            await self.bot.say(
                '👌 This user has had a warning applied for reason `{}`.'.
                format(reason))

        # Send a message to the logs channel
        if ctx.message.server.id != self.serverSettings['Server ID']: return
        c = self.logChannels[warnType]
        f = self.logMessages[warnType].format(user=member,
                                              moderator=moderator,
                                              reason=reason)
        await self.bot.send_message(c, f)