Exemple #1
0
        public async Task RemoveReactionByID(int id)
        {
            using (var uow = DBHandler.UnitOfWork())
            {
                uow.Reactions.Remove(id);
                await uow.CompleteAsync();
            }

            await HardReload();
        }
        public async Task LoadBotGamesFromDB()
        {
            using (var uow = DBHandler.UnitOfWork())
            {
                var gamesList = await uow.BotGames.LoadBotGames();

                foreach (var botGame in gamesList)
                {
                    _botGames.Add(botGame.GameName);
                }
            }
        }
Exemple #3
0
        public async Task LoadReactionsFromDatabase()
        {
            using (var uow = DBHandler.UnitOfWork())
            {
                var reactionList = await uow.Reactions.LoadReactions();

                foreach (var reactionVar in reactionList)
                {
                    Reaction reaction = new Reaction(reactionVar.Prompt, reactionVar.Reaction, reactionVar.AnywhereInSentence);
                    _reactions.Add(reaction);
                }
            }
        }
Exemple #4
0
        public async Task RemoveReaction(string prompt)
        {
            using (var uow = DBHandler.UnitOfWork())
            {
                var allReactions = await uow.Reactions.LoadReactions();

                var reactionsToDelete = allReactions.Where(x => x.Prompt.ToLower() == prompt.ToLower()).ToArray();

                uow.Reactions.RemoveRange(reactionsToDelete);
                await uow.CompleteAsync();
            }

            await HardReload();
        }
        public async Task RemoveBotGame(string gameName)
        {
            using (var uow = DBHandler.UnitOfWork())
            {
                var allBotGames = await uow.BotGames.LoadBotGames();

                var gamesToDelete = allBotGames.Where(x => x.GameName.ToLower() == gameName.ToLower()).ToArray();

                uow.BotGames.RemoveRange(gamesToDelete);
                await uow.CompleteAsync();
            }

            await HardReload();
        }
        public async Task HardReload()
        {
            using (var uow = DBHandler.UnitOfWork())
            {
                var gamesList = await uow.BotGames.LoadBotGames();

                List <string> temp = new List <string>();
                foreach (var botGame in gamesList)
                {
                    temp.Add(botGame.GameName);
                }

                _botGames = new List <string>(temp);
            }
        }
Exemple #7
0
        public async Task HardReload()
        {
            using (var uow = DBHandler.UnitOfWork())
            {
                var reactionList = await uow.Reactions.LoadReactions();

                List <Reaction> temp = new List <Reaction>();
                foreach (var reactionVar in reactionList)
                {
                    Reaction reaction = new Reaction(reactionVar.Prompt, reactionVar.Reaction, reactionVar.AnywhereInSentence);
                    temp.Add(reaction);
                }

                _reactions = new List <Reaction>(temp);
            }
        }
        public async Task <int> AddGame(string gameName)
        {
            int reactID = -1;

            using (var uow = DBHandler.UnitOfWork())
            {
                var BG = new Database.Models.BotGames()
                {
                    GameName = gameName
                };
                uow.BotGames.Add(BG);
                await uow.CompleteAsync();

                reactID = BG.ID;
            }

            _botGames.Add(gameName);

            return(reactID);
        }
Exemple #9
0
        public async Task <bool> SetReactionActivationMethod(int reactionID, bool anywhere)
        {
            using (var uow = DBHandler.UnitOfWork())
            {
                var allReactions = await uow.Reactions.LoadReactions();

                var reactionToEdit = allReactions.Where(x => x.ID == reactionID).FirstOrDefault();

                if (reactionToEdit == null)
                {
                    return(false);
                }

                //Edit
                reactionToEdit.AnywhereInSentence = anywhere;
                uow.Reactions.Update(reactionToEdit);
                await uow.CompleteAsync();
            }

            await HardReload();

            return(true);
        }
