Skip to content

Commit

Permalink
Purchase: ランキング表示のコマンドを追加 (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
2RiniaR authored Nov 3, 2024
1 parent e9ff8a5 commit 613c462
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 0 deletions.
1 change: 1 addition & 0 deletions Common/Master/SettingMaster.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ private int GetInt(string key)
public int PricePerGachaOnce => GetInt(nameof(PricePerGachaOnce));
public int PricePerGachaTenTimes => GetInt(nameof(PricePerGachaTenTimes));
public int PricePerGachaOnceCertain => GetInt(nameof(PricePerGachaOnceCertain));
public int PurchaseInfoRankingViewUserCount => GetInt(nameof(PurchaseInfoRankingViewUserCount));
public string SilentReplyMessage => GetString(nameof(SilentReplyMessage));
}

Expand Down
1 change: 1 addition & 0 deletions Common/Master/TriggerPhraseMaster.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public enum TriggerType
GachaExecute,
GachaGet,
Marugame,
PurchaseGet,
}

[SuppressMessage("ReSharper", "UnassignedGetOnlyAutoProperty")]
Expand Down
47 changes: 47 additions & 0 deletions Events/PurchaseInfoCommandPresenter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System.Text;
using Approvers.King.Common;
using Discord;
using Microsoft.EntityFrameworkCore;

namespace Approvers.King.Events;

public class PurchaseInfoCommandPresenter : DiscordMessagePresenterBase
{
protected override async Task MainAsync()
{
await using var app = AppService.CreateSession();

var selfUser = await app.FindOrCreateUserAsync(Message.Author.Id);
var rankingUsers = await app.Users
.OrderByDescending(user => user.MonthlyPurchase)
.Take(MasterManager.SettingMaster.PurchaseInfoRankingViewUserCount)
.ToListAsync();

await SendReplyAsync(selfUser, rankingUsers);
}

private async Task SendReplyAsync(User selfUser, IReadOnlyList<User> rankingUsers)
{
var embedBuilder = new StringBuilder();
var order = 1;
foreach (var user in rankingUsers)
{
var scoreText = Math.Min(999_999_999, user.MonthlyPurchase).ToString("N0");
var whiteSpace = Math.Max(0, 11 - scoreText.Length);
var line =
Format.Code($"#{order:D2} - {"".PadLeft(whiteSpace, ' ')}{scoreText}†カス†(税込)") + " " +
MentionUtils.MentionUser(user.DiscordID);
embedBuilder.AppendLine(line);
order++;
}

var embed = new EmbedBuilder()
.WithColor(Color.LightOrange)
.AddField("おまえの今月の課金額", $"{selfUser.MonthlyPurchase:N0}†カス†(税込)", inline: true)
.AddField("ランキング", embedBuilder.ToString())
.WithCurrentTimestamp()
.Build();

await Message.ReplyAsync(embed: embed);
}
}
7 changes: 7 additions & 0 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ private static async Task OnMessageReceived(SocketMessage message)
return;
}

if (IsContainsTriggerPhrase(userMessage.Content, TriggerType.PurchaseGet))
{
// 課金情報の表示
await DiscordManager.ExecuteAsync<PurchaseInfoCommandPresenter>(userMessage);
return;
}

if (IsContainsTriggerPhrase(userMessage.Content, TriggerType.GachaExecute))
{
// 10連ガチャ
Expand Down

0 comments on commit 613c462

Please sign in to comment.