|
|
@@ -2,12 +2,46 @@ import discord
|
|
|
from discord.ext import commands
|
|
|
from discord.commands import Option
|
|
|
from discord.commands import slash_command
|
|
|
+import mysql.connector
|
|
|
+import configparser
|
|
|
+import os
|
|
|
+from dotenv import load_dotenv
|
|
|
+
|
|
|
|
|
|
|
|
|
class userinfo(commands.Cog):
|
|
|
def __init__(self, bot: discord.Bot):
|
|
|
self.bot = bot
|
|
|
|
|
|
+ def _load_config(self):
|
|
|
+ config = configparser.ConfigParser()
|
|
|
+ configFilePath = r'config.cfg'
|
|
|
+ config.read(configFilePath)
|
|
|
+ return config
|
|
|
+
|
|
|
+ def _connect_db(self):
|
|
|
+ load_dotenv()
|
|
|
+ dbhost = os.getenv("HOST")
|
|
|
+ if dbhost is None:
|
|
|
+ raise ValueError("HOST not found in .env file")
|
|
|
+ dbname = os.getenv("NAME")
|
|
|
+ if dbname is None:
|
|
|
+ raise ValueError("NAME not found in .env file")
|
|
|
+ dbpsswd = os.getenv("PASSWORD")
|
|
|
+ if dbpsswd is None:
|
|
|
+ raise ValueError("PASSWORD not found in .env file")
|
|
|
+ dbdb = os.getenv("DATABASE")
|
|
|
+ if dbdb is None:
|
|
|
+ raise ValueError("DATABASE not found in .env file")
|
|
|
+
|
|
|
+ connection = mysql.connector.connect(
|
|
|
+ host=dbhost,
|
|
|
+ user=dbname,
|
|
|
+ password=dbpsswd,
|
|
|
+ database=dbdb
|
|
|
+ )
|
|
|
+ return connection
|
|
|
+
|
|
|
|
|
|
#Command initialization
|
|
|
@slash_command(name="userinfo", description="Show informations of a user from this server")
|
|
|
@@ -16,6 +50,18 @@ class userinfo(commands.Cog):
|
|
|
ctx,
|
|
|
user: str = Option(discord.User, "Select User"),
|
|
|
):
|
|
|
+
|
|
|
+ config = self._load_config()
|
|
|
+ team_role_id = config.get('Team Roles', 'team_role_id')
|
|
|
+ team_role = ctx.guild.get_role(int(team_role_id))
|
|
|
+ conn = self._connect_db().connection
|
|
|
+ cursor = conn.cursor()
|
|
|
+ conn.database = self._connect_db().dbdb
|
|
|
+
|
|
|
+ if team_role not in ctx.author.roles:
|
|
|
+ await ctx.respond("You don't have the permission to use this command!", ephemeral=True)
|
|
|
+ return
|
|
|
+
|
|
|
if user is None:
|
|
|
user = ctx.author
|
|
|
elif user not in ctx.guild.members:
|
|
|
@@ -31,6 +77,13 @@ class userinfo(commands.Cog):
|
|
|
color=discord.Color.blue()
|
|
|
)
|
|
|
|
|
|
+ #get database entrys of the notes
|
|
|
+ events = []
|
|
|
+ cursor.execute("SELECT moderatorname, information, date FROM Notes WHERE userid = %s", (user.id,))
|
|
|
+ for moderatorname, reason, date in cursor.fetchall():
|
|
|
+ events.append((moderatorname, reason, date))
|
|
|
+
|
|
|
+
|
|
|
time = discord.utils.format_dt(user.created_at, "R")
|
|
|
|
|
|
embed.add_field(name="Account creation date", value=time, inline=False)
|
|
|
@@ -40,6 +93,10 @@ class userinfo(commands.Cog):
|
|
|
embed.add_field(name="Roles", value="User has no roles", inline=False)
|
|
|
embed.add_field(name="Server join date", value=discord.utils.format_dt(user.joined_at, "R"), inline=False)
|
|
|
embed.add_field(name="User ID", value=user.id)
|
|
|
+ embed.add_field(name="Bot", value="Yes" if user.bot else "No")
|
|
|
+ if events:
|
|
|
+ for moderatorname, reason, date in events:
|
|
|
+ embed.add_field(name=f"Note by {moderatorname} on {date}", value=reason, inline=False)
|
|
|
|
|
|
embed.set_thumbnail(url=user.display_avatar.url)
|
|
|
embed.set_author(name="VicePD", icon_url="https://i.imgur.com/6QteFrg.png")
|