public async Task SetupNotificationsInteractive <T>(EventContext e, DatabaseSettingId settingId) { List <string> options = Enum.GetNames(typeof(T)) .Select(x => x.ToLower() .Replace('_', ' ')) .ToList(); string settingName = settingId.ToString().ToLower().Replace('_', ' '); var sEmbed = SettingsBaseEmbed; sEmbed.Description = ($"What kind of {settingName} do you want"); sEmbed.AddInlineField("Options", string.Join("\n", options)); var sMsg = await sEmbed.ToEmbed().SendToChannel(e.Channel); int newSetting; IDiscordMessage msg = null; while (true) { msg = await e.EventSystem.GetCommandHandler <MessageListener>().WaitForNextMessage(e.CreateSession()); if (Enum.TryParse <LevelNotificationsSetting>(msg.Content.Replace(" ", "_"), true, out var setting)) { newSetting = (int)setting; break; } await sMsg.EditAsync(new EditMessageArgs() { embed = e.ErrorEmbed("Oh, that didn't seem right! Try again") .AddInlineField("Options", string.Join("\n", options)) .ToEmbed() }); } sMsg = await SettingsBaseEmbed .SetDescription("Do you want this to apply for every channel? say `yes` if you do.") .ToEmbed().SendToChannel(e.Channel as IDiscordGuildChannel); msg = await e.EventSystem.GetCommandHandler <MessageListener>().WaitForNextMessage(e.CreateSession()); bool global = (msg.Content.ToLower()[0] == 'y'); await SettingsBaseEmbed .SetDescription($"Setting `{settingName}` Updated!") .ToEmbed().SendToChannel(e.Channel as IDiscordGuildChannel); if (!global) { await Setting.UpdateAsync(e.Channel.Id, settingId, newSetting); } else { await Setting.UpdateGuildAsync(e.Guild, settingId, newSetting); } }
public async Task SetupNotificationsInteractive <T>(EventContext e, DatabaseSettingId settingId) { List <string> options = Enum.GetNames(typeof(T)) .Select(x => x.ToLower() .Replace('_', ' ')) .ToList(); string settingName = settingId.ToString().ToLower().Replace('_', ' '); var sMsg = await SettingsBaseEmbed .SetDescription($"What kind of {settingName} do you want") .AddInlineField("Options", string.Join("\n", options)) .SendToChannel(e.Channel); int newSetting; while (true) { var msg = await EventSystem.Instance.ListenNextMessageAsync(e.Channel.Id, e.Author.Id); if (Enum.TryParse <LevelNotificationsSetting>(msg.Content.Replace(" ", "_"), true, out var setting)) { newSetting = (int)setting; break; } sMsg.Modify(null, e.ErrorEmbed("Oh, that didn't seem right! Try again") .AddInlineField("Options", string.Join("\n", options))); } sMsg = await SettingsBaseEmbed .SetDescription("Do you want this to apply for every channel? say `yes` if you do.") .SendToChannel(e.Channel); var cMsg = await EventSystem.Instance.ListenNextMessageAsync(e.Channel.Id, e.Author.Id); bool global = (cMsg.Content.ToLower()[0] == 'y'); await SettingsBaseEmbed .SetDescription($"Setting `{settingName}` Updated!") .SendToChannel(e.Channel); if (!global) { await Setting.UpdateAsync(e.Channel.Id, settingId, newSetting); } else { await Setting.UpdateGuildAsync(e.Guild, settingId, newSetting); } }