Example #1
0
 public MsgInfo(DateTime dateTime, IBaseInfo sender, string msgData, MsgType type = MsgType.Text)
 {
     MsgData  = msgData;
     DateTime = dateTime;
     _sender  = sender;
     Type     = type;
 }
Example #2
0
        public void chainReceived(IBaseInfo sender, IMessageBase[] msg, short type)
        {
            foreach (Conversation conv in conversations)
            {
                if (conv.peerid == sender.Id)
                {
                    conv.messages.Add(new KeyValuePair <IBaseInfo, IMessageBase[]>(sender, msg));
                    if (conv.Equals(current))
                    {
                        addonRefresh();
                    }
                    return;
                }
            }

            //没有符合的Conversation,创建。
            Conversation cv;

            if (type == 0)//好友私聊
            {
                cv = startConversation(sender.Id, sender.Name, type);
            }
            else//通过群聊临时聊天
            {
                cv = startConversation(sender.Id, sender.Name, type, ((IGroupMemberInfo)sender).Group.Id);
            }
            cv.messages.Add(new KeyValuePair <IBaseInfo, IMessageBase[]>(sender, msg));
        }
Example #3
0
    public static void Main(string[] args)
    {
        CCInfo ccInfo = new CCInfo();
        UCInfo ucInfo = new UCInfo();
        IBaseInfo <BaseDecision> x = ccInfo;

        x = ucInfo;
    }
Example #4
0
        public void AddMsg(IBaseInfo groupInfo, string msg, DateTime dateTime, IBaseInfo senderInfo,
                           MsgInfo.MsgType msgType = MsgInfo.MsgType.Text)
        {
            if (!Dic.ContainsKey(groupInfo.Id))
            {
                Dic.Add(groupInfo.Id, new HistoryMsgUnit(groupInfo));
            }

            Dic[groupInfo.Id].Msg.Enqueue(new MsgInfo(dateTime, senderInfo, msg, msgType));
            Dic[groupInfo.Id].Msg.ToLength(Config.Instance.HistoryLines);
        }
Example #5
0
        public static ICustomAttribute AddCustomAttribute(this IBaseInfo baseInfo, ICustomAttribute attribute)
        {
            for (int index = 0; index < attribute.Name.Split(';').Length; index++)
            {
                string s        = attribute.Name.Split(';')[index];
                var    theValue = attribute.Value.Split(';')[index];
                baseInfo.AddAttribute(new ModelDefaultAttribute(s, theValue));
            }

            return(attribute);
        }
Example #6
0
 static void PrintBasesAndVariants()
 {
     Log.Message("\nAvailable Bases:");
     foreach (Base item in Enum.GetValues(typeof(Base)))
     {
         if (item == Base.None)
         {
             continue;
         }
         IBaseInfo info = BaseMap.GetInfo(item);
         if (info == null)
         {
             continue;
         }
         string arg = item.ToString().ToLowerInvariant();
         Log.Message(
             " " + arg.PadTo(12) + info.DisplayName + " - " + info.Description
             );
     }
 }
Example #7
0
        public async void DoHandleAsync(MiraiHttpSession session, IMessageBase[] chain, IBaseInfo info, bool isGroupMessage = true)
        {
            logger.LogInformation($"{info.Name} 询问最新活动");
            var  latestEvent    = data.GetLatestEvent();
            bool isEventChanged = false;

            if (int.Parse(latestEvent.Item1) != latestEventId)
            {
                latestEventId  = int.Parse(latestEvent.Item1);
                isEventChanged = true;
            }
            string       message;
            IMessageBase img;

            if (isGroupMessage)
            {
                img = await session.UploadPictureAsync(UploadTarget.Group, await client.GetEventBannerImagePath(latestEvent.Item1));
            }
            else
            {
                img = await session.UploadPictureAsync(UploadTarget.Friend, await client.GetEventBannerImagePath(latestEvent.Item1));
            }
            DateTime endTime    = DateTimeOffset.FromUnixTimeMilliseconds(long.Parse(latestEvent.Item2.EndAt[0])).LocalDateTime;
            DateTime startTime  = DateTimeOffset.FromUnixTimeMilliseconds(long.Parse(latestEvent.Item2.StartAt[0])).LocalDateTime;
            string   eventState = startTime >= DateTime.Now ? $"即将开始,剩余{startTime - DateTime.Now:d\\日h\\小\\时m\\分}" : endTime <= DateTime.Now ? "结束" : $"正在进行,剩余{endTime - DateTime.Now:d\\日h\\小\\时m\\分}";

            message = $"活动名称: {latestEvent.Item2.EventName[0]}\n开始时间: {startTime}\n结束时间: {endTime}\n活动状态: {eventState}";
            logger.LogInformation($"已查到活动,并回复 {message}");
            IMessageBase[] result = new IMessageBase[]
            {
                new PlainMessage((isEventChanged ? "发现新活动!\n" : "") + message),
                img
            };
            if (isGroupMessage)
            {
                await session.SendGroupMessageAsync(((IGroupMemberInfo)info).Group.Id, result);
            }
            else
            {
                await session.SendFriendMessageAsync(info.Id, result);
            }
        }
Example #8
0
 public static void RemoveAttribute(this IBaseInfo info, Attribute attribute)
 => ((BaseInfo)info).RemoveAttribute(attribute);
Example #9
0
 private static IObservable <RestOperationAttribute> RestOperation(this Operation operation, IBaseInfo info)
 => info.FindAttributes <RestOperationAttribute>().Where(attribute => attribute.Operation == operation).ToObservable();
Example #10
0
 public HistoryMsgUnit(IBaseInfo info)
 {
     Id   = info.Id;
     Name = info.Name;
     Msg  = new Queue <MsgInfo>();
 }
Example #11
0
 public UnitInfo(IBaseInfo info)
 {
     Name = info.Name;
     Id   = info.Id;
 }
Example #12
0
 public BaseInfo(IBaseInfo baseInfo)
 {
     Id   = baseInfo.Id;
     Name = baseInfo.Name;
 }
Example #13
0
        public async void DoHandleAsync(MiraiHttpSession session, IMessageBase[] chain, IBaseInfo info, bool isGroupMessage = true)
        {
            ChineseLunisolarCalendar calendar = new ChineseLunisolarCalendar();
            var now          = DateTime.Now;
            var year         = calendar.GetYear(now);
            var month        = calendar.GetMonth(now);
            var day          = calendar.GetDayOfMonth(now);
            var hasLeapMonth = calendar.GetLeapMonth(year) > 0;

            if (hasLeapMonth)
            {
                if (month < 13 && day < 23)
                {
                    if (month > 1 && day > 15)
                    {
                        return;
                    }
                }
            }
            else
            {
                if (month < 12 && day < 23)
                {
                    if (month > 1 && day > 15)
                    {
                        return;
                    }
                }
            }
            List <IMessageBase> result = new List <IMessageBase>();
            IMessageBase        img    = null;

            switch (chain.First(m => m.Type == "Plain").ToString())
            {
            case "新年快乐":
                img = await session.UploadPictureAsync(UploadTarget.Group, "Resources\\NewYear\\NewYearStick.png");

                result.Add(img);
                break;

            case "新年抽签":
                string[] lotterise = Directory.GetFiles("Resources\\Lottery");
                img = await session.UploadPictureAsync(UploadTarget.Group, lotterise[randomer.Next(0, lotterise.Length - 1)]);

                result.Add(img);
                break;

            default:
                break;
            }
            if (isGroupMessage)
            {
                await session.SendGroupMessageAsync(((IGroupMemberInfo)info).Group.Id, result.ToArray());
            }
            else
            {
                await session.SendFriendMessageAsync(info.Id, result.ToArray());
            }
        }
Example #14
0
        public async void DoHandleAsync(MiraiHttpSession session, IMessageBase[] chain, IBaseInfo info, bool isGroupMessage = true)
        {
            List <IMessageBase> result = null;
            IMessageBase        img    = null;

            sb.Clear();
            switch (chain.First(m => m.Type == "Plain").ToString())
            {
            case "单抽":
                logger.LogInformation($"{info.Name} 单抽");
                var card = await GachaSingle();

                var message = $"单抽结果: {stars[card.Item2.Rarity]} {data.Characters[card.Item2.CharacterId.ToString()].CharacterName[0]} - {card.Item2.Prefix[0]}";
                img = await session.UploadPictureAsync(UploadTarget.Group, await client.GetCardThumbPath(card.Item2.ResourceSetName, card.Item1));

                result = new List <IMessageBase>
                {
                    new PlainMessage(message),
                    img
                };
                logger.LogInformation(message);
                break;

            case "当期池子":
                GachaDetail gd        = GetRecentGachaDetail();
                DateTime    endTime   = DateTimeOffset.FromUnixTimeMilliseconds(long.Parse(gd.ClosedAt[0])).LocalDateTime;
                DateTime    startTime = DateTimeOffset.FromUnixTimeMilliseconds(long.Parse(gd.PublishedAt[0])).LocalDateTime;
                sb.AppendLine(gd.GachaName[0]);
                sb.AppendLine(gd.Information.NewMemberInfo[0]);
                sb.AppendLine($"{startTime} - {endTime}");
                img = await session.UploadPictureAsync(UploadTarget.Group, await client.GetGachaBannerImagePath(gd.BannerAssetBundleName));

                result = new List <IMessageBase>
                {
                    new PlainMessage(sb.ToString()),
                    img
                };
                logger.LogInformation(sb.ToString());
                break;

            case "十连":
                List <(string, Card)> cards = new List <(string, Card)>(11);
                for (int i = 0; i < 9; i++)
                {
                    cards.Add(await GachaSingle());
                }
                cards.Add(await GachaSingle(tenTimes: true));
                img = await session.UploadPictureAsync(UploadTarget.Group, await render.RenderGachaImageAsync(cards));

                sb.AppendLine("十连结果:");
                foreach (var item in cards)
                {
                    sb.AppendLine($"{stars[item.Item2.Rarity]} {data.Characters[item.Item2.CharacterId.ToString()].CharacterName[0]} - {item.Item2.Prefix[0]}");
                }
                result = new List <IMessageBase>
                {
                    new PlainMessage(sb.ToString()),
                    img
                };
                logger.LogInformation(sb.ToString());
                break;

            default:
                break;
            }
            if (isGroupMessage)
            {
                await session.SendGroupMessageAsync(((IGroupMemberInfo)info).Group.Id, result.ToArray());
            }
            else
            {
                await session.SendFriendMessageAsync(info.Id, result.ToArray());
            }
        }