示例#1
0
    async def on_reaction_add(self, reaction: discord.Reaction,
                              user: discord.User):
        # Unsubscribe from vouch notifications
        description = reaction.message.embeds[0].description
        if 'Received a' in description and reaction.emoji == '❌':
            noNotifs = data.loadJSON(
                data.DATABASE_FILENAME)['NoNotificationIDs']
            if user.id not in noNotifs:
                embed = newEmbed(
                    description='Unsubscribed from notifications!')
                embed.set_footer(text='To resubscribe, react with ✅')
                noNotifs.append(user.id)
                data.updateJson(data.DATABASE_FILENAME,
                                {'NoNotificationIDs': noNotifs})
                await user.send(embed=embed)

        # Resubscribe to vouch notifications
        elif 'Unsubscribed' in description and reaction.emoji == '✅':
            noNotifs = data.loadJSON(
                data.DATABASE_FILENAME)['NoNotificationIDs']
            if user.id in noNotifs:
                embed = newEmbed(description='Resubscribed to notifications!')
                embed.set_footer(text='To unsubscribe, react with ❌')
                noNotifs.remove(user.id)
                data.updateJson(data.DATABASE_FILENAME,
                                {'NoNotificationIDs': noNotifs})
                await user.send(embed=embed)
    def __init__(self, userID: int, allData: dict = None):
        self.userID = int(userID)
        self.allData = allData or data.loadJSON(data.DATABASE_FILENAME)
        self.users = self.allData['Users']

        # Find the user in the database
        for i in self.users:
            if userID == i['ID']:
                userData = i
                self.isNewUser = False
                break
        else:
            self.isNewUser = True
            userData = {}

        self.ignoreNotifications = userID in self.allData['NoNotificationIDs']
        self.isMaster = userID in self.allData['Masters']
        self.link = userData.get('Link', '')
        self.dwc = userData.get('DWC', 0)
        if self.dwc is False or self.dwc is True:
            self.dwc = 0

        self.dwcReason = userData.get('DWC Reason', '')
        self.isScammer = userData.get('Scammer', False)
        self.token = userData.get('Token', generateToken())
        self.verified = userData.get('Verified', False)
        # Convert the data to Vouch objects
        self.vouches = [Vouch(i) for i in userData.get('Vouches', [])]
        self.posVouchCount = len([i for i in self.vouches if i.isPositive])
        self.negVouchCount = len(self.vouches) - self.posVouchCount

        if self.isNewUser:
            self.save()
示例#3
0
async def approve(vouchID: int, channel: discord.TextChannel,
                  logChannel: discord.TextChannel, getUser):
    '''
        Approves a vouch
    '''
    # Load the pending vouches
    allData = data.loadJSON(data.DATABASE_FILENAME)
    pendingVouches = allData['PendingVouches']

    # Check if the vouch exists, then delete it
    for i, x in enumerate(pendingVouches):
        if x['ID'] == vouchID:
            # vouch = x
            vouch = Vouch(x)
            del pendingVouches[i]
            break
    else:
        await errorMessage(message=f'Could not find vouch with ID: {vouchID}')
        return

    u = User(vouch.receiverID, allData)
    u.addVouch(vouch)
    receiverUser: discord.User = getUser(vouch.receiverID)
    giverUser: discord.User = getUser(vouch.giverID)

    # Message the user when their vouch is approved
    # and only if they haven't opted out of notifications
    if not u.ignoreNotifications:
        isPositive = vouch.isPositive
        vouchType = 'positive' if isPositive else 'negative'
        msg = f'Received a {vouchType} vouch!'

        embed = newEmbed(description=msg, color=(GREEN if isPositive else RED))
        embed.set_footer(
            text='React with ❌ to stop receiving vouch notifications')
        await receiverUser.send(embed=embed)

    # Save the vouch and send embed
    data.updateJson(data.DATABASE_FILENAME,
                    {'PendingVouches': pendingVouches})

    embed = newEmbed(description=f'Approved vouch #{vouchID}!', color=GREEN)
    await channel.send(embed=embed)

    # Send embed to log channel
    embed = newEmbed(description='', title=f'Vouch ID: {vouchID}')
    embed.add_field(name='Type', value=(
        'Pos' if isPositive else 'Neg'), inline=False)
    embed.add_field(name='Receiver', value=receiverUser.name, inline=False)
    embed.add_field(name='Giver', value=giverUser.name, inline=False)
    embed.add_field(name='Comment', value=vouch.message, inline=False)
    embed.set_footer(
        text='Approved Vouch')
    await logChannel.send(embed=embed)
示例#4
0
async def pending(channel: discord.TextChannel, getUser):
    pendingVouches = data.loadJSON(data.DATABASE_FILENAME)['PendingVouches']
    if len(pendingVouches) == 0:
        embed = newEmbed(description='No pending vouches!', color=YELLOW)
        await channel.send(embed=embed)
        return

    ids = ''
    for i in pendingVouches:
        ids += str(i['ID']) + (' | Positive'
                               if i['IsPositive'] else ' | Negative') + '\n'
    embed = newEmbed(description=ids, title='Pending vouches')
    await channel.send(embed=embed)
示例#5
0
async def add(user: discord.User,
              targetUser: discord.User,
              message: str,
              isPositive: bool,
              curChannel: discord.TextChannel,
              logChannel: discord.TextChannel,
              giverID: int = 0):
    '''
        Leaves a vouch for a user
    '''
    u = User(user.id)

    # Create a new vouch
    d = data.loadJSON(data.DATABASE_FILENAME)
    vouchNum: int = d['VouchCount'] + 1
    vouch = {
        'ID': vouchNum,
        'Giver': user.id if giverID == 0 else giverID,
        'Receiver': targetUser.id,
        'IsPositive': isPositive,
        'Message': message,
    }
    vouch = Vouch(vouch)
    u.addVouch(vouch)

    # Message the user when their vouch is approved
    # and only if they haven't opted out of notifications
    if not u.ignoreNotifications:
        vouchType = 'positive' if isPositive else 'negative'
        msg = f'Received a {vouchType} vouch!'

        embed = newEmbed(description=msg, color=(GREEN if isPositive else RED))
        embed.set_footer(
            text='React with ❌ to stop receiving vouch notifications')
        await targetUser.send(embed=embed)

    # Send confirmation message
    embed = newEmbed(description=f'Added vouch to {targetUser.mention}',
                     color=GREEN)
    await curChannel.send(embed=embed)

    # Send embed to log channel
    embed = newEmbed(description='', title=f'Vouch ID: {vouchNum}')
    embed.add_field(name='Type',
                    value=('Pos' if isPositive else 'Neg'),
                    inline=False)
    embed.add_field(name='Receiver', value=targetUser.name, inline=False)
    embed.add_field(name='Giver', value=user.name, inline=False)
    embed.add_field(name='Comment', value=message, inline=False)
    embed.set_footer(text='Added Vouch')
    await logChannel.send(embed=embed)
示例#6
0
async def admin(targetUser: discord.User, channel: discord.TextChannel):
    '''
        Toggles Master privileges to mentioned user
    '''
    masters = data.loadJSON(data.DATABASE_FILENAME)['Masters']
    if targetUser.id in masters:
        masters.remove(targetUser.id)
        embed = newEmbed(description='Removed admin!', color=GREEN)
    else:
        masters.append(targetUser.id)
        embed = newEmbed(description='Added admin!', color=GREEN)

    data.updateJson(data.DATABASE_FILENAME, {'Masters': masters})
    await channel.send(embed=embed)
示例#7
0
async def blacklist(targetUserID: int, channel: discord.TextChannel):
    '''
        Toggles the blacklist for the mentioned
        user from vouching other people
    '''
    blacklist: list = data.loadJSON(data.DATABASE_FILENAME)['Blacklist']
    if targetUserID in blacklist:
        blacklist.remove(targetUserID)
        embed = newEmbed(description='Removed user from blacklist!',
                         color=GREEN)
    else:
        blacklist.append(targetUserID)
        embed = newEmbed(description=f'Added to blacklist!', color=GREEN)

    data.updateJson(data.DATABASE_FILENAME, {'Blacklist': blacklist})
    await channel.send(embed=embed)
示例#8
0
async def deny(vouchID: int, channel: discord.TextChannel):
    '''
        Denies a vouch
    '''
    # Load the pending vouches
    pendingVouches = data.loadJSON(data.DATABASE_FILENAME)['PendingVouches']
    # Check if it exists, then delete it
    for i, x in enumerate(pendingVouches):
        if x['ID'] == vouchID:
            del pendingVouches[i]
            break
    else:
        await errorMessage(message=f'Could not find vouch with ID: {vouchID}')
        return

    data.updateJson(data.DATABASE_FILENAME, {'PendingVouches': pendingVouches})
    embed = newEmbed(description=f'Deleted vouch #{vouchID}!', color=GREEN)
    await channel.send(embed=embed)
