public override async Task <string> Run(string parameters, CancellationToken cancellationToken) { if (string.IsNullOrWhiteSpace(Program.Saliens.Token)) { return("{warn}No token has been set."); } var info = await SaliensApi.GetPlayerInfo(Program.Settings.Token); Program.Saliens.PlayerInfo = info; return($"Level: {{level}}{info.Level}{{reset}}{Environment.NewLine}" + $"XP: {{xp}}{long.Parse(info.Score).ToString("#,##0")}{{reset}} (required for next level: {{reqxp}}{long.Parse(info.NextLevelScore).ToString("#,##0")}{{reset}}){Environment.NewLine}" + $"Clan: {info.ClanInfo.Name}{Environment.NewLine}" + $"Active planet: {{planet}}{info.ActivePlanet} {{reset}}{Environment.NewLine}" + $"Time spent on planet: {info.TimeOnPlanet.ToString()}{Environment.NewLine}" + $"Active zone: {{zone}}{info.ActiveZonePosition} ({info.ActiveZoneGame}){{reset}}{Environment.NewLine}" + $"Time spent in zone: {info.TimeInZone.TotalSeconds} seconds"); }
public override async Task <string> Run(string parameters, CancellationToken cancellationToken) { if (string.IsNullOrWhiteSpace(parameters)) { // Show the current token if (!string.IsNullOrWhiteSpace(Program.Saliens.Token)) { this.WriteConsole($"Your token is currently set to: {{value}}{Program.Saliens.Token}{{reset}}."); } else { this.WriteConsole("You have currently no token set."); } this.WriteConsole("You can change the token by appending the token to this command: {command}token {param}<your_token>"); this.WriteConsole("where {param}<your_token>{reset} is replaced with your token."); return(""); } else { // Set the token try { Program.Saliens.PlayerInfo = await SaliensApi.GetPlayerInfo(parameters); Program.Settings.Token = parameters; Program.Settings.Save(); return("Your token has been saved."); } catch (WebException ex) { return($"{{err}}Invalid response. {ex.Message}"); } } }
private void PresenceLoopThread() { while (!this.cancelSource.Token.IsCancellationRequested) { if (string.IsNullOrWhiteSpace(this.ApiToken)) { return; } TimeSpan timeToWait = TimeSpan.FromSeconds(fallbackRefreshRate); try { var playerInfo = SaliensApi.GetPlayerInfo(this.ApiToken); this.presence.Logger?.LogMessage($"Updating Discord presence with {playerInfo.Score} XP"); this.presence.SetSaliensPlayerState(playerInfo); if (!string.IsNullOrWhiteSpace(playerInfo.ActiveZonePosition)) { if (playerInfo.TimeInZone < TimeSpan.FromSeconds(110)) { timeToWait = TimeSpan.FromSeconds(110) - playerInfo.TimeInZone; } else if (playerInfo.TimeInZone < TimeSpan.FromSeconds(120)) { timeToWait = TimeSpan.FromSeconds(120) - playerInfo.TimeInZone; } timeToWait += TimeSpan.FromSeconds(5); } } catch (Exception ex) { this.presence.Logger?.LogException(ex); } this.cancelSource.Token.WaitHandle.WaitOne(timeToWait); } }