Esempio n. 1
0
        public async Task GiveGoldToEveryone()
        {
            var da = new DataAccess(new DatabaseContext());
            var bl = new MarvBotBusinessLayer(da);

            var guilds = _discord.Guilds;

            foreach (var guild in guilds)
            {
                var onlineUsers = guild.Users.Where(x => !x.IsSelfDeafened && x.Status == UserStatus.Online && !x.IsBot).ToList();
                onlineUsers.Remove(bl.GetCurrentRichestPerson(guild));
                var userActivities = onlineUsers.GroupBy(x => new { x.Activity?.Name })
                                     .Where(x => x.Key.Name != null && x.Count() > 1 && x.Key.Name != "Custom Status")
                                     .Select(x => x.ToList());

                foreach (var user in onlineUsers)
                {
                    await bl.SaveGold(user, guild, 1);
                }

                foreach (var act in userActivities)
                {
                    foreach (var user in act)
                    {
                        await bl.SaveGold(user, guild, 2);
                    }
                }
            }
            //await da.GiveGoldEveryone(users, 1); // Is super wierd after a days running for some reason
            //await da.GiveGoldEveryone(extraGoldUsers, 2);
        }
Esempio n. 2
0
        public async Task MessageReceivedAsync(SocketMessage rawMessage)
        {
            // Ignore system messages, or messages from other bots
            if (rawMessage is not SocketUserMessage message)
            {
                return;
            }
            if (message.Source != MessageSource.User)
            {
                return;
            }

            if (Program.serverConfig.blacklistWords.Any(message.Content.ToLower().Contains))
            {
                await message.DeleteAsync();

                return;
            }

            if (Program.serverConfig.whiteList == null || Program.serverConfig.whiteList.All(x => x != message.Author.Id))
            {
                if (!Program.serverConfig.publicChannel.Contains(message.Channel.Id)) // Special channel that does not follow the normal rules
                {
                    if (Program.serverConfig.videoChannel != 0)
                    {
                        if (Program.serverConfig.videoList.Any(message.Content.ToLower().Contains) && message.Channel.Id == Program.serverConfig.videoChannel)
                        {
                            if (!freeMsgList.Contains(message.Author))
                            {
                                freeMsgList.Add(message.Author);
                            }

                            Emoji thumbsUp = new Emoji("👍");
                            await message.AddReactionAsync(thumbsUp);
                        }
                        else if (Program.serverConfig.videoList.Any(message.Content.ToLower().Contains) && message.Channel.Id != Program.serverConfig.videoChannel)
                        {
                            if (!freeMsgList.Contains(message.Author))
                            {
                                freeMsgList.Add(message.Author);
                            }

                            ulong videoChan = Program.serverConfig.videoChannel;
                            await message.DeleteAsync();

                            await message.Channel.SendMessageAsync("Please don't post videos in this channel. I have posted it for you in " + MentionUtils.MentionChannel(videoChan));

                            var cchannel    = (message.Channel as SocketGuildChannel)?.Guild;
                            var textChannel = (ISocketMessageChannel)cchannel.GetChannel(videoChan);
                            await textChannel.SendMessageAsync(message + " Posted by: " + message.Author.Mention);
                        }
                        else if (!Program.serverConfig.videoList.Any(message.Content.ToLower().Contains) && message.Channel.Id == Program.serverConfig.videoChannel)
                        {
                            if (freeMsgList.Contains(message.Author))
                            {
                                freeMsgList.Remove(message.Author);
                            }
                            else
                            {
                                await message.DeleteAsync();

                                await message.Author.SendMessageAsync("Please only post videos in the video channel");
                            }
                        }
                    }
                }
            }

            var context = new ShardedCommandContext(_discord, message);

            foreach (var duel in Program.awaitingDuels)
            {
                if (duel.TimeStamp < DateTime.Now.AddMinutes(-1))
                {
                    Program.awaitingDuels.Remove(duel);
                }
            }

            if (Program.awaitingDuels.Select(x => x.Challenge).Contains(rawMessage.Author.Id) && rawMessage.Content.ToLower().Split(" ").Contains("yes"))
            {
                var duel       = Program.awaitingDuels.Last(x => x.Challenge == rawMessage.Author.Id);
                var challenger = duel.Challenger;
                await context.Channel
                .SendMessageAsync($"{rawMessage.Author.Mention} has accepted {MentionUtils.MentionUser(challenger)}s call to duel. Be ready to shoot (🔫).");

                Program.awaitingDuels.Remove(duel);
                _ = CountDownInChat(context.Channel, challenger, rawMessage.Author.Id, duel.BetAmount);
            }

            if ((Program.activeDuels.Select(x => x.Challenge).Contains(rawMessage.Author.Id) ||
                 Program.activeDuels.Select(x => x.Challenger).Contains(rawMessage.Author.Id)) &&
                rawMessage.Content.ToLower().Split(" ").Contains("🔫"))
            {
                var duel  = Program.activeDuels.Last(x => x.Challenge == rawMessage.Author.Id || x.Challenger == rawMessage.Author.Id);
                var loser = duel.Challenge == rawMessage.Author.Id ? duel.Challenger : duel.Challenge;
                await context.Channel.SendMessageAsync($"{rawMessage.Author.Mention} has won {duel.BetAmount.ToString("n0", nfi)} of {MentionUtils.MentionUser(loser)} gold");

                Program.activeDuels.Remove(duel);
                var da = new DataAccess(new DatabaseContext());
                var bl = new MarvBotBusinessLayer(da);
                await bl.SaveGold(rawMessage.Author, context.Guild, duel.BetAmount);

                await bl.SaveGold(context.Guild.GetUser(loser), context.Guild, -duel.BetAmount);

                await da.SetDuel(duel.Challenger, duel.Challenge, rawMessage.Author.Id, duel.BetAmount);
            }

            // This value holds the offset where the prefix ends
            var argPos = 0;

            if (!message.HasCharPrefix(prefix, ref argPos) && !message.HasMentionPrefix(_discord.CurrentUser, ref argPos))
            {
                return;
            }

            var result = await _commands.ExecuteAsync(context, argPos, _services);

            if (result.Error.HasValue)
            {
                await context.Channel.SendMessageAsync(result.ToString());
            }
        }
 public PublicCommands()
 {
     da = new DataAccess(new DatabaseContext());
     bl = new MarvBotBusinessLayer(da);
     rb = new BusinessLayer.RiksbankenBusiness(da);
 }