Skip to content

Commit

Permalink
fix: fix weight of choose
Browse files Browse the repository at this point in the history
  • Loading branch information
Yushu2606 committed Jul 22, 2024
1 parent b116490 commit 5b14eab
Showing 1 changed file with 18 additions and 24 deletions.
42 changes: 18 additions & 24 deletions src/Functions/Choose.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public sealed partial class Choose : RegexFunctionBase
protected override async Task Main(object? sender, MessageReceivedEventArgs args)
{
Match match = MessageRegex().Match(args.Text);
HashSet<string> values = [];
List<string> values = [];
foreach (Group group in match.Groups)
{
if (group.Index is 0)
Expand All @@ -23,30 +23,24 @@ protected override async Task Main(object? sender, MessageReceivedEventArgs args
}
}

switch (values.Count)
if (values.Count is 0)
{
case 0:
{
string filePath = Path.Combine("Static", nameof(Choose), "1.png");
MediaMessage message = new(MediaType.Photo, filePath);
await args.Reply(new("没有选项要让迪拉熊怎么选嘛~", message));
break;
}
case 1:
{
string filePath = Path.Combine("Static", nameof(Choose), "1.png");
MediaMessage message = new(MediaType.Photo, filePath);
await args.Reply(new("就一个选项要让迪拉熊怎么选嘛~", message));
break;
}
default:
{
int index = Random.Shared.Next(values.Count);
string filePath = Path.Combine("Static", nameof(Choose), "0.png");
MediaMessage message = new(MediaType.Photo, filePath);
await args.Reply(new($"迪拉熊建议你选择“{values.ElementAt(index)}”呢~", message));
break;
}
string filePath = Path.Combine("Static", nameof(Choose), "1.png");
MediaMessage message = new(MediaType.Photo, filePath);
await args.Reply(new("没有选项要让迪拉熊怎么选嘛~", message));
}
else if (values.Count is 1 || values.All(x => x == values[0]))
{
string filePath = Path.Combine("Static", nameof(Choose), "1.png");
MediaMessage message = new(MediaType.Photo, filePath);
await args.Reply(new("就一个选项要让迪拉熊怎么选嘛~", message));
}
else
{
int index = Random.Shared.Next(values.Count);
string filePath = Path.Combine("Static", nameof(Choose), "0.png");
MediaMessage message = new(MediaType.Photo, filePath);
await args.Reply(new($"迪拉熊建议你选择“{values[index]}”呢~", message));
}
}

Expand Down

0 comments on commit 5b14eab

Please sign in to comment.