public async Task <bool> ProcessAsync(CQApiClient client, MessageEvent me, long srcid) { const string keyword = "色图"; const string keyword1 = "下班"; if (Global.msgFilter(me.message, false, s => s.TrimStart().Contains(keyword))) { foreach (var ele in me.message.data) { if (ele is ElementText) { byte[] img = System.IO.File.ReadAllBytes("e:\\static\\1.png"); await client.SendMessageAsync(me.messageType, srcid, new Message(new ElementImage(img))); } } } if (Global.msgFilter(me.message, false, s => s.TrimStart().Contains(keyword1))) { foreach (var ele in me.message.data) { if (ele is ElementText) { byte[] img = System.IO.File.ReadAllBytes("e:\\static\\2.jpg"); await client.SendMessageAsync(me.messageType, srcid, new Message(new ElementImage(img))); } } } return(false); }
public async static Task Dispatch( CQApiClient cli, MessageEvent e ) { if (System.IO.File.Exists("bots") && new List <string> ( System.IO.File.ReadLines("bots") ).Contains(e.sender.user_id.ToString())) { Console.Write(e.sender.user_id); Console.WriteLine(" is bot"); return; } try { string raw_text = ""; foreach (var i in e.message.data) { if (i.type == "text") { raw_text += i.data["text"]; } } var command = ParseCommand(raw_text); List <Task> to_run = new List <Task> (); if (await Module.loaded_modules.Values.AllAsync(async(mod) => { var result = await mod.InvokeCommand(command.Item1, command.Item2, e); if (!result.data.Any()) { return(true); } to_run.Append(cli.SendMessageAsync(e.GetEndpoint(), result)); return(false); })) { throw new CommandErrorException(); } await Task.WhenAll(to_run); } catch (CommandErrorException) { foreach (var i in Module.loaded_modules.Values) { var ret = await i.InvokeMessage(e.message, e); if (ret.data.Count != 0) //can respond { await cli.SendMessageAsync(e.GetEndpoint(), ret); } } } }
//Translator tr_ = new Translator(); async public Task <bool> ProcessAsync(CQApiClient client, MessageEvent me, long srcid) { bool isGroup = me is cqhttp.Cyan.Events.CQEvents.GroupMessageEvent; if (Global.msgFilter(me.message, isGroup, s => true)) { if (me.sender.user_id == Global.sbid) { return(true); } string ques = Global.msgText(me.message); string ans = ai_.chat(ques); if (ans == "") { return(false); } Message message = new Message(); if (isGroup) { message.data.Add(new ElementAt(me.sender.user_id)); } message.data.Add(new ElementText(ans)); await client.SendMessageAsync(me.messageType, srcid, message); return(true); } return(false); }
async public Task <bool> ProcessAsync(CQApiClient client, MessageEvent me, long srcid) { foreach (var ele in me.message.data) { if (ele is ElementAt) { return(false); } } if (me.message.ToString() == lastMsg_) { otherRepeater_++; if (otherRepeater_ > rand_.Next(3, 10)) { await client.SendMessageAsync(me.messageType, srcid, me.message); otherRepeater_ = 0; lastMsg_ = ""; return(true); } } else { lastMsg_ = me.message.ToString(); otherRepeater_ = 0; } return(false); }
public async Task <bool> ProcessAsync(CQApiClient client, MessageEvent me, long srcid) { const string keyword = "/mc"; const string keyword1 = "status"; if (Global.msgFilter(me.message, false, s => s.TrimStart().StartsWith(keyword))) { foreach (var ele in me.message.data) { if (ele is ElementText && (ele as ElementText).text.ToLower().Contains(keyword1)) { try { string ip = null; IPHostEntry iph = Dns.GetHostEntry("bgp.wintopidc.com"); foreach (IPAddress ip1 in iph.AddressList) { ip = ip1.ToString(); break; } MinecraftServerInfo a; IPAddress c; c = IPAddress.Parse(ip); IPEndPoint b = new IPEndPoint(c, 5035); a = MinecraftServerInfo.GetServerInformation(b); string statusString = "獭のMinecraft测试服" + "\n在线人数:" + a.CurrentPlayerCount + "\n最大人数:" + a.MaxPlayerCount + "\n服务器Motd:" + a.ServerMotd + "\n版本:" + a.MinecraftVersion; await client.SendMessageAsync(me.messageType, srcid, new Message(new ElementText(statusString))); } catch (Exception e) { await client.SendMessageAsync(me.messageType, srcid, new Message(new ElementText("服务器貌似没开?\n"), new ElementText(e.ToString()))); } } } } return(false); }
async public Task <bool> ProcessAsync(CQApiClient client, MessageEvent msgevt, long srcid) { if (Global.msgFilter(msgevt.message, true, s => s.Contains("图") || s.Contains("工"))) { Message msg = new Message(); foreach (var ele in msgevt.message.data) { if (ele is ElementAt) { ElementAt eat = ele as ElementAt; if (eat.data["qq"] == Global.botid.ToString()) { msg.data.Add(new ElementAt(Global.sbid)); continue; } } msg.data.Add(ele); } await client.SendMessageAsync(msgevt.messageType, srcid, msg); return(true); } if (Global.msgFilter(msgevt.message, true, s => s.Contains("下次区域") || s.Contains("下次鱼") || s.Contains("下次蛤") || s.Contains("下次塔"))) { string text = schedule_.nextMode(Global.msgText(msgevt.message)); if (text == "") { await client.SendMessageAsync(msgevt.messageType, srcid, new Message( new ElementAt(msgevt.sender.user_id), new ElementText(" 最近没有呢"))); } else { await client.SendMessageAsync(msgevt.messageType, srcid, new Message( new ElementAt(Global.sbid), new ElementText(" " + text))); } return(true); } return(false); }
async public Task <bool> ProcessAsync(CQApiClient client, MessageEvent me, long srcid) { const string trKeyword = "翻译"; bool isGroup = me is cqhttp.Cyan.Events.CQEvents.GroupMessageEvent; if (Global.msgFilter(me.message, isGroup, s => s.Contains("金句"))) { await client.SendMessageAsync(me.messageType, srcid, new Message( new ElementAt(me.sender.user_id), new ElementText(" " + gvj_.generate()))); return(true); } else if (Global.msgFilter(me.message, isGroup, s => s.Contains("签名") || s.Contains("個性佥洺"))) { await client.SendMessageAsync(me.messageType, srcid, new Message( new ElementAt(me.sender.user_id), new ElementText(" " + tr_.generate()))); return(true); } else if (Global.msgFilter(me.message, isGroup, s => s.TrimStart().StartsWith(trKeyword))) { foreach (var ele in me.message.data) { if (ele is ElementText) { string txt = (ele as ElementText).text.TrimStart(); if (!txt.StartsWith(trKeyword)) { continue; } txt = txt.Substring(trKeyword.Length); await client.SendMessageAsync(me.messageType, srcid, new Message( new ElementAt(me.sender.user_id), new ElementText(" " + tr_.translate(txt)))); return(true); } } } return(false); }
public async Task <bool> ProcessAsync(CQApiClient client, MessageEvent me, long srcid) { const string keyword = "/nuannuan"; const string keyword1 = "/nn"; const string keyword2 = "text"; if (Global.msgFilter(me.message, false, s => s.TrimStart().StartsWith(keyword)) || Global.msgFilter(me.message, false, s => s.TrimStart().StartsWith(keyword1))) { foreach (var ele in me.message.data) { if (ele is ElementText && !(ele as ElementText).text.ToLower().Contains(keyword2)) { WebClient mwc = new WebClient(); byte[] nndata = mwc.DownloadData("http://nuannuan.yorushika.co:5000/"); string nnjson = Encoding.UTF8.GetString(nndata); nnjd nnjsonb = JsonConvert.DeserializeObject <nnjd>(nnjson); if (nnjsonb.content.StartsWith("[CQ:")) { string nnI1 = nnjsonb.content.Replace("[CQ:", ""); string nnI = nnI1.Replace("]", ""); await client.SendMessageAsync(me.messageType, srcid, new Message(new Element(nnI), new ElementText("\nPowered by 露儿「Yorushika」"))); return(true); } } if (ele is ElementText && (ele as ElementText).text.ToLower().Contains(keyword2)) { WebClient mwc = new WebClient(); byte[] nndata = mwc.DownloadData("http://nuannuan.yorushika.co:5000/text/"); string nnjson = Encoding.UTF8.GetString(nndata); nnjd nnjsonb = JsonConvert.DeserializeObject <nnjd>(nnjson); await client.SendMessageAsync(me.messageType, srcid, new Message(new ElementText(nnjsonb.content), new ElementText("\nPowered by 露儿「Yorushika」"))); } } } return(false); }
async public Task <bool> ProcessAsync(CQApiClient client, MessageEvent me, long srcid) { bool isGroup = me is cqhttp.Cyan.Events.CQEvents.GroupMessageEvent; if (!Global.msgFilter(me.message, isGroup, s => true)) { return(false); } if (me.sender.user_id == Global.sbid) { return(false); } await client.SendMessageAsync(me.messageType, srcid, new Message( new ElementImage(imgConfuse_))); return(true); }
public async Task <bool> ProcessAsync(CQApiClient client, MessageEvent me, long srcid) { const string keyword = "/cat"; if (Global.msgFilter(me.message, false, s => s.TrimStart().StartsWith(keyword))) { foreach (var ele in me.message.data) { if (ele is ElementText) { var rollp = rand_.Next(0, 749); await client.SendMessageAsync(me.messageType, srcid, new Message(new ElementImage($"http://111.231.102.248/static/cat/{rollp}.jpg"))); } } } return(false); }
async public Task <bool> ProcessAsync(CQApiClient client, MessageEvent me, long srcid) { const string keyword = "/ping"; const string keyword1 = ".ping"; if (Global.msgFilter(me.message, false, s => s.TrimStart().StartsWith(keyword)) || Global.msgFilter(me.message, false, s => s.TrimStart().StartsWith(keyword1))) { foreach (var ele in me.message.data) { if (ele is ElementText) { await client.SendMessageAsync(me.messageType, srcid, new Message(new ElementAt(me.sender.user_id), new ElementText(" 啪!"))); } } } return(false); }
public async Task <bool> ProcessAsync(CQApiClient client, MessageEvent me, long srcid) { bool isGroup = me is cqhttp.Cyan.Events.CQEvents.GroupMessageEvent; if (Global.msgFilter(me.message, !isGroup, s => true)) { foreach (var ele in me.message.data) { if (ele is ElementAt) { WebClient mwc = new WebClient(); byte[] chatdlb = mwc.DownloadData($"https://api.sc2h.cn/api/maid.php?data=0&sign={srcid}&msg={me.message}"); string chats = Encoding.UTF8.GetString(chatdlb); await client.SendMessageAsync(me.messageType, srcid, new Message(new ElementAt(me.sender.user_id), new ElementText($" {me.message}"))); } } } return(false); }
private static async Task <CQResponse> OnEventAsync(CQApiClient client, CQEvent eventObj) { long srcid = -1; MessageEvent msgeve = null; if (eventObj is GroupMessageEvent) { var me = eventObj as GroupMessageEvent; msgeve = me; srcid = me.group_id; } else if (eventObj is PrivateMessageEvent) { var me = eventObj as PrivateMessageEvent; msgeve = me; srcid = me.sender_id; } if (msgeve != null && Global.enabled_) { try { foreach (var prcs in Global.processers) { if (await prcs.ProcessAsync(client, msgeve, srcid)) { break; } } } catch (Exception e) { byte[] img = System.IO.File.ReadAllBytes("E:\\static\\1.jpg"); await client.SendMessageAsync(msgeve.messageType, srcid, new Message(new ElementImage(img), new ElementText($"\n我崩了: {e.Message}"))); } } return(new EmptyResponse()); }
async public Task <bool> ProcessAsync(CQApiClient client, MessageEvent me, long srdid) { bool cloud = false; bool includeLocked = false; bool isGroup = me is cqhttp.Cyan.Events.CQEvents.GroupMessageEvent; if (Global.msgFilter(me.message, isGroup, (s) => s.Contains("云抽奖") || s.Contains("雲菗奬") || s.Contains("抽云奖") || s.Contains("抽奖云"))) { cloud = true; } else if (Global.msgFilter(me.message, true, s => s.Contains("非酋检定"))) { includeLocked = true; } else if (!Global.msgFilter(me.message, true, (s) => s.Contains("抽奖"))) { return(false); } if (me.sender.user_id == Global.koiid) { cloud = true; } if (me.sender.user_id == Global.kusuriid) { includeLocked = true; } Image img = gd.Generate(cloud, includeLocked); MemoryStream ms = new MemoryStream(); img.Save(ms, ImageFormat.Jpeg); await client.SendMessageAsync(me.messageType, srdid, new cqhttp.Cyan.Messages.Message( new ElementAt(me.sender.user_id), new ElementImage(ms.ToArray()))); return(true); }
public async Task <bool> ProcessAsync(CQApiClient client, MessageEvent me, long srcid) { const string keyword = "/help"; if (Global.msgFilter(me.message, false, s => s.TrimStart().StartsWith(keyword))) { foreach (var ele in me.message.data) { if (ele is ElementText) { await client.SendMessageAsync(me.messageType, srcid, new Message(new ElementText("獭獭Remake Ver.Alpha\n" + "命令列表:\n" + "/cat 猫图\n" + "/dice <骰子个数>d<点数上限> 骰子\n" + "/nn & /nuannuan 暖暖(可加参数:text)\n" + "/mc 獭のMinecraft服务器相关(WIP)\n" + "/ping 啪\n" + "功能还在继续开发w"))); } } } return(false); }
async public Task <bool> ProcessAsync(CQApiClient client, MessageEvent me, long srcid) { const string keyword = "/dice"; bool isGroup = me is cqhttp.Cyan.Events.CQEvents.GroupMessageEvent; if (Global.msgFilter(me.message, false, s => s.TrimStart().StartsWith(keyword))) { foreach (var ele in me.message.data) { if (ele is ElementText && (ele as ElementText).text.ToLower().Contains('d')) { try { string txt = (ele as ElementText).text.TrimStart(); if (!txt.StartsWith(keyword)) { continue; } string[] sa = txt.Split(new[] { "d", keyword }, StringSplitOptions.RemoveEmptyEntries); if (sa.Length == 2) { int cnt = int.Parse(sa[0]); int rng = int.Parse(sa[1]); if (cnt == 0) { await client.SendMessageAsync(me.messageType, srcid, new Message(new ElementAt(me.sender.user_id), new ElementText(" wdnmd,你不用骰子还摇个鸡掰?"))); break; } if (cnt < 0) { await client.SendMessageAsync(me.messageType, srcid, new Message(new ElementAt(me.sender.user_id), new ElementText(" wdnmd,你是在用虚空骰子?"))); break; } if (rng < 1) { await client.SendMessageAsync(me.messageType, srcid, new Message(new ElementAt(me.sender.user_id), new ElementText(" wdnmd,你那个是骰子?"))); break; } if (cnt > 32) { await client.SendMessageAsync(me.messageType, srcid, new Message(new ElementAt(me.sender.user_id), new ElementText(" wdnmd,你哪有那么多骰子?"))); break; } if (rng > 999) { await client.SendMessageAsync(me.messageType, srcid, new Message(new ElementAt(me.sender.user_id), new ElementText(" wdnmd,哪有那么多面的骰子?"))); break; } int[] result = new int[cnt]; for (int i = 0; i < cnt; i++) { result[i] = rand_.Next(rng) + 1; } string ans = string.Join(",", result); await client.SendMessageAsync(me.messageType, srcid, new Message(new ElementAt(me.sender.user_id), new ElementText($" 转动{cnt}个{rng}面骰子,掷出了[ {ans} ]。"))); } } catch (Exception e) { Console.WriteLine(e); throw; } } } } return(false); }
async public Task <bool> ProcessAsync(CQApiClient client, MessageEvent msgevt, long srcid) { if (currentList_.Count > 0) { if (!Global.msgFilter(msgevt.message, false, (s) => s == "1")) { return(false); } if (currentList_.Contains(msgevt.sender.user_id)) { return(false); } currentList_.Add(msgevt.sender.user_id); if (currentList_.Count == expectCnt) { await client.SendMessageAsync(msgevt.messageType, srcid, new Message("比赛开始了!")); await Task.Delay(TimeSpan.FromSeconds(5)); Message win = new Message(); for (int i = 0; i < expectCnt; i++) { win.data.Add(new ElementAt(currentList_[i])); } win.data.Add(new ElementText(" 取得了胜利!")); await client.SendMessageAsync(msgevt.messageType, srcid, win); await Task.Delay(TimeSpan.FromSeconds(2)); Message gold = new Message(); for (int i = 0; i < expectCnt; i++) { gold.data.Add(new ElementAt(currentList_[i])); } gold.data.Add(new ElementText(" 获得了金牌!")); await client.SendMessageAsync(msgevt.messageType, srcid, gold); currentList_.Clear(); } else { await client.SendMessageAsync(msgevt.messageType, srcid, new Message( $"云{new string('排', expectCnt)} {currentList_.Count}q{expectCnt-currentList_.Count}")); } return(true); } if (Global.msgFilter(msgevt.message, true, s => s.ToLower().Contains("云pppp") || s.Contains("云排排排排"))) { expectCnt = 4; } else if (Global.msgFilter(msgevt.message, true, s => s.ToLower().Contains("云pp") || s.Contains("云排排"))) { expectCnt = 2; } else { return(false); } if (currentList_.Count == 0) { await client.SendMessageAsync(msgevt.messageType, srcid, new Message( new ElementAt(msgevt.sender.user_id), new ElementText($"发起了云{new string('排',expectCnt)} 加入的人请打1"))); currentList_.Add(msgevt.sender.user_id); } return(true); }
async public Task <bool> ProcessAsync(CQApiClient client, MessageEvent me, long srcid) { if (Global.msgFilter(me.message, true, s => s.Trim().ToLower() == "hi")) { await client.SendMessageAsync(me.messageType, srcid, new Message( "抽取随机装备:@bot {[云]抽奖|非酋检定}\r\n" + "抽取随机武器:@bot 抽[很多]武器\r\n" + "抽签:@bot 抽签([<第一项>][,<第二项>][...][)]\r\n" + "生成帅气的签名(联网):@bot 签名\r\n" + "生成不那么帅气的签名(本地1500条随机抽取):@bot 金句\r\n" + "将文字转换为帅气的格式:@bot 翻译[内容]\r\n" + "云排排排排:@bot {云排排[排排]|云pp[pp]}\r\n" + "喷喷的模式与打工时间表(调用其它模块):@bot [下]{图|工}\r\n" + "复读机模式:触发条件未知\r\n" + "(不区分大小写与全角半角标点)")); return(true); } //if (Global.msgFilter(me.message,true,s=>s.ToLower().Contains("akira"))) //{ // string ans; // if (me.sender.user_id == Global.masterid) // ans = "我问你,你是我的master吗"; // else // ans = "akira是我的master"; // await client.SendMessageAsync(me.messageType, srcid, new cqhttp.Cyan.Messages.Message(ans)); // return true; //} if (Global.msgFilter(me.message, false, s => s.Contains("我今晚一个人在家"))) { await client.SendMessageAsync(me.messageType, srcid, new Message("我们谁又不是呢")); return(true); } if (Global.msgFilter(me.message, false, s => s.Contains("还行")) && testRand(30)) { await client.SendMessageAsync(me.messageType, srcid, new Message("还行")); return(true); } if (Global.msgFilter(me.message, false, s => s.TrimEnd().EndsWith("呢")) && testRand(10)) { await client.SendMessageAsync(me.messageType, srcid, new Message("是的呢")); return(true); } if (Global.msgFilter(me.message, false, s => s.Contains("涂地吗")) && testRand(30)) { await client.SendMessageAsync(me.messageType, srcid, new Message( new ElementImage(File.ReadAllBytes(Path.Combine(Global.appDir, "image", "nawabari.jpg"))))); return(true); } if (Global.msgFilter(me.message, false, s => s.Contains("排排吗")) && testRand(30)) { await client.SendMessageAsync(me.messageType, srcid, new Message( new ElementImage(File.ReadAllBytes(Path.Combine(Global.appDir, "image", "pp.jpg"))))); return(true); } if (Global.msgFilter(me.message, true, s => s.Contains("你真棒") || s.Contains("你好棒"))) { await client.SendMessageAsync(me.messageType, srcid, new Message( new ElementImage(File.ReadAllBytes(Path.Combine(Global.appDir, "image", "emoshy.jpg"))))); return(true); } if (me.sender.user_id == Global.masterid && Global.msgFilter(me.message, true, s => s.Contains("闭嘴"))) { Global.enabled_ = false; await Task.Delay(TimeSpan.FromMinutes(1)); Global.enabled_ = true; return(true); } bool isGroup = me is cqhttp.Cyan.Events.CQEvents.GroupMessageEvent; if (Global.msgFilter(me.message, isGroup, s => s.TrimStart().StartsWith("你叫"))) { await client.SendMessageAsync(me.messageType, srcid, new Message( Global.msgText(me.message).Replace("你叫", "我叫"))); return(true); } if (Global.msgFilter(me.message, isGroup, s => s.ToLower().Contains("koi今天论文写完了吗"))) { await client.SendMessageAsync(me.messageType, srcid, new Message( Global.randItem(new string[] { "并没有~", "没有", "没", "Nope" }))); return(true); } if (Global.msgFilter(me.message, isGroup, s => s.ToLower().Contains("akira区域上s了吗"))) { await client.SendMessageAsync(me.messageType, srcid, new Message( Global.randItem(new string[] { "没有", "还没有", "还是A-", "还是A-,鱼也是A-" }))); return(true); } if (/*(me.sender.user_id == Global.koiid || me.sender.user_id == Global.masterid) &&*/ Global.msgFilter(me.message, isGroup, s => (s.Contains("戳") || s.Contains("摸") || s.Contains("蹭")) && s.Length < 5)) { if (testRand(10)) { await client.SendMessageAsync(me.messageType, srcid, new Message( new ElementImage(si_.seal()))); } else { await client.SendMessageAsync(me.messageType, srcid, new Message( Global.randItem(new string[] { "呜……", "啊!", "啊~", "(噗)", "(噗呲)", "嗷!" /*, "こい"*/, "emmmmm", "嗯……", "嘤!", "嘤……", "rua!" }))); } return(true); } if (Global.msgFilter(me.message, isGroup, s => s.Contains("噗") && s.Length < 5)) { await client.SendMessageAsync(me.messageType, srcid, new Message( Global.randItem(new string[] { "戳", "戳~" }))); return(true); } if (Global.msgFilter(me.message, isGroup, s => s.Trim() == "草" || s.Trim() == "?" || s.Trim() == "?")) { return(true); } if (me.sender.user_id != Global.koiid && testRand(1) && Global.msgFilter(me.message, isGroup, s => s.Trim() == "在吗")) { await client.SendMessageAsync(me.messageType, srcid, new Message( "buzai,cnm")); return(true); } if (me.sender.user_id == Global.kusuriid && testRand(1) && Global.msgFilter(me.message, isGroup, s => true)) { await client.SendMessageAsync(me.messageType, srcid, new Message( new ElementImage(File.ReadAllBytes(Path.Combine(Global.appDir, "image", "emorefuse.jpg"))))); return(true); } return(false); }
public async Task <bool> ProcessAsync(CQApiClient client, MessageEvent me, long srcid) { const string keyword0 = "管理员"; const string keyword1 = "狗管理"; const string keyword2 = "来一份"; const string keyword3 = "禁言"; const string keyword4 = "分"; const string keyword5 = "小时"; const string keyword6 = "天"; bool isGroup = me is cqhttp.Cyan.Events.CQEvents.GroupMessageEvent; if (Global.msgFilter(me.message, !isGroup, s => s.TrimStart().StartsWith(keyword0)) || Global.msgFilter(me.message, !isGroup, s => s.TrimStart().StartsWith(keyword1))) { if (Global.msgFilter(me.message, !isGroup, s => s.TrimStart().Contains(keyword2)) && Global.msgFilter(me.message, !isGroup, s => s.TrimStart().Contains(keyword3))) { foreach (var ele in me.message.data) { if (ele is ElementText) { if ((ele as ElementText).text.Contains(keyword4) || (ele as ElementText).text.Contains(keyword5) || (ele as ElementText).text.Contains(keyword6)) { string txt = (ele as ElementText).text.TrimStart(); int k2leng = txt.IndexOf(keyword2); string txt0 = txt.Remove(0, k2leng + 3); string txt1 = "0"; string txt2 = null; int btype = 0; long aleng = 0; long aleng0 = 0; if (txt0.Contains(keyword4) && !txt0.Contains(keyword5) && !txt0.Contains(keyword6)) { btype = 1; int k4leng = txt0.IndexOf(keyword4); txt1 = txt0.Remove(k4leng); } else if (!txt0.Contains(keyword4) && txt0.Contains(keyword5) && !txt0.Contains(keyword6)) { btype = 2; int k5leng = txt0.IndexOf(keyword5); txt1 = txt0.Remove(k5leng); } else if (!txt0.Contains(keyword4) && !txt0.Contains(keyword5) && txt0.Contains(keyword6)) { btype = 3; int k6leng = txt0.IndexOf(keyword6); txt1 = txt0.Remove(k6leng); } else if (txt0.Contains(keyword4) && txt0.Contains(keyword5) && !txt0.Contains(keyword6)) { await client.SendMessageAsync(me.messageType, srcid, new Message(new ElementAt(me.sender.user_id), new ElementText(" 暂时不支持同时定义分钟和小时"))); } else if (!txt0.Contains(keyword4) && txt0.Contains(keyword5) && txt0.Contains(keyword6)) { await client.SendMessageAsync(me.messageType, srcid, new Message(new ElementAt(me.sender.user_id), new ElementText(" 暂时不支持同时定义小时和天数"))); } else if (txt0.Contains(keyword4) && !txt0.Contains(keyword5) && txt0.Contains(keyword6)) { await client.SendMessageAsync(me.messageType, srcid, new Message(new ElementAt(me.sender.user_id), new ElementText(" 暂时不支持同时定义分钟和天数"))); } else if (txt0.Contains(keyword4) && txt0.Contains(keyword5) && txt0.Contains(keyword6)) { await client.SendMessageAsync(me.messageType, srcid, new Message(new ElementAt(me.sender.user_id), new ElementText(" 暂时不支持同时定义分钟和小时和天数"))); } if (btype == 0) { return(false); } if (btype == 1) { try { aleng0 = long.Parse(txt1); if (aleng0 > 43200) { aleng0 = 43200; } if (aleng0 < 0) { btype = 4; } aleng = aleng0 * 60; txt2 = "分钟"; } catch (Exception) { btype = 4; } } else if (btype == 2) { try { aleng0 = long.Parse(txt1); if (aleng0 > 720) { aleng0 = 720; } if (aleng0 < 0) { btype = 4; } aleng = aleng0 * 60 * 60; txt2 = "小时"; } catch (Exception) { btype = 4; } } else if (btype == 3) { try { aleng0 = long.Parse(txt1); if (aleng0 > 30) { aleng0 = 30; } if (aleng0 < 0) { btype = 4; } aleng = aleng0 * 60 * 60 * 24; txt2 = "天"; } catch (Exception) { btype = 4; } } if (btype == 4) { aleng = 3600; await client.SendMessageAsync(me.messageType, srcid, new Message(new ElementAt(me.sender.user_id), new ElementText($" 居然调戏我w,先咬死!"))); await client.SendRequestAsync(new SetGroupBanRequest(srcid, me.sender.user_id, aleng)); return(true); } await client.SendMessageAsync(me.messageType, srcid, new Message(new ElementAt(me.sender.user_id), new ElementText($" 您点的{aleng0}{txt2}禁言套餐已到,请尽情享用"))); await client.SendRequestAsync(new SetGroupBanRequest(srcid, me.sender.user_id, aleng)); return(true); } } } } } return(false); }
public async Task <bool> ProcessAsync(CQApiClient client, MessageEvent me, long srcid) { string rHash = Global.GetMd5Hash(MD5.Create(), me.message.ToString()); int[] repeatlist_ = new int[10]; int repeatlistCounter_ = 0; for (int i = 0; i < 500; i++) { if (repeatHash_[i] == rHash) { if (repeatTime_[i] + 60 > me.time) { repeatlist_[repeatlistCounter_] = i; repeatlistCounter_ = repeatlistCounter_ + 1; } foreach (var rlist in repeatlist_) { if (repeatAlready_[rlist]) { return(false); } if (rlist == 0) { break; } } } } if (repeatlistCounter_ > 2) { int rroll = rand_.Next(1, 100); if (rroll < 15) { await client.SendMessageAsync(me.messageType, srcid, me.message); repeatHash_[repeatCounter_] = rHash; repeatTime_[repeatCounter_] = me.time; repeatAlready_[repeatCounter_] = true; await client.SendMessageAsync(me.messageType, srcid, new Message(new ElementText($"{repeatAlready_[4]}, {repeatCounter_}"))); repeatCounter_ = repeatCounter_ + 1; if (repeatCounter_ > 500) { repeatCounter_ = 0; } return(true); } repeatHash_[repeatCounter_] = rHash; repeatTime_[repeatCounter_] = me.time; repeatAlready_[repeatCounter_] = false; repeatCounter_ = repeatCounter_ + 1; if (repeatCounter_ > 500) { repeatCounter_ = 0; } return(true); } repeatHash_[repeatCounter_] = rHash; repeatTime_[repeatCounter_] = me.time; repeatAlready_[repeatCounter_] = false; repeatCounter_ = repeatCounter_ + 1; if (repeatCounter_ > 500) { repeatCounter_ = 0; } return(false); }
async public Task <bool> ProcessAsync(CQApiClient client, MessageEvent me, long srcid) { if (Global.msgFilter(me.message, true, s => s.TrimStart().StartsWith(keyword))) { Kv kv = await processDefine(me.message, me.sender); if (kv == null) { await client.SendMessageAsync(me.messageType, srcid, new Message( new ElementAt(me.sender.user_id), new ElementText(" 识别不了定义呢"))); return(true); } try { kvt_.insertOrUpdate(kv); await client.SendMessageAsync(me.messageType, srcid, new Message( new ElementAt(me.sender.user_id), new ElementText($" 学会 {kv.k} 了!"))); } catch (Exception e) { await client.SendMessageAsync(me.messageType, srcid, new Message( new ElementAt(Global.masterid), new ElementText($" 数据库插不进去:{e.Message}"))); } return(true); } if (!Global.msgFilter(me.message, true, s => true)) { return(false); } Kv ans = processQuestion(Global.msgText(me.message)); if (ans == null) { return(false); } Tag tag = JsonConvert.DeserializeObject <Tag>(ans.r); if (tag.anstype == Tag.ansenum.text) { await client.SendMessageAsync(me.messageType, srcid, new Message( new ElementAt(me.sender.user_id), new ElementText(" " + ans.v))); return(true); } else if (tag.anstype == Tag.ansenum.image) { await client.SendMessageAsync(me.messageType, srcid, new Message( new ElementAt(me.sender.user_id), new ElementImage(ans.v))); return(true); } return(false); }
public async Task <bool> ProcessAsync(CQApiClient client, MessageEvent me, long srcid) { const string keyword = "/lotteryban"; const string keyword1 = "/lob"; double dts = (DateTime.Now.ToUniversalTime() - new DateTime(1970, 1, 1)).TotalSeconds; long bts = (long)dts; if (islbing && cts + 420 < bts) { islbing = false; currentList_.Clear(); } bool isGroup = me is cqhttp.Cyan.Events.CQEvents.GroupMessageEvent; if (Global.msgFilter(me.message, !isGroup, s => s.TrimStart().StartsWith(keyword))) { if (islbing) { await client.SendMessageAsync(me.messageType, srcid, new Message(new ElementText("已经有禁言抽奖正在进行咯!\n(或许不是这个群的)"))); return(true); } if (!islbing) { islbing = true; lbqun = srcid; currentList_.Add(me.sender.user_id); double ats = (DateTime.Now.ToUniversalTime() - new DateTime(1970, 1, 1)).TotalSeconds; cts = (long)ats; await client.SendMessageAsync(me.messageType, srcid, new Message(new ElementAt(me.sender.user_id), new ElementText(" 发起了1分钟的禁言抽奖(1/5)\n" + "各位快输入「/lob」参与吧!(7分钟后没达到人数自动关闭)"))); return(true); } } if (Global.msgFilter(me.message, !isGroup, s => s.TrimStart().StartsWith(keyword1))) { if (islbing && srcid == lbqun) { foreach (var qqid in currentList_) { if (qqid == me.sender.user_id) { await client.SendMessageAsync(me.messageType, srcid, new Message(new ElementAt(me.sender.user_id), new ElementText(" 你已经在名单里了哦~"))); return(false); } } currentList_.Add(me.sender.user_id); if (currentList_.Count == 5) { int rroll0 = rand_.Next(1, 100); int rroll1 = rand_.Next(1, 100); int rroll2 = rand_.Next(1, 100); int rroll3 = rand_.Next(1, 100); int rroll4 = rand_.Next(1, 100); int winnum = 0; for (int i = 100; i > 1; i--) { if (rroll0 == i) { winnum = 0; break; } if (rroll1 == i) { winnum = 1; break; } if (rroll2 == i) { winnum = 2; break; } if (rroll3 == i) { winnum = 3; break; } if (rroll4 == i) { winnum = 4; break; } } await client.SendMessageAsync(me.messageType, srcid, new Message(new ElementText("禁言1分钟抽奖开奖啦!\n"), new ElementAt(currentList_[0]), new ElementText($" 的点数为[{rroll0}]\n"), new ElementAt(currentList_[1]), new ElementText($" 的点数为[{rroll1}]\n"), new ElementAt(currentList_[2]), new ElementText($" 的点数为[{rroll2}]\n"), new ElementAt(currentList_[3]), new ElementText($" 的点数为[{rroll3}]\n"), new ElementAt(currentList_[4]), new ElementText($" 的点数为[{rroll4}]\n"), new ElementText("点数最大的是:"), new ElementAt(currentList_[winnum]), new ElementText("恭喜这位群友获得1分钟禁言礼包~"))); await client.SendRequestAsync(new SetGroupBanRequest(srcid, currentList_[winnum], 60L)); islbing = false; currentList_.Clear(); return(true); } await client.SendMessageAsync(me.messageType, srcid, new Message(new ElementAt(me.sender.user_id), new ElementText($" 也参与到禁言抽奖啦!({currentList_.Count}/5)\n" + "还没有参与的群友们赶紧输入「/lob」参与吧!"))); return(true); } if (!islbing) { await client.SendMessageAsync(me.messageType, srcid, new Message(new ElementText("目前还没有禁言抽奖活动进行哦!"))); return(true); } } return(false); }
async public Task <bool> ProcessAsync(CQApiClient client, MessageEvent me, long srcid) { const string keyword = "抽签"; //if (me.message.data.Count > 0 && me.message.data[0] is ElementText) //{ // ElementText ele = me.message.data[0] as ElementText; // if (ele.text.ToLower().Contains('d')) // { // try // { // string s = ele.text.ToLower().Trim(); // string[] sa = s.Split('d', options: StringSplitOptions.RemoveEmptyEntries); // if (sa.Length == 2) // { // int cnt = int.Parse(sa[0]); // int rng = int.Parse(sa[1]); // if (cnt > 0 && cnt < 100 && rng > 0) // { // int[] result = new int[cnt]; // for (int i = 0; i < cnt; i++) // result[i] = rand_.Next(rng) + 1; // string ans = string.Join(",", result); // await client.SendMessageAsync(me.messageType, srcid, new Message( // $"{me.sender.nickname}转动{cnt}个{rng}面骰子,掷出了{ans}。")); // } // } // } // catch // { // } // } //} bool isGroup = me is cqhttp.Cyan.Events.CQEvents.GroupMessageEvent; if (Global.msgFilter(me.message, isGroup, s => s.TrimStart().StartsWith(keyword))) { foreach (var ele in me.message.data) { if (ele is ElementText) { string txt = (ele as ElementText).text.TrimStart(); if (!txt.StartsWith(keyword)) { continue; } txt = txt.Replace("(", "(").Replace(")", ")").Replace(",", ","); int bi = txt.IndexOf("(") + 1; int ei = txt.IndexOf(")"); if (bi == -1 || bi == txt.Length) { continue; } txt = ei != -1 ? txt.Substring(bi, ei - bi) : txt.Substring(bi); string[] choices = txt.Split(','); string result = choices[rand_.Next(choices.Length)]; await client.SendMessageAsync(me.messageType, srcid, new cqhttp.Cyan.Messages.Message( new ElementAt(me.sender.user_id), new ElementText($" 抽到了 {result} 呢!"))); break; } } return(true); } else if (Global.msgFilter(me.message, true, s => s.Contains("抽很多武器"))) { await client.SendMessageAsync(me.messageType, srcid, new cqhttp.Cyan.Messages.Message( ".随机武器")); return(true); } else if (Global.msgFilter(me.message, isGroup, s => s.Contains("抽武器"))) { var img = /*me.sender.user_id == Global.kusuriid ? wp_.generate4K() : */ wp_.generate(); MemoryStream ms = new MemoryStream(); img.Item1.Save(ms, ImageFormat.Jpeg); await client.SendMessageAsync(me.messageType, srcid, new cqhttp.Cyan.Messages.Message( new ElementAt(me.sender.user_id), new ElementText($" 抽到 {img.Item2} 了呢"), new ElementImage(ms.ToArray()))); return(true); } return(false); }