public bool StartPBG(PushButtonGame game, DiscordSocketClient client) { var ph = new Common.PushButtonHandler(game, client); if (ActivePBG.TryAdd(game.Channel, ph)) { ph.OnResponse += pbg_onresp; return(true); } return(false); }
public async Task PushTheButton(string benefit, string consquence, int timeout = 30) { benefit = benefit.FirstCharToLower().Trim(); consquence = consquence.FirstCharToLower().Trim(); PushButtonGame Game = new PushButtonGame { Channel = Context.Channel.Id, Benefit = benefit, Consequence = consquence, Responses = new HashSet <ButtonResponse>() }; if (timeout > 300) { timeout = 0; } if (timeout > 0) { timeout = timeout * 1000; } else { timeout = 30000; } if (_pushButtonService.StartPBG(Game, (DiscordSocketClient)Context.Client)) { EmbedBuilder embed = new EmbedBuilder().WithOkColour().WithTitle("Push The Button Game.").WithDescription($"Would you push the button if...") .AddField(new EmbedFieldBuilder().WithName($"Pro").WithValue($"{benefit}").WithIsInline(true)) .AddField(new EmbedFieldBuilder().WithName("...").WithValue("*but*").WithIsInline(true)) .AddField(new EmbedFieldBuilder().WithName($"Con?").WithValue($"{consquence}?").WithIsInline(true)) .WithFooter(new EmbedFooterBuilder().WithText($"Type yes/no now! You have {timeout / 1000} seconds.")); await Context.Channel.BlankEmbedAsync(embed.Build()); await Task.Delay(timeout); await _pushButtonService.EndGameInChannel(Context.Guild, Context.Channel); } }
public async Task EndGameInChannel(IGuild guild, IMessageChannel ChannelID) { PushButtonGame game = StopPBG(ChannelID.Id); if (game != null) { //Pushed int total = game.Responses.Count; int pushed = game.Responses.Where(x => x.Pushed == true).Count(); int notpushed = total - pushed; EmbedBuilder embed = new EmbedBuilder().WithOkColour() .WithTitle("Push the Button Game Results.") .WithDescription($"Would you push the button if...") .AddField(new EmbedFieldBuilder().WithName($"Pro").WithValue($"{game.Benefit}").WithIsInline(true)) .AddField(new EmbedFieldBuilder().WithName("...").WithValue("*but*").WithIsInline(true)) .AddField(new EmbedFieldBuilder().WithName($"Con?").WithValue($"{game.Consequence}?").WithIsInline(true)) .AddField(new EmbedFieldBuilder().WithName("✅ Yes").WithValue(pushed).WithIsInline(true)) .AddField(new EmbedFieldBuilder().WithName("❌ No").WithValue(notpushed).WithIsInline(true)); await ChannelID.BlankEmbedAsync(embed.Build()); } }
public PushButtonHandler(PushButtonGame game, DiscordSocketClient client) { Game = game; _client = client; _client.MessageReceived += TryResponse; }