diff --git a/src/Bot/BotInstance.cs b/src/Bot/BotInstance.cs index 9b02771..851835f 100644 --- a/src/Bot/BotInstance.cs +++ b/src/Bot/BotInstance.cs @@ -15,7 +15,14 @@ public sealed class BotInstance(Config config) private static void RegisterFunctions() { LoveYou loveYou = new(); + WannaCao wannaCao = new(); + Cum cum = new(); + Choose choose = new(); + loveYou.Register(); + wannaCao.Register(); + cum.Register(); + choose.Register(); } private void RegisterEvents() diff --git a/src/Bot/Telegram/TgBot.cs b/src/Bot/Telegram/TgBot.cs index d1a5614..a079486 100644 --- a/src/Bot/Telegram/TgBot.cs +++ b/src/Bot/Telegram/TgBot.cs @@ -53,7 +53,7 @@ private async Task SendMessageAsync(long id, MessagePair messages, int? threadId { if (messages.Media is null) { - await _bot.SendTextMessageAsync(id, messages.Text!.Text, threadId, ParseMode.MarkdownV2, + await _bot.SendTextMessageAsync(id, messages.Text!.Text, threadId, replyParameters: source is null ? default(ReplyParameters) : source); return; } @@ -62,11 +62,11 @@ await _bot.SendTextMessageAsync(id, messages.Text!.Text, threadId, ParseMode.Mar switch (messages.Media.Type) { case MediaType.Audio: - await _bot.SendAudioAsync(id, file, threadId, messages.Text?.Text, ParseMode.MarkdownV2, + await _bot.SendAudioAsync(id, file, threadId, messages.Text?.Text, replyParameters: source is null ? default(ReplyParameters) : source); break; case MediaType.Photo: - await _bot.SendPhotoAsync(id, file, threadId, messages.Text?.Text, ParseMode.MarkdownV2, + await _bot.SendPhotoAsync(id, file, threadId, messages.Text?.Text, replyParameters: source is null ? default(ReplyParameters) : source); break; default: diff --git a/src/Functions/Choose.cs b/src/Functions/Choose.cs new file mode 100644 index 0000000..450dff0 --- /dev/null +++ b/src/Functions/Choose.cs @@ -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 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(); +} \ No newline at end of file diff --git a/src/Functions/Cum.cs b/src/Functions/Cum.cs new file mode 100644 index 0000000..2589802 --- /dev/null +++ b/src/Functions/Cum.cs @@ -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(); +} \ No newline at end of file diff --git a/src/Functions/LoveYou.cs b/src/Functions/LoveYou.cs index b4940b2..ce8ef4a 100644 --- a/src/Functions/LoveYou.cs +++ b/src/Functions/LoveYou.cs @@ -8,7 +8,7 @@ public sealed partial class LoveYou : RegexFunctionBase { protected override async Task Main(object? sender, MessageReceivedEventArgs args) { - string filePath = Path.Combine("Static", "LoveYou", "0.png"); + string filePath = Path.Combine("Static", nameof(LoveYou), "0.png"); MediaMessage message = new(MediaType.Photo, filePath); await args.Reply(new("迪拉熊也喜欢你❤️", message)); } diff --git a/src/Functions/WannaCao.cs b/src/Functions/WannaCao.cs new file mode 100644 index 0000000..1fb8b95 --- /dev/null +++ b/src/Functions/WannaCao.cs @@ -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(); +} \ No newline at end of file diff --git a/src/Utils/RandomExtensions.cs b/src/Utils/RandomExtensions.cs new file mode 100644 index 0000000..aa41b67 --- /dev/null +++ b/src/Utils/RandomExtensions.cs @@ -0,0 +1,20 @@ +namespace DXKumaBot.Utils; + +public static class RandomExtensions +{ + public static int Choose(this Random random, IList 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; + } +} \ No newline at end of file