mirror of
https://github.com/RPCS3/discord-bot.git
synced 2025-02-07 19:06:24 +00:00
add some spice to update announcements
This commit is contained in:
parent
c454308937
commit
b2ffc15540
@ -183,7 +183,7 @@ Example usage:
|
||||
|
||||
if (updateAnnouncementRestore && info?.CurrentBuild != null)
|
||||
info.LatestBuild = info.CurrentBuild;
|
||||
var embed = await info.AsEmbedAsync(updateAnnouncement).ConfigureAwait(false);
|
||||
var embed = await info.AsEmbedAsync(discordClient, updateAnnouncement).ConfigureAwait(false);
|
||||
if (info == null || embed.Color.Value.Value == Config.Colors.Maintenance.Value)
|
||||
{
|
||||
if (updateAnnouncementRestore)
|
||||
@ -192,7 +192,7 @@ Example usage:
|
||||
return false;
|
||||
}
|
||||
|
||||
embed = await CachedUpdateInfo.AsEmbedAsync(updateAnnouncement).ConfigureAwait(false);
|
||||
embed = await CachedUpdateInfo.AsEmbedAsync(discordClient, updateAnnouncement).ConfigureAwait(false);
|
||||
}
|
||||
else if (!updateAnnouncementRestore)
|
||||
CachedUpdateInfo = info;
|
||||
@ -226,7 +226,7 @@ Example usage:
|
||||
}
|
||||
|
||||
if (!updateAnnouncement)
|
||||
embed = await CachedUpdateInfo.AsEmbedAsync(true).ConfigureAwait(false);
|
||||
embed = await CachedUpdateInfo.AsEmbedAsync(discordClient, true).ConfigureAwait(false);
|
||||
if (embed.Color.Value.Value == Config.Colors.Maintenance.Value)
|
||||
return false;
|
||||
|
||||
|
@ -132,7 +132,7 @@ namespace CompatBot.Commands
|
||||
if (updateInfo != null)
|
||||
{
|
||||
if (DateTime.TryParse(updateInfo.LatestBuild?.Datetime, out var masterBuildTime) && masterBuildTime.Ticks >= mergeTime.Ticks)
|
||||
embed = await updateInfo.AsEmbedAsync(false, embed).ConfigureAwait(false);
|
||||
embed = await updateInfo.AsEmbedAsync(client, false, embed).ConfigureAwait(false);
|
||||
else
|
||||
{
|
||||
var waitTime = TimeSpan.FromMinutes(5);
|
||||
|
@ -156,7 +156,7 @@ namespace CompatBot.Utils
|
||||
return GetEmoji(client, emojiName, fallbackEmoji == null ? null : DiscordEmoji.FromUnicode(fallbackEmoji));
|
||||
}
|
||||
|
||||
public static DiscordEmoji GetEmoji(this DiscordClient client, string emojiName, DiscordEmoji fallbackEmoji = null)
|
||||
public static DiscordEmoji GetEmoji(this DiscordClient client, string emojiName, DiscordEmoji fallbackEmoji)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -35,5 +35,16 @@ namespace CompatBot.Utils
|
||||
{
|
||||
yield return item;
|
||||
}
|
||||
|
||||
public static T RandomElement<T>(this IList<T> collection, int? seed = null)
|
||||
{
|
||||
if (collection?.Count > 0)
|
||||
{
|
||||
var rng = seed.HasValue ? new Random(seed.Value) : new Random();
|
||||
return collection[rng.Next(collection.Count)];
|
||||
}
|
||||
else
|
||||
return default;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ using System.Threading.Tasks;
|
||||
using CompatApiClient.POCOs;
|
||||
using CompatApiClient.Utils;
|
||||
using CompatBot.EventHandlers;
|
||||
using DSharpPlus;
|
||||
using DSharpPlus.Entities;
|
||||
using GithubClient.POCOs;
|
||||
|
||||
@ -16,7 +17,7 @@ namespace CompatBot.Utils.ResultFormatters
|
||||
private static readonly GithubClient.Client githubClient = new GithubClient.Client();
|
||||
private static readonly AppveyorClient.Client appveyorClient = new AppveyorClient.Client();
|
||||
|
||||
public static async Task<DiscordEmbedBuilder> AsEmbedAsync(this UpdateInfo info, bool includePrBody = false, DiscordEmbedBuilder builder = null)
|
||||
public static async Task<DiscordEmbedBuilder> AsEmbedAsync(this UpdateInfo info, DiscordClient client, bool includePrBody = false, DiscordEmbedBuilder builder = null)
|
||||
{
|
||||
if ((info?.LatestBuild?.Windows?.Download ?? info?.LatestBuild?.Linux?.Download) == null)
|
||||
return builder ?? new DiscordEmbedBuilder {Title = "Error", Description = "Error communicating with the update API. Try again later.", Color = Config.Colors.Maintenance};
|
||||
@ -36,7 +37,11 @@ namespace CompatBot.Utils.ResultFormatters
|
||||
{
|
||||
latestPrInfo = await githubClient.GetPrInfoAsync(latestPr.Value, Config.Cts.Token).ConfigureAwait(false);
|
||||
url = latestPrInfo?.HtmlUrl ?? "https://github.com/RPCS3/rpcs3/pull/" + latestPr;
|
||||
prDesc = $"PR #{latestPr} by {latestPrInfo?.User?.Login ?? "???"}";
|
||||
var userName = latestPrInfo?.User?.Login ?? "???";
|
||||
var emoji = GetUserNameEmoji(client, userName);
|
||||
if (emoji != null)
|
||||
userName += " " + emoji;
|
||||
prDesc = $"PR #{latestPr} by {userName}";
|
||||
}
|
||||
else
|
||||
prDesc = "PR #???";
|
||||
@ -126,6 +131,33 @@ namespace CompatBot.Utils.ResultFormatters
|
||||
return $"[⏬ {text}]({link}){" ".FixSpaces()}";
|
||||
}
|
||||
|
||||
private static DiscordEmoji GetUserNameEmoji(DiscordClient client, string githubLogin)
|
||||
=> client.GetEmoji(githubLogin switch
|
||||
{
|
||||
#if DEBUG
|
||||
_ => client.Guilds.Values.First().Emojis.Values.ToList().RandomElement(githubLogin.GetHashCode()).GetDiscordName(),
|
||||
#else
|
||||
"Nekotekina" => ":nekotekina:",
|
||||
"kd-11" => ":kd11:",
|
||||
"Megamouse" => ":megamouse:",
|
||||
"elad335" => ":elad:",
|
||||
"hcorion" => ":hcorion:",
|
||||
"AniLeo" => ":ani:",
|
||||
"Talkashie" => ":font:",
|
||||
"jarveson" => ":jarves:",
|
||||
/*
|
||||
"RipleyTom" => null,
|
||||
"VelocityRa" => null,
|
||||
"Whatcookie" => null,
|
||||
"CookiePLMonster" => null,
|
||||
"Ruipin" => null,
|
||||
"rajkosto" => null,
|
||||
"isJuhn" => null,
|
||||
*/
|
||||
_ => null,
|
||||
#endif
|
||||
});
|
||||
|
||||
public static TimeSpan? GetUpdateDelta(DateTime? latest, DateTime? current)
|
||||
{
|
||||
if (latest.HasValue && current.HasValue)
|
||||
|
Loading…
x
Reference in New Issue
Block a user