Beispiel #1
0
        private void incrementPressure(UserProfile up, Discord.Message currentMessage)
        {
            Debug.WriteLine("Last message - " + up.lastMessage.Text);
            Debug.WriteLine("Current message - " + currentMessage.Text);
            double timeSince = TimeSpan.FromTicks(currentMessage.Timestamp.Ticks - up.lastMessage.Timestamp.Ticks).TotalSeconds;
            double factor    = 1;

            if (currentMessage.Text.Equals(up.lastMessage.Text, StringComparison.OrdinalIgnoreCase))
            {
                factor *= 1.3;
            }
            if (currentMessage.Embeds.Length > 0)
            {
                factor *= 1.5;
                Debug.WriteLine("Message had embed.");
            }
            else if (currentMessage.Attachments.Length > 0)
            {
                factor *= 1.5;
                Debug.WriteLine("Message has attatchment.");
            }
            if (currentMessage.IsTTS)
            {
                factor *= 1.5;
            }
            if (currentMessage.Text.Length > 200)
            {
                factor *= 1.5;
            }
            up.pressure -= (getSpamCD(server.Id) * timeSince);
            if (factor < getSpamCD(server.Id) / 2)
            {
                factor = getSpamCD(server.Id) / 2;
            }
            up.pressure += factor;
            if (up.pressure < 0)
            {
                up.pressure = 0;
            }
            up.setMessage(currentMessage);
            Debug.WriteLine("new pressure for " + up.user.Name + ": " + up.pressure);
            if (up.pressure > getSpamLimit(server.Id))
            {
                server.Ban(up.user, 1);
                try
                {
                    server.FindChannels(getLogChannel(server.Id)).FirstOrDefault().SendMessage("Banned user **" + up.user.Name + "** for spam. Last message sent: " + up.lastMessage.Text);
                }
                catch (NullReferenceException)
                {
                    server.Owner.SendMessage("Banned user **" + up.user.Name + "** for spam. Last message sent: " + up.lastMessage.Text + "\nIf you want me to log these to your channel instead of DM, set a log channel with .setlogchannel {channel name}!");
                }
            }
        }
Beispiel #2
-1
 internal static Channel ValidateChannel(Server server, string channelName) {
     if (string.IsNullOrWhiteSpace(channelName))
         throw new ArgumentNullException(nameof(channelName));
     var channel = server.FindChannels(channelName, ChannelType.Text).FirstOrDefault();
     if (channel == null)
         throw new NullReferenceException("That channel does not exist.");
     return channel;
 }