public ServiceMenuModule() { Configuration = new LocalConfiguration <ServiceMenuActionSettings>(GetType().Name); var config = Configuration.GetConfiguration(); if (config != null) { Settings.ActionCommandAttribute = config.ActionCommandAttribute; Settings.ViewOrder = config.ViewOrder; } else { DefaultSettings(); } }
public async System.Threading.Tasks.Task MenuEmulation(CommandContext ctx, CommandAttributes.RequireAuthentication context) { await ctx.Message.DeleteAsync(); await ctx.TriggerTypingAsync(); var config = _configuration.GetConfiguration(); var ftpInfo = context.Service.FtpInfo.Split(':'); var embedBuilder = new DiscordEmbedBuilder { Title = context.Service.Name, Thumbnail = new DiscordEmbedBuilder.EmbedThumbnail { Url = config.ThumbnailUrl }, Footer = new DiscordEmbedBuilder.EmbedFooter { Text = $"Requested by {ctx.User.Username}#{ctx.User.Discriminator}", IconUrl = ctx.User.AvatarUrl }, Timestamp = DateTime.Now, Url = new CompanyInfo(2).ControlPanelUrl + "/Service/Home/" + context.Service.ServiceId, Description = $"**Name: **{context.Service.Name}\n" + $"**Owner: **{context.Service.UserName}\n" + $"**Server Info: **{context.Service.IpAddress} Port: {context.Service.GamePort}\n" + $"**FTP: **{ftpInfo[0]} Port: {ftpInfo[1]}\n" + $"{(context.User.UserType != UserType.User ? "**Server: **" + context.Service.ServerName : string.Empty)}\n" }; var currentStatistics = config.ShowCpu ? $"**CPU:** {context.Service.CurrentCpu}%\n" : ""; currentStatistics += config.ShowMemory ? $"**Memory:** {SizeSuffix(context.Service.CurrentMemory)}/{SizeSuffix(context.Service.MemoryLimitMB)} **[{context.Service.CurrentMemoryPercent}%]**\n" : ""; currentStatistics += config.ShowPlayers ? $"**Players:** {context.Service.CurrentPlayers}/{context.Service.CurrentMaxPlayers}" : ""; if (!string.IsNullOrEmpty(currentStatistics)) { embedBuilder.AddField("Stats", currentStatistics, true); } switch (context.Service.Status.ServiceStatus) { case ServiceStatus.Running: case ServiceStatus.Starting: case ServiceStatus.Resuming: embedBuilder.Color = DiscordColor.Green; break; case ServiceStatus.StartError: case ServiceStatus.Disabled: case ServiceStatus.Stopped: case ServiceStatus.Stopping: embedBuilder.Color = DiscordColor.Red; break; case ServiceStatus.Processing: case ServiceStatus.Pausing: case ServiceStatus.Paused: embedBuilder.Color = DiscordColor.Orange; break; case ServiceStatus.Unknown: embedBuilder.Color = DiscordColor.DarkRed; break; default: embedBuilder.Color = DiscordColor.Gray; break; } var modules = NexusServiceMenuModules.ToList(); embedBuilder.AddField("Actions", GenerateActions(ctx.Client, modules)); var menuMsg = await ctx.RespondAsync(embed : embedBuilder); foreach (var module in modules.OrderBy(x => x.Settings.ViewOrder)) { module.CommandContext = ctx; module.Authentication = context; module.MenuMessage = menuMsg; await menuMsg.CreateReactionAsync(DiscordEmoji.FromName(ctx.Client, module.Settings.ActionCommandAttribute.EmojiName)); await System.Threading.Tasks.Task.Delay(250); } while (true) { var reactAction = await menuMsg.WaitForReactionAsync(ctx.User, TimeSpan.FromMinutes(5)); if (reactAction.TimedOut) { return; } if (reactAction.Result.User.Id != ctx.User.Id) { continue; } await ctx.TriggerTypingAsync(); await menuMsg.DeleteReactionAsync(reactAction.Result.Emoji, ctx.User); var modulePressed = modules.FirstOrDefault(x => x.Settings.ActionCommandAttribute.EmojiName == reactAction.Result.Emoji.GetDiscordName()); if (modulePressed != null) { #pragma warning disable 4014 System.Threading.Tasks.Task.Run(async() => { await modulePressed.DoAction(); }); #pragma warning restore 4014 } } }