From 231d1b5d89c1af93710a8da72e21636a351ccd99 Mon Sep 17 00:00:00 2001 From: Ben Harris Date: Tue, 12 Dec 2017 10:57:34 -0500 Subject: [PATCH] PollOption.Votes is now an int --- Services/PollService.cs | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/Services/PollService.cs b/Services/PollService.cs index 411cca1..2d29a5e 100644 --- a/Services/PollService.cs +++ b/Services/PollService.cs @@ -9,34 +9,26 @@ namespace dotbot.Services { public class PollService { - private readonly DiscordSocketClient _discord; + private readonly DiscordSocketClient ; public Dictionary currentPolls; public PollService(DiscordSocketClient discord) { currentPolls = new Dictionary(); - _discord = discord; - _discord.ReactionAdded += OnReactionAddedAsync; + discord.ReactionAdded += OnReactionAddedAsync; } private Task OnReactionAddedAsync(Cacheable CachedMessage, ISocketMessageChannel Channel, SocketReaction Reaction) { if (currentPolls.ContainsKey(Channel.Id)) { - currentPolls[Channel.Id].Options.First(o => o.Message.Id == CachedMessage.Id).Message = CachedMessage.Value; + currentPolls[Channel.Id].Options.First(o => o.Message.Id == CachedMessage.Id).Votes++; } - Console.WriteLine(CachedMessage.Value.Reactions.Count); - + Console.WriteLine($"{Reaction.Emote} reaction added to {CachedMessage.Id} in {Channel.Name}"); return Task.CompletedTask; } - //var msg = s as SocketUserMessage; - //if (msg == null) return; - //var context = new SocketCommandContext(_discord, msg); - //if (!currentPolls.ContainsKey(context.Channel.Id)) return; - - } @@ -46,14 +38,14 @@ namespace dotbot.Services public List Options { get; set; } public bool IsOpen { get; set; } public IUser Owner { get; set; } - public PollOption Winner => Options.OrderBy(o => o.Votes).First(); + public PollOption Winner => Options.OrderBy(o => o.Votes).Last(); } public class PollOption { public string Text { get; set; } public IUserMessage Message { get; set; } - public int Votes => Message.Reactions.Count; + public int Votes { get; set; } public override string ToString() => Text; } }