public async Task Status(CommandContext ctx) { await ctx.TriggerTypingAsync(); string lang = Config.GetLang(ctx.Guild.Id.ToString()); IReadOnlyList <DiscordChannel> channelList = await ctx.Guild.GetChannelsAsync(); string[] list = channelList.Cast <DiscordChannel>().Select(x => x.Id.ToString()).ToArray(); JObject streams = EventStreams.GetData(list); // Inform about streams if they exist on a server string streamingMsg = ""; if (streams.Count > 0) { TimeSpan timestamp = DateTime.UtcNow - EventStreams.LatestTimestamp; streamingMsg = " " + Locale.GetMessage("configuring-status-streaming", lang, (int)timestamp.TotalMinutes, timestamp.Seconds); // Restart the stream if it is offline for five minutes if (timestamp.TotalMinutes > 5) { Program.LogMessage("EventStreams restart was requested from !status command.", "EventStreams"); EventStreams.Init(); } } // Respond to message await ctx.RespondAsync(Locale.GetMessage("configuring-status", lang) + streamingMsg); }
public async Task ListStreams(CommandContext ctx) { string lang = Config.GetLang(ctx.Guild.Id.ToString()); await ctx.TriggerTypingAsync(); IReadOnlyList <DiscordChannel> channelList = await ctx.Guild.GetChannelsAsync(); string[] list = channelList.Cast <DiscordChannel>().Select(x => x.Id.ToString()).ToArray(); JObject result = EventStreams.GetData(list); // Send a ping if there are no results if (result.Count == 0) { await ctx.RespondAsync(Locale.GetMessage("streaming-list-nothing", lang)); return; } // Compile a list of streams List <string> msg = new List <string>(); foreach (KeyValuePair <string, JToken> entry in result) { string output = ""; string goal = entry.Key.Trim('<', '>'); string goalMsg = GetGoalMessage(lang, (goal == entry.Key ? "title" : "namespace"), goal); output += Locale.GetMessage("streaming-list-stream", lang, goalMsg, entry.Value.Count()) + "\n"; // List each stream with an editing command foreach (KeyValuePair <string, JToken> item in (JObject)entry.Value) { ulong id = ulong.Parse(item.Key); DiscordChannel channel = ctx.Guild.GetChannel(id); Dictionary <string, dynamic> args = ((JObject)item.Value).ToObject <Dictionary <string, dynamic> >(); // Combine everything string editGoal = (goal == entry.Key ? $" --title {goal}" : $" --namespace {goal}"); string argsMsg = ListArguments(args, lang); argsMsg = (argsMsg.Length > 0 ? $":\n{argsMsg}" : ""); output += $"{channel.Mention}{argsMsg}\n`!editStream #{channel.Name}{editGoal}`"; } msg.Add(output); } string response = Locale.GetMessage("streaming-list", lang, result.Count, string.Join("\n", msg)); if (response.Length <= 2000) { await ctx.RespondAsync(response); } else { // Split long lists of streams into multiple messages response = Locale.GetMessage("streaming-list", lang, result.Count, ""); foreach (var stream in msg) { string output = stream + "\n"; if (response.Length + output.Length <= 2000) { response += output; } else { await ctx.RespondAsync(response); response = ""; } } if (response.Length > 0) { await ctx.RespondAsync(response); } } }