예제 #1
0
        public async Task AddRank(IRole rankRole, double cashRequired)
        {
            var guild = GuildRepository.FetchGuild(Context.Guild.Id);

            if (rankRole.Position >= Context.Guild.CurrentUser.Roles.OrderByDescending(x => x.Position).First().Position)
            {
                throw new Exception($"DEA must be higher in the heigharhy than {rankRole.Mention}.");
            }
            if (guild.RankRoles == null)
            {
                GuildRepository.Modify(DEABot.GuildUpdateBuilder.Set(x => x.RankRoles, new BsonDocument()
                {
                    { rankRole.Id.ToString(), cashRequired }
                }), Context.Guild.Id);
            }
            else
            {
                if (guild.RankRoles.Any(x => x.Name == rankRole.Id.ToString()))
                {
                    throw new Exception("This role is already a rank role.");
                }
                if (guild.RankRoles.Any(x => (int)x.Value.AsDouble == (int)cashRequired))
                {
                    throw new Exception("There is already a role set to that amount of cash required.");
                }
                guild.RankRoles.Add(rankRole.Id.ToString(), cashRequired);
                GuildRepository.Modify(DEABot.GuildUpdateBuilder.Set(x => x.RankRoles, guild.RankRoles), Context.Guild.Id);
            }

            await ReplyAsync($"You have successfully added the {rankRole.Mention} rank!");
        }
예제 #2
0
        public async Task Ranks()
        {
            var guild = GuildRepository.FetchGuild(Context.Guild.Id);

            if (guild.RankRoles == null)
            {
                throw new Exception("There are no ranks yet!");
            }
            var description = "";

            foreach (var rank in guild.RankRoles.OrderBy(x => x.Value))
            {
                var role = Context.Guild.GetRole(Convert.ToUInt64(rank.Name));
                if (role == null)
                {
                    guild.RankRoles.Remove(rank.Name);
                    GuildRepository.Modify(DEABot.GuildUpdateBuilder.Set(x => x.RankRoles, guild.RankRoles), Context.Guild.Id);
                    continue;
                }
                description += $"{rank.Value.AsDouble.ToString("C", Config.CI)}: {role.Mention}\n";
            }
            if (description.Length > 2048)
            {
                throw new Exception("You have too many ranks to be able to use this command.");
            }
            var builder = new EmbedBuilder()
            {
                Title       = "Ranks",
                Color       = new Color(0x00AE86),
                Description = description
            };

            await ReplyAsync("", embed : builder);
        }
예제 #3
0
        public async Task AddRank(IRole rankRole, double cashRequired)
        {
            var guild = await GuildRepository.FetchGuildAsync(Context.Guild.Id);

            if (rankRole.Position >= Context.Guild.CurrentUser.Roles.OrderByDescending(x => x.Position).First().Position)
            {
                throw new Exception($"DEA must be higher in the heigharhy than {rankRole.Mention}.");
            }
            if (guild.RankRoles.Any(x => x.RoleId == rankRole.Id))
            {
                throw new Exception("This role is already a rank role.");
            }
            if (guild.RankRoles.Any(x => x.CashRequired == cashRequired))
            {
                throw new Exception("There is already a role set to that amount of cash required.");
            }
            await GuildRepository.ModifyAsync(x => { x.RankRoles.Add(new RankRole()
                {
                    RoleId       = rankRole.Id,
                    CashRequired = cashRequired,
                    GuildId      = guild.Id
                }); return(Task.CompletedTask); }, Context.Guild.Id);

            await ReplyAsync($"You have successfully added the {rankRole.Mention} rank!");
        }
