///-------------------------------------------------------------------------------------------------------- /// 기동 시 자동 스테이킹 시작 private async static Task StartupAutoStaking() { if (Config.StartupAutoStaking) { Logger.Log("StartupAutoStaking"); await UserList.ForeachSendMsg(strings.Format("자동 채굴 시작이 설정되어 있습니다. 채굴을 시작합니다.")); Command.ICommand command = Command.CommandFactory.CreateCommand(Command.eCommand.StartStaking); if (command != null) { await command.Process(-1, "", DateTimeHandler.GetTimeZoneNow()); } } }
///-------------------------------------------------------------------------------------------------------- /// 사용자로 부터 메세지를 받음 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)); } }