コード例 #1
0
ファイル: BotManager.cs プロジェクト: lythm/orb3d
 public void EmmitBotCommand(BotCommand command)
 {
     for (int i = 0; i < FBotList.Count; ++i)
     {
         FBotList[i].EmmitBotCommand(command);
     }
 }
コード例 #2
0
 private static RfqComment ParseComment(BotCommand command)
 {
     return(new RfqComment(
                command.Get("requestId"),
                command["requestParty"],
                command["counterParty"],
                null,
                command["comment"]));
 }
コード例 #3
0
 public void Deconstruct(
     out JokeType type,
     out BotCommand command,
     out string lang)
 {
     type    = JokeType;
     command = BotCommand;
     lang    = Language;
 }
コード例 #4
0
 private Command(
     JokeType type,
     BotCommand command,
     string lang)
 {
     JokeType   = type;
     BotCommand = command;
     Language   = lang;
 }
コード例 #5
0
ファイル: Bot.cs プロジェクト: lythm/orb3d
            public void EmmitBotCommand(BotCommand command)
            {
                lock (FLock)
                {
                    if(FLua == null)
                        return;

                    EmmitBotEvent(new BotEvent_Command(command));
                }
            }
コード例 #6
0
ファイル: Bot.cs プロジェクト: mambotuna/DOTS-training
    private void CompleteCommand()
    {
        BotCommand _tempCommand = commandQueue.Dequeue();

        if (_tempCommand.appendWhenComplete)
        {
            commandQueue.Enqueue(_tempCommand);
        }
        BeginCommand(commandQueue.Peek());
    }
コード例 #7
0
 private async Task Send(BotCommand command, string payload)
 {
     if (ControlPort > 0 && ControlPort <= ushort.MaxValue)
     {
         var pl   = Encoding.UTF8.GetBytes(payload);
         var data = new[] { (byte)command };
         data = data.Concat(pl).ToArray();
         await _controlClient.SendAsync(data, data.Length, new IPEndPoint(IPAddress.Loopback, ControlPort));
     }
 }
コード例 #8
0
            public PlayCommand(string audioType, string cmdPath)
            {
                this.audioType = audioType;
                var builder = new CommandBuildInfo(
                    this,
                    Method,
                    new CommandAttribute(cmdPath));

                Command = new BotCommand(builder);
            }
コード例 #9
0
            public PlayListCommand(IPlaylistResolver resolver, string cmdPath)
            {
                this.resolver = resolver;
                var builder = new CommandBuildInfo(
                    this,
                    Method,
                    new CommandAttribute(cmdPath));

                Command = new BotCommand(builder);
            }
コード例 #10
0
        public JsonResult RemovePotentialRetweet(string id)
        {
            var command = new BotCommand()
            {
                Value = id, Command = BotCommand.CommandType.RemovePotentialRetweet
            };

            commandRepo.Save(RepoKey, command);
            return(Json(command, JsonRequestBehavior.AllowGet));
        }
コード例 #11
0
            public SearchCommand(ISearchFactory factory, string cmdPath)
            {
                this.factory = factory;
                var builder = new CommandBuildInfo(
                    this,
                    Method,
                    new CommandAttribute(cmdPath));

                Command = new BotCommand(builder);
            }
コード例 #12
0
        public JsonResult IgnoreTweep(string id)
        {
            var command = new BotCommand()
            {
                Value = id, Command = BotCommand.CommandType.IgnoreTweep
            };

            commandRepo.Save(RepoKey, command);
            return(Json(command, JsonRequestBehavior.AllowGet));
        }
コード例 #13
0
        public JsonResult Refresh()
        {
            var command = new BotCommand()
            {
                Value = DateTime.Now.ToString(), Command = BotCommand.CommandType.Refresh
            };

            commandRepo.Save(RepoKey, command);
            return(Json(command, JsonRequestBehavior.AllowGet));
        }