예제 #4
0
        public async Task Ranked()
        {
            using (var db = new DbContext())
            {
                var guildRepo = new GuildRepository(db);
                var guild     = await guildRepo.FetchGuildAsync(Context.Guild.Id);

                var    role1  = Context.Guild.GetRole(guild.Rank1Id);
                var    role2  = Context.Guild.GetRole(guild.Rank2Id);
                var    role3  = Context.Guild.GetRole(guild.Rank3Id);
                var    role4  = Context.Guild.GetRole(guild.Rank4Id);
                string prefix = guild.Prefix;
                if (role1 == null || role2 == null || role3 == null || role4 == null)
                {
                    throw new Exception($"You do not have 4 different functional roles added in with the " +
                                        $"`{prefix}SetRankRoles` command, therefore the `{prefix}ranked` command will not work!");
                }
                var count1  = Context.Guild.Users.Count(x => x.Roles.Any(y => y.Id == role1.Id));
                var count2  = Context.Guild.Users.Count(x => x.Roles.Any(y => y.Id == role2.Id));
                var count3  = Context.Guild.Users.Count(x => x.Roles.Any(y => y.Id == role3.Id));
                var count4  = Context.Guild.Users.Count(x => x.Roles.Any(y => y.Id == role4.Id));
                var count   = Context.Guild.Users.Count(x => x.Roles.Any(y => y.Id == role1.Id));
                var builder = new EmbedBuilder()
                {
                    Title       = "Ranked Users",
                    Color       = new Color(0x00AE86),
                    Description = $"{role4.Mention}: {count4} members\n" +
                                  $"{role3.Mention}: {count3 - count4} members\n" +
                                  $"{role2.Mention}: {count2 - count3} members\n" +
                                  $"{role1.Mention}: {count1 - count2} members"
                };
                await ReplyAsync("", embed : builder);
            }
        }
예제 #5
0
파일: NSFW.cs 프로젝트: txhawkeye/DEA
        public async Task JoinNSFW()
        {
            using (var db = new DbContext())
            {
                var guildRepo = new GuildRepository(db);
                var guild     = await guildRepo.FetchGuildAsync(Context.Guild.Id);

                var NSFWRole = Context.Guild.GetRole(guild.NSFWRoleId);
                if (NSFWRole == null)
                {
                    throw new Exception("Everyone will always be able to use NSFW commands since there has been no NSFW role that has been set.\n" +
                                        $"In order to change this, an administrator may use the `{guild.Prefix}SetNSFWRole` command.");
                }
                if ((Context.User as IGuildUser).RoleIds.Any(x => x == guild.NSFWRoleId))
                {
                    await(Context.User as IGuildUser).RemoveRoleAsync(NSFWRole);
                    await ReplyAsync($"{Context.User.Mention}, You have successfully disabled your ability to use NSFW commands.");
                }
                else
                {
                    await(Context.User as IGuildUser).AddRoleAsync(NSFWRole);
                    await ReplyAsync($"{Context.User.Mention}, You have successfully enabled your ability to use NSFW commands.");
                }
            }
        }
예제 #6
0
        public async Task Rate(IGuildUser userToView = null)
        {
            userToView = userToView ?? Context.User as IGuildUser;
            using (var db = new DbContext())
            {
                var guildRepo = new GuildRepository(db);
                var userRepo  = new UserRepository(db);
                var user      = await userRepo.FetchUserAsync(userToView.Id);

                var builder = new EmbedBuilder()
                {
                    Color       = new Color(0x00AE86),
                    Description = $"**Rate of {userToView}**\nCurrently receiving " +
                                  $"{(user.InvestmentMultiplier * user.TemporaryMultiplier).ToString("C2")} " +
                                  $"per message sent every {user.MessageCooldown / 1000} seconds that is at least 7 characters long.\n" +
                                  $"Chatting multiplier: {user.TemporaryMultiplier.ToString("N2")}\nInvestment multiplier: " +
                                  $"{user.InvestmentMultiplier.ToString("N2")}\nMessage cooldown: " +
                                  $"{user.MessageCooldown / 1000} seconds"
                };
                if ((await guildRepo.FetchGuildAsync(Context.Guild.Id)).DM)
                {
                    var channel = await Context.User.CreateDMChannelAsync();

                    await channel.SendMessageAsync("", embed : builder);
                }
                else
                {
                    await ReplyAsync("", embed : builder);
                }
            }
        }
예제 #7
0
        public override async Task <PreconditionResult> CheckPermissions(ICommandContext context, CommandInfo command, IDependencyMap map)
        {
            using (var db = new DbContext())
            {
                var guildRepo = new GuildRepository(db);
                var guild     = await guildRepo.FetchGuildAsync(context.Guild.Id);

                if (!guild.NSFW)
                {
                    return(PreconditionResult.FromError("This command may not be used while NSFW is disabled. " +
                                                        $"An administrator may enable with the `{guild.Prefix}EnableNSFW` command."));
                }
                var nsfwChannel = await context.Guild.GetChannelAsync(guild.NSFWChannelId);

                if (nsfwChannel != null && context.Channel.Id != guild.NSFWChannelId)
                {
                    return(PreconditionResult.FromError($"You may only use this command in {(nsfwChannel as ITextChannel).Mention}."));
                }
                var nsfwRole = context.Guild.GetRole(guild.NSFWRoleId);
                if (nsfwRole != null && (context.User as IGuildUser).RoleIds.All(x => x != guild.NSFWRoleId))
                {
                    return(PreconditionResult.FromError($"You do not have permission to use this command.\nRequired role: {nsfwRole.Mention}"));
                }
                return(PreconditionResult.FromSuccess());
            }
        }
