Merge branch 'develop' into 'master'
Develop See merge request discord-bots/chaosbot!2
This commit is contained in:
commit
4b490a8f3b
@ -11,6 +11,7 @@ using System.Text;
|
|||||||
using Antlr4.Runtime.Misc;
|
using Antlr4.Runtime.Misc;
|
||||||
using ChaosBot.Discord.PreConditions;
|
using ChaosBot.Discord.PreConditions;
|
||||||
using ChaosBot.Lodestone;
|
using ChaosBot.Lodestone;
|
||||||
|
using ChaosBot.Models;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using NLog;
|
using NLog;
|
||||||
@ -28,6 +29,8 @@ namespace ChaosBot.Discord.Modules.Admin
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
await Context.Channel.TriggerTypingAsync();
|
||||||
|
|
||||||
List<LodestoneRank> ranks = await GetRank();
|
List<LodestoneRank> ranks = await GetRank();
|
||||||
|
|
||||||
var sb = new StringBuilder();
|
var sb = new StringBuilder();
|
||||||
@ -44,7 +47,30 @@ namespace ChaosBot.Discord.Modules.Admin
|
|||||||
foreach (var lsID in ranks.FindAll(x => x.IngameRole == ERole.Recruit))
|
foreach (var lsID in ranks.FindAll(x => x.IngameRole == ERole.Recruit))
|
||||||
{
|
{
|
||||||
if ((lsID.ShouldBeRole != lsID.IngameRole) && (lsID.ShouldBeRole != null))
|
if ((lsID.ShouldBeRole != lsID.IngameRole) && (lsID.ShouldBeRole != null))
|
||||||
sb.AppendLine(string.Format("{0} {1}", lsID.DisplayName, $"linked to <@{lsID.DiscordId}>"));
|
{
|
||||||
|
if(lsID.DiscordId != null)
|
||||||
|
sb.AppendLine(string.Format("{0}{1}", lsID.DisplayName, (lsID.DiscordId != null ? $", linked to <@{lsID.DiscordId}>)" : "")));
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ulong lodeId = Convert.ToUInt64(lsID.LodestoneId);
|
||||||
|
using (ChaosbotContext dbContext = new ChaosbotContext())
|
||||||
|
{
|
||||||
|
IQueryable<LodestoneCharacter> ctxlsChars = dbContext.LodestoneCharacter;
|
||||||
|
List<LodestoneCharacter> lsChar = ctxlsChars
|
||||||
|
.Where(x => x.DiscordGuildId.Equals(Context.Guild.Id))
|
||||||
|
.Where(x => x.LodestoneId.Equals(lodeId)).ToList();
|
||||||
|
|
||||||
|
if (lsChar.Any())
|
||||||
|
{
|
||||||
|
sb.AppendLine(string.Format("{0}{1}", lsID.DisplayName, $", linked to <@{lsChar.First().DiscordUserId.ToString()}>"));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sb.AppendLine(string.Format("{0}", lsID.DisplayName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -57,7 +83,30 @@ namespace ChaosBot.Discord.Modules.Admin
|
|||||||
foreach (var lsID in ranks.FindAll(x => x.IngameRole == ERole.Initiate))
|
foreach (var lsID in ranks.FindAll(x => x.IngameRole == ERole.Initiate))
|
||||||
{
|
{
|
||||||
if ((lsID.ShouldBeRole != lsID.IngameRole) && (lsID.ShouldBeRole != null))
|
if ((lsID.ShouldBeRole != lsID.IngameRole) && (lsID.ShouldBeRole != null))
|
||||||
sb.AppendLine(string.Format("{0} {1}", lsID.DisplayName, $"linked to <@{lsID.DiscordId}>"));
|
{
|
||||||
|
if(lsID.DiscordId != null)
|
||||||
|
sb.AppendLine(string.Format("{0}{1}", lsID.DisplayName, (lsID.DiscordId != null ? $", linked to <@{lsID.DiscordId}>)" : "")));
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ulong lodeId = Convert.ToUInt64(lsID.LodestoneId);
|
||||||
|
using (ChaosbotContext dbContext = new ChaosbotContext())
|
||||||
|
{
|
||||||
|
IQueryable<LodestoneCharacter> ctxlsChars = dbContext.LodestoneCharacter;
|
||||||
|
List<LodestoneCharacter> lsChar = ctxlsChars
|
||||||
|
.Where(x => x.DiscordGuildId.Equals(Context.Guild.Id))
|
||||||
|
.Where(x => x.LodestoneId.Equals(lodeId)).ToList();
|
||||||
|
|
||||||
|
if (lsChar.Any())
|
||||||
|
{
|
||||||
|
sb.AppendLine(string.Format("{0}{1}", lsID.DisplayName, $", linked to <@{lsChar.First().DiscordUserId.ToString()}>"));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sb.AppendLine(string.Format("{0}", lsID.DisplayName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@ -8,9 +8,12 @@ using System.Linq;
|
|||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using ChaosBot.Discord.PreConditions;
|
using ChaosBot.Discord.PreConditions;
|
||||||
using ChaosBot.Lodestone;
|
using ChaosBot.Lodestone;
|
||||||
|
using ChaosBot.Models;
|
||||||
using ChaosBot.Repositories;
|
using ChaosBot.Repositories;
|
||||||
using ChaosBot.Services;
|
using ChaosBot.Services;
|
||||||
using Discord.Net;
|
using Discord.Net;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Newtonsoft.Json;
|
||||||
using NLog;
|
using NLog;
|
||||||
|
|
||||||
namespace ChaosBot.Discord.Modules.User
|
namespace ChaosBot.Discord.Modules.User
|
||||||
@ -37,6 +40,17 @@ namespace ChaosBot.Discord.Modules.User
|
|||||||
await LodestoneHelp();
|
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"))
|
else if ((cmd.ToLower() == "c") || (cmd.ToLower() == "character")|| (cmd.ToLower() == "char")|| (cmd.ToLower() == "toon"))
|
||||||
{
|
{
|
||||||
if(args.Length >= 1)
|
if(args.Length >= 1)
|
||||||
@ -78,6 +92,12 @@ namespace ChaosBot.Discord.Modules.User
|
|||||||
sb.AppendLine("To get Character Info:");
|
sb.AppendLine("To get Character Info:");
|
||||||
sb.AppendLine($"By Id: {ConfigurationRepository.GetValue<string>("Discord:Prefix", Context.Guild.Id, "!")}lodestone character 9231394073691143535");
|
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");
|
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();
|
sb.AppendLine();
|
||||||
sb.AppendLine("To view this help:");
|
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)
|
public async Task GetCharacter(string value, [Remainder] string name)
|
||||||
{
|
{
|
||||||
CharacterDetailed character;
|
CharacterDetailed character;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user