Exemple #10
0
        public async Task <int> AddReaction(string prompt, string reaction)
        {
            int reactID = -1;

            using (var uow = DBHandler.UnitOfWork())
            {
                var ReactionMod = new Database.Models.ReactionModel()
                {
                    Prompt             = prompt,
                    Reaction           = reaction,
                    AnywhereInSentence = false
                };
                uow.Reactions.Add(ReactionMod);
                await uow.CompleteAsync();

                reactID = ReactionMod.ID;
            }

            Reaction react = new Reaction(prompt, reaction, false);

            _reactions.Add(react);

            return(reactID);
        }
        private async Task OnMessageAsync(SocketMessage s)
        {
            var msg = s as SocketUserMessage;

            if (msg == null)
            {
                return;
            }
            if (msg.Author.Id == _discord.CurrentUser.Id)
            {
                return;
            }

            var context = new SocketCommandContext(_discord, msg);

            //Get URL in string
            MatchCollection Matches = Regex.Matches(context.Message.Content, @"((http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&amp;:/~\+#]*[\w\-\@?^=%&amp;/~\+#])?)");

            //Right first step
            //Check if the message has an image. If it doesn't and doesn't have a URL, we don't care.
            if (context.Message.Attachments.Count == 0 && Matches.Count == 0)
            {
                return;
            }

            //Now we fetch each part
            User     U = null;
            Channels C = null;

            using (var uow = DBHandler.UnitOfWork())
            {
                U = uow.User.GetOrCreateUser(context.User.Id);
                C = uow.Channels.GetOrCreateChannel(context.Channel.Id, DefaultCD);

                //Create just to make sure it exists so more doesn't fail down there
                uow.UserRate.GetOrCreateUserRate(C.ID, U.ID);
            }

            //Is the user exempt?

            if (U == null || U.IsExempt)
            {
                return;
            }

            //Now we need to check if the channel is even part of it all

            if (C == null || !C.State)
            {
                return;
            }

            //Alright we need to limit shit now.
            //Lets check if the user is allowed to post
            bool canPost = true;
            int  UserPostsSinceLastTrack = 0;

            using (var uow = DBHandler.UnitOfWork())
            {
                canPost = uow.UserRate.CanUserPostImages(C.ID, U.ID, C.CooldownTime, C.MaxPosts);
                UserPostsSinceLastTrack = uow.UserRate.GetPostsSinceLastTrack(C.ID, U.ID);
            }

            int amountToAdd = context.Message.Attachments.Count + Matches.Count;

            //If they can post we need to add one to their posts and then we're done here
            if (canPost && amountToAdd <= (C.MaxPosts - UserPostsSinceLastTrack))
            {
                using (var uow = DBHandler.UnitOfWork())
                {
                    uow.UserRate.AddUserPost(C.ID, U.ID, amountToAdd);
                }

                return;
            }

            //If they can't post we have a lot to deal with here.
            //First we have to actually delete the message
            await context.Message.DeleteAsync();

            //Then we need to tell the user not to post so quick
            var tellingOff = await context.Channel.SendErrorAsync("Slow down dummy!");

            //Remove after 2 seconds
            tellingOff.DeleteAfter(5);
        }
Exemple #12
0
        private async Task DeletedAsync(Cacheable <IMessage, ulong> CacheableMessage, ISocketMessageChannel origChannel)
        {
            var CachedMessage = await CacheableMessage.GetOrDownloadAsync();

            var MessageChannel = (ITextChannel)origChannel;

            if (CachedMessage.Source != MessageSource.User)
            {
                return;
            }
            if (MessageChannel.Guild == null)
            {
                return;
            }
            if (CachedMessage == null)
            {
                return;
            }

            Guild G = null;
            List <BlockedLogs> BLs = new List <BlockedLogs>();

            using (var uow = DBHandler.UnitOfWork())
            {
                if (!uow.Guild.IsDeleteLoggingEnabled(MessageChannel.Guild.Id))
                {
                    return;
                }
                G = uow.Guild.GetOrCreateGuild(MessageChannel.Guild.Id);
                if (G.GuildID == 0)
                {
                    return;
                }
                BLs = uow.BlockedLogs.GetServerBlockedLogs(MessageChannel.Guild.Id);
            }

            if (BLs != null && BLs.Count > 0)
            {
                if (BLs.Any(x => CachedMessage.Content.StartsWith(x.BlockedString)))
                {
                    return;
                }
            }

            if (G == null)
            {
                return;
            }

            var ChannelToSend = (IMessageChannel)_discord.GetChannel(G.DeleteLogChannel);

            string content = CachedMessage.Content;

            if (content == "")
            {
                content = "*original message was blank*";
            }

            EmbedBuilder embed = new EmbedBuilder().WithAuthor(eab => eab.WithIconUrl(CachedMessage.Author.GetAvatarUrl()).WithName(CachedMessage.Author.Username)).WithOkColour()
                                 .AddField(efb => efb.WithName("Channel").WithValue("#" + origChannel.Name).WithIsInline(true))
                                 .AddField(efb => efb.WithName("MessageID").WithValue(CachedMessage.Id).WithIsInline(true))
                                 .AddField(efb => efb.WithName("UserID").WithValue(CachedMessage.Author.Id).WithIsInline(true))
                                 .AddField(efb => efb.WithName("Message").WithValue(content));

            string footerText = "Created: " + CachedMessage.CreatedAt.ToString();

            if (CachedMessage.EditedTimestamp != null)
            {
                footerText += $" | Edited: " + CachedMessage.EditedTimestamp.ToString();
            }

            EmbedFooterBuilder footer = new EmbedFooterBuilder().WithText(footerText);

            await ChannelToSend.BlankEmbedAsync(embed.WithFooter(footer).Build());

            if (CachedMessage.Attachments.Count > 0)
            {
                await ChannelToSend.SendMessageAsync(string.Format("Message ID: {0} contained {1} attachment{2}.", CachedMessage.Id, CachedMessage.Attachments.Count, CachedMessage.Attachments.Count > 1 || CachedMessage.Attachments.Count == 0 ? "s" : string.Empty));
            }
        }