示例#1
0
        public async Task <bool> EvalTrust(SocketCommandContext context, SocketUserMessage msg)
        {
            bool actionTaken = false;

            SocketGuildUser user       = context.Guild.Users.FirstOrDefault(it => it.Id == msg.Author.Id);;//fetch guild user object
            var             userStatus = await OwlBrain.GetUserStatus(user);

            List <msgTimestamp> timestamps = (userStatus.timestamps as List <msgTimestamp>);

            if (timestamps == null)
            {
                timestamps = new List <msgTimestamp>();
            }

            timestamps.Add(new msgTimestamp(msg.Id.ToString(), msg.Channel.Id.ToString()));

            if (timestamps.Count >= 4)
            {
                var firstTimestamp = timestamps.First();
                var lastTimeStamp  = timestamps.Last();

                var seconds = (lastTimeStamp.Stamp - firstTimestamp.Stamp).TotalSeconds;

                if (seconds < 45) // if posted 4 messages in 45 seconds
                {
                    var  channels             = timestamps.Select(it => it.ChannelID);
                    bool allDifferentChannels = channels.Distinct().Count() == channels.Count();

                    if (allDifferentChannels)
                    {
                        actionTaken = true;
                        timestamps.Clear();
                    }
                }

                if (!actionTaken)
                {
                    timestamps.RemoveAt(0);
                }
            }

            //var guild = context.Guild;
            //var channel = context.Channel.Id.ToString();

            var server_id = context.Guild.Id.ToString();
            var user_id   = user.Id.ToString();
            await UserDB.db.UpdateUserTimestamps(server_id, user_id, timestamps);

            //check for bot rules



            return(actionTaken);
        }
示例#2
0
        internal static async Task MessageDeleted(Discord.Cacheable <Discord.IMessage, ulong> cachedMsg, ISocketMessageChannel channel)
        {
            if (cachedMsg.HasValue)
            {
                var imsg = cachedMsg.Value;

                if (imsg is SocketUserMessage msg)
                {
                    SocketCommandContext context = new SocketCommandContext(Globals.discord, msg);
                    bool suspicious = await OwlBrain.EvaluateSuspiciousness(context, msg);

                    if (suspicious)
                    {
                        await OwlBrain.ReportSuspicious(context, msg, "Suspicious message was deleted");
                    }
                }
            }
        }
示例#3
0
        public async Task RunAsync()
        {
            var services = new ServiceCollection();             // Create a new instance of a service collection

            ConfigureServices(services);

            var provider = services.BuildServiceProvider();                    // Build the service provider

            Globals.logger = provider.GetRequiredService <LoggingService>();   // Start the logging service
            provider.GetRequiredService <CommandHandler>();                    // Start the command handler service

            await provider.GetRequiredService <StartupService>().StartAsync(); // Start the startup service

            //initial sync
            await OwlBrain.RunStartupJob(services);


            await Task.Delay(-1);                               // Keep the program alive
        }
示例#4
0
        internal static async Task WatchForQuickReconnect(SocketGuildUser user)
        {
            ulong userId = user.Id;

            //run this in another thread to not block the gateway thread

            (new Thread(() =>
            {
                // wait some time
                int minutes = 10;
                Thread.Sleep(1000 * 60 * minutes);

                var guild = user.Guild;
                var dl = guild.DownloadUsersAsync();
                dl.Wait();

                var userReturned = guild.Users.FirstOrDefault(iterator => iterator.Id == userId);
                if (userReturned != null)
                {
                    var rps = OwlBrain.ReportSuspicious(guild, null, user, null, $"User has left the server and rejoined within {minutes} minute{(minutes > 1 ? "s" : "")}. Ban/Role evade attempt?");
                    rps.Wait();
                }
            })).Start();
        }
示例#5
0
 internal static async Task UserJoined(SocketGuildUser user)
 {
     //handle user joined
     await OwlBrain.RestoreRoles(user);
 }
示例#6
0
 internal static async Task UserLeft(SocketGuildUser user)
 {
     //handle user left
     await OwlBrain.WatchForQuickReconnect(user);
 }