예제 #8
0
        private async Task HandleUserJoin(SocketGuildUser u)
        {
            await Logger.DetailedLog(u.Guild, "Event", "User Joined", "User", $"{u}", u.Id, new Color(12, 255, 129), false);

            using (var db = new DbContext())
            {
                var guildRepo = new GuildRepository(db);
                var muteRepo  = new MuteRepository(db);
                var user      = u as IGuildUser;
                var mutedRole = user.Guild.GetRole((await guildRepo.FetchGuildAsync(user.Guild.Id)).MutedRoleId);
                if (mutedRole != null && u.Guild.CurrentUser.GuildPermissions.ManageRoles &&
                    mutedRole.Position < u.Guild.CurrentUser.Roles.OrderByDescending(x => x.Position).First().Position)
                {
                    await RankHandler.Handle(u.Guild, u.Id);

                    if (await muteRepo.IsMutedAsync(user.Id, user.Guild.Id) && mutedRole != null && user != null)
                    {
                        await user.AddRoleAsync(mutedRole);
                    }
                }

                if (Config.BLACKLISTED_IDS.Any(x => x == u.Id))
                {
                    if (u.Guild.CurrentUser.GuildPermissions.BanMembers &&
                        u.Guild.CurrentUser.Roles.OrderByDescending(x => x.Position).First().Position >
                        u.Roles.OrderByDescending(x => x.Position).First().Position&& u.Guild.OwnerId != u.Id)
                    {
                        await u.Guild.AddBanAsync(u);
                    }
                }
            }
        }
예제 #9
0
        public async Task CleanAsync(int count = 25, [Remainder] string reason = "No reason.")
        {
            if (count < Config.MIN_CLEAR)
            {
                throw new Exception($"You may not clear less than {Config.MIN_CLEAR} messages.");
            }
            if (count > Config.MAX_CLEAR)
            {
                throw new Exception($"You may not clear more than {Config.MAX_CLEAR} messages.");
            }
            using (var db = new DbContext())
            {
                var guildRepo = new GuildRepository(db);
                var guild     = await guildRepo.FetchGuildAsync(Context.Guild.Id);

                if (Context.Channel.Id == guild.ModLogChannelId || Context.Channel.Id == guild.DetailedLogsChannelId)
                {
                    throw new Exception("For security reasons, you may not use this command in a log channel.");
                }
            }
            var messages = await Context.Channel.GetMessagesAsync(count).Flatten();

            await Context.Channel.DeleteMessagesAsync(messages);

            await Logger.ModLog(Context, "Clear", new Color(34, 59, 255), reason, null, $"\n**Quantity:** {count}");
        }
예제 #10
0
        public Context(SocketUserMessage msg, IServiceProvider serviceProvider, DiscordSocketClient client = null) : base(client, msg)
        {
            _serviceProvider = serviceProvider;
            _userRepo        = _serviceProvider.GetService <UserRepository>();
            _guildRepo       = _serviceProvider.GetService <GuildRepository>();

            GuildUser = User as IGuildUser;
        }
예제 #11
0
        public RpgController()
        {
            EventRepository = new EventRepository(_context);
            EventLinkItemRepository = new EventLinkItemRepository(_context);
            QuestRepository = new QuestRepository(_context);
            HeroRepository = new HeroRepository(_context);
            SkillRepository = new SkillRepository(_context);
            GuildRepository = new GuildRepository(_context);
            SkillSchoolRepository = new SkillSchoolRepository(_context);
            TrainingRoomRepository = new TrainingRoomRepository(_context);
            CharacteristicRepository = new CharacteristicRepository(_context);
            CharacteristicTypeRepository = new CharacteristicTypeRepository(_context);
            StateRepository = new StateRepository(_context);
            StateTypeRepository = new StateTypeRepository(_context);

            //using (var scope = StaticContainer.Container.BeginLifetimeScope())
            //{
            //    EventRepository = scope.Resolve<IEventRepository>();
            //    QuestRepository = scope.Resolve<IQuestRepository>();
            //    HeroRepository = scope.Resolve<IHeroRepository>();
            //    SkillRepository = scope.Resolve<ISkillRepository>();
            //}
        }