Esempio n. 1
0
        public async Task Welcome(string option = null, string value = null)
        {
            if (option == null && value == null)
            {
                var fetchedChannelId = await _servers.GetWelcomeAsync(Context.Guild.Id);

                if (fetchedChannelId == 0)
                {
                    await Context.Channel.SendErrorAsync("Error!",
                                                         "There has not been set a welcome channel yet!");

                    return;
                }

                var fetchedChannel = Context.Guild.GetTextChannel(fetchedChannelId);
                if (fetchedChannel == null)
                {
                    await Context.Channel.SendErrorAsync("Error!",
                                                         "There has not been set a welcome channel yet!");

                    await _servers.ClearWelcomeAsync(Context.Guild.Id);

                    return;
                }

                var fetchedBackground = await _servers.GetBackgroundAsync(Context.Guild.Id);

                if (fetchedBackground != null)
                {
                    await Context.Channel.SendSuccessAsync("Success!",
                                                           $"The channel used for the welcome module is {fetchedChannel.Mention}." +
                                                           $"\nThe background is set to {fetchedBackground}.");
                }
                else
                {
                    await Context.Channel.SendSuccessAsync("Success!",
                                                           $"The channel used for the welcome module is {fetchedChannel.Mention}.");
                }

                return;
            }

            if (option == "channel" && value != null)
            {
                if (!MentionUtils.TryParseChannel(value, out ulong parsedId))
                {
                    await Context.Channel.SendErrorAsync("Error!", "Please pass in a valid channel!");

                    return;
                }

                var parsedChannel = Context.Guild.GetTextChannel(parsedId);
                if (parsedChannel == null)
                {
                    await Context.Channel.SendErrorAsync("Error!", "Please pass in a valid channel!");

                    return;
                }

                await _servers.ModifyWelcomeAsync(Context.Guild.Id, parsedId);

                await Context.Channel.SendSuccessAsync("Success!", $"Successfully modified the welcome channel to {parsedChannel.Mention}.");

                return;
            }

            if (option == "background" && value != null)
            {
                if (value == "clear")
                {
                    await _servers.ClearBckgroundAsync(Context.Guild.Id);

                    await Context.Channel.SendSuccessAsync("Success!", "Successfully cleared the background for this server.");
                }

                await _servers.ModifyBackgroundAsync(Context.Guild.Id, value);

                await Context.Channel.SendSuccessAsync("Success!", $"Successfully modified the background to {value}.");

                return;
            }

            if (option == "clear" && value == null)
            {
                await _servers.ClearWelcomeAsync(Context.Guild.Id);

                await Context.Channel.SendSuccessAsync("Success!", "Successfully cleared the welcome channel.");

                return;
            }

            await Context.Channel.SendErrorAsync("Error!", "You did not use this command properly.");
        }