// GET
        public async Task <IActionResult> StreamAnnouncerSettings([FromServices] IDiscordUserService userService, [FromServices] IBot bot)
        {
            var guilds = await userService.GetUserGuilds();

            var botGuilds = bot.GetGuilds();

            var viewModel = new StreamAnnouncerSettingsViewModel()
            {
                Guilds = new SelectList(
                    guilds.FilterAdministrator().FilterGuildsByIds(botGuilds.Select(b => b.Id).ToList()), "Id", "Name")
            };

            return(View(viewModel));
        }
示例#2
0
        public IActionResult Index(ulong guildId, [FromServices] IBot bot,
                                   [FromServices] IDiscordSettings discordSettings, [FromServices] IList <IModule> modules)
        {
            if (bot.IsBotInGuild(guildId))
            {
                var viewModel = new SettingsIndexViewModel
                {
                    GuildId   = guildId,
                    GuildName = bot.GetGuilds().FirstOrDefault(g => g.Id == guildId)?.Name,
                    Modules   = modules.Where(mod => mod.Configurable).ToList()
                };

                return(View(viewModel));
            }

            // Bot is not in guild so redirect to the add bot URL.
            var redirectUrl = Uri.EscapeDataString($"{HttpContext.Request.Scheme}://{HttpContext.Request.Host}");

            return(Redirect(
                       $"https://discordapp.com/api/oauth2/authorize?client_id={discordSettings.ClientId}&permissions=8&redirect_uri={redirectUrl}&scope=bot&guild_id={guildId}"));
        }