public static void Set(AnimeName.Anime anime) { Init(); Update(); string stateString = string.IsNullOrEmpty(anime.episode) ? "" : string.Format("Episode {0} ", anime.episode); stateString += string.IsNullOrEmpty(anime.website) ? "" : string.Format("On {0}", anime.website); // Hack from string to byte[128] to fix UTF-8 problem var activity = new Discord.Activity { State = StringToByte(stateString), Details = StringToByte(anime.name), Timestamps = { Start = DateTimeOffset.UtcNow.ToUnixTimeSeconds(), }, Instance = true, }; MainLogic.Log("Try to set discord activity..."); try { activityManager.UpdateActivity(activity, StatusCallback); } catch { MainLogic.Log("Could not set activity. Discord error. (Maybe try opening discord...)"); } }
public static void Run() { stop = false; pause = false; Console.WriteLine("Scaning for anime every {0} miliseconds...", Config.program.ScanInterval); while (!stop) { if (!pause) { AnimeName.Anime anime = AnimeName.GetAnime(); if (anime == null) { if (lastAnime != null) { Log("No anime detected."); DiscordActivity.Clear(); } } else { if (lastAnime == null) { Log("Anime detected."); DiscordActivity.Set(anime); } else if (lastAnime.name != anime.name) { Log("New anime detected."); DiscordActivity.Set(anime); } else if (lastAnime.episode != anime.episode) { Log("New episode detected."); DiscordActivity.Set(anime); } } lastAnime = anime; } int sleepTime = Config.program.ScanInterval; do { DiscordActivity.Update(); if (sleepTime <= 0 || stop) { break; } else { Thread.Sleep(Math.Min(200, sleepTime)); } sleepTime -= 200; }while (sleepTime > 0); } DiscordActivity.Clear(); }
public static void Pause() { Log("Anime detection paused."); pause = true; if (lastAnime != null) { lastAnime = null; DiscordActivity.Clear(); } }
public static void ForceUpdate() { lastAnime = AnimeName.GetAnime(); if (lastAnime != null) { Log("Force update anime to discord."); DiscordActivity.Set(lastAnime); } else { Log("Cannot force update. (No anime detected)."); } }
public static void ForceReconnect() { DiscordActivity.Clear(); lastAnime = AnimeName.GetAnime(); if (lastAnime != null) { Log("Force reconnect discord."); DiscordActivity.Set(lastAnime); } else { Log("Cannot force reconnect. (No anime detected)."); } }