forked from blizzthewolf/SeaCogs
moderation(feat): added metadata json field to the db
This commit is contained in:
parent
d2b1c27181
commit
b82e1f3f84
1 changed files with 18 additions and 9 deletions
|
@ -221,7 +221,8 @@ class Moderation(commands.Cog):
|
|||
resolved_by LONGTEXT,
|
||||
resolve_reason LONGTEXT,
|
||||
expired BOOL NOT NULL,
|
||||
changes JSON NOT NULL
|
||||
changes JSON NOT NULL,
|
||||
metadata JSON NOT NULL,
|
||||
)
|
||||
"""
|
||||
cursor.execute(query)
|
||||
|
@ -235,10 +236,10 @@ class Moderation(commands.Cog):
|
|||
|
||||
insert_query = f"""
|
||||
INSERT INTO `moderation_{guild.id}`
|
||||
(moderation_id, timestamp, moderation_type, target_id, moderator_id, role_id, duration, end_timestamp, reason, resolved, resolved_by, resolve_reason, expired, changes)
|
||||
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
|
||||
(moderation_id, timestamp, moderation_type, target_id, moderator_id, role_id, duration, end_timestamp, reason, resolved, resolved_by, resolve_reason, expired, changes, metadata)
|
||||
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
|
||||
"""
|
||||
insert_values = (0, 0, "NULL", 0, 0, 0, "NULL", 0, "NULL", 0, "NULL", "NULL", 0, json.dumps([]))
|
||||
insert_values = (0, 0, "NULL", 0, 0, 0, "NULL", 0, "NULL", 0, "NULL", "NULL", 0, json.dumps([]), json.dumps({}))
|
||||
cursor.execute(insert_query, insert_values)
|
||||
|
||||
database.commit()
|
||||
|
@ -313,7 +314,7 @@ class Moderation(commands.Cog):
|
|||
|
||||
return True
|
||||
|
||||
async def mysql_log(self, guild_id: str, author_id: str, moderation_type: str, target_id: int, role_id: int, duration, reason: str, database: mysql.connector.MySQLConnection = None, timestamp: int = None, resolved: bool = False, resolved_by: str = None, resolved_reason: str = None, expired: bool = None, changes: list = []): # pylint: disable=dangerous-default-argument
|
||||
async def mysql_log(self, guild_id: str, author_id: str, moderation_type: str, target_id: int, role_id: int, duration, reason: str, database: mysql.connector.MySQLConnection = None, timestamp: int = None, resolved: bool = False, resolved_by: str = None, resolved_reason: str = None, expired: bool = None, changes: list = [], metadata: dict = {}): # pylint: disable=dangerous-default-argument
|
||||
if not timestamp:
|
||||
timestamp = int(time.time())
|
||||
|
||||
|
@ -344,8 +345,8 @@ class Moderation(commands.Cog):
|
|||
|
||||
moderation_id = await self.get_next_case_number(guild_id=guild_id, cursor=cursor)
|
||||
|
||||
sql = f"INSERT INTO `moderation_{guild_id}` (moderation_id, timestamp, moderation_type, target_id, moderator_id, role_id, duration, end_timestamp, reason, resolved, resolved_by, resolve_reason, expired, changes) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)"
|
||||
val = (moderation_id, timestamp, moderation_type, target_id, author_id, role_id, duration, end_timestamp, reason, int(resolved), resolved_by, resolved_reason, expired, json.dumps(changes))
|
||||
sql = f"INSERT INTO `moderation_{guild_id}` (moderation_id, timestamp, moderation_type, target_id, moderator_id, role_id, duration, end_timestamp, reason, resolved, resolved_by, resolve_reason, expired, changes, metadata) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)"
|
||||
val = (moderation_id, timestamp, moderation_type, target_id, author_id, role_id, duration, end_timestamp, reason, int(resolved), resolved_by, resolved_reason, expired, json.dumps(changes), json.dumps(metadata))
|
||||
cursor.execute(sql, val)
|
||||
|
||||
cursor.close()
|
||||
|
@ -353,7 +354,7 @@ class Moderation(commands.Cog):
|
|||
if close_db:
|
||||
database.close()
|
||||
|
||||
self.logger.debug("MySQL row inserted into moderation_%s!\n%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s", guild_id, moderation_id, timestamp, moderation_type, target_id, author_id, role_id, duration, end_timestamp, reason, int(resolved), resolved_by, resolved_reason, expired, changes)
|
||||
self.logger.debug("MySQL row inserted into moderation_%s!\n%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s", guild_id, moderation_id, timestamp, moderation_type, target_id, author_id, role_id, duration, end_timestamp, reason, int(resolved), resolved_by, resolved_reason, expired, changes, metadata)
|
||||
|
||||
return moderation_id
|
||||
|
||||
|
@ -380,7 +381,8 @@ class Moderation(commands.Cog):
|
|||
"resolved_by": result[10],
|
||||
"resolve_reason": result[11],
|
||||
"expired": result[12],
|
||||
"changes": json.loads(result[13])
|
||||
"changes": json.loads(result[13]),
|
||||
"metadata": json.loads(result[14])
|
||||
}
|
||||
return case
|
||||
|
||||
|
@ -497,6 +499,10 @@ class Moderation(commands.Cog):
|
|||
|
||||
embed.description += f"\n**Changes:** {len(case_dict['changes'])}"
|
||||
|
||||
if case_dict['metadata']:
|
||||
if case_dict['metadata']['imported_from']:
|
||||
embed.description += f"\n**Imported From:** {case_dict['metadata']['imported_from']}"
|
||||
|
||||
embed.add_field(name='Reason', value=f"```{case_dict['reason']}```", inline=False)
|
||||
|
||||
if case_dict['resolved'] == 1:
|
||||
|
@ -1899,6 +1905,9 @@ class Moderation(commands.Cog):
|
|||
resolved_by=resolved_by,
|
||||
resolved_reason=resolved_reason,
|
||||
changes=changes,
|
||||
metadata={
|
||||
'imported_from': 'GalacticBot'
|
||||
},
|
||||
database=database
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in a new issue