amici-ursi / ImagesOfNetwork

Tools for managing the ImagesOfNetwork on reddit
MIT License
7 stars 9 forks source link

Announce to Discord when admin actions are found in the mod log #81

Open amici-ursi opened 8 years ago

amici-ursi commented 8 years ago

We can head off trouble from above by monitoring the modlog for admin actions. They should be announced to #moderator on discord.

SmithsonianDSP commented 8 years ago

I'm not really seeing any way to really determine if a user in the mod log is an admin. There isn't a property on the praw.objects.ModAction object to distinguish if the user is a mod vs. admin.

The only way would be load the list of moderators for the subreddit and check for actions that are made by users who are not in list of mods... but then actions by users that have been removed as a mod will appear as false-positives. (But this also presents an additional challenge because modlog actions are currently processed via the multireddits, and you can't do /about/moderators for multireddits...)

There's a possibility that, if the action is performed by an admin, it might be distinguished in the ModAction._get_json_dict() returned, but, without having an actual admin mod_log action that I can look at and work with, I have no way of actually knowing whether or not there is actually a special json key/value added for admin actions.

If there isn't a special key/value in the json dict for the modlog action, then I don't think this will currently be possible.

amici-ursi commented 8 years ago

The data is here: https://www.reddit.com/user/ImagesOfNetwork/m/imagesofplaces/about/log?mod=a

I haven't looked to see how PRAW handles it.

SmithsonianDSP commented 8 years ago

I'm aware of how to look at it on the website, but reddit unmute user actions aren't the same as admin user actions.

And ultimately it doesn't matter how praw handles it; we have access to the JSON, if needed, so it's a question of how the reddit API handles it (i.e., whether or not the reddit API supplies any sort of indication if the ModAction's user is an admin or not).

This is what the JSON looks like for reddit actions:

    {
        "kind": "modaction",
        "data": {
            "description": null,
            "target_body": null,
            "mod_id36": "1qwk",
            "created_utc": 1458746409.0,
            "subreddit": "ImagesOfTexas",
            "target_title": null,
            "target_permalink": null,
            "details": null,
            "action": "unmuteuser",
            "target_author": "dziban303",
            "target_fullname": "t2_vowd",
            "sr_id36": "39d5j",
            "id": "ModAction_bb324a3a-f10a-11e5-8ed3-0e31fc1b0d95",
            "mod": "reddit"
        }
    }

... but the type of admin actions we want to see on Discord aren't unmuteuser, and they won't be shown in the modlog as being performed by reddit.

13steinj commented 8 years ago

@SmithsonianDSP

Best bet would be to store the mods of /r/reddit.com, /r/announcements, /r/blog, /r/changelog and /r/modsupport, /r/spam, /r/beta cached and test against it. Ex something like the following on https://github.com/amici-ursi/ImagesOfNetwork/blob/master/images_of/discord_announcer.py#L197

self.admin_cache = 0  # in __init__
self.admins = set()  # in __init__

if time.time() >= self.admin_cache + 864000:  # 10 days passed, double check the admins
    self.admin_cache = time.time()
    self.admins = set(user.name for userlist in (self.reddit.get_moderators(subreddit) for subreddit in ['reddit.com', 'modsupport', 'blog', 'changelog', 'spam', 'announcements', 'beta']) for user in userlist)

Then use self.admins as a crosscheck with ModAction.mod.

Testing as of right now this gives 43 of the ~75 admins I remember existing from /about/team, but those that aren't in the list are devs / part of PR, not community admins (which would be the ones doing actions).