added account creation to the Discord bot
This commit is contained in:
parent
69337e69ae
commit
56cb43a479
18 changed files with 198 additions and 152 deletions
|
@ -27,6 +27,7 @@ namespace DiscordBot
|
||||||
_client.SlashCommandExecuted += SlashCommandHandler;
|
_client.SlashCommandExecuted += SlashCommandHandler;
|
||||||
_client.ButtonExecuted += ButtonHandler;
|
_client.ButtonExecuted += ButtonHandler;
|
||||||
_client.SelectMenuExecuted += SelectMenuHandler;
|
_client.SelectMenuExecuted += SelectMenuHandler;
|
||||||
|
_client.ModalSubmitted += ModalHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task SlashCommandHandler(SocketSlashCommand command)
|
private async Task SlashCommandHandler(SocketSlashCommand command)
|
||||||
|
@ -72,14 +73,20 @@ namespace DiscordBot
|
||||||
switch(ids[0])
|
switch(ids[0])
|
||||||
{
|
{
|
||||||
case Constants.ComponentIds.SIGN_UP_BUTTON:
|
case Constants.ComponentIds.SIGN_UP_BUTTON:
|
||||||
roles = await _httpService.GetRoles(parsedRaidId, component.User.Id);
|
if(await IsRaidSignUpAllowed(component, parsedRaidId, ids[0]))
|
||||||
await component.RespondAsync("Please choose a role.", components: SignUpMessage.buildMessage(roles, parsedRaidId, ids[0], false) , ephemeral: true);
|
{
|
||||||
|
roles = await _httpService.GetRoles(parsedRaidId, component.User.Id);
|
||||||
|
await component.RespondAsync("Please choose a role.", components: SignUpMessage.buildMessage(roles, parsedRaidId, ids[0], false) , ephemeral: true);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case Constants.ComponentIds.MAYBE_BUTTON:
|
case Constants.ComponentIds.MAYBE_BUTTON:
|
||||||
case Constants.ComponentIds.BACKUP_BUTTON:
|
case Constants.ComponentIds.BACKUP_BUTTON:
|
||||||
case Constants.ComponentIds.FLEX_BUTTON:
|
case Constants.ComponentIds.FLEX_BUTTON:
|
||||||
roles = await _httpService.GetRoles(parsedRaidId, component.User.Id);
|
if(await IsRaidSignUpAllowed(component, parsedRaidId, ids[0]))
|
||||||
await component.RespondAsync("Please choose a role.", components: SignUpMessage.buildMessage(roles, parsedRaidId, ids[0], true) , ephemeral: true);
|
{
|
||||||
|
roles = await _httpService.GetRoles(parsedRaidId, component.User.Id);
|
||||||
|
await component.RespondAsync("Please choose a role.", components: SignUpMessage.buildMessage(roles, parsedRaidId, ids[0], true) , ephemeral: true);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case Constants.ComponentIds.SIGN_OFF_BUTTON:
|
case Constants.ComponentIds.SIGN_OFF_BUTTON:
|
||||||
ApiSignUp signOff = new ApiSignUp()
|
ApiSignUp signOff = new ApiSignUp()
|
||||||
|
@ -93,6 +100,28 @@ namespace DiscordBot
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<bool> IsRaidSignUpAllowed(SocketInteraction component, int raidId, string pressedButtonId)
|
||||||
|
{
|
||||||
|
if(! await _httpService.DoesUserExist(component.User.Id))
|
||||||
|
{
|
||||||
|
var mb = new ModalBuilder()
|
||||||
|
.WithTitle("Create Account")
|
||||||
|
.WithCustomId($"{Constants.ComponentIds.CREATE_ACCOUNT_MODAL}-{raidId}-{pressedButtonId}")
|
||||||
|
.AddTextInput("Name", Constants.ComponentIds.NAME_TEXT_BOX, placeholder: component.User.Username, required: true, value: component.User.Username)
|
||||||
|
.AddTextInput("Guild Wars 2 Account", Constants.ComponentIds.ACCOUNT_TEXT_BOX, placeholder: "Account.1234", required: true);
|
||||||
|
|
||||||
|
await component.RespondWithModalAsync(mb.Build());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Tuple<bool, string> signUpAllowed = await _httpService.IsSignUpAllowed(raidId, component.User.Id);
|
||||||
|
if(!signUpAllowed.Item1)
|
||||||
|
{
|
||||||
|
await component.RespondAsync(signUpAllowed.Item2, ephemeral: true);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public async Task SelectMenuHandler(SocketMessageComponent component)
|
public async Task SelectMenuHandler(SocketMessageComponent component)
|
||||||
{
|
{
|
||||||
string[] ids = component.Data.CustomId.Split('-');
|
string[] ids = component.Data.CustomId.Split('-');
|
||||||
|
@ -139,8 +168,39 @@ namespace DiscordBot
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task ModalHandler(SocketModal modal)
|
||||||
|
{
|
||||||
|
List<SocketMessageComponentData> components = modal.Data.Components.ToList();
|
||||||
|
string name = components.First(x => x.CustomId == Constants.ComponentIds.NAME_TEXT_BOX).Value;
|
||||||
|
string account = components.First(x => x.CustomId == Constants.ComponentIds.ACCOUNT_TEXT_BOX).Value;
|
||||||
|
|
||||||
|
//create Account
|
||||||
|
ApiRaid.Role.User user = new ApiRaid.Role.User()
|
||||||
|
{
|
||||||
|
UserName = name,
|
||||||
|
AccountName = account,
|
||||||
|
UserId = modal.User.Id
|
||||||
|
};
|
||||||
|
Tuple<bool, string> createAccountResult = await _httpService.CreateAccount(user);
|
||||||
|
if(!createAccountResult.Item1)
|
||||||
|
{
|
||||||
|
await modal.RespondAsync(createAccountResult.Item2, ephemeral: true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//sign up
|
||||||
|
string[] ids = modal.Data.CustomId.Split('-');
|
||||||
|
if(ids.Length > 2 && int.TryParse(ids[1], out int parsedRaidId) && await IsRaidSignUpAllowed(modal, parsedRaidId, ids[2]))
|
||||||
|
{
|
||||||
|
List<ApiRole> roles = await _httpService.GetRoles(parsedRaidId, modal.User.Id);
|
||||||
|
await modal.RespondAsync("Please choose a role.", components: SignUpMessage.buildMessage(roles, parsedRaidId, ids[2], false) , ephemeral: true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await Respond(modal);
|
||||||
|
}
|
||||||
|
|
||||||
//to avoid error messages because of no response...
|
//to avoid error messages because of no response...
|
||||||
private async Task Respond(SocketMessageComponent component)
|
private async Task Respond(SocketInteraction component)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
|
@ -12,6 +12,10 @@
|
||||||
public const string SIGN_OFF_BUTTON = "signOffButton";
|
public const string SIGN_OFF_BUTTON = "signOffButton";
|
||||||
|
|
||||||
public const string SIGN_UP_DROP_DOWN = "signUpDropDown";
|
public const string SIGN_UP_DROP_DOWN = "signUpDropDown";
|
||||||
|
|
||||||
|
public const string NAME_TEXT_BOX = "nameTextbox";
|
||||||
|
public const string ACCOUNT_TEXT_BOX = "accountTextBox";
|
||||||
|
public const string CREATE_ACCOUNT_MODAL = "createAccountModal";
|
||||||
}
|
}
|
||||||
|
|
||||||
public class SlashCommands
|
public class SlashCommands
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Discord.Net" Version="3.7.2" />
|
<PackageReference Include="Discord.Net" Version="3.8.1" />
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|
|
@ -88,8 +88,10 @@ namespace DiscordBot.Messages
|
||||||
|
|
||||||
private void AddMessageDetails(ApiRaid raid, ref EmbedBuilder embed)
|
private void AddMessageDetails(ApiRaid raid, ref EmbedBuilder embed)
|
||||||
{
|
{
|
||||||
embed.AddField("Date", $"{raid.StartTimeUTC.ToLocalTime().DateTime.ToLongDateString()}");
|
//embed.AddField("Date", $"{raid.StartTimeUTC.ToLocalTime().DateTime.ToLongDateString()}");
|
||||||
embed.AddField("Time", $"from: {raid.StartTimeUTC.ToLocalTime().DateTime.ToShortTimeString()} to: {raid.EndTimeUTC.ToLocalTime().DateTime.ToShortTimeString()}");
|
//embed.AddField("Time", $"from: {raid.StartTimeUTC.ToLocalTime().DateTime.ToShortTimeString()} to: {raid.EndTimeUTC.ToLocalTime().DateTime.ToShortTimeString()}");
|
||||||
|
embed.AddField("Start ", $"<t:{raid.StartTimeUTC.ToUnixTimeSeconds()}:F>");
|
||||||
|
embed.AddField("End", $"<t:{raid.EndTimeUTC.ToUnixTimeSeconds()}:F>");
|
||||||
embed.AddField("Organisator", raid.Organizer, true);
|
embed.AddField("Organisator", raid.Organizer, true);
|
||||||
embed.AddField("Guild", raid.Guild, true);
|
embed.AddField("Guild", raid.Guild, true);
|
||||||
embed.AddField("Voice chat", raid.VoiceChat, true);
|
embed.AddField("Voice chat", raid.VoiceChat, true);
|
||||||
|
|
|
@ -27,42 +27,5 @@ namespace DiscordBot.Messages
|
||||||
|
|
||||||
return builder.Build();
|
return builder.Build();
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
public static MessageComponent buildMessage(List<ApiRole> roles, int raidId)
|
|
||||||
{
|
|
||||||
var signUpSelect = new SelectMenuBuilder()
|
|
||||||
.WithPlaceholder("Select an option")
|
|
||||||
.WithCustomId(Constants.ComponentIds.SIGN_UP_DROP_DOWN)
|
|
||||||
.WithMinValues(1)
|
|
||||||
.WithMaxValues(1);
|
|
||||||
|
|
||||||
foreach(ApiRole role in roles)
|
|
||||||
{
|
|
||||||
if(role.IsSignUpAllowed)
|
|
||||||
signUpSelect.AddOption(role.Name, role.roleId.ToString(), role.Description);
|
|
||||||
}
|
|
||||||
|
|
||||||
var flexSelect = new SelectMenuBuilder()
|
|
||||||
.WithPlaceholder("Select an option")
|
|
||||||
.WithCustomId(Constants.ComponentIds.FLEX_DROP_DOWN)
|
|
||||||
.WithMinValues(1)
|
|
||||||
.WithMaxValues(1);
|
|
||||||
|
|
||||||
foreach(ApiRole role in roles)
|
|
||||||
{
|
|
||||||
flexSelect.AddOption(role.Name, role.roleId.ToString(), role.Description);
|
|
||||||
}
|
|
||||||
|
|
||||||
var builder = new ComponentBuilder()
|
|
||||||
.WithSelectMenu(signUpSelect, 0)
|
|
||||||
.WithButton("SignUp", $"{Constants.ComponentIds.SIGN_UP_BUTTON}-{raidId.ToString()}", ButtonStyle.Success, row: 1)
|
|
||||||
.WithSelectMenu(flexSelect, 2)
|
|
||||||
.WithButton("Maybe", $"{Constants.ComponentIds.MAYBE_BUTTON}-{raidId.ToString()}", ButtonStyle.Success, row: 3)
|
|
||||||
.WithButton("Backup", $"{Constants.ComponentIds.BACKUP_BUTTON}-{raidId.ToString()}", ButtonStyle.Success, row: 3)
|
|
||||||
.WithButton("Flex", $"{Constants.ComponentIds.FLEX_BUTTON}-{raidId.ToString()}", ButtonStyle.Success, row: 3);
|
|
||||||
|
|
||||||
return builder.Build();
|
|
||||||
}*/
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
using SharedClasses.SharedModels;
|
using SharedClasses.SharedModels;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using static System.Net.Mime.MediaTypeNames;
|
using static System.Net.Mime.MediaTypeNames;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
@ -20,6 +21,37 @@ namespace DiscordBot.Services
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<bool> DoesUserExist(ulong userId)
|
||||||
|
{
|
||||||
|
var httpClient = _httpClientFactory.CreateClient(Constants.HTTP_CLIENT_NAME);
|
||||||
|
|
||||||
|
var httpResponseMessage = await httpClient.GetAsync($"DiscordBot/DoesUserExist/{userId}");
|
||||||
|
|
||||||
|
if (httpResponseMessage.IsSuccessStatusCode)
|
||||||
|
{
|
||||||
|
using var contentStream =
|
||||||
|
await httpResponseMessage.Content.ReadAsStreamAsync();
|
||||||
|
|
||||||
|
return await JsonSerializer.DeserializeAsync<bool>(contentStream, _serializerOptions);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<Tuple<bool, string>> IsSignUpAllowed(int raidId, ulong userId)
|
||||||
|
{
|
||||||
|
var httpClient = _httpClientFactory.CreateClient(Constants.HTTP_CLIENT_NAME);
|
||||||
|
|
||||||
|
var httpResponseMessage = await httpClient.GetAsync($"DiscordBot/IsSignUpAllowed/{raidId}/{userId}");
|
||||||
|
|
||||||
|
if (!httpResponseMessage.IsSuccessStatusCode)
|
||||||
|
{
|
||||||
|
ProblemDetails problemDetails = await httpResponseMessage.Content.ReadFromJsonAsync<ProblemDetails>(_serializerOptions) ?? new ProblemDetails();
|
||||||
|
string errorMessage = string.IsNullOrEmpty(problemDetails.Detail) ? string.Empty : problemDetails.Detail;
|
||||||
|
return new Tuple<bool, string>(false, errorMessage);
|
||||||
|
}
|
||||||
|
return new Tuple<bool, string>(true, string.Empty);
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<List<ApiRole>> GetRoles(int raidId, ulong userId)
|
public async Task<List<ApiRole>> GetRoles(int raidId, ulong userId)
|
||||||
{
|
{
|
||||||
var httpClient = _httpClientFactory.CreateClient(Constants.HTTP_CLIENT_NAME);
|
var httpClient = _httpClientFactory.CreateClient(Constants.HTTP_CLIENT_NAME);
|
||||||
|
@ -73,5 +105,25 @@ namespace DiscordBot.Services
|
||||||
var httpResponseMessage = await httpClient.PostAsync(requestUri, raidItemJson);
|
var httpResponseMessage = await httpClient.PostAsync(requestUri, raidItemJson);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<Tuple<bool, string>> CreateAccount(ApiRaid.Role.User user)
|
||||||
|
{
|
||||||
|
var httpClient = _httpClientFactory.CreateClient(Constants.HTTP_CLIENT_NAME);
|
||||||
|
|
||||||
|
var raidItemJson = new StringContent(
|
||||||
|
JsonSerializer.Serialize(user),
|
||||||
|
Encoding.UTF8,
|
||||||
|
Application.Json);
|
||||||
|
|
||||||
|
var httpResponseMessage = await httpClient.PostAsync("DiscordBot/CreateAccount", raidItemJson);
|
||||||
|
|
||||||
|
if (!httpResponseMessage.IsSuccessStatusCode)
|
||||||
|
{
|
||||||
|
ProblemDetails problemDetails = await httpResponseMessage.Content.ReadFromJsonAsync<ProblemDetails>(_serializerOptions) ?? new ProblemDetails();
|
||||||
|
string errorMessage = string.IsNullOrEmpty(problemDetails.Detail) ? string.Empty : problemDetails.Detail;
|
||||||
|
return new Tuple<bool, string>(false, errorMessage);
|
||||||
|
}
|
||||||
|
return new Tuple<bool, string>(true, string.Empty);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -2,9 +2,11 @@ using Microsoft.AspNetCore.Authentication;
|
||||||
using Microsoft.AspNetCore.Authentication.Cookies;
|
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||||
using Microsoft.AspNetCore.DataProtection;
|
using Microsoft.AspNetCore.DataProtection;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
using Lieb.Data;
|
using Lieb.Data;
|
||||||
using Lieb.Models.GuildWars2.Raid;
|
using Lieb.Models.GuildWars2.Raid;
|
||||||
using Lieb.Models.GuildWars2;
|
using Lieb.Models.GuildWars2;
|
||||||
|
using Lieb.Models;
|
||||||
using SharedClasses.SharedModels;
|
using SharedClasses.SharedModels;
|
||||||
|
|
||||||
namespace Lieb.Controllers
|
namespace Lieb.Controllers
|
||||||
|
@ -15,11 +17,33 @@ namespace Lieb.Controllers
|
||||||
{
|
{
|
||||||
RaidService _raidService;
|
RaidService _raidService;
|
||||||
UserService _userService;
|
UserService _userService;
|
||||||
|
GuildWars2AccountService _gw2AccountService;
|
||||||
|
|
||||||
public DiscordBotController(RaidService raidService, UserService userService)
|
public DiscordBotController(RaidService raidService, UserService userService, GuildWars2AccountService gw2AccountService)
|
||||||
{
|
{
|
||||||
_raidService = raidService;
|
_raidService = raidService;
|
||||||
_userService = userService;
|
_userService = userService;
|
||||||
|
_gw2AccountService = gw2AccountService;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
[Route("[action]/{userId}")]
|
||||||
|
public ActionResult<bool> DoesUserExist(ulong userId)
|
||||||
|
{
|
||||||
|
LiebUser user = _userService.GetLiebUserGW2AccountOnly(userId);
|
||||||
|
return user != null && user.GuildWars2Accounts.Count() > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
[Route("[action]/{raidId}/{userId}")]
|
||||||
|
public ActionResult IsSignUpAllowed(int raidId, ulong userId)
|
||||||
|
{
|
||||||
|
Raid raid = _raidService.GetRaid(raidId);
|
||||||
|
if(!_raidService.IsRaidSignUpAllowed(userId, raidId, out string errorMessage))
|
||||||
|
{
|
||||||
|
return Problem(errorMessage);
|
||||||
|
}
|
||||||
|
return Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
|
@ -27,10 +51,6 @@ namespace Lieb.Controllers
|
||||||
public ActionResult<List<ApiRole>> GetRoles(int raidId, ulong userId)
|
public ActionResult<List<ApiRole>> GetRoles(int raidId, ulong userId)
|
||||||
{
|
{
|
||||||
Raid raid = _raidService.GetRaid(raidId);
|
Raid raid = _raidService.GetRaid(raidId);
|
||||||
if(!_raidService.IsRaidSignUpAllowed(userId, raidId, out string errorMessage))
|
|
||||||
{
|
|
||||||
return Problem(errorMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
List<ApiRole> apiRoles = new List<ApiRole>();
|
List<ApiRole> apiRoles = new List<ApiRole>();
|
||||||
foreach(RaidRole role in raid.Roles)
|
foreach(RaidRole role in raid.Roles)
|
||||||
|
@ -84,5 +104,23 @@ namespace Lieb.Controllers
|
||||||
int accountId = _userService.GetLiebUserGW2AccountOnly(signUp.userId).GuildWars2Accounts.FirstOrDefault(new GuildWars2Account()).GuildWars2AccountId;
|
int accountId = _userService.GetLiebUserGW2AccountOnly(signUp.userId).GuildWars2Accounts.FirstOrDefault(new GuildWars2Account()).GuildWars2AccountId;
|
||||||
await _raidService.SignOff(signUp.raidId, signUp.userId);
|
await _raidService.SignOff(signUp.raidId, signUp.userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
[Route("[action]")]
|
||||||
|
public async Task<ActionResult> CreateAccount(ApiRaid.Role.User user)
|
||||||
|
{
|
||||||
|
if(!Regex.IsMatch(user.AccountName, Constants.GW2_ACCOUNT_REGEX))
|
||||||
|
{
|
||||||
|
return Problem("Invalid Account Name");
|
||||||
|
}
|
||||||
|
|
||||||
|
GuildWars2Account gw2Account = new GuildWars2Account()
|
||||||
|
{
|
||||||
|
AccountName = user.AccountName
|
||||||
|
};
|
||||||
|
await _userService.CreateUser(user.UserId, user.UserName);
|
||||||
|
await _gw2AccountService.AddOrEditAccount(gw2Account, user.UserId);
|
||||||
|
return Ok();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -4,6 +4,7 @@
|
||||||
{
|
{
|
||||||
public const string HttpClientName = "Discord";
|
public const string HttpClientName = "Discord";
|
||||||
public const string ClaimType = "Role";
|
public const string ClaimType = "Role";
|
||||||
|
public const string GW2_ACCOUNT_REGEX = "^[a-zA-z ]{3,27}\\.[0-9]{4}$";
|
||||||
public static readonly int RaidEditPowerLevel = Roles.Moderator.PowerLevel;
|
public static readonly int RaidEditPowerLevel = Roles.Moderator.PowerLevel;
|
||||||
|
|
||||||
public static class Roles
|
public static class Roles
|
||||||
|
|
|
@ -40,8 +40,8 @@ namespace Lieb.Data
|
||||||
GuildWars2Account bloodseeker = new GuildWars2Account() { AccountName = "Bloodseeker.2043" };
|
GuildWars2Account bloodseeker = new GuildWars2Account() { AccountName = "Bloodseeker.2043" };
|
||||||
var users = new LiebUser[]
|
var users = new LiebUser[]
|
||||||
{
|
{
|
||||||
//new LiebUser{Id=0, Name="Sarah", Birthday=DateTime.Parse("1992-01-15"), GuildWars2Accounts = new List<GuildWars2Account>(){ linaith, sarah} },
|
new LiebUser{Id=0, Name="Sarah", Birthday=DateTime.Parse("1992-01-15"), GuildWars2Accounts = new List<GuildWars2Account>(){ linaith, sarah} },
|
||||||
new LiebUser{Id=194863625477816321, Name="Sarah", Birthday=DateTime.Parse("1992-01-15"), GuildWars2Accounts = new List<GuildWars2Account>(){ linaith, sarah} },
|
//new LiebUser{Id=194863625477816321, Name="Sarah", Birthday=DateTime.Parse("1992-01-15"), GuildWars2Accounts = new List<GuildWars2Account>(){ linaith, sarah} },
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
new LiebUser{Id=194455125769715713, Name="Lisa", GuildWars2Accounts = new List<GuildWars2Account>(){ hierpiepts}},
|
new LiebUser{Id=194455125769715713, Name="Lisa", GuildWars2Accounts = new List<GuildWars2Account>(){ hierpiepts}},
|
||||||
new LiebUser{Id=2, Name="Simon", GuildWars2Accounts = new List<GuildWars2Account>(){ bloodseeker}}
|
new LiebUser{Id=2, Name="Simon", GuildWars2Accounts = new List<GuildWars2Account>(){ bloodseeker}}
|
||||||
|
@ -195,6 +195,16 @@ namespace Lieb.Data
|
||||||
context.Equipped.AddRange(equippedBuilds);
|
context.Equipped.AddRange(equippedBuilds);
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
|
|
||||||
|
var discordMessage = new DiscordRaidMessage()
|
||||||
|
{
|
||||||
|
DiscordChannelId = 666954070388637697,
|
||||||
|
DiscordGuildId = 666953424734257182,
|
||||||
|
DiscordMessageId = 1040355092630614087,
|
||||||
|
RaidId = raid.RaidId
|
||||||
|
};
|
||||||
|
context.DiscordRaidMessages.Add(discordMessage);
|
||||||
|
context.SaveChanges();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -204,11 +204,15 @@ namespace Lieb.Data
|
||||||
|
|
||||||
foreach(RaidSignUp signUp in raid.SignUps.Where(x => x.RaidRoleId == role.RaidRoleId))
|
foreach(RaidSignUp signUp in raid.SignUps.Where(x => x.RaidRoleId == role.RaidRoleId))
|
||||||
{
|
{
|
||||||
apiRole.Users.Add(new ApiRaid.Role.User(){
|
if(signUp.SignUpType != SignUpType.SignedOff)
|
||||||
AccountName = signUp.GuildWars2Account.AccountName,
|
{
|
||||||
Status = signUp.SignUpType.ToString(),
|
string status = signUp.SignUpType != SignUpType.SignedUp ? signUp.SignUpType.ToString() : string.Empty;
|
||||||
UserName = signUp.LiebUser.Name
|
apiRole.Users.Add(new ApiRaid.Role.User(){
|
||||||
});
|
AccountName = signUp.GuildWars2Account.AccountName,
|
||||||
|
Status = status,
|
||||||
|
UserName = signUp.LiebUser.Name
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
apiRaid.Roles.Add(apiRole);
|
apiRaid.Roles.Add(apiRole);
|
||||||
}
|
}
|
||||||
|
|
|
@ -333,6 +333,7 @@ namespace Lieb.Data
|
||||||
|
|
||||||
if(raid.EndTimeUTC < DateTimeOffset.UtcNow)
|
if(raid.EndTimeUTC < DateTimeOffset.UtcNow)
|
||||||
{
|
{
|
||||||
|
errorMessage = $"The raid already ended.";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,62 +0,0 @@
|
||||||
using Discord.Commands;
|
|
||||||
using Discord.WebSocket;
|
|
||||||
using System.Reflection;
|
|
||||||
|
|
||||||
namespace Lieb.Discord
|
|
||||||
{
|
|
||||||
public class CommandHandler
|
|
||||||
{
|
|
||||||
private readonly DiscordSocketClient _client;
|
|
||||||
private readonly CommandService _commands;
|
|
||||||
|
|
||||||
// Retrieve client and CommandService instance via ctor
|
|
||||||
public CommandHandler(DiscordSocketClient client, CommandService commands)
|
|
||||||
{
|
|
||||||
_commands = commands;
|
|
||||||
_client = client;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task InstallCommandsAsync()
|
|
||||||
{
|
|
||||||
// Hook the MessageReceived event into our command handler
|
|
||||||
_client.MessageReceived += HandleCommandAsync;
|
|
||||||
|
|
||||||
// Here we discover all of the command modules in the entry
|
|
||||||
// assembly and load them. Starting from Discord.NET 2.0, a
|
|
||||||
// service provider is required to be passed into the
|
|
||||||
// module registration method to inject the
|
|
||||||
// required dependencies.
|
|
||||||
//
|
|
||||||
// If you do not use Dependency Injection, pass null.
|
|
||||||
// See Dependency Injection guide for more information.
|
|
||||||
await _commands.AddModulesAsync(assembly: Assembly.GetEntryAssembly(),
|
|
||||||
services: null);
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task HandleCommandAsync(SocketMessage messageParam)
|
|
||||||
{
|
|
||||||
// Don't process the command if it was a system message
|
|
||||||
var message = messageParam as SocketUserMessage;
|
|
||||||
if (message == null) return;
|
|
||||||
|
|
||||||
// Create a number to track where the prefix ends and the command begins
|
|
||||||
int argPos = 0;
|
|
||||||
|
|
||||||
// Determine if the message is a command based on the prefix and make sure no bots trigger commands
|
|
||||||
if (!(message.HasCharPrefix('!', ref argPos) ||
|
|
||||||
message.HasMentionPrefix(_client.CurrentUser, ref argPos)) ||
|
|
||||||
message.Author.IsBot)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Create a WebSocket-based command context based on the message
|
|
||||||
var context = new SocketCommandContext(_client, message);
|
|
||||||
|
|
||||||
// Execute the command with the command context we just
|
|
||||||
// created, along with the service provider for precondition checks.
|
|
||||||
await _commands.ExecuteAsync(
|
|
||||||
context: context,
|
|
||||||
argPos: argPos,
|
|
||||||
services: null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,25 +0,0 @@
|
||||||
using Lieb.Models.GuildWars2.Raid;
|
|
||||||
|
|
||||||
namespace Lieb.Discord.Messages
|
|
||||||
{
|
|
||||||
public class RaidMessage
|
|
||||||
{
|
|
||||||
private Raid _raid;
|
|
||||||
|
|
||||||
public RaidMessage(Raid raid)
|
|
||||||
{
|
|
||||||
_raid = raid;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void PostRaidMessage()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void UpdateRaidMessage()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -7,7 +7,6 @@
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Discord.Net" Version="3.7.2" />
|
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="6.0.2" />
|
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="6.0.2" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.10" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.10" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.2" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.2" />
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using Lieb.Data;
|
||||||
|
|
||||||
namespace Lieb.Models.GuildWars2
|
namespace Lieb.Models.GuildWars2
|
||||||
{
|
{
|
||||||
|
@ -9,7 +10,7 @@ namespace Lieb.Models.GuildWars2
|
||||||
public string ApiKey { get; set; } = string.Empty;
|
public string ApiKey { get; set; } = string.Empty;
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
[RegularExpression("^[a-zA-z ]{3,27}\\.[0-9]{4}$", ErrorMessage = "Invalid Account Name")]
|
[RegularExpression(Constants.GW2_ACCOUNT_REGEX, ErrorMessage = "Invalid Account Name")]
|
||||||
public string AccountName { get; set; } = string.Empty;
|
public string AccountName { get; set; } = string.Empty;
|
||||||
|
|
||||||
public ICollection<Equipped> EquippedBuilds { get; set; } = new List<Equipped>();
|
public ICollection<Equipped> EquippedBuilds { get; set; } = new List<Equipped>();
|
||||||
|
|
|
@ -323,7 +323,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
_raid.StartTimeUTC = await TimeZoneService.GetUTCDateTime(_raidDate.Date + _startTime.TimeOfDay);
|
_raid.StartTimeUTC = await TimeZoneService.GetUTCDateTime(_raidDate.Date + _startTime.TimeOfDay);
|
||||||
if(_startTime.TimeOfDay > _endTime.TimeOfDay)
|
if(_startTime.TimeOfDay <= _endTime.TimeOfDay)
|
||||||
{
|
{
|
||||||
_raid.EndTimeUTC = await TimeZoneService.GetUTCDateTime(_raidDate.Date + _endTime.TimeOfDay);
|
_raid.EndTimeUTC = await TimeZoneService.GetUTCDateTime(_raidDate.Date + _endTime.TimeOfDay);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,5 @@
|
||||||
using Discord;
|
using Discord.OAuth2;
|
||||||
using Discord.Commands;
|
|
||||||
using Discord.OAuth2;
|
|
||||||
using Discord.WebSocket;
|
|
||||||
using Lieb.Data;
|
using Lieb.Data;
|
||||||
using Lieb.Discord;
|
|
||||||
using Microsoft.AspNetCore.Authentication.Cookies;
|
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.Net.Http.Headers;
|
using Microsoft.Net.Http.Headers;
|
||||||
|
|
|
@ -49,6 +49,8 @@ namespace SharedClasses.SharedModels
|
||||||
|
|
||||||
public class User
|
public class User
|
||||||
{
|
{
|
||||||
|
public ulong UserId {get; set;}
|
||||||
|
|
||||||
public string UserName { get; set; } = string.Empty;
|
public string UserName { get; set; } = string.Empty;
|
||||||
|
|
||||||
public string AccountName { get; set; } = string.Empty;
|
public string AccountName { get; set; } = string.Empty;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue