-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Converted the !login command into the /login slash command.
- Loading branch information
Showing
5 changed files
with
46 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using DiscordBot.Apis; | ||
using DiscordBot.Services; | ||
using DSharpPlus; | ||
using DSharpPlus.EventArgs; | ||
using DSharpPlus.SlashCommands; | ||
using System.Xml.Linq; | ||
|
||
namespace DiscordBot.Commands; | ||
|
||
public class AuthenticationCommands : ApplicationCommandModule | ||
{ | ||
private readonly DiscordService _discordService; | ||
private readonly IServerDiscordApi _serverDiscordApi; | ||
|
||
public AuthenticationCommands(DiscordService discordService, IServerDiscordApi serverDiscordApi) | ||
{ | ||
_discordService = discordService; | ||
_serverDiscordApi = serverDiscordApi; | ||
} | ||
|
||
[SlashCommand("login", "Use to link your Discord user to an in-game account. Use via direct message only!", defaultPermission: false)] | ||
public async Task LoginCommand(InteractionContext ctx, [Option("account", "your in-game account name")] string username, [Option("password", "the password for your in-game account")] string password) | ||
{ | ||
if (ctx.Channel.Type != ChannelType.Private) | ||
{ | ||
// Do not provide an interaction context response so the command parameters remain hidden to others. Send a direct message instead. | ||
await ctx.Member.SendMessageAsync("Please do not use the **/login** command in public channels as it could compromise your in-game account! It is also recommended to click **\"Dismiss message\"** on all of the notifications that contain the bot command to permanently hide your credentials."); | ||
return; | ||
} | ||
|
||
var discordMember = await _discordService.Guild.GetMemberAsync(ctx.User.Id); | ||
|
||
if (discordMember != null) | ||
{ | ||
var response = await _serverDiscordApi.PostLogin(username, discordMember.Id, discordMember.Username, discordMember.Discriminator, discordMember.AvatarUrl, password); | ||
|
||
if (response.Status) | ||
await discordMember.GrantRoleAsync(_discordService.MemberRole); | ||
|
||
await ctx.CreateResponseAsync(response.Message); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters