Created
February 26, 2024 08:04
-
-
Save reitowo/73d840cbb6ecb10c535f4b7ff111ecc1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public override async Task OnAtMessage(TBot z, Message msg) { | |
if (msg.Author.Id != App.MeId || msg.Content != "!抽装扮") | |
return; | |
var ctx = _store.Contexts.First(); | |
string[] dynamicIds = ["901551426888532038", "901677050380681222"]; | |
var userPossibilities = new Dictionary<string, int>(); | |
var replies = new List<BiliUserContext.ReplyRecord>(); | |
foreach (var id in dynamicIds) { | |
var dyn = await ctx.GetDynamic(id); | |
var commentId = dyn["data"]!["item"]!["basic"]!["comment_id_str"]!.Value<string>(); | |
var commentType = dyn["data"]["item"]["basic"]["comment_type"]!.Value<string>(); | |
var comments = await ctx.GetReplyList(commentId, commentType); | |
var reactions = await ctx.GetReactionList(id); | |
var reposts = reactions.Where(a => a.Type == BiliUserContext.ReactionType.Repost).ToList(); | |
replies.AddRange(comments); | |
foreach (var comment in comments) { | |
if (comment.Time > new DateTime(2024, 2, 26, 12, 0, 0)) | |
continue; | |
userPossibilities.TryAdd(comment.UserId, 0); | |
userPossibilities[comment.UserId] += reposts.Any(a => a.UserId == comment.UserId) ? 5 : 1; | |
} | |
} | |
var users = userPossibilities.Keys.ToList(); | |
users.Sort((a, b) => long.Parse(a).CompareTo(long.Parse(b))); | |
foreach (var u in userPossibilities) { | |
Logger.LogTrace($"{u.Key}: {u.Value}"); | |
} | |
var sb = new StringBuilder(); | |
var seed = 297702; | |
sb.AppendLine($"## 任务"); | |
sb.AppendLine($"> 随机数种子:{seed}\n"); | |
sb.AppendLine($"> 动态:{string.Join(", ", dynamicIds)}\n"); | |
sb.AppendLine($"> 规则:评论+1, 转发+5, 不重复得奖\n"); | |
sb.AppendLine($"## 结果"); | |
var rnd = new Random(seed); | |
var suiteConsume = new Queue<int>([37, 38, 39, 40, 41, 42, 43, 44, 49, 53]); | |
while (suiteConsume.Count != 0) { | |
var suite = suiteConsume.Dequeue(); | |
var total = 0; | |
var map = new List<string>(); | |
foreach (var user in users) { | |
map.AddRange(Enumerable.Repeat(user, userPossibilities[user])); | |
total += userPossibilities[user]; | |
} | |
var select = rnd.Next(0, total); | |
var userId = map[select]; | |
var userName = replies.First(a => a.UserId == userId).Username; | |
sb.AppendLine($"- {suite}: {userName} {map[select]} ({select}/{total})"); | |
users.Remove(userId); | |
} | |
var image = await MarkdownRenderer.Instance.MarkdownSnapshot(sb.ToString()); | |
await z.api.GetMessageApi().SendMessageAsync(msg.ChannelId, imageData: image, passiveMsgId: msg.Id); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment