Repository: Cog-Creators/Red-DiscordBot

Issue:
Feature request, core modlog.py, Add Timestamp for sanitized embeds.
# Feature request

Add Timestamp for sanitization outside embeds with core modlog python file.


#### Select the type of feature you are requesting:

- [x] Cog
- [ ] Command
- [ ] API functionality

#### Describe your requested feature

Referencing code section: https://github.com/Cog-Creators/Red-DiscordBot/blob/28b5be21b3d3dac5313c2c701bdb4ce491889b04/redbot/core/modlog.py#L380-L394


We should have the timestamp being shown on the sanitized embed of the current case as seen below

```python
        else:
            user = filter_mass_mentions(filter_urls(user))  # Further sanitization outside embeds
            case_text = ""
            case_text += "{}\n".format(title)
            case_text += _("**User:** {}\n").format(user)
            case_text += _("**Moderator:** {}\n").format(moderator)
            case_text += _("**Time Stamp:** {}\n").format(datetime.fromtimestamp(self.created_at)) # Time Stamp added here
            case_text += "{}\n".format(reason)
            if until and duration:
                case_text += _("**Until:** {}\n**Duration:** {}\n").format(until, duration)
            if self.channel:
                case_text += _("**Channel**: {}\n").format(self.channel.name)
            if amended_by:
                case_text += _("**Amended by:** {}\n").format(amended_by)
            if last_modified:
                case_text += _("**Last modified at:** {}\n").format(last_modified)
            return case_text.strip()
```

