Beispiel #1
0
        public void HandleMessage(RequestMessage message)
        {
            bool handledAsAsmin = false;

            if (message.ChatId == AdminUserChatId())
            {
                string[] tokens = message.Message.Split(' ');
                if (tokens.Length == 2)
                {
                    long param = 0;
                    if (tokens[0] == "추가" && long.TryParse(tokens[1], out param))
                    {
                        if (AddSubscriber(param))
                        {
                            handledAsAsmin = true;
                            ResponseQueue.Enqueue(new List <ChatId>()
                            {
                                message.ChatId
                            }, "추가하였습니다");
                        }
                    }
                }
            }
            if (!handledAsAsmin)
            {
                StringBuilder sb = new StringBuilder();
                sb.AppendFormat("당신의 텔레그램 ChatId 는 {0} 입니다.\n이 봇은 등록된 사용자만 사용가능합니다.", message.ChatId);
                sb.AppendFormat("\n\nYour Telegram ChatId is {0}.\nThis bot is for registered users only.", message.ChatId);
                ResponseQueue.Enqueue(new List <ChatId>()
                {
                    message.ChatId
                }, sb.ToString());
            }
        }
        public void HandleMessage(RequestMessage message)
        {
            bool handledAsAsmin = false;

            if (message.ChatId == AdminUserChatId())
            {
                string[] tokens = message.Message.Split(' ');
                if (tokens.Length == 3)
                {
                    long param = 0;
                    if (tokens[0] == "추가" && long.TryParse(tokens[1], out param))
                    {
                        string[] exclusionStrings = tokens[2].Split(',');

                        HashSet <ContentType> exclusions = new HashSet <ContentType>();
                        foreach (string ex in exclusionStrings)
                        {
                            ContentType ct = ContentTypeConverter.StringToContentType(ex);
                            if (ct == ContentType.UNSPECIFIED)
                            {
                                string error = String.Format("올바르지 않은 이름입니다 : {0}", ex);
                                ResponseQueue.Enqueue(new HashSet <long>()
                                {
                                    message.ChatId
                                }, error);
                                return;
                            }
                            else
                            {
                                exclusions.Add(ct);
                            }
                        }

                        if (AddSubscriber(param, exclusions))
                        {
                            handledAsAsmin = true;
                            ResponseQueue.Enqueue(new HashSet <long>()
                            {
                                message.ChatId
                            }, "추가하였습니다");
                        }
                    }
                }
            }
            if (!handledAsAsmin)
            {
                StringBuilder sb = new StringBuilder();
                sb.AppendFormat("당신의 텔레그램 ChatId 는 {0} 입니다.\n이 봇은 등록된 사용자만 사용가능합니다.", message.ChatId);
                sb.AppendFormat("\n\nYour Telegram ChatId is {0}.\nThis bot is for registered users only.", message.ChatId);
                ResponseQueue.Enqueue(new HashSet <long>()
                {
                    message.ChatId
                }, sb.ToString());
            }
        }