<commit_before>﻿using System;

using Discord;

namespace Advobot.AutoMod.Context
{
	public static class AutoModContext
	{
		public static IAutoModContext? CreateContext(this IGuildUser user)
			=> new PrivateAutoModContext(user, null, null);

		public static IAutoModMessageContext? CreateContext(this IMessage message)
		{
			var userMessage = message as IUserMessage;
			var user = userMessage?.Author as IGuildUser;
			var channel = message?.Channel as ITextChannel;
			return new PrivateAutoModContext(user!, userMessage, channel);
		}

		private sealed class PrivateAutoModContext : IAutoModMessageContext
		{
			private readonly ITextChannel? _Channel;
			private readonly IUserMessage? _Message;
			public IGuild Guild { get; }<commit_msg>AutoModContext creation won't throw exceptions on system messages/DMs now.<commit_after>﻿using System;

using AdvorangesUtils;

using Discord;

namespace Advobot.AutoMod.Context
{
	public static class AutoModContext
	{
		public static IAutoModContext? CreateContext(this IGuildUser user)
			=> new PrivateAutoModContext(user, null, null);

		public static IAutoModMessageContext? CreateContext(this IMessage message)
		{
			if (!(message is IUserMessage userMessage)
				|| !(userMessage.Author is IGuildUser user)
				|| !(userMessage.Channel is ITextChannel channel))
			{
				return null;
			}
			return new PrivateAutoModContext(user!, userMessage, channel);
		}

		private sealed class PrivateAutoModContext : IAutoModMessageContext
		{
			private readonly ITextChannel? _Channel;
			private readonly IUserMessage? _Message;
			public IGuild Guild { get; }
{'fraction_non_alphanumeric': 0.07093963907902924, 'fraction_numerical': 0.0, 'mean_word_length': 5.022471910112359, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5447248', 'n_tokens_mistral': 511, 'n_tokens_neox': 444, 'n_words': 136}