Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
182 changes: 46 additions & 136 deletions client/csharp/BrandishBotWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1716,166 +1716,76 @@ public bool GetUnlockedRecipes()
#region Account Linking

/// <summary>
/// Initiate account linking process
/// Command: !linkAccount
/// Consolidates account linking operations under a single command (!link)
/// Command: !link [status|confirm|unlink|<code>]
/// </summary>
public bool InitiateLinking()
public bool ManageLinking()
{
EnsureInitialized();
string error = null;

if (!ValidateContext(out string platform, out string platformId, out string username, ref error))
{
CPH.LogWarn($"InitiateLinking Failed: {error}");
CPH.LogWarn($"ManageLinking Failed: {error}");
return false;
}

try
{
var result = client.InitiateLinking(platform, platformId, username).Result;
var formatted = ResponseFormatter.FormatLinkInitiate(result);
CPH.SetArgument("response", formatted);
return true;
}
catch (Exception ex)
{
LogWarning("InitiateLinking", ex);
CPH.SetArgument("response", StripStatusCode(GetErrorMessage(ex)));
return true;
}
}

/// <summary>
/// Claim a linking code from another platform
/// Command: !claimCode <code>
/// </summary>
public bool ClaimLinkingCode()
{
EnsureInitialized();
string error = null;

if (!ValidateContext(out string platform, out string platformId, out string username, ref error))
{
CPH.LogWarn($"ClaimLinkingCode Failed: {error}");
return false;
}

if (!GetInputString(0, "code", true, out string code, ref error))
{
CPH.SetArgument("response", $"{error} Usage: !claimCode <code>");
return true;
}
GetInputString(0, "action", false, out string action, ref error);

try
{
var result = client.ClaimLinkingCode(platform, platformId, username, code).Result;
var formatted = ResponseFormatter.FormatLinkClaim(result);
CPH.SetArgument("response", formatted);
return true;
}
catch (Exception ex)
{
LogWarning("ClaimLinkingCode", ex);
CPH.SetArgument("response", StripStatusCode(GetErrorMessage(ex)));
return true;
}
}

/// <summary>
/// Confirm account linking
/// Command: !confirmLink
/// </summary>
public bool ConfirmLinking()
{
EnsureInitialized();
string error = null;

if (!ValidateContext(out string platform, out string platformId, out string discardedUsername, ref error))
{
CPH.LogWarn($"ConfirmLinking Failed: {error}");
return false;
}

try
{
var result = client.ConfirmLinking(platform, platformId).Result;
var formatted = ResponseFormatter.FormatLinkConfirm(result);
CPH.SetArgument("response", formatted);
return true;
}
catch (Exception ex)
{
LogWarning("ConfirmLinking", ex);
CPH.SetArgument("response", StripStatusCode(GetErrorMessage(ex)));
return true;
}
}

/// <summary>
/// Unlink accounts
/// Command: !unlink <target_platform>
/// </summary>
public bool UnlinkAccounts()
{
EnsureInitialized();
string error = null;

if (!ValidateContext(out string platform, out string platformId, out string discardedUsername, ref error))
{
CPH.LogWarn($"UnlinkAccounts Failed: {error}");
return false;
}
if (string.IsNullOrWhiteSpace(action) || action.ToLower() == "initiate" || action.ToLower() == "start")
{
var result = client.InitiateLinking(platform, platformId, username).Result;
CPH.SetArgument("response", ResponseFormatter.FormatLinkInitiate(result));
}
else if (action.ToLower() == "status")
{
var result = client.GetLinkingStatus(platform, platformId).Result;
CPH.SetArgument("response", ResponseFormatter.FormatLinkingStatus(result));
}
else if (action.ToLower() == "confirm")
{
var result = client.ConfirmLinking(platform, platformId).Result;
CPH.SetArgument("response", ResponseFormatter.FormatLinkConfirm(result));
}
else if (action.ToLower() == "unlink")
{
if (!GetInputString(1, "target_platform", true, out string targetPlatform, ref error))
{
CPH.SetArgument("response", $"{error} Usage: !link unlink <target_platform>");
return true;
}
var result = client.UnlinkAccounts(platform, platformId, targetPlatform).Result;
CPH.SetArgument("response", ResponseFormatter.FormatMessage(result));
}
else
{
string code = action;
if (action.ToLower() == "claim")
{
if (!GetInputString(1, "code", true, out string claimCode, ref error))
{
CPH.SetArgument("response", $"{error} Usage: !link claim <code>");
return true;
}
code = claimCode;
}

if (!GetInputString(0, "target_platform", true, out string targetPlatform, ref error))
{
CPH.SetArgument("response", $"{error} Usage: !unlink <target_platform>");
return true;
}
var result = client.ClaimLinkingCode(platform, platformId, username, code).Result;
CPH.SetArgument("response", ResponseFormatter.FormatLinkClaim(result));
}

try
{
var result = client.UnlinkAccounts(platform, platformId, targetPlatform).Result;
var formatted = ResponseFormatter.FormatMessage(result);
CPH.SetArgument("response", formatted);
return true;
}
catch (Exception ex)
{
LogWarning("UnlinkAccounts", ex);
LogWarning("ManageLinking", ex);
CPH.SetArgument("response", StripStatusCode(GetErrorMessage(ex)));
return true;
}
}