コード例 #14
0
            public SearchCommand(ISearchResolver resolver, string cmdPath)
            {
                this.resolver = resolver;
                var builder = new CommandBuildInfo(
                    this,
                    Method,
                    new CommandAttribute(cmdPath));

                Command = new BotCommand(builder);
            }
コード例 #15
0
            public PlayListCommand(IPlaylistFactory factory, string cmdPath)
            {
                this.factory = factory;
                var builder = new CommandBuildInfo(
                    this,
                    Method,
                    new CommandAttribute(cmdPath));

                Command = new BotCommand(builder);
            }
コード例 #16
0
ファイル: IrcClient.cs プロジェクト: krt523/chibot9001
        //logic for actually monitoring channel.
        private void ControlLoop()
        {
            while (!exit)
            {
                string currentTextLine = _inputStream.ReadLine();

                /* IRC commands come in one of these formats:
                 * :NICK!USER@HOST COMMAND ARGS ... :DATA\r\n
                 * :SERVER COMAND ARGS ... :DATA\r\n
                 */

                //Display received irc message
                Console.WriteLine(currentTextLine);
                //if (currentTextLine[0] != ':') continue;

                //Send pong reply to any ping messages
                if (currentTextLine.StartsWith("PING "))
                {
                    _outputStream.Write(currentTextLine.Replace("PING", "PONG") + "\r\n");
                    _outputStream.Flush();
                }
                else if (currentTextLine[0] != ':')
                {
                    continue;
                }
                else if (BotCommand.isPotentialCommand(currentTextLine))
                {
                    BotCommand    command = new BotCommand(currentTextLine);
                    TwitchChannel channel = _channels.Find(c => '#' + c.Name == command.Channel);
                    foreach (ICommandHandler handler in _commandHandlers)
                    {
                        CommandHandlerResult result = handler.ProcessCommand(command, channel).Result;
                        bool breakLoop = false;
                        switch (result.ResultType)
                        {
                        case ResultType.Handled:
                            breakLoop = true;
                            break;

                        case ResultType.HandledWithMessage:
                            SendPrivmsg(result.Channel, result.Message);
                            breakLoop = true;
                            break;

                        default:
                            break;
                        }
                        if (breakLoop)
                        {
                            break;
                        }
                    }
                }
            }
        }
コード例 #17
0
        private async void OnMessageReceivedAsync(object sender, MessageEventArgs e)
        {
            System.Console.WriteLine("Message Received");
            if (e.Message.Chat.Id == _settings.MetaCountingChatId)
            {
                BotCommand command = new BotCommand(e.Message.Text);
                if (command.commandType != BotCommandEnum.noCommand)
                {
                    await _statsManager.HandleStatsCommandAsync(command, e.Message.From.Username, _serviceProvider);

                    return;
                }
            }

            if (e.Message.Chat.Id == _settings.CountingChatId)
            {
                MessageEntry messageEntry = new MessageEntry
                {
                    Username  = e.Message.From.Username == null ? e.Message.From.FirstName : e.Message.From.Username,
                    Timestamp = DateTime.UtcNow
                };

                bool isNumberValue = int.TryParse(e.Message.Text, out int number);
                if (e.Message.Text != null)
                {
                    isNumberValue &= MoreRobustNumberCheck(e.Message.Text);
                }

                if (!isNumberValue ||
                    (_lastUserToSendCorrect != null && (_lastUserToSendCorrect == e.Message.From.Username)) ||
                    ((_lastNumber != null) && number != _lastNumber + 1))
                {
                    _lastUserToSendCorrect = null;
                    _lastNumber            = null;

                    messageEntry.Correct = false;
                    messageEntry.Number  = -1;

                    await SendMessageAsync(GetRandomInsultMessageForUser( e.Message.From.Username ));
                }
                else
                {
                    _lastNumber            = number;
                    _lastUserToSendCorrect = e.Message.From.Username;

                    messageEntry.Correct = true;
                    messageEntry.Number  = number;

                    await HandleCoolNumbersAsync(number, e.Message.From.Username);
                }

                _stateTimer.Change(_settings.TimerWaitTime, _settings.TimerWaitTime);
                await _numberStoreRepository.AddNewMessageEntryAsync(_serviceProvider, messageEntry);
            }
        }
