コード例 #1
0
        public void TestInfractions()
        {
            var   guild       = new MockGuild();
            ulong userID      = 12345;
            var   infractions = userID.LoadInfractions(guild, false);

            Assert.Null(infractions);
            infractions = userID.LoadInfractions(guild, true);
            Assert.NotNull(infractions);
            Assert.Empty(infractions);
            userID.AddWarn(1, "Test", guild, "link");
            infractions = userID.LoadInfractions(guild, false);
            Assert.NotNull(infractions);
            Assert.NotEmpty(infractions);
        }
コード例 #2
0
        public static async Task <WarnResult> Warn(this ulong userID, float size, string reason, ITextChannel channel, IUser warnee = null, string logLink = null)
        {
            if (size > 999 || size < 0.01)
            {
                return(new WarnResult("Why would you need to warn someone with that size?"));
            }

            try
            {
                List <Infraction> infractions = userID.AddWarn(size, reason, channel.Guild, logLink);

                //Try to message but will fail if user has DMs blocked
                try
                {
                    if (warnee != null)
                    {
                        LogSettings logSettings = channel.Guild.LoadFromFile <LogSettings>(false);
                        IUser[]     users       = null;
                        if (logSettings?.pubLogChannel != null && channel.Guild.TryGetChannel(logSettings.pubLogChannel.Value, out IGuildChannel logChannel))
                        {
                            users = await(logChannel as IMessageChannel).GetUsersAsync().Flatten().ToArrayAsync();
                        }
                        else
                        {
                            users = await(channel as IMessageChannel).GetUsersAsync().Flatten().ToArrayAsync();
                        }
                        if (!users.Any(xUser => xUser.Id == userID))
                        {
                            warnee.TryNotify($"You have been warned in {channel.Guild.Name} discord for \"{reason}\" in a channel you can't view");
                        }
                    }
                }
                catch { }
                return(new WarnResult(infractions.Count));
            }
            catch (Exception e)
            {
                List <Infraction> infractions = userID.LoadInfractions(channel.Guild, true);
                await new LogMessage(LogSeverity.Error, "Warn", $"An exception has happened while warning a user ({userID}) with {infractions.Count} warns in {await channel.Guild.Describe()}", e).Log();
                return(new WarnResult(("Something has gone wrong with trying to warn. Try again in a while, if it's still not working email [email protected] or leave an issue on the GitHub" + e.ToString()).Truncate(1500)));
            }
        }