Esempio n. 1
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);
                    }
                }
            }
        }
Esempio n. 2
0
        public static async Task EditCashAsync(SocketCommandContext context, ulong userId, double change)
        {
            var cash = FetchUser(userId, context.Guild.Id).Cash;

            DEABot.Users.UpdateOne(y => y.UserId == userId && y.GuildId == context.Guild.Id,
                                   DEABot.UserUpdateBuilder.Set(x => x.Cash, change + cash));
            await RankHandler.Handle(context.Guild, userId);
        }
Esempio n. 3
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);
        }
Esempio n. 4
0
        public async Task EditOtherCashAsync(SocketCommandContext context, ulong userId, float change)
        {
            var user = await FetchUser(userId);

            user.Cash = (float)Math.Round(user.Cash + change, 2);
            await UpdateAsync(user);

            if ((context.Guild.CurrentUser as IGuildUser).GuildPermissions.ManageRoles)
            {
                await RankHandler.Handle(context.Guild, userId);
            }
        }
Esempio n. 5
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);

            var user      = u as IGuildUser;
            var mutedRole = user.Guild.GetRole(((GuildRepository.FetchGuild(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 (MuteRepository.IsMuted(user.Id, user.Guild.Id) && mutedRole != null && user != null)
                {
                    await user.AddRoleAsync(mutedRole);
                }
            }
        }
Esempio n. 6
0
        private async Task HandleCommandAsync(SocketMessage s)
        {
            var msg = s as SocketUserMessage;

            if (msg == null)
            {
                return;
            }

            PrettyConsole.NewLine(msg.Content);



            var Context = new SocketCommandContext(_client, msg);

            PrettyConsole.NewLine((await GuildRepository.FetchGuildAsync(Context.Guild.Id)).Prefix);

            if (Context.User.IsBot)
            {
                return;
            }

            if (!(Context.Channel is SocketTextChannel))
            {
                return;
            }

            if (!(Context.Guild.CurrentUser as IGuildUser).GetPermissions(Context.Channel as SocketTextChannel).SendMessages)
            {
                return;
            }

            int    argPos = 0;
            string prefix = (await GuildRepository.FetchGuildAsync(Context.Guild.Id)).Prefix;

            if (msg.HasStringPrefix(prefix, ref argPos) ||
                msg.HasMentionPrefix(_client.CurrentUser, ref argPos))
            {
                PrettyConsole.Log(LogSeverity.Debug, $"Guild: {Context.Guild.Name}, User: {Context.User}", msg.Content);
                var result = await _service.ExecuteAsync(Context, argPos, _map);

                if (!result.IsSuccess && result.Error != CommandError.UnknownCommand)
                {
                    var cmd = _service.Search(Context, argPos).Commands.First().Command;
                    if (result.ErrorReason.Length == 0)
                    {
                        return;
                    }
                    switch (result.Error)
                    {
                    case CommandError.BadArgCount:
                        await msg.Channel.SendMessageAsync($"{Context.User.Mention}, You are incorrectly using this command. Usage: `{prefix}{cmd.Remarks}`");

                        break;

                    case CommandError.ParseFailed:
                        await msg.Channel.SendMessageAsync($"{Context.User.Mention}, Invalid number.");

                        break;

                    default:
                        await msg.Channel.SendMessageAsync($"{Context.User.Mention}, {result.ErrorReason}");

                        break;
                    }
                }
            }
            else if (msg.ToString().Length >= Config.MIN_CHAR_LENGTH && !msg.ToString().StartsWith(":"))
            {
                var user = await UserRepository.FetchUserAsync(Context);

                var rate = Config.TEMP_MULTIPLIER_RATE;
                if (DateTimeOffset.Now.Subtract(user.Message).TotalMilliseconds > user.MessageCooldown.TotalMilliseconds)
                {
                    await UserRepository.ModifyAsync(x => {
                        x.Cash += user.TemporaryMultiplier *user.InvestmentMultiplier;
                        x.TemporaryMultiplier = user.TemporaryMultiplier + rate;
                        x.Message             = DateTimeOffset.Now;
                        return(Task.CompletedTask);
                    }, Context);

                    await RankHandler.Handle(Context.Guild, Context.User.Id);
                }
            }
        }
Esempio n. 7
0
        private async Task HandleCommandAsync(SocketMessage s)
        {
            var msg = s as SocketUserMessage;

            if (msg == null)
            {
                return;
            }

            var Context = new SocketCommandContext(_client, msg);

            if (Context.User.IsBot)
            {
                return;
            }

            if (!(Context.Channel is SocketTextChannel))
            {
                return;
            }

            if (!(Context.Guild.CurrentUser as IGuildUser).GetPermissions(Context.Channel as SocketTextChannel).SendMessages)
            {
                return;
            }

            int argPos = 0;

            var guild = GuildRepository.FetchGuild(Context.Guild.Id);

            string prefix = guild.Prefix;

            if (msg.HasStringPrefix(prefix, ref argPos) ||
                msg.HasMentionPrefix(_client.CurrentUser, ref argPos))
            {
                PrettyConsole.Log(LogSeverity.Debug, $"Guild: {Context.Guild.Name}, User: {Context.User}", msg.Content);
                var result = await _service.ExecuteAsync(Context, argPos, _map);

                if (!result.IsSuccess && result.Error != CommandError.UnknownCommand)
                {
                    var cmd = _service.Search(Context, argPos).Commands.First().Command;
                    if (result.ErrorReason.Length == 0)
                    {
                        return;
                    }
                    switch (result.Error)
                    {
                    case CommandError.BadArgCount:
                        await msg.Channel.SendMessageAsync($"{Context.User.Mention}, You are incorrectly using this command. Usage: `{prefix}{cmd.Remarks}`");

                        break;

                    case CommandError.ParseFailed:
                        await msg.Channel.SendMessageAsync($"{Context.User.Mention}, Invalid number.");

                        break;

                    default:
                        await msg.Channel.SendMessageAsync($"{Context.User.Mention}, {result.ErrorReason}");

                        break;
                    }
                }
            }
            else if (msg.ToString().Length >= Config.MIN_CHAR_LENGTH && !msg.ToString().StartsWith(":"))
            {
                var user = UserRepository.FetchUser(Context);

                if (DateTime.UtcNow.Subtract(user.Message).TotalMilliseconds > user.MessageCooldown)
                {
                    UserRepository.Modify(DEABot.UserUpdateBuilder.Combine(
                                              DEABot.UserUpdateBuilder.Set(x => x.Cash, guild.GlobalChattingMultiplier * user.TemporaryMultiplier * user.InvestmentMultiplier + user.Cash),
                                              DEABot.UserUpdateBuilder.Set(x => x.TemporaryMultiplier, user.TemporaryMultiplier + guild.TempMultiplierIncreaseRate),
                                              DEABot.UserUpdateBuilder.Set(x => x.Message, DateTime.UtcNow)), Context);
                    await RankHandler.Handle(Context.Guild, Context.User.Id);
                }
            }
        }