コード例 #18
0
ファイル: Parser.cs プロジェクト: TravisTX/AIBlockBattleBot
        public EngineCommand PollCommand(Bot bot)
        {
            var line = Console.ReadLine();

            if (string.IsNullOrWhiteSpace(line))
            {
                return(null);
            }

            EngineCommand command = null;
            var           parse   = line.Split(' ');

            switch (parse[0])
            {
            case "settings":
                command = new SettingsCommand(bot.MatchSettings, parse[1], parse[2]);
                break;

            case "update":
                if (parse[1] == "game")
                {
                    command = new GameStateCommand(bot.GameState, parse[2], parse[3]);
                }
                else
                {
                    if (bot.MatchSettings.PlayerNames.Contains(parse[1]))
                    {
                        if (!bot.Players.ContainsKey(parse[1]))
                        {
                            bot.Players.Add(parse[1], new PlayerState(bot.MatchSettings.FieldWidth, bot.MatchSettings.FieldHeight));
                        }

                        var player = bot.Players[parse[1]];
                        command = new PlayerCommand(player, parse[1], parse[2], parse[3]);
                    }
                    else
                    {
                        Console.WriteLine("Invalid player: '{0}'", parse[1]);
                    }
                }
                break;

            case "action":
                command = new BotCommand(bot, parse[1], parse[2]);
                break;
            }

            if (command == null)
            {
                Console.WriteLine("Invalid command: '{0}'", parse[0]);
            }

            return(command);
        }
コード例 #19
0
 public static BotCommand WithRegexGroup(
     this BotCommand command,
     GroupCollection group,
     params string[] parameterNames)
 {
     foreach (var parameter in parameterNames)
     {
         command = command.Add(parameter, group[parameter].Value);
     }
     return(command);
 }
コード例 #20
0
            public PlayListCommand(AudioType audioType, string cmdPath)
            {
                this.audioType = audioType;
                var builder = new CommandBuildInfo(
                    this,
                    playMethod,
                    new CommandAttribute(cmdPath),
                    null);

                Command = new BotCommand(builder);
            }
コード例 #21
0
        public void ChatBotWarnsOnInvalidCommand()
        {
            var cmd = new BotCommand {
                IsCommand = true, Key = "invalid"
            };

            Mock.Get(this.commandParser).Setup(x => x.Parse("/invalid=code")).Returns(cmd);
            var result = this.sut.Process("/invalid=code");

            Assert.AreEqual("Invalid command. Please use a valid command (Valid commands: stock)", result);
        }
コード例 #22
0
            public PlayCommand(AudioType audioType)
            {
                this.audioType = audioType;
                var builder = new CommandBuildInfo(
                    this,
                    playMethod,
                    new CommandAttribute(CommandRights.Private, string.Empty),
                    null);

                Command = new BotCommand(builder);
            }
コード例 #23
0
        public void ChatBotProcessesOnlyCommands()
        {
            var cmd = new BotCommand()
            {
                IsCommand = false
            };

            Mock.Get(this.commandParser).Setup(x => x.Parse("Hello")).Returns(cmd);
            var result = this.sut.Process("Hello");

            Assert.AreEqual(string.Empty, result);
        }
コード例 #24
0
 public Task <BotCommandResult> PutBotCommand(string id, BotCommand command)
 {
     if (string.IsNullOrWhiteSpace(id))
     {
         throw new ArgumentNullException(nameof(id));
     }
     if (command == null)
     {
         throw new ArgumentNullException(nameof(command));
     }
     return(BotCommandClient.UpdateAsync(id, command));
 }
コード例 #25
0
        public void ChatBotRespondsOnCommands()
        {
            var cmd = new BotCommand()
            {
                IsCommand = true
            };

            Mock.Get(this.commandParser).Setup(x => x.Parse("/stock=code")).Returns(cmd);
            var result = this.sut.Process("/stock=code");

            Assert.AreNotEqual(string.Empty, result);
        }
