예제 #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 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))
예제 #3
0
 def __init__(self, bot):
     self.bot = bot
     self.logChannels, self.logMessages, self.privateMessages, self.serverSettings = getCogConfigurations(
         bot)
     self.serverSettings = getFileJson('Configs.json')
     self.handler = DeleteHandler(bot, self.logChannels['Deleted Messages'])
     bot.loop.create_task(self.handler.run())
예제 #4
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)
        )
예제 #5
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)
예제 #6
0
    async def money(self, ctx):
        '''
        Shows you how much money you have in your user account
        '''

        userData = getFileJson('userMoney.json')
        userMoney = userData.get(ctx.message.author.id, 0)
        try:
            await self.bot.whisper(
                'You have `{}` credits in your account.'.format(userMoney))
        except Exception as e:
            await self.bot.say(
                'I can\'t send you PMs. Please enable these to allow me to send you messages.'
            )
예제 #7
0
    async def moneyof(self, ctx, user: Member):
        '''
        Shows you the amount of money a particular user has
        '''

        userData = getFileJson('userMoney.json')
        userMoney = userData.get(user.id, 0)
        try:
            await self.bot.whisper(
                'The user `{}` has `{}` credits in their account.'.format(
                    user, userMoney))
        except Exception as e:
            await self.bot.say(
                'I can\'t send you PMs. Please enable these to allow me to send you messages.'
            )
예제 #8
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))
예제 #9
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.'
        )
예제 #10
0
    async def remove(self, *, roleName: str):
        '''
        Remove a role that users can buy
        '''

        roleData = getFileJson('buyableRoles.json')
        roleIDs = list(roleData.keys())
        serverRoles = list(ctx.message.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(wantedRole))
            await self.bot.say(v)
            return
        else:
            # There was only one role that matched that hitstring
            pass

        try:
            del roleData[wantedRole[0]]
        except Exception as e:
            pass

        r = wantedRole[0]
        await self.bot.say(
            f'The role `{r.name}` (`{r.id}`) has been successfully deleted as a buyable role.'
        )
예제 #11
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))
예제 #12
0
 def __init__(self, bot: commands.Bot):
     self.bot = bot
     commands = getFileJson('customCommands.json')
     self.cc = commands
예제 #13
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)