/// <summary>
/// Get linking status for a user
/// Command: !linkStatus
/// </summary>
public bool GetLinkingStatus()
{
EnsureInitialized();
string error = null;

if (!ValidateContext(out string platform, out string platformId, out string discardedUsername, ref error))
{
CPH.LogWarn($"GetLinkingStatus Failed: {error}");
return false;
}

try
{
var result = client.GetLinkingStatus(platform, platformId).Result;
CPH.SetArgument("response", ResponseFormatter.FormatLinkingStatus(result));
return true;
}
catch (Exception ex)
{
LogWarning("GetLinkingStatus", ex);
CPH.SetArgument("response", $"Error: {StripStatusCode(GetErrorMessage(ex))}");
return true;
}
}

#endregion

#region Admin Utilities
Expand Down
4 changes: 2 additions & 2 deletions client/csharp/ResponseFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ public static string FormatLinkInitiate(LinkInitiateResponse response)
return "Failed to initiate linking: No token received.";

string expireMsg = response.ExpiresIn > 0 ? $" (Expires in {response.ExpiresIn / 60}m)" : "";
return $"Linking code: {response.Token}{expireMsg}. Run '!claimCode {response.Token}' on your other platform.";
return $"Linking code: {response.Token}{expireMsg}. Run '!link {response.Token}' on your other platform.";
}

/// <summary>
Expand All @@ -463,7 +463,7 @@ public static string FormatLinkClaim(LinkClaimResponse response)
if (response == null) return "Claim request failed.";
if (response.AwaitingConfirmation)
{
return $"Code claimed! Please return to {response.SourcePlatform} and run '!confirmLink' to complete the process.";
return $"Code claimed! Please return to {response.SourcePlatform} and run '!link confirm' to complete the process.";
}
return "Code claimed successfully.";
}
Expand Down
1 change: 0 additions & 1 deletion docs/issues/todo.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
Client: reduce number of !link commands and sort based on arguments
Expedition journal too long for 1 discord post
Bomb usage message is outdated.
2 changes: 1 addition & 1 deletion internal/discord/cmd_link.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func LinkCommand() (*discordgo.ApplicationCommand, CommandHandler) {
embed = createEmbed("🔗 Link Started", fmt.Sprintf("**Your link code:** `%s`\n\n"+
"**1. Copy Code:** `%s`\n"+
"**2. Go to External Chat:** Twitch or YouTube chat\n"+
"**3. Type Command:** `!link %s`\n"+
"**3. Type Command:** `!link claim %s`\n"+
"**4. Return Here:** Come back to this channel\n"+
"**5. Confirm:** Type `/link confirm:true`\n\n"+
"⏰ This code expires in **%d minutes**.",
Expand Down
3 changes: 0 additions & 3 deletions internal/info/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ func NewLoader(dir string) *Loader {
}

func (l *Loader) Load() error {

entries, err := os.ReadDir(l.dir)
if err != nil {
return fmt.Errorf("failed to read info directory: %w", err)
Expand Down Expand Up @@ -64,7 +63,6 @@ func (l *Loader) loadFeatureFile(path string) (*Feature, error) {
}

func (l *Loader) GetFeature(name string) (*Feature, bool) {

feature, ok := l.cache[name]
return feature, ok
}
Expand All @@ -84,7 +82,6 @@ func (l *Loader) GetTopic(featureName, topicName string) (*Topic, bool) {
}

func (l *Loader) SearchTopic(topicName string) (*Topic, string, bool) {

for featureName, feature := range l.cache {
if topic, ok := feature.Topics[topicName]; ok {
return &topic, featureName, true
Expand Down
Loading