コード例 #26
0
ファイル: BotCommandTests.cs プロジェクト: krt523/chibot9001
        public void CreateBotCommand_ConstructorPassedIRCLine_BotCommandCreatedCorrecty()
        {
            //Arrange
            var command = new BotCommand(IRCLine);

            //Act


            //Assert
            Assert.AreEqual("feelthechi", command.Sender);
            Assert.AreEqual("!quote", command.Command);
            Assert.AreEqual("5 6 7 8", command.Arguments);
            Assert.AreEqual("#tminator64", command.Channel);
        }
コード例 #27
0
 private void HandleExpiredCommand(BotCommand cmd, User sender)
 {
     RaiseQuoteInquiryResponseReceived(
         new RfqQuoteInquiryResponse(
             RfqResponseType.Expired,
             null,
             cmd["requestId"],
             cmd["party"],
             sender.EmailAddress,
             null,
             null,
             null,
             null));
 }
コード例 #28
0
ファイル: JuvoClient.cs プロジェクト: edrochenski/juvo
        /// <summary>
        /// Called when <see cref="commandTimer" /> tick occurs.
        /// </summary>
        /// <param name="state">State object.</param>
        protected async void CommandTimerTick(object?state)
        {
            if (this.State != JuvoState.Running)
            {
                return;
            }

            if (this.commandQueue.Count > 0)
            {
                var toRun = new List <IBotCommand>();
                lock (this.commandQueue)
                {
                    IBotCommand cmd;
                    while (this.commandQueue.Count > 0 && (cmd = this.commandQueue.Dequeue()) != null)
                    {
                        toRun.Add(cmd);
                    }
                }

                await Task.Run(() => toRun.ForEach(async cmd => await this.ProcessCommand(cmd)));
            }

            if (this.commandTimerLastMin != DateTime.Now.Minute && this.plugins.Count > 0)
            {
                this.commandTimerLastMin = DateTime.Now.Minute;
                foreach (var plugin in this.plugins.Values)
                {
                    if (plugin.CommandTimeMin is null || !plugin.CommandTimeMin.Contains(DateTime.Now.Minute))
                    {
                        continue;
                    }

                    var src = new CommandSource {
                        SourceType = CommandSourceType.None
                    };
                    var cmd = new BotCommand(null, CommandTriggerType.Timer, src, string.Empty);

                    await plugin.Execute(cmd, this); // nocommit: how do we know where to send the unsolicited response??
                }
            }

            lock (this.lastPerfLock)
            {
                if (DateTime.Now.Minute % 5 == 0 && DateTime.Now.Second == 0 &&
                    (this.lastPerf == null || this.lastPerfTime.AddMinutes(5) < DateTime.UtcNow))
                {
                    this.LogPerf();
                }
            }
        }
コード例 #29
0
 Task SendJokeAsync(string joke, BotCommand command, CancellationToken cancellationToken)
 => _chatHub.Clients
 .All
 .SendAsync(
     "MessageReceived",
     new
 {
     text      = joke,
     id        = Guid.NewGuid().ToString(),
     user      = ChatBotUserName,
     isChatBot = true,
     sayJoke   = command == BotCommand.SayJokes
 },
     cancellationToken);
コード例 #30
0
ファイル: Parser.cs プロジェクト: squid-box/BattleBlockBot
        public EngineCommand PollCommand(Bot bot)
        {
            var line = Console.ReadLine();

            if (string.IsNullOrWhiteSpace(line))
                return null;

            EngineCommand command = null;
            var parse = line.Split(' ');
            switch (parse[0])
            {
                case "settings":
                    command = new SettingsCommand(bot.MatchSettings, parse[1], parse[2]);
                    break;
                case "update":
                    if (parse[1] == "game")
                    {
                        command = new GameStateCommand(bot.GameState, parse[2], parse[3]);
                    }
                    else
                    {
                        if (bot.MatchSettings.PlayerNames.Contains(parse[1]))
                        {
                            if (!bot.Players.ContainsKey(parse[1]))
                            {
                                bot.Players.Add(parse[1], new PlayerState(bot.MatchSettings.FieldWidth, bot.MatchSettings.FieldHeight));
                            }

                            var player = bot.Players[parse[1]];
                            command = new PlayerCommand(player, parse[1], parse[2], parse[3]);
                        }
                        else
                        {
                            Console.WriteLine("Invalid player: '{0}'", parse[1]);
                        }
                    }
                    break;
                case "action":
                    command = new BotCommand(bot, parse[1], parse[2]);
                    break;
            }

            if (command == null)
            {
                Console.WriteLine("Invalid command: '{0}'", parse[0]);
            }

            return command;
        }
