コード例 #1
0
 public static void CheckMethod()
 {
     while (true)
     {
         Thread.Sleep(CheckSpan);
         lock (_lock)
         {
             Task.Run(async() =>
             {
                 var now  = DateTime.Now;
                 var bots = Program.QQServer.GetBotList();
                 var msgs = await TipMessageService.GetTipMessages(TipMessage.TipTargetType.QQGroup, now);
                 foreach (var msg in msgs)
                 {
                     foreach (var bot in bots)
                     {
                         var api = Program.QQServer.GetSoraApi(bot);
                         if (await api.CheckHasGroup(msg.TargetID))
                         {
                             ConsoleLog.Debug("TipMessage", $"Send tip message to group {msg.TargetID} with bot {bot}");
                             var m = new ArrayList
                             {
                                 "[Tip Message]",
                                 Environment.NewLine
                             };
                             int n = 0;
                             int i = msg.Message.IndexOf("[@all]", n);
                             while (i < msg.Message.Length && i >= n)
                             {
                                 m.Add(msg.Message[n..i]);
                                 m.Add(CQCode.CQAtAll());
                                 i = msg.Message.IndexOf("[@all]", n = i + 6);
                             }
                             m.Add(msg.Message[n..]);
コード例 #2
0
        public static async void AddTip(SoraMessage e, DateTime time, string message)
        {
            message = SoraMessage.Escape(message);
            var now = DateTime.Now;

            if (time < now)
            {
                await e.ReplyToOriginal("提示时间不可设置为过去的时间");

                return;
            }
            else if ((time - now).TotalSeconds < 300)
            {
                await e.ReplyToOriginal("提示时间不可设置为 5 分钟内的目标");

                return;
            }
            try
            {
                await TipMessageService.AddTipMessage(TipTargetType.QQGroup, e.SourceGroup, time, message);

                await e.ReplyToOriginal("已添加单次提示信息");
            }
            catch (Exception ex)
            {
                await e.ReplyToOriginal(ex.Message);
            }
        }
コード例 #3
0
        public static async void TipList(SoraMessage e)
        {
            var list = await TipMessageService.GetTipMessages(TipTargetType.QQGroup, e.SourceGroup.Id);

            if (list.Length > 0)
            {
                var sb = new StringBuilder("本群现有的所有的提醒项目:");
                foreach (var tip in list)
                {
                    sb.AppendLine().AppendLine($"[ID:{tip.Id}]");
                    if (tip.Duplicate)
                    {
                        sb.AppendLine($"下一次提醒时间:{tip.TipTime:yyyy-MM-dd HH:mm:ss}");
                        sb.AppendLine($"提醒间隔:{tip.Interval.Days}天{tip.Interval.Hours}时{tip.Interval.Minutes}分{tip.Interval.Seconds}秒");
                        sb.AppendLine($"提醒结束于:{tip.EndTime:yyyy-MM-dd HH:mm:ss}");
                    }
                    else
                    {
                        sb.AppendLine($"提醒时间:{tip.TipTime:yyyy-MM-dd HH:mm:ss}");
                    }
                    sb.AppendLine("提醒内容:");
                    sb.Append(tip.Message);
                }
                await e.Reply(sb.ToString());
            }
            else
            {
                await e.Reply("本群目前不存在提示信息");
            }
        }
コード例 #4
0
        public static async void TipRemove(SoraMessage e, int id)
        {
            var tip = await TipMessageService.GetTipMessageById(id);

            if (tip != null && tip.TargetType == TipTargetType.QQGroup && tip.TargetID == e.SourceGroup.Id)
            {
                await tip.DeleteAsync();

                await e.ReplyToOriginal("操作成功");
            }
            await e.ReplyToOriginal($"不存在ID为 {id} 的提示消息");
        }