-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
144 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using DXKumaBot.Bot; | ||
using DXKumaBot.Bot.Message; | ||
using System.Text.RegularExpressions; | ||
|
||
namespace DXKumaBot.Functions; | ||
|
||
public sealed partial class Choose : RegexFunctionBase | ||
{ | ||
protected override async Task Main(object? sender, MessageReceivedEventArgs args) | ||
{ | ||
Match match = MessageRegex().Match(args.Text); | ||
HashSet<string> values = []; | ||
foreach (Group group in match.Groups) | ||
{ | ||
if (group.Index is 0) | ||
{ | ||
continue; | ||
} | ||
|
||
foreach (Capture capture in group.Captures) | ||
{ | ||
values.Add(capture.Value); | ||
} | ||
} | ||
|
||
switch (values.Count) | ||
{ | ||
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; | ||
} | ||
} | ||
} | ||
|
||
[GeneratedRegex("^(?:.*?是)(.+?)(?:还是(.+?))+$", | ||
RegexOptions.IgnoreCase | RegexOptions.Compiled | RegexOptions.Singleline)] | ||
protected override partial Regex MessageRegex(); | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using DXKumaBot.Bot; | ||
using DXKumaBot.Bot.Message; | ||
using DXKumaBot.Utils; | ||
using System.Text.RegularExpressions; | ||
|
||
namespace DXKumaBot.Functions; | ||
|
||
public sealed partial class Cum : RegexFunctionBase | ||
{ | ||
protected override async Task Main(object? sender, MessageReceivedEventArgs args) | ||
{ | ||
int index = Random.Shared.Choose([9, 1]); | ||
string filePath = Path.Combine("Static", nameof(Cum), $"{index}.png"); | ||
MediaMessage message = new(MediaType.Photo, filePath); | ||
await args.Reply(message); | ||
} | ||
|
||
[GeneratedRegex("dlxcum", RegexOptions.IgnoreCase | RegexOptions.Compiled | RegexOptions.Singleline)] | ||
protected override partial Regex MessageRegex(); | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using DXKumaBot.Bot; | ||
using DXKumaBot.Bot.Message; | ||
using DXKumaBot.Utils; | ||
using System.Text.RegularExpressions; | ||
|
||
namespace DXKumaBot.Functions; | ||
|
||
public sealed partial class WannaCao : RegexFunctionBase | ||
{ | ||
private readonly (string, int)[] _replies = | ||
[ | ||
("变态!!!", 0), | ||
("走开!!!", 0), | ||
("别靠近迪拉熊!!!", 0), | ||
("迪拉熊不和你玩了!", 0), | ||
("信不信迪拉熊吃你绝赞!", 0), | ||
("信不信迪拉熊吃你星星!", 0), | ||
("你不能这样对迪拉熊!", 0), | ||
("迪拉熊不想理你了,哼!", 0), | ||
("不把白潘AP了就别想!", 0), | ||
("……你会对迪拉熊负责的,对吧?", 1) | ||
]; | ||
|
||
private readonly int[] _weights = [11, 11, 11, 11, 11, 11, 11, 11, 11, 1]; | ||
|
||
protected override async Task Main(object? sender, MessageReceivedEventArgs args) | ||
{ | ||
int index = Random.Shared.Choose(_weights); | ||
(string Text, int PhotoIndex) reply = _replies[index]; | ||
string filePath = Path.Combine("Static", nameof(WannaCao), $"{reply.PhotoIndex}.png"); | ||
MediaMessage message = new(MediaType.Photo, filePath); | ||
await args.Reply(new(reply.Text, message)); | ||
} | ||
|
||
[GeneratedRegex("^(香草|想草)(迪拉熊|dlx)$", RegexOptions.IgnoreCase | RegexOptions.Compiled | RegexOptions.Singleline)] | ||
protected override partial Regex MessageRegex(); | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
namespace DXKumaBot.Utils; | ||
|
||
public static class RandomExtensions | ||
{ | ||
public static int Choose(this Random random, IList<int> weights) | ||
{ | ||
int totalWeight = weights.Sum(); | ||
int randomResult = random.Next(totalWeight); | ||
for (int index = 0; index < weights.Count; index++) | ||
{ | ||
randomResult -= weights[index]; | ||
if (randomResult < weights[index]) | ||
{ | ||
return index; | ||
} | ||
} | ||
|
||
return -1; | ||
} | ||
} |