Esempio n. 1
0
        private async Task AttemptRun(string serverId, string input, IChatResponseToken responseToken)
        {
            // Time to do some work
            var serverName = ChatHelper.PreParseInputString(input.Replace("-run ", "").Replace("-start ", ""));
            var gameServer = _serverStore.GetGameServerByName(serverName, GetContainerInterfaceType());

            if (gameServer == null)
            {
                await responseToken.Respond("Image could not be found. Find all possible game servers with -possible");

                return;
            }
            var contId = await _containerInterface.Setup(responseToken, gameServer);

            await _containerInterface.Run(serverId, responseToken, contId);
        }
Esempio n. 2
0
        private async Task MessageGuildIfGameServerExists(SocketGuild mutualGuild,
                                                          SocketUser postUser)
        {
            // Get all the users in all the servers we exist in playing this game.
            var usrList  = mutualGuild.Users.Where(u => u.Activity?.Name == postUser.Activity.Name).ToList();
            var serverId = mutualGuild.Id;
            //Assume general channel for now.
            SocketGuildChannel sgc;

            if (mutualGuild.Channels.Any(c => c.Name == "general"))
            {
                sgc = mutualGuild.Channels.First(gc => gc.Name == "general");
            }
            else
            {
                // Catch all. eventually we want to use a value from the db that the guild has set.
                // Could probably do this with -configure
                sgc = mutualGuild.Channels.First();
            }

            var lastMsg = _lastMsgPerServer.GetValueOrDefault(serverId);

            //Make sure we don't send a loads of updates within a short period of time
            if (lastMsg != null && DateTime.Now.Subtract(lastMsg).Seconds <= 2)
            {
                return;
            }

            // Get the multiple word (people/person) playing a game.
            string multipleWord = "people";

            if (usrList.Count == 1)
            {
                multipleWord = "person";
            }

            //Decides if we have a person playing it and if we've got a server.
            if (sgc is IMessageChannel imc)
            {
                var parsedActivityName = ChatHelper.PreParseInputString(postUser.Activity.Name);
                var gameServer         = _serverStore.GetGameServerByName(parsedActivityName);

                if (gameServer != null)
                {
                    //Definitley got one
                    var msg = DiscordHelper.CreateEmbeddedMessage(
                        $"{usrList.Count} {multipleWord} playing {postUser.Activity.Name}. I've got a server for it. Enter `-run {parsedActivityName}` to start one.");
                    await imc.SendMessageAsync(embed : msg);
                }
                else
                {
                    var possibleGameServers = _serverStore.SearchGameServersByName(parsedActivityName);

                    if (possibleGameServers == null)
                    {
                        return;
                    }

                    //Probably got one, the server name is contained within their activity
                    if (possibleGameServers.Count == 1)
                    {
                        var msg = DiscordHelper.CreateEmbeddedMessage(
                            $"{usrList.Count} {multipleWord} playing {postUser.Activity.Name}. I think I've got a server for it. Enter `-run {possibleGameServers[0].ServerName}` to start one.");
                        await imc.SendMessageAsync(embed : msg);
                    }
                    //Almost certainly got one, just don't know which one
                    else if (possibleGameServers.Count > 1)
                    {
                        var msg = DiscordHelper.CreateEmbeddedMessage(
                            $"{usrList.Count} {multipleWord} playing {postUser.Activity.Name}. I've got a few servers that match that title. Enter `-possible` to see if one matches what you're playing.");
                        await imc.SendMessageAsync(embed : msg);
                    }
                }

                await SetOrAddToLastMsgDictionary(serverId);
            }
        }