Skip to content

Commit

Permalink
Merge pull request #10 from approvers/feature/rinia/shuffle/002_info
Browse files Browse the repository at this point in the history
GachaInfo: 排出率を表示するコマンドを実装
  • Loading branch information
2RiniaR authored Jan 20, 2024
2 parents 2e2ccd1 + 88c1a31 commit 484ede8
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 31 deletions.
20 changes: 20 additions & 0 deletions Common/DiscordMessageUtility.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System.Text;
using Discord;

namespace Approvers.King.Common;

public static class DiscordMessageUtility
{
public static string Table(IEnumerable<(string key, string value)> records)
{
var recordList = records.ToList();
var maxLength = recordList.Max(r => r.key.Length);
var sb = new StringBuilder();
foreach (var (key, value) in recordList)
{
sb.AppendLine($"| {value.PadLeft(maxLength)} | {Format.Sanitize(key)}");
}

return Format.Code(sb.ToString());
}
}
5 changes: 5 additions & 0 deletions Common/MasterManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ public static class MasterManager
"10連", "ガチャ", "おみくじ",
};

public static IReadOnlyList<string> GachaInfoTriggerMessages => new List<string>
{
"今日", "本日", "確率", "何パー", "何%", "何%", "分布", "排出", "today",
};

public static IReadOnlyList<string> RidiculeMessages => new List<string>
{
"雑魚", "雑魚じゃん", "雑魚すぎ",
Expand Down
16 changes: 0 additions & 16 deletions Common/PresenterBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,4 @@ public static Embed ErrorEmbed(string message)
.WithCurrentTimestamp()
.Build();
}

public static class Format
{
public static string Table(IEnumerable<(string key, string value)> records)
{
var recordList = records.ToList();
var maxLength = recordList.Max(r => r.key.Length);
var sb = new StringBuilder();
foreach (var (key, value) in recordList)
{
sb.AppendLine($"| {value.PadLeft(maxLength)} | {Discord.Format.Sanitize(key)}");
}

return Discord.Format.Code(sb.ToString());
}
}
}
15 changes: 15 additions & 0 deletions Events/GachaInfoCommandPresenter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Approvers.King.Common;

namespace Approvers.King.Events;

public class GachaInfoCommandPresenter : DiscordMessagePresenterBase
{
protected override async Task MainAsync()
{
// 排出率を投稿する
await DiscordManager.Client
.GetGuild(SettingManager.DiscordTargetGuildId)
.GetTextChannel(SettingManager.DiscordMainChannelId)
.SendMessageAsync(embed: GachaUtility.GetInfoEmbedBuilder().Build());
}
}
16 changes: 1 addition & 15 deletions Events/GachaRateUpdatePresenter.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
using Approvers.King.Common;
using Discord;

namespace Approvers.King.Events;

public class GachaRateUpdatePresenter : SchedulerJobPresenterBase
{
private static readonly string IssoSmileStamp = "<:isso_smile:1081501060369236069>";

protected override async Task MainAsync()
{
// 排出確率を変える
Expand All @@ -15,22 +12,11 @@ protected override async Task MainAsync()

// 名前を更新する
var guild = DiscordManager.Client.GetGuild(SettingManager.DiscordTargetGuildId);

await guild.CurrentUser.ModifyAsync(x =>
x.Nickname = $"{GachaManager.Instance.RareReplyRate:P0}の確率でわかってくれる創造主");

// 排出率を投稿する
var records = GachaManager.Instance.ReplyMessageTable
.OrderByDescending(x => x.Rate)
.Select(x => (x.Message, x.Rate.ToString("P0")));
var embed = new EmbedBuilder()
.WithTitle(
$"{IssoSmileStamp}{IssoSmileStamp}{IssoSmileStamp} 本日のいっそう {IssoSmileStamp}{IssoSmileStamp}{IssoSmileStamp}")
.WithColor(new Color(0xf1, 0xc4, 0x0f))
.WithDescription($"本日は {Discord.Format.Bold($"{GachaManager.Instance.RareReplyRate:P0}")} の確率で反応します")
.AddField("排出確率", Format.Table(records));

await guild.GetTextChannel(SettingManager.DiscordMainChannelId)
.SendMessageAsync(embed: embed.Build());
.SendMessageAsync(embed: GachaUtility.GetInfoEmbedBuilder().Build());
}
}
20 changes: 20 additions & 0 deletions Events/GachaUtility.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Approvers.King.Common;
using Discord;

namespace Approvers.King.Events;

public static class GachaUtility
{
public static EmbedBuilder GetInfoEmbedBuilder()
{
var records = GachaManager.Instance.ReplyMessageTable
.OrderByDescending(x => x.Rate)
.Select(x => (x.Message, x.Rate.ToString("P0")));
return new EmbedBuilder()
.WithTitle(
$"{IssoUtility.SmileStamp}{IssoUtility.SmileStamp}{IssoUtility.SmileStamp} 本日のいっそう {IssoUtility.SmileStamp}{IssoUtility.SmileStamp}{IssoUtility.SmileStamp}")
.WithColor(new Color(0xf1, 0xc4, 0x0f))
.WithDescription($"本日は {Format.Bold($"{GachaManager.Instance.RareReplyRate:P0}")} の確率で反応します")
.AddField("排出確率", DiscordMessageUtility.Table(records));
}
}
6 changes: 6 additions & 0 deletions Events/IssoUtility.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Approvers.King.Events;

public static class IssoUtility
{
public const string SmileStamp = "<:isso_smile:1081501060369236069>";
}
7 changes: 7 additions & 0 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ private static async Task OnMessageReceived(SocketMessage message)
return;
}

if (MasterManager.GachaInfoTriggerMessages.Any(userMessage.Content.Contains))
{
// 排出率を投稿する
await DiscordManager.ExecuteAsync<GachaInfoCommandPresenter>(userMessage);
return;
}

// 返信
await DiscordManager.ExecuteAsync<InteractReplyPresenter>(userMessage);
return;
Expand Down

0 comments on commit 484ede8

Please sign in to comment.