Overhaul frontend, change to md-app #minor

This commit is contained in:
Daniel_I_Am 2020-09-27 23:13:36 +02:00
commit 70eae4351d
No known key found for this signature in database
GPG Key ID: 80C428FCC9743E84
2 changed files with 51 additions and 3 deletions

View File

@ -1,8 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
using ChaosBot.Discord;
using ChaosBot.Repositories;
using Discord;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json;
@ -49,6 +53,25 @@ namespace ChaosBot.WebServer.App
return LocalRedirect($"/#/?access_token={responseObject.access_token}");
}
[HttpGet("invite")]
public IActionResult Invite()
{
string clientId = Program.AppSettingsHandler.GetValue<string>("Discord:ClientId");
const ulong permissions =
0x00000020 + // MANAGE_CHANNELS
0x04000000 + // CHANGE_NICKNAME
0x00010000 + // READ_MESSAGE_HISTORY
0x00000800 + // SEND_MESSAGES
0x00002000 + // MANAGE_MESSAGES
0x00008000 + // ATTACH_FILES
0x00040000 + // USE_EXTERNAL_EMOJIS
0x00000040 + // ADD_REACTIONS
0x00000400 // VIEW_CHANNEL
;
return Redirect($"https://discord.com/oauth2/authorize?client_id={clientId}&scope=bot&permissions={permissions}");
}
[HttpGet("user")]
public IActionResult GetUser()
{
@ -77,7 +100,13 @@ namespace ChaosBot.WebServer.App
string responseString = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
List<DiscordGuildResponse> userResponse = JsonConvert.DeserializeObject<List<DiscordGuildResponse>>(responseString);
return Json(userResponse);
List<ulong> presentGuilds = DiscordConnect._client.Guilds.Select(g => g.Id).ToList();
List<DiscordGuildResponseWithPresence> userResponseWithPresence =
userResponse
.Select(guild => guild.AddPresence(presentGuilds.Contains(guild.id)))
.ToList();
return Json(userResponseWithPresence);
}
private static DiscordUserResponse GetDiscordUser(string accessToken)
@ -127,11 +156,30 @@ namespace ChaosBot.WebServer.App
public class DiscordGuildResponse
{
public string id { get; set; }
public ulong id { get; set; }
public string name { get; set; }
public string icon { get; set; }
public bool owner { get; set; }
public int permissions { get; set; }
public int permissions_new { get; set; }
public DiscordGuildResponseWithPresence AddPresence(bool presence)
{
return new DiscordGuildResponseWithPresence
{
id = id,
name = name,
icon = icon,
owner = owner,
permissions = permissions,
permissions_new = permissions_new,
bot_present = presence
};
}
}
public class DiscordGuildResponseWithPresence : DiscordGuildResponse
{
public bool bot_present { get; set; }
}
}

@ -1 +1 @@
Subproject commit 5d42f98ba9efc9ff5f31f4fb4cd4f2f560584433
Subproject commit 5d1ee1a5568be4bb30122ad25d65a1015d4185bd