|
|
@ -13,6 +13,7 @@ with open("cogs/essentials/config.toml", "r") as f:
|
|
|
|
class EssentialCommands(commands.Cog):
|
|
|
|
class EssentialCommands(commands.Cog):
|
|
|
|
def __init__(self, bot):
|
|
|
|
def __init__(self, bot):
|
|
|
|
self.bot = bot
|
|
|
|
self.bot = bot
|
|
|
|
|
|
|
|
self.rep_file = "cogs/essentials/reputation"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@discord.Cog.listener()
|
|
|
|
@discord.Cog.listener()
|
|
|
@ -38,6 +39,87 @@ class EssentialCommands(commands.Cog):
|
|
|
|
|
|
|
|
|
|
|
|
await gb_channel.send(embed=embed)
|
|
|
|
await gb_channel.send(embed=embed)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@commands.Cog.listener()
|
|
|
|
|
|
|
|
async def on_message(self, message):
|
|
|
|
|
|
|
|
print(message.content)
|
|
|
|
|
|
|
|
if message.content.startswith('+rep') or message.content.startswith('-rep'):
|
|
|
|
|
|
|
|
# extract the necessary information from the message content
|
|
|
|
|
|
|
|
reputation_type = message.content[0] # '+' or '-'
|
|
|
|
|
|
|
|
mentioned_users = message.mentions
|
|
|
|
|
|
|
|
author_id = message.author.id
|
|
|
|
|
|
|
|
comment = message.content.split(' ', 2)[2] if len(message.content.split(' ')) > 2 else ''
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print(f"Rep for: {mentioned_users}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# load the reputation data from the TOML file
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
with open(f"{self.rep_file}/{message.guild.id}.toml", 'r') as f:
|
|
|
|
|
|
|
|
reputation_data = toml.load(f)
|
|
|
|
|
|
|
|
print(reputation_data)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
except:
|
|
|
|
|
|
|
|
with open(f"{self.rep_file}/{message.guild.id}.toml", "w+") as f:
|
|
|
|
|
|
|
|
f.write("[reputations]")
|
|
|
|
|
|
|
|
with open(f"{self.rep_file}/{message.guild.id}.toml", 'r') as f:
|
|
|
|
|
|
|
|
reputation_data = toml.load(f)
|
|
|
|
|
|
|
|
print(reputation_data)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# loop through the mentioned users
|
|
|
|
|
|
|
|
for user in mentioned_users:
|
|
|
|
|
|
|
|
# create the reputation entry if it doesn't exist
|
|
|
|
|
|
|
|
if str(user.id) not in reputation_data:
|
|
|
|
|
|
|
|
reputation_data[str(user.id)] = {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# check if the author has already given reputation to the user
|
|
|
|
|
|
|
|
if str(author_id) in reputation_data[str(user.id)]:
|
|
|
|
|
|
|
|
await message.channel.send(f'You have already given reputation to {user.mention} before.')
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# update the reputation data with the new entry
|
|
|
|
|
|
|
|
reputation_data[str(user.id)][str(author_id)] = {'type': reputation_type, 'points': 1 if reputation_type == '+' else -1, 'comment': comment}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# save the reputation data back to the TOML file
|
|
|
|
|
|
|
|
with open(f"{self.rep_file}/{message.guild.id}.toml", 'w') as f:
|
|
|
|
|
|
|
|
toml.dump(reputation_data, f)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await message.channel.send(f'You have given {reputation_type} reputation to {user.mention} with the comment: {comment}')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@commands.slash_command()
|
|
|
|
|
|
|
|
async def reputation(self, ctx, user: discord.User):
|
|
|
|
|
|
|
|
# load the reputation data from the TOML file
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
with open(f"{self.rep_file}/{ctx.guild.id}.toml", 'r') as f:
|
|
|
|
|
|
|
|
reputation_data = toml.load(f)
|
|
|
|
|
|
|
|
except:
|
|
|
|
|
|
|
|
reputation_data = ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# check if the user has any reputation entries
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if str(user.id) not in reputation_data or reputation_data == "":
|
|
|
|
|
|
|
|
await ctx.respond(f'{user.mention} has not received any reputation yet.')
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# get the total reputation points for the user
|
|
|
|
|
|
|
|
total_points = sum([data['points'] for author_id, data in reputation_data[str(user.id)].items()])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# create the reputation leaderboard embed
|
|
|
|
|
|
|
|
embed = discord.Embed(title=f'{user.name}#{user.discriminator}\'s Reputation', color=discord.Color.blue())
|
|
|
|
|
|
|
|
embed.add_field(name='Total Reputation Points', value=total_points)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# loop through the reputation entries for the user and add them to the embed
|
|
|
|
|
|
|
|
for author_id, data in reputation_data[str(user.id)].items():
|
|
|
|
|
|
|
|
author = self.bot.get_user(int(author_id))
|
|
|
|
|
|
|
|
reputation_type = '+' if data['type'] == '+' else '-'
|
|
|
|
|
|
|
|
comment = data['comment'] if data['comment'] else 'No comment.'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
embed.add_field(name=f'{author.name}#{author.discriminator} {reputation_type}', value=comment, inline=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await ctx.respond(embed=embed)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@commands.slash_command(guild_ids=guild_ids)
|
|
|
|
@commands.slash_command(guild_ids=guild_ids)
|
|
|
|
async def ping(self, ctx):
|
|
|
|
async def ping(self, ctx):
|
|
|
|
if not esconf["commands"]["ping"]:
|
|
|
|
if not esconf["commands"]["ping"]:
|
|
|
|