示例#1
0
 public override void Start()
 {
     Player.step          = -1;
     Player.targetCommand = "game";
     Player.currentGame   = this;
     movesCount           = 0;
     userMove             = false;
     gameKeyboard         = BotResponses.GetGameKeyboard();
 }
示例#2
0
        public void AddBotMessage(string message)
        {
            //variablie check
            var processedMessage = ConvertVariables(message);

            BotResponses.Add(new SessionMessage()
            {
                MessageContent = processedMessage, Type = SessionMessage.MessageType.BotMessage
            });
        }
示例#3
0
 public override void Start()
 {
     movesCount = 0;
     firstPlayer.currentGame    = this;
     secondPlayer.currentGame   = this;
     firstPlayer.step           = -1;
     secondPlayer.step          = -1;
     firstPlayer.targetCommand  = "game";
     secondPlayer.targetCommand = "game";
     gameKeyboard = BotResponses.GetGameKeyboard();
 }
示例#4
0
        public async Task RunCommand(SocketMessage msg)
        {
            try
            {
                var content = msg.Content.Trim().ToLower();

                if (msg is SocketUserMessage userMsg &&
                    userMsg.Channel is SocketGuildChannel guildChannel && userMsg.Author is SocketGuildUser author && content.StartsWith(_prefix))
                {
                    var isBlacklisted = await _context.BlacklistedChannels.AnyAsync(x =>
                                                                                    x.GuildId == guildChannel.Guild.Id && x.ChannelId == guildChannel.Id);

                    if (!isBlacklisted)
                    {
                        var cmdTxt = content.Split(' ', StringSplitOptions.RemoveEmptyEntries).First();
                        _logger.LogInformation($"User \"{_msgContext.Author.Username}#{_msgContext.Author.DiscriminatorValue}\" is executing command \"{cmdTxt}\" on guild \"{_msgContext.Guild.Name}\"");


                        const StringComparison ignoreCase = StringComparison.InvariantCultureIgnoreCase;

                        var command = _commands.SingleOrDefault(x =>
                                                                cmdTxt.Equals(_prefix + x.Name, ignoreCase) ||
                                                                x.Aliases.Any(y => cmdTxt.Equals(_prefix + y, ignoreCase)));

                        var customCommand = _customCommandRepository.Get().Where(x => x.GuildId == _msgContext.Guild.Id).ToList()
                                            .SingleOrDefault(x => cmdTxt.Equals(_prefix + x.Name, ignoreCase));
                        if (command != null)
                        {
                            //Check if command needs authorization
                            var commandRequiresAuthentication =
                                _commandCache.GetAuthorizedTypes().Any(x => x.IsInstanceOfType(command));
                            if (commandRequiresAuthentication)
                            {
                                await msg.Channel.SendMessageAsync("This is a spooky command");

                                if (await _roleService.UserIsAdmin(userMsg))
                                {
                                    await command.Invoke(userMsg);
                                }
                                else
                                {
                                    await msg.Channel.SendMessageAsync(BotResponses.AccessDenied(author));
                                }
                            }
                            else
                            {
                                await command.Invoke(userMsg);
                            }
                        }
                        else if (customCommand != null)
                        {
                            await msg.Channel.SendMessageAsync(customCommand.Response);
                        }
                        else
                        {
                            throw new ArgumentException("Invalid Command: " + cmdTxt);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Error executing command");
                switch (ex)
                {
                case ArgumentException _:
                    _logger.LogWarning(ex.Message);
                    break;

                default:
                    await msg.Channel.SendMessageAsync(BotResponses.Error);

                    break;
                }
            }
        }
        public async Task <bool> ContinueSubject(V4ReferenceContext context)
        {
            var conversation = ConversationState <ConversationData> .Get(context);

            if (context.Activity.Type == ActivityTypes.Message)
            {
                var luisResult =
                    context.Services.Get <RecognizerResult>(LuisRecognizerMiddleware.LuisRecognizerResultKey);

                if (luisResult != null)
                {
                    (string key, double score)topItem = luisResult.GetTopScoringIntent();

                    switch (topItem.key)
                    {
                    case "GetActivities":
                        // var activityId = luisResult.Entities.GetValue("ActivityID")[0].Value<string>();
                        // await context.SendActivity($" Found Entity Name: ActivityID : 04030201");
                        await context.SendActivities(BotResponses.GetSingle("04030201"));

                        break;

                    case "ListActivities":
                        await context.SendActivities(BotResponses.GetMultiple());

                        break;

                    case "SendAlert":
                        var xactivityId = luisResult.Entities.GetValue("ActivityID")[0].Value <string>();
                        await context.SendActivity($" Alert for Activity: {xactivityId} has been sent");

                        break;

                    case "CancelAlert":
                        var yactivityId = luisResult.Entities.GetValue("ActivityID")[0].Value <string>();
                        await context.SendActivity($"Activity : {yactivityId} has been cancelled");

                        break;

                    case "Help":
                        // show help
                        await context.SendActivity(MessageFactory.Text("Try commands like: latest, get latest alert, get last activity"));

                        break;

                    case "MainMenu":
                        // show Main Menu
                        conversation.CurrentSubject = conversation.MainMenuSubject;
                        await conversation.MainMenuSubject.ContinueSubject(context);

                        break;

                    case "Quit":
                        // show Main Menu
                        conversation.CurrentSubject = ParentSubject;
                        await ParentSubject.StartSubject(context);

                        break;

                    default:
                        // show our confusion
                        await GuessingGamesSubjectResponses.ReplyWithConfused(context);

                        break;
                    }
                }
            }

            return(true);
        }