private async Task _client_UserJoined(SocketGuildUser user)
        {
            if (Config.Load().AutoSave)
            {
                if (ServerPairs.PairList.Any(x => x.LoadedServer == user.Guild.Id))
                {
                    var server = ServerPairs.PairList.Where(x => x.LoadedServer == user.Guild.Id)
                                 .OrderBy(x => x.TimeLoaded).ToList();
                    var max  = server.Max(x => x.TimeLoaded);
                    var serv = ServerObject.GetSave(server.First(x => x.TimeLoaded == max).SavedServer);
                    if (serv != null)
                    {
                        if (serv.Roles.Any() || serv.Users.Any(x => x.UserID == user.Id))
                        {
                            var rlist = new List <string>();
                            var embed = new EmbedBuilder {
                                Color = Color.Blue
                            };
                            if (serv.Roles.Any())
                            {
                                foreach (var role in serv.Roles)
                                {
                                    if (!role.RoleMembers.Contains(user.Id))
                                    {
                                        continue;
                                    }
                                    try
                                    {
                                        var NewRole = user.Guild.Roles.FirstOrDefault(x => x.Name == role.RoleName);
                                        if (NewRole != null)
                                        {
                                            await user.AddRoleAsync(NewRole);

                                            rlist.Add($"{NewRole.Name}");
                                        }
                                    }
                                    catch
                                    {
                                        //
                                    }
                                }
                                if (rlist.Count > 0)
                                {
                                    embed.AddField($"{user.Username} Roles Updated in {user.Guild.Name}", $"{string.Join("\n", rlist)}");
                                }
                            }

                            if (serv.Users.Any(x => x.UserID == user.Id))
                            {
                                var u = serv.Users.First(x => x.UserID == user.Id);
                                if (u.Nickname != null)
                                {
                                    try
                                    {
                                        await user.ModifyAsync(x => x.Nickname = u.Nickname);

                                        embed.AddField("Nickname", $"User Nickname Updated to {u.Nickname}");
                                    }
                                    catch
                                    {
                                        //
                                    }
                                }
                            }


                            await user.SendMessageAsync("", false, embed.Build());
                        }
                    }
                }
                await ServerObject.SaveServer(user.Guild.DefaultChannel, false);

                Logger.LogInfo($"Autosaved {user.Guild.Name}");
            }
        }
Exemple #2
0
        public static void CheckExistence()
        {
            bool auto;

            try
            {
                auto = Load().AutoRun;
            }
            catch
            {
                auto = false;
            }

            if (auto)
            {
            }
            else
            {
                Logger.LogInfo("Run (Y for run, N for setup Config)");

                Logger.LogInfo("Y or N: ");
                var res = Console.ReadKey();
                if (res.KeyChar == 'N' || res.KeyChar == 'n')
                {
                    File.Delete("setup/config.json");
                }

                if (!Directory.Exists(Path.Combine(AppContext.BaseDirectory, "setup/")))
                {
                    Directory.CreateDirectory(Path.Combine(AppContext.BaseDirectory, "setup/"));
                }
            }


            if (!File.Exists(ConfigPath))
            {
                var cfg = new Config();

                Logger.LogInfo(
                    @"Please enter a name for your bot");
                Console.Write("Name: ");
                cfg.BotName = Console.ReadLine();

                Logger.LogInfo(
                    @"Please enter a prefix for the bot eg. '+' (do not include the '' outside of the prefix)");
                Console.Write("Prefix: ");
                cfg.Prefix = Console.ReadLine();

                Log.Information(
                    @"After you input your token, a config will be generated at 'setup/config.json'");
                Console.Write("Token: ");
                cfg.Token = Console.ReadLine();

                // Logger.LogInfo("Will you be using this bot as a UserBot (selfbot)? Y/N");
                // var selbot = Console.ReadKey();
                //  if (selbot.KeyChar == 'y' || selbot.KeyChar == 'Y')
                //      cfg.UserBot = true;
                //  else
                //      cfg.UserBot = false;

                Logger.LogInfo("Would you like to AutoRun the bot from now on? Y/N");
                var type2 = Console.ReadKey();
                if (type2.KeyChar == 'y' || type2.KeyChar == 'Y')
                {
                    cfg.AutoRun = true;
                }
                else
                {
                    cfg.AutoRun = false;
                }

                cfg.Save();
            }

            Logger.LogInfo("Config Loaded!");
            Logger.LogInfo($"Prefix: {Load().Prefix}");
            Logger.LogInfo($"Token Length: {Load().Token.Length} (should be 59)");
            Logger.LogInfo($"Autorun: {Load().AutoRun}");
        }
        public async Task DoCommand(SocketMessage parameterMessage)
        {
            Messages++;
            if (!(parameterMessage is SocketUserMessage message))
            {
                return;
            }
            var argPos  = 0;
            var context = new SocketCommandContext(_client, message);


            //Do not react to commands initiated by a bot
            if (context.User.IsBot)
            {
                return;
            }

            //Ensure that commands are only executed if thet start with the bot's prefix
            if (!(message.HasMentionPrefix(_client.CurrentUser, ref argPos) ||
                  message.HasStringPrefix(Config.Load().Prefix, ref argPos)))
            {
                return;
            }


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

            var commandsuccess = result.IsSuccess;


            if (!commandsuccess)
            {
                if (Config.Load().Stealth == false)
                {
                    var embed = new EmbedBuilder();

                    foreach (var module in _commands.Modules)
                    {
                        foreach (var command in module.Commands)
                        {
                            if (context.Message.Content.ToLower()
                                .StartsWith($"{Config.Load().Prefix}{command.Name} ".ToLower()))
                            {
                                embed.AddField("COMMAND INFO", $"Name: {command.Name}\n" +
                                               $"Summary: {command.Summary}\n" +
                                               $"Info: {command.Remarks}");
                                break;
                            }
                        }
                    }

                    embed.AddField($"ERROR {result.Error.ToString().ToUpper()}", $"Command: {context.Message}\n" +
                                   $"Error: {result.ErrorReason}");


                    embed.Color = Color.Red;
                    await context.Channel.SendMessageAsync("", false, embed.Build());
                }
                Logger.LogError($"{message.Content} || {message.Author}");
            }
            else
            {
                Logger.LogInfo($"{message.Content} || {message.Author}");
                Commands++;
            }
        }
 private static Task Client_Log(LogMessage arg)
 {
     Logger.LogInfo(arg.Message);
     return(Task.CompletedTask);
 }