Result: 
![image](https://user-images.githubusercontent.com/19499442/88477238-54f32700-cf0c-11ea-99be-a7d39bb1f4ff.png)



Discussion:
I'm curious on why you want this as its own separate field, as discord provides an timestamp on the message.
> I'm curious on why you want this as its own separate field, as discord provides an timestamp on the message.

Time stamp of the current warning, not the current date and time of the message*

example: 
![image](https://user-images.githubusercontent.com/19499442/88489806-bba42f00-cf64-11ea-9c98-af5f9faf89cf.png)
 test warns from March 1st and Second

![image](https://user-images.githubusercontent.com/19499442/88489831-e5f5ec80-cf64-11ea-9964-b392c1a19ca0.png)
No time stamp, 

with timestamp 
![image](https://user-images.githubusercontent.com/19499442/88489850-0c1b8c80-cf65-11ea-90b7-f2c53d479305.png)

Kowlin means this:
![image](https://user-images.githubusercontent.com/6032823/88489833-34bc7a00-cf97-11ea-81ef-c465b954c22a.png)
Time of case creation and time of message creation are pretty much equivalent, unless I'm missing something.
It'll be good to have when checking overall logs of a single user, seeing when their strike/ flag/ action was taken against them

![image](https://user-images.githubusercontent.com/19499442/88489973-15f1bf80-cf66-11ea-96ea-a00396d5f9e5.png)



I can see how the lack of that info in non-embed variants of `[p]casesfor` and `[p]case` commands is an issue. Considering that we would have to add it to those commands, we probably could also add it to the message in modlog channel as well, although I still haven't heard a use case from you that isn't already fulfilled by the timestamp of the sent message in modlog channel.

Also, it doesn't seem like you're using core modlog cog for this - the command output is different from the one in that cog.
They're using my version of ```[p]casesfor``` which adds the lines. Casereader in https://github.com/Dav-Git/Dav-Cogs It does in fact print out standard modlog entries though.
> They're using my version of `[p]casesfor` which adds the lines. Casereader in https://github.com/Dav-Git/Dav-Cogs It does in fact print out standard modlog entries though.

this

> I can see how the lack of that info in non-embed variants of `[p]casesfor` and `[p]case` commands is an issue. Considering that we would have to add it to those commands, we probably could also add it to the message in modlog channel as well, although I still haven't heard a use case from you that isn't already fulfilled by the timestamp of the sent message in modlog channel.
> 
> Also, it doesn't seem like you're using core modlog cog for this - the command output is different from the one in that cog.

Still the core modlog system just using extendedmodlog for better managing of warnings.

as editing modlog core file affects the output of sanitized modlogs as i shown in the start

https://github.com/Cog-Creators/Red-DiscordBot/blob/28b5be21b3d3dac5313c2c701bdb4ce491889b04/redbot/core/modlog.py#L380-L394

addthing this in the modlog core file 
```python
case_text += _("**Time Stamp:** {}\n").format(datetime.fromtimestamp(self.created_at)) 
```

Affects the output of the sanitizing.  
This doesn't belong in the message content method IMO. Things displaying it (including core's `casesfor` should add the timestamp to the display (they have access to it) if needed, but this method is also used for things such as the immediate sending where the timestamp would just be noise.
> This doesn't belong in the message content method IMO. 

Could always add optional keyword argument for that so that `[p]casesfor` and `[p]case` commands could still utilise the same method.

> this method is also used for things such as the immediate sending where the timestamp would just be noise.

I don't use modlog myself, but same as you, I was thinking that this might be considered noise for some (it isn't so much for me but I am not modlog user) so I'm inclined to agree that it *most likely* shouldn't be changed.
I'm not sure of the top of my head if modlog cases always contain a timestamp. If that's teh case I'd agree that this should be implemented in ``casesfor`` and ``case`` instead of being added to all modlog messages.
> I'm not sure of the top of my head if modlog cases always contain a timestamp. If that's teh case I'd agree that this should be implemented in `casesfor` and `case` instead of being added to all modlog messages.

They should up on the embed of casesfor and case, but do not show up on the sanitized version,

Ref for embed: Line 377
https://github.com/Cog-Creators/Red-DiscordBot/blob/28b5be21b3d3dac5313c2c701bdb4ce491889b04/redbot/core/modlog.py#L357-L378

Compared to sanitized which as no date or time of the warn for the case
Ref: https://github.com/Cog-Creators/Red-DiscordBot/blob/28b5be21b3d3dac5313c2c701bdb4ce491889b04/redbot/core/modlog.py#L379-L394

No date is included.

I would find it useful to have the date of action included in the 'clean' version of the warn/strike/ etc, im sure other users will find it useful aswell.

--------------------------

Having a timestamp in the sanitize version is no different than a embed, unless adding a new text line breaks the bot, which i have found it does not break anything, including these cogs
![image](https://user-images.githubusercontent.com/19499442/88491640-3aec2f80-cf72-11ea-814b-da8492416ef5.png)

--------------------------

The timestamp of action in a the cleaned version of embed is super useful, it adds no new functions or adds new calls that could interfere



> but this method is also used for things such as the immediate sending where the timestamp would just be noise.

I do would like to know where would this be noise at? Example?
>> but this method is also used for things **such as the immediate sending** where the timestamp would just be noise.

> I do would like to know where would this be noise at? Example?

When modlog cases are created, (ie right when the action is taken) they also get sent to the modlog channel using message content. As this is happening right at the time of the action, adding the timestamp to it here is just noise, as the time of the message is also the time of the action.

This can be better solved by things which display modlog cases for later viewing actually utilizing the attributes of the cases, rather than putting it here.


Resolving patch:
diff --git a/redbot/cogs/modlog/modlog.py b/redbot/cogs/modlog/modlog.py
--- a/redbot/cogs/modlog/modlog.py
+++ b/redbot/cogs/modlog/modlog.py
@@ -1,14 +1,14 @@
-from datetime import timezone
+from datetime import datetime, timezone
+
 from typing import Optional, Union
 
 import discord
 
-from redbot.core import checks, modlog, commands
+from redbot.core import checks, commands, modlog
 from redbot.core.bot import Red
 from redbot.core.i18n import Translator, cog_i18n
 from redbot.core.utils.chat_formatting import box
-from redbot.core.utils.menus import menu, DEFAULT_CONTROLS
-
+from redbot.core.utils.menus import DEFAULT_CONTROLS, menu
 
 _ = Translator("ModLog", __file__)
 
@@ -117,7 +117,13 @@ async def case(self, ctx: commands.Context, number: int):
             if await ctx.embed_requested():
                 await ctx.send(embed=await case.message_content(embed=True))
             else:
-                await ctx.send(await case.message_content(embed=False))
+                message = _("{case}\n**Timestamp:** {timestamp}").format(
+                    case=await case.message_content(embed=False),
+                    timestamp=datetime.utcfromtimestamp(case.created_at).strftime(
+                        "%Y-%m-%d %H:%M:%S UTC"
+                    ),
+                )
+                await ctx.send(message)
 
     @commands.command()
     @commands.guild_only()
@@ -143,8 +149,18 @@ async def casesfor(self, ctx: commands.Context, *, member: Union[discord.Member,
             return await ctx.send(_("That user does not have any cases."))
 
         embed_requested = await ctx.embed_requested()
-
-        rendered_cases = [await case.message_content(embed=embed_requested) for case in cases]
+        if embed_requested:
+            rendered_cases = [await case.message_content(embed=True) for case in cases]
+        elif not embed_requested:
+            rendered_cases = []
+            for case in cases:
+                message = _("{case}\n**Timestamp:** {timestamp}").format(
+                    case=await case.message_content(embed=False),
+                    timestamp=datetime.utcfromtimestamp(case.created_at).strftime(
+                        "%Y-%m-%d %H:%M:%S UTC"
+                    ),
+                )
+                rendered_cases.append(message)
 
         await menu(ctx, rendered_cases, DEFAULT_CONTROLS)
 


Test patch: