forked from Sarah/Lieb-Website
implemented polls in the discord bot
This commit is contained in:
parent
1d999e89bf
commit
715b14ecc5
13 changed files with 277 additions and 6 deletions
|
@ -5,6 +5,7 @@ using System.Text.Json;
|
|||
using System.Text;
|
||||
using Lieb.Models.GuildWars2.Raid;
|
||||
using Lieb.Models;
|
||||
using Lieb.Models.Poll;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Lieb.Data
|
||||
|
@ -421,5 +422,42 @@ namespace Lieb.Data
|
|||
}
|
||||
catch {}
|
||||
}
|
||||
|
||||
public async Task SendPoll(Poll poll, List<ulong>? userIds = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
var httpClient = _httpClientFactory.CreateClient(Constants.HttpClientName);
|
||||
|
||||
if(userIds == null)
|
||||
{
|
||||
userIds = poll.Answers.Select(a => a.UserId).ToList();
|
||||
}
|
||||
|
||||
ApiPoll apiPoll = new ApiPoll()
|
||||
{
|
||||
AllowCustomAnswer = poll.AllowCustomAnswer,
|
||||
PollId = poll.PollId,
|
||||
Question = poll.Question,
|
||||
UserIds = userIds,
|
||||
Options = poll.Options.ToDictionary(o => o.PollOptionId, o => o.Name)
|
||||
};
|
||||
|
||||
var messageItemJson = new StringContent(
|
||||
JsonSerializer.Serialize(apiPoll),
|
||||
Encoding.UTF8,
|
||||
Application.Json);
|
||||
|
||||
if(poll.AnswerType == AnswerType.Dropdown)
|
||||
{
|
||||
var httpResponseMessage = await httpClient.PostAsync("raid/SendDropdownPoll", messageItemJson);
|
||||
}
|
||||
else
|
||||
{
|
||||
var httpResponseMessage = await httpClient.PostAsync("raid/SendButtonPoll", messageItemJson);
|
||||
}
|
||||
}
|
||||
catch {}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue