reworked the commandHandler

added Slash Commands
This commit is contained in:
Sarah Faey 2022-11-15 19:00:56 +01:00
parent 17dceda408
commit b8feed971c
15 changed files with 599 additions and 214 deletions

View file

@ -68,40 +68,75 @@ namespace Lieb.Controllers
[Route("[action]")]
public async Task SignUp(ApiSignUp signUp)
{
int accountId = _userService.GetLiebUserGW2AccountOnly(signUp.userId).GuildWars2Accounts.FirstOrDefault(new GuildWars2Account()).GuildWars2AccountId;
await _raidService.SignUp(signUp.raidId, signUp.userId, accountId, signUp.roleId, SignUpType.SignedUp);
if(signUp.userId != 0)
{
int accountId = _userService.GetLiebUserGW2AccountOnly(signUp.userId).GuildWars2Accounts.FirstOrDefault(new GuildWars2Account()).GuildWars2AccountId;
await _raidService.SignUp(signUp.raidId, signUp.userId, accountId, signUp.roleId, SignUpType.SignedUp, signUp.signedUpByUserId);
}
else
{
await _raidService.SignUpExternalUser(signUp.raidId, signUp.userName, signUp.roleId, SignUpType.SignedUp, signUp.signedUpByUserId);
}
}
[HttpPost]
[Route("[action]")]
public async Task SignUpMaybe(ApiSignUp signUp)
{
int accountId = _userService.GetLiebUserGW2AccountOnly(signUp.userId).GuildWars2Accounts.FirstOrDefault(new GuildWars2Account()).GuildWars2AccountId;
await _raidService.SignUp(signUp.raidId, signUp.userId, signUp.gw2AccountId, signUp.roleId, SignUpType.Maybe);
if(signUp.userId != 0)
{
int accountId = _userService.GetLiebUserGW2AccountOnly(signUp.userId).GuildWars2Accounts.FirstOrDefault(new GuildWars2Account()).GuildWars2AccountId;
await _raidService.SignUp(signUp.raidId, signUp.userId, accountId, signUp.roleId, SignUpType.Maybe, signUp.signedUpByUserId);
}
else
{
await _raidService.SignUpExternalUser(signUp.raidId, signUp.userName, signUp.roleId, SignUpType.Maybe, signUp.signedUpByUserId);
}
}
[HttpPost]
[Route("[action]")]
public async Task SignUpBackup(ApiSignUp signUp)
{
int accountId = _userService.GetLiebUserGW2AccountOnly(signUp.userId).GuildWars2Accounts.FirstOrDefault(new GuildWars2Account()).GuildWars2AccountId;
await _raidService.SignUp(signUp.raidId, signUp.userId, signUp.gw2AccountId, signUp.roleId, SignUpType.Backup);
if(signUp.userId != 0)
{
int accountId = _userService.GetLiebUserGW2AccountOnly(signUp.userId).GuildWars2Accounts.FirstOrDefault(new GuildWars2Account()).GuildWars2AccountId;
await _raidService.SignUp(signUp.raidId, signUp.userId, accountId, signUp.roleId, SignUpType.Backup, signUp.signedUpByUserId);
}
else
{
await _raidService.SignUpExternalUser(signUp.raidId, signUp.userName, signUp.roleId, SignUpType.Backup, signUp.signedUpByUserId);
}
}
[HttpPost]
[Route("[action]")]
public async Task SignUpFlex(ApiSignUp signUp)
{
int accountId = _userService.GetLiebUserGW2AccountOnly(signUp.userId).GuildWars2Accounts.FirstOrDefault(new GuildWars2Account()).GuildWars2AccountId;
await _raidService.SignUp(signUp.raidId, signUp.userId, signUp.gw2AccountId, signUp.roleId, SignUpType.Flex);
if(signUp.userId != 0)
{
int accountId = _userService.GetLiebUserGW2AccountOnly(signUp.userId).GuildWars2Accounts.FirstOrDefault(new GuildWars2Account()).GuildWars2AccountId;
await _raidService.SignUp(signUp.raidId, signUp.userId, accountId, signUp.roleId, SignUpType.Flex, signUp.signedUpByUserId);
}
else
{
await _raidService.SignUpExternalUser(signUp.raidId, signUp.userName, signUp.roleId, SignUpType.Flex, signUp.signedUpByUserId);
}
}
[HttpPost]
[Route("[action]")]
public async Task SignOff(ApiSignUp signUp)
{
int accountId = _userService.GetLiebUserGW2AccountOnly(signUp.userId).GuildWars2Accounts.FirstOrDefault(new GuildWars2Account()).GuildWars2AccountId;
await _raidService.SignOff(signUp.raidId, signUp.userId);
if(signUp.userId != 0)
{
int accountId = _userService.GetLiebUserGW2AccountOnly(signUp.userId).GuildWars2Accounts.FirstOrDefault(new GuildWars2Account()).GuildWars2AccountId;
await _raidService.SignOff(signUp.raidId, signUp.userId, signUp.signedUpByUserId);
}
else
{
await _raidService.SignOffExternalUser(signUp.raidId, signUp.userName, signUp.signedUpByUserId);
}
}
[HttpPost]
@ -121,5 +156,14 @@ namespace Lieb.Controllers
await _gw2AccountService.AddOrEditAccount(gw2Account, user.UserId);
return Ok();
}
[HttpGet]
[Route("[action]/{raidId}")]
public ActionResult<ApiRaid> GetRaid(int raidId)
{
Raid raid = _raidService.GetRaid(raidId);
return DiscordService.ConvertRaid(raid);
}
}
}

