Exemplo n.º 1
0
        public static async Task ModifyAsync(Func <Guild, Task> function, ulong guildId)
        {
            var guild = await FetchGuildAsync(guildId);

            await function(guild);

            await BaseRepository <Guild> .UpdateAsync(guild);
        }
Exemplo n.º 2
0
        public static async Task ModifyAsync(Func <Gang, Task> function, ulong userId, ulong guildId)
        {
            var gang = await FetchGangAsync(userId, guildId);

            await function(gang);

            await BaseRepository <Gang> .UpdateAsync(gang);
        }
Exemplo n.º 3
0
        public static async Task ModifyAsync(Func <Gang, Task> function, SocketCommandContext context)
        {
            var gang = await FetchGangAsync(context.User.Id, context.Guild.Id);

            await function(gang);

            await BaseRepository <Gang> .UpdateAsync(gang);
        }
Exemplo n.º 4
0
        public static async Task ModifyAsync(Func <User, Task> function, ulong userId, ulong guildId)
        {
            var user = await FetchUserAsync(userId, guildId);

            await function(user);

            await BaseRepository <User> .UpdateAsync(user);
        }
Exemplo n.º 5
0
        public static async Task ModifyAsync(Func <User, Task> function, SocketCommandContext context)
        {
            var user = await FetchUserAsync(context.User.Id, context.Guild.Id);

            await function(user);

            await BaseRepository <User> .UpdateAsync(user);
        }
Exemplo n.º 6
0
        public static async Task AddMemberAsync(ulong userId, ulong guildId, ulong newMemberId)
        {
            var gang = await FetchGangAsync(userId, guildId);

            var user = await UserRepository.FetchUserAsync(userId, guildId);

            gang.Members.Add(user);
            await BaseRepository <Gang> .UpdateAsync(gang);
        }
Exemplo n.º 7
0
        public static async Task EditCashAsync(SocketCommandContext context, ulong userId, double change)
        {
            var user = await FetchUserAsync(userId, context.Guild.Id);

            user.Cash = Math.Round(user.Cash + change, 2);
            await BaseRepository <User> .UpdateAsync(user);

            await RankHandler.Handle(context.Guild, userId);
        }
Exemplo n.º 8
0
        public static async Task AddMuteAsync(ulong userId, ulong guildId, TimeSpan muteLength)
        {
            var guild = await GuildRepository.FetchGuildAsync(guildId);

            guild.Mutes.Add(new Mute()
            {
                UserId     = userId,
                GuildId    = guild.Id,
                MuteLength = muteLength
            });
            await BaseRepository <Guild> .UpdateAsync(guild);
        }
Exemplo n.º 9
0
        public static async Task <User> FetchUserAsync(ulong userId, ulong guildId)
        {
            var guild = await GuildRepository.FetchGuildAsync(guildId);

            var existingUser = guild.Users.FirstOrDefault(x => x.UserId == userId);

            if (existingUser == null)
            {
                var createdUser = new User()
                {
                    UserId  = userId,
                    GuildId = guild.Id
                };
                guild.Users.Add(createdUser);
                await BaseRepository <Guild> .UpdateAsync(guild);

                return(createdUser);
            }
            return(existingUser);
        }
Exemplo n.º 10
0
        public static async Task <User> FetchUserAsync(SocketCommandContext context)
        {
            var guild = await GuildRepository.FetchGuildAsync(context.Guild.Id);

            var existingUser = guild.Users.FirstOrDefault(x => x.UserId == context.User.Id);

            if (existingUser == null)
            {
                var createdUser = new User()
                {
                    UserId  = context.User.Id,
                    GuildId = guild.Id
                };
                guild.Users.Add(createdUser);
                await BaseRepository <Guild> .UpdateAsync(guild);

                return(createdUser);
            }
            return(existingUser);
        }
Exemplo n.º 11
0
        public static async Task <Gang> CreateGangAsync(ulong leaderId, ulong guildId, string name)
        {
            var guild = await GuildRepository.FetchGuildAsync(guildId);

            if (guild.Gangs.Any(x => x.Name.ToLower() == name.ToLower() && x.GuildId == guildId))
            {
                throw new Exception($"There is already a gang by the name {name}.");
            }
            if (name.Length > Config.GANG_NAME_CHAR_LIMIT)
            {
                throw new Exception($"The length of a gang name may not be longer than {Config.GANG_NAME_CHAR_LIMIT} characters.");
            }
            var createdGang = new Gang()
            {
                LeaderId = leaderId,
                Name     = name,
                GuildId  = guild.Id
            };

            guild.Gangs.Add(createdGang);
            await BaseRepository <Guild> .UpdateAsync(guild);

            return(createdGang);
        }