mirror of
https://git.recroomarchive.org/RecRoomArchive/RRAC.git
synced 2026-09-08 14:41:25 -07:00
Initialize repository
Added basic info to get in game for like...August 2016 ;-; It's not much but it's a start
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
using RecRoomArchive.Models.API.Activities;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace RecRoomArchive.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// Service used to get the message of the day as it is used in multiple areas of the server
|
||||
/// </summary>
|
||||
public class MessageOfTheDayService
|
||||
{
|
||||
/// <summary>
|
||||
/// HttpClient for making requests to Gitea
|
||||
/// </summary>
|
||||
private static readonly HttpClient httpClient = new HttpClient();
|
||||
|
||||
/// <summary>
|
||||
/// MessageOfTheDay reference
|
||||
/// </summary>
|
||||
private static string? MessageOfTheDay { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the message of the day from Gitea. If the URL cannot be resolved, it will fall back to "Welcome to RecRoomArchive!"
|
||||
/// </summary>
|
||||
/// <returns>String related to the Message of the Day</returns>
|
||||
public async Task<string> GetMessageOfTheDay(string? version = null)
|
||||
{
|
||||
// I wouldn't want to re-request the MOTD from the server a bunch of times...
|
||||
if (string.IsNullOrEmpty(MessageOfTheDay))
|
||||
{
|
||||
var motd = await httpClient.GetAsync($"https://git.recroomarchive.org/RecRoomArchive/RRAC/raw/branch/main/MOTD");
|
||||
if (!motd.IsSuccessStatusCode)
|
||||
return "Welcome to RecRoomArchive!";
|
||||
|
||||
MessageOfTheDay = await motd.Content.ReadAsStringAsync();
|
||||
}
|
||||
|
||||
return MessageOfTheDay;
|
||||
}
|
||||
|
||||
// move out of motdservice
|
||||
private DateTime CharadesWordsLastFetchedAt { get; set; }
|
||||
private List<CharadesWord> CachedCharadesWords { get; set; } = [];
|
||||
|
||||
public async Task <List<CharadesWord>> GetCharadesWordsList()
|
||||
{
|
||||
if (CharadesWordsLastFetchedAt - DateTime.UtcNow > TimeSpan.FromMinutes(30))
|
||||
return CachedCharadesWords;
|
||||
|
||||
var request = await httpClient.GetAsync("https://git.recroomarchive.org/RecRoomArchive/RRAC/raw/branch/main/CharadesWords");
|
||||
if (!request.IsSuccessStatusCode)
|
||||
return [];
|
||||
|
||||
var words = await request.Content.ReadAsStringAsync();
|
||||
if (words == null)
|
||||
return [];
|
||||
|
||||
CachedCharadesWords = JsonSerializer.Deserialize<List<CharadesWord>>(words)!;
|
||||
|
||||
return CachedCharadesWords;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user