View file

@ -43,7 +43,8 @@ namespace Lieb.Data
//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} },
#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=1, Name="Lisa", GuildWars2Accounts = new List<GuildWars2Account>(){ hierpiepts}},
new LiebUser{Id=2, Name="Simon", GuildWars2Accounts = new List<GuildWars2Account>(){ bloodseeker}}
#endif
};

View file

@ -196,7 +196,7 @@ namespace Lieb.Data
await context.SaveChangesAsync();
}
private ApiRaid ConvertRaid(Raid raid)
public static ApiRaid ConvertRaid(Raid raid)
{
ApiRaid apiRaid = new ApiRaid(){
Title = raid.Title,
@ -239,7 +239,8 @@ namespace Lieb.Data
apiRole.Users.Add(new ApiRaid.Role.User(){
AccountName = signUp.GuildWars2Account.AccountName,
Status = status,
UserName = signUp.LiebUser.Name
UserName = signUp.LiebUser.Name,
UserId = signUp.LiebUserId
});
}
}
@ -249,7 +250,7 @@ namespace Lieb.Data
return apiRaid;
}
private List<ApiRaid.DiscordMessage> ConvertMessages(IEnumerable<DiscordRaidMessage> messages)
public static List<ApiRaid.DiscordMessage> ConvertMessages(IEnumerable<DiscordRaidMessage> messages)
{
List<ApiRaid.DiscordMessage> apiMessages = new List<ApiRaid.DiscordMessage>();
foreach(DiscordRaidMessage message in messages)
@ -264,7 +265,7 @@ namespace Lieb.Data
return apiMessages;
}
private ApiUserReminder ConvertUserReminder(string message, Raid raid)
public static ApiUserReminder ConvertUserReminder(string message, Raid raid)
{
ApiUserReminder apiReminder = new ApiUserReminder()
{
@ -281,7 +282,7 @@ namespace Lieb.Data
return apiReminder;
}
private ApiChannelReminder ConvertChannelReminder(ulong discordServerId, ulong discordChannelId, string message)
public static ApiChannelReminder ConvertChannelReminder(ulong discordServerId, ulong discordChannelId, string message)
{
return new ApiChannelReminder()
{

View file

@ -102,7 +102,7 @@ namespace Lieb.Data
}
}
public async Task SignUp(int raidId, ulong liebUserId, int guildWars2AccountId, int plannedRoleId, SignUpType signUpType)
public async Task SignUp(int raidId, ulong liebUserId, int guildWars2AccountId, int plannedRoleId, SignUpType signUpType, ulong signedUpByUserId = 0)
{
if (!IsRoleSignUpAllowed(raidId, liebUserId, plannedRoleId, signUpType, true))
{
@ -127,7 +127,7 @@ namespace Lieb.Data
};
context.RaidSignUps.Add(signUp);
await context.SaveChangesAsync();
await LogSignUp(signUp);
await LogSignUp(signUp, signedUpByUserId);
}
await _discordService.PostRaidMessage(raidId);
}