示例#9
0
    async def on_message(self, message: discord.Message):
        '''
            Handles all the discord commands
        '''
        # Make sure we don't respond to ourselves
        if message.author == self.user:
            return

        isMaster = message.author.id in self.masterIDs
        isStaff = message.author.id in self.staffIDs or isMaster
        loweredMsg = message.content.lower()
        words = message.content.split()

        # =====================================================

        if loweredMsg.startswith('+vouch') or loweredMsg.startswith('-vouch'):
            if len(message.mentions) == 0 or len(words) < 3:
                await errorMessage(
                    'Please follow this format: [+ or -]vouch [@user] [message]',
                    message.channel)
                return

            if message.author.id == message.mentions[0].id:
                await errorMessage('You cannot vouch for yourself.',
                                   message.channel)
                return

            vouchMessage = ' '.join(words[2:])
            isPositive = loweredMsg[0] == '+'
            pendingChannel = self.get_channel(config.PENDING_VOUCHES_CHANNELID)
            await userCommands.vouch(message.author, message.mentions[0],
                                     vouchMessage, isPositive, message.channel,
                                     pendingChannel)

        # =====================================================

        elif loweredMsg.startswith(f'{PREFIX}dwc') and isMaster:
            if 'dwc1' in loweredMsg:
                level = 1
            elif 'dwc2' in loweredMsg:
                level = 2
            elif 'dwc3' in loweredMsg:
                level = 3
            else:
                level = 0

            if len(message.mentions) == 0 or (level != 0 and len(words) < 3):
                await errorMessage(
                    f'Please follow this format: {PREFIX}dwc [@user] [reason]',
                    message.channel)
                return

            reason = ' '.join(words[2:]) if level != 0 else ''
            await adminCommands.dwc(message.mentions[0], level, reason,
                                    message.channel)

        # =====================================================

        elif loweredMsg.startswith(f'{PREFIX}scammer') and isMaster:
            if len(message.mentions) == 0:
                await errorMessage(
                    f'Please follow this format: {PREFIX}scammer [@user]',
                    message.channel)
                return

            await adminCommands.scammer(message.mentions[0], message.channel)

        # =====================================================

        elif loweredMsg.startswith(f'{PREFIX}pending') and isStaff:
            await adminCommands.pending(message.channel, self.get_user)

        # =====================================================

        elif loweredMsg.startswith(f'{PREFIX}leaderboard'):
            await userCommands.leaderboard(message.channel, self.get_user,
                                           self.user.avatar_url)

        # =====================================================

        elif loweredMsg.startswith(f'{PREFIX}reply') and isStaff:
            if len(words) < 3 or not words[1].isdigit():
                await errorMessage(
                    f'Please follow this format: {PREFIX}reply [vouch id] [message]',
                    message.channel)
                return

            targetUser = None
            try:
                vouchID = int(words[1])
                pending = data.loadJSON(
                    data.DATABASE_FILENAME)['PendingVouches']
                for i in pending:
                    if i['ID'] == vouchID:
                        targetUser = self.get_user(i['Giver'])
                        break
                else:
                    raise Exception('User not found')

            except Exception as e:
                print(e)
                await errorMessage(f'Could not find user with ID {vouchID}',
                                   message.channel)
                return

            replyMsg = ' '.join(words[2:])
            await adminCommands.reply(targetUser, replyMsg, message.channel)

        # =====================================================

        elif loweredMsg.startswith(f'{PREFIX}remove') and isMaster:
            if len(message.mentions) == 0 or len(words) < 2:
                await errorMessage(
                    f'Please follow this format:\n{PREFIX}remove [@user]\n**or**\n{PREFIX}remove [@user] [vouch ID]',
                    message.channel)
                return

            vouchNum = -1
            if len(words) >= 3 and words[2].isdigit():
                vouchNum = int(words[2])
                if vouchNum < 0:
                    await errorMessage('Vouch ID cannot be negative!',
                                       message.channel)
                    return

            await adminCommands.remove(message.mentions[0], message.channel,
                                       vouchNum)

        # =====================================================

        elif loweredMsg.startswith(f'{PREFIX}verify') and isMaster:
            if len(message.mentions) == 0:
                await errorMessage(
                    f'Please follow this format: {PREFIX}verify [@user]',
                    message.channel)
                return

            await adminCommands.verify(message.mentions[0], message.channel)

        # =====================================================

        elif (loweredMsg.startswith('+add')
              or loweredMsg.startswith('-add')) and isMaster:
            if len(message.mentions) == 0 or len(words) < 3:
                await errorMessage(
                    f'Please follow this format: [+ or -]add [@user] [giverID (optional)] [message]',
                    message.channel)
                return

            # Check if they specify the giver ID
            hasGiverID = False
            giverID = 0
            if words[2].isdigit():
                hasGiverID = True
                giverID = int(words[2])

            vouchMessage = ' '.join(words[3:]) if hasGiverID else ' '.join(
                words[2:])
            isPositive = loweredMsg[0] == '+'
            logChannel = self.get_channel(config.LOG_CHANNEL_ID)
            await adminCommands.add(message.author, message.mentions[0],
                                    vouchMessage, isPositive, message.channel,
                                    logChannel, giverID)

        # =====================================================

        elif loweredMsg.startswith(f'{PREFIX}token'):
            await userCommands.token(message.author, message.channel)

        # =====================================================

        elif loweredMsg.startswith(f'{PREFIX}profile'):
            if len(message.mentions) == 0:
                user = message.author
            else:
                user = message.mentions[0]

            await userCommands.profile(
                targetUser=user,
                bcGuild=self.get_guild(583416004974084107),
                channel=message.channel)

        # =====================================================

        elif loweredMsg.startswith(f'{PREFIX}link'):
            if len(words) < 2:
                await errorMessage(
                    f'Please follow this format: {PREFIX}link [https://nulled.to/ link]',
                    message.channel)
                return

            if 'https://nulled.to/' not in words[1]:
                await errorMessage('Please provide a proper nulled.to link!',
                                   message.channel)
                return

            await userCommands.link(message.author, words[1], message.channel)

        # =====================================================

        elif loweredMsg.startswith(f'{PREFIX}redeem'):
            if len(words) <= 1:
                await errorMessage(
                    f'Please follow this format: {PREFIX}redeem [token]',
                    message.channel)
                return

            await userCommands.redeem(message.author, words[1],
                                      message.channel, self.logChannel)

        # =====================================================

        elif loweredMsg.startswith(f'{PREFIX}admin') and isMaster:
            if len(message.mentions) == 0:
                await errorMessage(
                    f'Please follow this format: {PREFIX}admin [@user]',
                    message.channel)
                return

            await adminCommands.admin(message.mentions[0], message.channel)
            if message.mentions[0].id in self.masterIDs:
                self.masterIDs.remove(message.mentions[0].id)
            else:
                self.masterIDs.append(message.mentions[0].id)

        # =====================================================

        elif loweredMsg.startswith(f'{PREFIX}staff') and isMaster:
            if len(message.mentions) == 0:
                await errorMessage(
                    f'Please follow this format: {PREFIX}staff [@user]',
                    message.channel)
                return

            await adminCommands.staff(message.mentions[0], message.channel)
            if message.mentions[0].id in self.staffIDs:
                self.staffIDs.remove(message.mentions[0].id)
            else:
                self.staffIDs.append(message.mentions[0].id)

        # =====================================================

        elif loweredMsg.startswith(f'{PREFIX}blacklist') and isMaster:
            if len(message.mentions) == 0:
                if len(words) >= 2 and not words[1].isdigit():
                    await errorMessage(
                        f'Please follow this format: {PREFIX}blacklist [@user]',
                        message.channel)
                    return

            if len(message.mentions) != 0:
                id = message.mentions[0].id
            else:
                id = int(words[1])

            await adminCommands.blacklist(id, message.channel)

        # =====================================================

        elif (loweredMsg.startswith(f'{PREFIX}approve')
              or loweredMsg.startswith(f'{PREFIX}accept')) and isStaff:
            if len(words) < 2 or not words[1].isdigit():
                await errorMessage(
                    f'Please follow this format: {PREFIX}approve [vouch ID]',
                    message.channel)
                return

            ids = [int(i) for i in words[1:] if i.isdigit()]
            logChannel = self.get_channel(config.LOG_CHANNEL_ID)
            for i in ids:
                await adminCommands.approve(i, message.channel, logChannel,
                                            self.get_user)

        # =====================================================

        elif loweredMsg.startswith(f'{PREFIX}deny') and isStaff:
            if len(words) < 2 or not words[1].isdigit():
                await errorMessage(
                    f'Please follow this format: {PREFIX}deny [vouch ID]',
                    message.channel)
                return

            ids = [int(i) for i in words[1:] if i.isdigit()]
            for i in ids:
                await adminCommands.deny(i, message.channel)

        # =====================================================

        elif loweredMsg.startswith(f'{PREFIX}help'):
            await userCommands.help(PREFIX, message.channel, isMaster)

        # =====================================================

        elif loweredMsg.startswith(f'{PREFIX}about'):
            await userCommands.about(message.channel, self.user.avatar_url)
示例#10
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        allData = data.loadJSON(data.DATABASE_FILENAME)
        self.masterIDs = allData['Masters']
        self.staffIDs = allData['Staff']