forked from Sarah/Lieb-Website
Added renaming users and main gw2 accounts
This commit is contained in:
parent
aad07809d2
commit
c4ecb512d7
13 changed files with 172 additions and 22 deletions
|
@ -39,6 +39,42 @@ namespace DiscordBot.CommandHandlers
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public async Task<Tuple<bool, string>> CreateAccount(SocketInteraction interaction, DiscordSocketClient client, string name, string account)
|
||||
{
|
||||
//create Account
|
||||
ApiRaid.Role.User user = new ApiRaid.Role.User()
|
||||
{
|
||||
UserName = name,
|
||||
AccountName = account,
|
||||
UserId = interaction.User.Id
|
||||
};
|
||||
Tuple<bool, string> createAccountResult = await _httpService.CreateAccount(user);
|
||||
if(createAccountResult.Item1)
|
||||
{
|
||||
List<ulong> serverList = await _httpService.GetUserRenameServers();
|
||||
await RenameUser(client, interaction.User.Id, name, account, serverList);
|
||||
}
|
||||
return createAccountResult;
|
||||
}
|
||||
|
||||
|
||||
public static async Task RenameUser(DiscordSocketClient client, ulong userId, string name, string account, List<ulong> serverList)
|
||||
{
|
||||
string nickname = $"{name} | {account}";
|
||||
foreach(ulong serverId in serverList)
|
||||
{
|
||||
SocketGuild guild = client.Guilds.FirstOrDefault(g => g.Id == serverId);
|
||||
if(guild != null)
|
||||
{
|
||||
SocketGuildUser user = guild.GetUser(userId);
|
||||
if(user != null)
|
||||
{
|
||||
await user.ModifyAsync(p => p.Nickname = nickname);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//to avoid error messages because of no response...
|
||||
public async Task Respond(SocketInteraction component)
|
||||
|
|
|
@ -11,11 +11,13 @@ namespace DiscordBot.CommandHandlers
|
|||
{
|
||||
public class ModalHandler
|
||||
{
|
||||
private readonly DiscordSocketClient _client;
|
||||
private readonly HttpService _httpService;
|
||||
private readonly HandlerFunctions _handlerFunctions;
|
||||
|
||||
public ModalHandler(HttpService httpService)
|
||||
public ModalHandler(DiscordSocketClient client, HttpService httpService)
|
||||
{
|
||||
_client = client;
|
||||
_httpService = httpService;
|
||||
_handlerFunctions = new HandlerFunctions(_httpService);
|
||||
}
|
||||
|
@ -31,13 +33,7 @@ namespace DiscordBot.CommandHandlers
|
|||
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);
|
||||
Tuple<bool, string> createAccountResult = await _handlerFunctions.CreateAccount(modal, _client, name, account);
|
||||
if(!createAccountResult.Item1)
|
||||
{
|
||||
await modal.RespondAsync(createAccountResult.Item2, ephemeral: true);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue