private static async Task BroadcastTxNotify(DateTime startTime, List <QtumTxInfo> txList)
        {
            if (txList == null)
            {
                return;
            }

            if (startTime == DateTime.MinValue)
            {
                return;
            }

            await UserList.ForeachSendMsg("---------------------------------");

            await UserList.ForeachSendMsg("A new transaction has occurred!\n");

            for (int i = txList.Count - 1; i >= 0; --i)
            {
                QtumTxInfo txInfo = txList[i];
                DateTime   txTime = QtumHandler.BlockTimeToUtcTime(txInfo.time);

                if (txTime < startTime)
                {
                    break;
                }

                string notifyStr = txInfo.GetString();

                Logger.Log(notifyStr);
                Logger.Log("");

                await UserList.ForeachSendMsg(notifyStr);
            }

            await UserList.ForeachSendMsg("---------------------------------");
        }
コード例 #2
0
        ///--------------------------------------------------------------------------------------------------------
        /// 사용자로 부터 메세지를 받음
        private static async void Bot_OnMessage(object sender, Telegram.Bot.Args.MessageEventArgs messageEventArgs)
        {
            /// Message 객체
            var message = messageEventArgs.Message;

            /// 예외처리
            if (message == null || message.Type != MessageType.Text)
            {
                return;
            }

            if (UserList.Exists(message.Chat.Id) == false)
            {
                const int  kickDurationMinute = 30;
                const uint accessCountMax     = 1;
                uint       accessCount        = UserList.AddInvalidUser(message.Chat.Id);

                if (accessCount > accessCountMax)
                {
                    return;
                }

                try
                {
                    string alretMsg = string.Format(
                        "user name : {0}\nuser id : {1}\n you are not registered on user list.\n add the your user id to UserList.txt and restart the bot program."
                        , message.Chat.Username, message.Chat.Id);

                    await TelegramBot.Bot.SendTextMessageAsync(message.Chat.Id, alretMsg);

                    Logger.Log("Invalid Access User {0:yyyy/MM/dd HH:mm:ss} {1} {2}", DateTimeHandler.ToLocalTime(message.Date), message.Chat.Id, message.Chat.Username);
                }
                catch (Exception)
                {
                }

                if (accessCount >= accessCountMax)
                {
                    try
                    {
                        DateTime now = DateTime.UtcNow;
                        await TelegramBot.Bot.RestrictChatMemberAsync(message.Chat.Id, message.From.Id, now.Add(new TimeSpan(0, kickDurationMinute, 0)));

                        Logger.Log("Kick User {0:yyyy/MM/dd HH:mm:ss} {1} {2}", DateTimeHandler.ToLocalTime(message.Date), message.Chat.Id, message.Chat.Username);
                    }
                    catch (Exception)
                    {
                    }
                }

                return;
            }

            if (currentCommand != null && currentCommand.IsCompleted == false)
            {
                await currentCommand.OnMessage(message);

                return;
            }

            //string cmdStr = message.Text.Replace("-", "").Trim();
            string cmdStr = message.Text.Trim();

            Command.eCommand commandType = Command.CommandFactory.ParseCommand(cmdStr);

            Command.ICommand command = Command.CommandFactory.CreateCommand(commandType);

            if (command != null)
            {
                currentCommand = command;

                string[] args = cmdStr.Split(' ');

                bool success = await currentCommand.Process(message.Chat.Id, message.Chat.Username, DateTimeHandler.ToLocalTime(message.Date), args);
            }
            else
            {
                string helpStr = Command.CommandFactory.GetCommandHelpString();

                await TelegramBot.Bot.SendTextMessageAsync(message.Chat.Id, strings.Format(helpStr));
            }
        }