Adding Character Linking Security + DM's
This commit is contained in:
parent
082e7a0741
commit
7d31e5a217
@ -8,9 +8,12 @@ using System.Linq;
|
||||
using System.Reflection;
|
||||
using ChaosBot.Discord.PreConditions;
|
||||
using ChaosBot.Lodestone;
|
||||
using ChaosBot.Models;
|
||||
using ChaosBot.Repositories;
|
||||
using ChaosBot.Services;
|
||||
using Discord.Net;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Newtonsoft.Json;
|
||||
using NLog;
|
||||
|
||||
namespace ChaosBot.Discord.Modules.User
|
||||
@ -37,6 +40,17 @@ namespace ChaosBot.Discord.Modules.User
|
||||
await LodestoneHelp();
|
||||
}
|
||||
}
|
||||
if (((cmd.ToLower() == "link") || (cmd.ToLower() == "l") || (cmd.ToLower() == "attach") || (cmd.ToLower() == "claim") || (cmd.ToLower() == "take")) && (await CheckPermissions.CheckPerms(Context, "lodestone.link", "User")))
|
||||
{
|
||||
if(args.Length >= 1)
|
||||
{
|
||||
await ClaimCharacter(args[0], string.Join(" ", args.Skip(1)));
|
||||
}
|
||||
else
|
||||
{
|
||||
await LodestoneHelp();
|
||||
}
|
||||
}
|
||||
else if ((cmd.ToLower() == "c") || (cmd.ToLower() == "character")|| (cmd.ToLower() == "char")|| (cmd.ToLower() == "toon"))
|
||||
{
|
||||
if(args.Length >= 1)
|
||||
@ -78,6 +92,12 @@ namespace ChaosBot.Discord.Modules.User
|
||||
sb.AppendLine("To get Character Info:");
|
||||
sb.AppendLine($"By Id: {ConfigurationRepository.GetValue<string>("Discord:Prefix", Context.Guild.Id, "!")}lodestone character 9231394073691143535");
|
||||
sb.AppendLine($"By Name: {ConfigurationRepository.GetValue<string>("Discord:Prefix", Context.Guild.Id, "!")}lodestone character Siren Luna Kaisar");
|
||||
if (await CheckPermissions.CheckPerms(Context, "lodestone.link", "User"))
|
||||
{
|
||||
sb.AppendLine("To Link your Character:");
|
||||
sb.AppendLine($"By Id: {ConfigurationRepository.GetValue<string>("Discord:Prefix", Context.Guild.Id, "!")}lodestone link 9231394073691143535");
|
||||
sb.AppendLine($"By Name: {ConfigurationRepository.GetValue<string>("Discord:Prefix", Context.Guild.Id, "!")}lodestone link Siren Luna Kaisar");
|
||||
}
|
||||
sb.AppendLine();
|
||||
sb.AppendLine();
|
||||
sb.AppendLine("To view this help:");
|
||||
@ -127,6 +147,99 @@ namespace ChaosBot.Discord.Modules.User
|
||||
}
|
||||
}
|
||||
|
||||
public async Task ClaimCharacter(string value, [Remainder] string name)
|
||||
{
|
||||
CharacterDetailed character;
|
||||
try
|
||||
{
|
||||
await Context.Channel.TriggerTypingAsync();
|
||||
|
||||
var sb = new StringBuilder();
|
||||
var embed = new EmbedBuilder();
|
||||
|
||||
embed.WithColor(new Color(255, 255, 0));
|
||||
embed.Title = $"Discord to FFXIV Linking";
|
||||
sb.AppendLine();
|
||||
sb.AppendLine();
|
||||
|
||||
if (name.Length == 0)
|
||||
character = LodestoneManager.GetCharacter(Convert.ToInt64(value));
|
||||
else
|
||||
{
|
||||
character = LodestoneManager.GetCharacter(value, string.Join(" ", name));
|
||||
}
|
||||
|
||||
Boolean linked = false;
|
||||
using (ChaosbotContext dbContext = new ChaosbotContext())
|
||||
{
|
||||
IQueryable<LodestoneCharacter> ctxlsChars = dbContext.LodestoneCharacter;
|
||||
IQueryable<LodestoneCharacter> lsChar = ctxlsChars.Where(p => p.DiscordGuildId.Equals(Context.Guild.Id)).Where(p => p.LodestoneId.Equals(Convert.ToUInt64(character.Character.ID)));
|
||||
|
||||
linked = lsChar.Any();
|
||||
}
|
||||
|
||||
if(!linked)
|
||||
{
|
||||
string b64 =
|
||||
System.Convert.ToBase64String(Encoding.GetEncoding(28591)
|
||||
.GetBytes(character.Character.ID.ToString())) + '|' +
|
||||
System.Convert.ToBase64String(Encoding.GetEncoding(28591)
|
||||
.GetBytes(Context.Guild.Id.ToString())) + '|' +
|
||||
System.Convert.ToBase64String(Encoding.GetEncoding(28591).GetBytes(Context.User.Id.ToString()));
|
||||
|
||||
if (character.Character.Bio.Contains(b64))
|
||||
{
|
||||
using (ChaosbotContext dbContext = new ChaosbotContext())
|
||||
{
|
||||
LodestoneCharacter lsChar = new LodestoneCharacter();
|
||||
|
||||
lsChar.LodestoneId = Convert.ToUInt64(character.Character.ID);
|
||||
lsChar.DiscordUserId = Context.User.Id;
|
||||
lsChar.DiscordGuildId = Context.Guild.Id;
|
||||
lsChar.Name = character.Character.Name;
|
||||
lsChar.Avatar = character.Character.Avatar;
|
||||
|
||||
await dbContext.LodestoneCharacter.Upsert(lsChar)
|
||||
.On(x => new {x.DiscordGuildId, x.LodestoneId}).RunAsync();
|
||||
}
|
||||
|
||||
embed.ImageUrl = character.Character.Avatar;
|
||||
sb.AppendLine(
|
||||
$"{Context.User.Mention} has been successfully linked to {character.Character.Name}");
|
||||
embed.Description = sb.ToString();
|
||||
await ReplyAsync(null, false, embed.Build());
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.AppendLine($"Please add the following code anywhere in your bio.");
|
||||
sb.AppendLine($"```{b64}```");
|
||||
sb.AppendLine(
|
||||
$"You can access your bio by going to https://na.finalfantasyxiv.com/lodestone/my/setting/profile/ and signing in with our Final Fantasy Lodestone account.");
|
||||
sb.AppendLine();
|
||||
sb.AppendLine($"Please rerun the below command in <#{Context.Channel.Id}>");
|
||||
sb.AppendLine($"```{Context.Message.Content}```");
|
||||
|
||||
embed.Description = sb.ToString();
|
||||
await Context.User.SendMessageAsync("", false, embed.Build());
|
||||
|
||||
await ReplyAsync($"{Context.User.Mention}, please check your Private Messages.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
embed.ImageUrl = character.Character.Avatar;
|
||||
sb.AppendLine(
|
||||
$"{Context.User.Mention}, {character.Character.Name} is already linked.");
|
||||
embed.Description = sb.ToString();
|
||||
await ReplyAsync(null, false, embed.Build());
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.Error($"{MethodBase.GetCurrentMethod().ReflectedType.FullName}: Exception [{ex}] thrown, <[{ex.Message}]>.");
|
||||
}
|
||||
}
|
||||
|
||||
public async Task GetCharacter(string value, [Remainder] string name)
|
||||
{
|
||||
CharacterDetailed character;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user