コード例 #31
0
        private void HandleCounterPartyToRequestCommentCommand(BotCommand cmd, User sender)
        {
            var comment = ParseComment(cmd);

            lock (mx_)
            {
                if (!requestPartiesTrackingRequestsFromCounterParties_.Contains(comment.RequestParty))
                {
                    Logger.InfoFormat("Ignoring comment for {0}, not subscribed as this party for counter party comments", comment.RequestParty);
                    return;
                }
            }

            RaiseCounterPartyCommentReceived(comment);
        }
コード例 #32
0
 private void HandleErrorCommand(BotCommand cmd, User sender)
 {
     // error [email protected]:1 Wrong RFQ request
     RaiseQuoteInquiryResponseReceived(
         new RfqQuoteInquiryResponse(
             RfqResponseType.Error,
             cmd["message"],
             cmd["requestId"],
             cmd["party"],
             sender.EmailAddress,
             null,
             null,
             null,
             null));
 }
コード例 #33
0
        private string BuildCallData(string CommandName, params int[] Argument)
        {
            BotCommand command = new BotCommand
            {
                Cmd = CommandName,
                Arg = new List <int>()
            };

            for (int i = 0; i < Argument.Length; i++)
            {
                command.Arg.Add(Argument[i]);
            }

            return(JsonConvert.SerializeObject(command));
        }
コード例 #34
0
ファイル: BotEngine.cs プロジェクト: lythm/orb3d
            public void EmmitBotCommand(BotCommand cmd)
            {
                try
                {
                    BotManager manager = FindBotManager(cmd.BotDesc);

                    if (manager == null)
                        return;

                    manager.EmmitBotCommand(cmd);

                }
                catch (Exception e)
                {
                    AppContext.WriteLog(e.Message);
                    return;
                }
            }
コード例 #35
0
ファイル: Bot.cs プロジェクト: squid-box/BattleBlockBot
        public void ReceiveCommand(BotCommand command)
        {
            switch (command.Key)
            {
                case "moves":
                    var moves = MovesForRound(int.Parse(command.Value));
                    if (moves.Length == 0)
                    {
                        Console.WriteLine("no_moves");
                    }
                    else
                    {
                        Console.WriteLine("{0},drop", string.Join(",", moves).ToLower());
                    }
                    break;

                default:
                    Console.WriteLine("Invalid bot command: {0}", command.Key);
                    break;
            }
        }
コード例 #36
0
ファイル: Structures.cs プロジェクト: mys/BotWaRz
 public void SetCommand(BotCommand cmd)
 {
     this.cmd = cmd.ToString();
 }
コード例 #37
0
 public RemindWhenMoreRequirementsNeedsToBeApproved(IGitHubClient client, Repository repository, BotCommand.IResponse response)
 {
     this.client = client;
     this.repository = repository;
     this.response = response;
 }
コード例 #38
0
ファイル: BotEvent.cs プロジェクト: lythm/orb3d
                public BotEvent_Command(BotCommand cmd)
                {
                    command = cmd.CommandName;
                    id = (int)EventID.BOT_EVENT_ON_COMMAND;

                    parameters = new Dictionary<string, string>();

                    foreach (BotCommand.Parameter param in cmd.Parameters)
                    {
                        parameters[param.Name] = param.Value;
                    }
                }