private async Task SocketClientOnReady() { this.State = DiscordState.Ready; await this.specialChars.TryFindEmote(this.socketClient); PluginLog.Verbose("DiscordHandler READY!!"); }
public async Task Start() { if (string.IsNullOrEmpty(this.plugin.Config.DiscordToken)) { this.State = DiscordState.TokenInvalid; PluginLog.Error("Token empty, cannot start bot."); return; } try { await this.socketClient.LoginAsync(TokenType.Bot, this.plugin.Config.DiscordToken); await this.socketClient.StartAsync(); } catch (Exception ex) { PluginLog.Error(ex, "Token invalid, cannot start bot."); } this.MessageQueue.Start(); lodestoneClient = await LodestoneClient.GetClientAsync(); PluginLog.Verbose("DiscordHandler START!!"); }
public static void UpdateStatus(DiscordState state, string details = null, string secret = null, int?players = null, int?slots = null) { if (Service.Value != null) { Service.Value.SetStatus(state, details, secret, players, slots); } }
public static void UpdateStatus(DiscordState state, string details = null, string secret = null, int?players = null, int?slots = null) { var service = GetService(); if (service != null) { service.SetStatus(state, details, secret, players, slots); } }
void SetStatus(DiscordState state, string details = null, string secret = null, int?players = null, int?slots = null) { if (currentState == state) { return; } if (instance == null) { return; } string stateText; DateTime?timestamp = null; Party party = null; Secrets secrets = null; switch (state) { case DiscordState.InMenu: stateText = "In menu"; break; case DiscordState.InMapEditor: stateText = "In Map Editor"; break; case DiscordState.InSkirmishLobby: stateText = "In Skirmish Lobby"; break; case DiscordState.InMultiplayerLobby: stateText = "In Multiplayer Lobby"; timestamp = DateTime.UtcNow; party = new Party { ID = Secrets.CreateFriendlySecret(new Random()), Size = players.Value, Max = slots.Value }; secrets = new Secrets { JoinSecret = secret }; break; case DiscordState.PlayingMultiplayer: stateText = "Playing Multiplayer"; timestamp = DateTime.UtcNow; break; case DiscordState.PlayingCampaign: stateText = "Playing Campaign"; timestamp = DateTime.UtcNow; break; case DiscordState.WatchingReplay: stateText = "Watching Replay"; timestamp = DateTime.UtcNow; break; case DiscordState.PlayingSkirmish: stateText = "Playing Skirmish"; timestamp = DateTime.UtcNow; break; default: throw new ArgumentOutOfRangeException(nameof(state), state, null); } var richPresence = new RichPresence { Details = details, State = stateText, Assets = new Assets { LargeImageKey = "large", LargeImageText = Game.ModData.Manifest.Metadata.Title, }, Timestamps = timestamp.HasValue ? new Timestamps(timestamp.Value) : null, Party = party, Secrets = secrets }; client.SetPresence(richPresence); currentState = state; }