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)
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)
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)
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)
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)
def save(self): ''' Saves the current user into the database ''' d = { 'ID': self.userID, 'Token': self.token, 'DWC': self.dwc, 'DWC Reason': self.dwcReason, 'Vouches': [i.toDict() for i in self.vouches], 'Link': self.link, 'Scammer': self.isScammer, 'Verified': self.verified, 'PositiveVouches': len([i for i in self.vouches if i.isPositive]), 'NegativeVouches': len(self.vouches) - self.posVouchCount, } for i, x in enumerate(self.users): if x['ID'] == self.userID: self.users[i] = d break else: self.users.append(d) data.updateJson(data.DATABASE_FILENAME, {'Users': self.users})