Created Poll Maker plugin

This commit is contained in:
2025-05-22 20:18:50 +03:00
parent f70e8a565b
commit 8ba9448beb
4 changed files with 235 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
namespace PollMaker.Internal;
internal sealed record PollState(string Question, string[] Options)
{
public List<HashSet<ulong>> Votes { get; } =
Enumerable.Range(0, Options.Length).Select(_ => new HashSet<ulong>()).ToList();
public bool IsOpen { get; private set; } = true;
public void Close() => IsOpen = false;
/// <summary>
/// Toggle the members vote.
/// Clicking the **same button** again removes their vote;
/// clicking a **different** button moves the vote.
/// </summary>
public void ToggleVote(int optionIdx, ulong userId)
{
if (!IsOpen) return;
if (Votes[optionIdx].Contains(userId))
{
Votes[optionIdx].Remove(userId);
return;
}
foreach (var set in Votes)
set.Remove(userId);
Votes[optionIdx].Add(userId);
}
}