示例#7
0
        private async Task OnMessageReceivedAsync(SocketMessage s)
        {
            SocketUserMessage msg = s as SocketUserMessage;     // Ensure the message is from a user/bot

            if (msg == null)
            {
                return;
            }
            if (msg.Author.Id == _discord.CurrentUser.Id)
            {
                return;                                               // Ignore self when checking commands
            }
            if (msg.Channel.ToString().StartsWith('@'))
            {
                return;                                             // Ignore DMs
            }
            var context = new SocketCommandContext(_discord, msg);  // Create the command context

            var guild = context.Guild;
            var user  = guild.Users.FirstOrDefault(iterator => iterator.Id == msg.Author.Id);

            if (user == null)
            {
                return;
            }

            var isUserAdmin = user.GuildPermissions.Administrator;

            if (string.IsNullOrWhiteSpace(msg.Content))
            {
                return;
            }

            if (await BotDetector.Instance.ScanMessage(context, msg)) // returns true if an action was taken
            {
                return;                                               //don't evaluate further if an action was taken
            }
            if (await OwlBrain.ReportSuspiciousness(context, msg))    // returns true if an action was taken
            {
                return;                                               //don't evaluate further if an action was taken
            }
            var mentionnedUsers = s.MentionedUsers;
            var mentionnedRoles = s.MentionedRoles;

            var msgParts = msg.Content.Split(" ");

            if (isUserAdmin)
            {
                switch (msgParts[0].ToUpper())
                {
                case "ORLY.HELP":
                    await Handlers.HELP(context);

                    return;

                case "ORLY.ADD_BLACKLISTED_ROLES":
                    await Handlers.ADD_BLACKLISTED_ROLES(msg, context, guild);

                    return;

                case "ORLY.REMOVE_BLACKLISTED_ROLES":
                    await Handlers.REMOVE_BLACKLISTED_ROLES(msg, context, guild);

                    return;

                case "ORLY.CLEAR_BLACKLISTED_ROLES":
                    await Handlers.CLEAR_BLACKLISTED_ROLES(context, guild);

                    return;

                case "ORLY.SHOW_BLACKLISTED_ROLES":
                    await Handlers.SHOW_BLACKLISTED_ROLES(context, guild);

                    return;

                case "ORLY.SET_REPORT_CHANNEL":
                    await Handlers.SET_REPORT_CHANNEL(s, context, guild);

                    return;

                case "ORLY.DISABLE_REPORT_CHANNEL":
                    await Handlers.DISABLE_REPORT_CHANNEL(context, guild);

                    return;

                case "ORLY.SHOW_REPORT_CHANNEL":
                    await Handlers.SHOW_REPORT_CHANNEL(context, guild);

                    return;

                case "ORLY.ADD_SUSPICIOUS_WORDS":
                    await Handlers.ADD_SUSPICIOUS_WORDS(msg, context, guild, msgParts);

                    return;

                case "ORLY.REMOVE_SUSPICIOUS_WORDS":
                    await Handlers.REMOVE_SUSPICIOUS_WORDS(msg, context, guild, msgParts);

                    return;

                case "ORLY.CLEAR_SUSPICIOUS_WORDS":
                    await Handlers.CLEAR_SUSPICIOUS_WORDS(context, guild);

                    return;

                case "ORLY.SHOW_SUSPICIOUS_WORDS":
                    await Handlers.SHOW_SUSPICIOUS_WORDS(context, guild);

                    return;

                case "ORLY.ADD_IGNORED_CHANNELS":
                    await Handlers.ADD_IGNORED_CHANNELS(msg, context, guild);

                    return;

                case "ORLY.REMOVE_IGNORED_CHANNELS":
                    await Handlers.REMOVE_IGNORED_CHANNELS(msg, context, guild);

                    return;

                case "ORLY.CLEAR_IGNORED_CHANNELS":
                    await Handlers.CLEAR_IGNORED_CHANNELS(context, guild);

                    return;

                case "ORLY.SHOW_IGNORED_CHANNELS":
                    await Handlers.SHOW_IGNORED_CHANNELS(context, guild);

                    return;
                }
            }
        }