internal string GetCurrentPlayerList(SocketMessage message, bool returnCountOnly = false)
        {
            var       sheetsService = AuthorizeGoogleSheets();
            HomeSheet homesheet     = GetHomeSheet(message.Channel.Name);
            int       nameIndex     = 1;

            try
            {
                // Define request parameters.
                var range = $"{homesheet.SheetName}!A:E";

                // load the data
                var           sheetRequest       = sheetsService.Spreadsheets.Values.Get(homesheet.SheetId, range);
                var           sheetResponse      = sheetRequest.Execute();
                var           values             = sheetResponse.Values;
                StringBuilder currentPlayerList  = new StringBuilder();
                int           currentPlayerCount = 0;

                for (int i = 1; i < values.Count; i++)
                {
                    if (values[i].Count > 0 && !values[i][0].ToString().ToUpper().Equals("DROPPED"))
                    {
                        string name = values[i][nameIndex].ToString();
                        currentPlayerList.AppendLine(name);
                        currentPlayerCount++;
                    }
                }

                if (returnCountOnly)
                {
                    return($"There are currently {currentPlayerCount} humans registered (and no robots)");
                }
                else
                {
                    return($"There are currently {currentPlayerCount} humans registered (and no robots):{Environment.NewLine}{currentPlayerList}");
                }
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc.Message);
                return("Sorry, wasn't able to determine player list");
            }
        }
        internal HomeSheet GetHomeSheet(string channelName)
        {
            var       sheetsService = AuthorizeGoogleSheets();
            HomeSheet sheetInfo     = new HomeSheet();

            if (channelName == "weekly-dice-arena")
            {
                sheetInfo.SheetId   = WDASheetId;
                sheetInfo.SheetName = Refs.WdaSheetName;
            }
            else if (channelName == "dice-fight")
            {
                sheetInfo.SheetId   = DiceFightSheetId;
                sheetInfo.SheetName = Refs.DiceFightSheetName;
            }
            else if (channelName == Refs.EVENT_ONEOFF)
            {
                sheetInfo.SheetId   = OneOffSheetId;
                sheetInfo.SheetName = Refs.EVENT_ONEOFF;
            }
            else if (channelName == "team-of-the-month")
            {
                sheetInfo.SheetId   = TotMSheetId;
                sheetInfo.SheetName = Refs.TotMSheetName;
            }
            else if (channelName == "monthly-one-shot-team-submission")
            {
                sheetInfo.SheetId   = CRGRM1SSheetId;
                sheetInfo.SheetName = Refs.CRGRM1SSheetName;
            }
            else if (channelName == "tttd-team-submission")
            {
                sheetInfo.SheetId   = CRGRTTTDSheetId;
                sheetInfo.SheetName = Refs.CRGRTTTDSheetName;
            }
            else
            {
                return(null);
            }

            try
            {
                var range         = $"HomeSheet!A:E";
                var sheetRequest  = sheetsService.Spreadsheets.Values.Get(sheetInfo.SheetId, range);
                var sheetResponse = sheetRequest.Execute();


                try
                {
                    sheetInfo.EventName = sheetResponse.Values[0][1].ToString();
                }
                catch
                {
                    // no biggee if it isn't there
                }

                foreach (var row in sheetResponse.Values)
                {
                    if (row.Count >= 1 && row[0].ToString().ToLower() == sheetInfo.SheetName.ToLower())
                    {
                        sheetInfo.EventDate         = row[0] != null ? row[0].ToString() : string.Empty;
                        sheetInfo.SheetName         = row[1] != null ? row[1].ToString() : string.Empty;
                        sheetInfo.FormatDescription = row.Count >= 3 ? row[2].ToString() : "No information for this event yet";
                        sheetInfo.Info = row.Count >= 4 ? row[3].ToString() : string.Empty;
                        string authUserList = row.Count >= 5 ? row[4].ToString() : string.Empty;
                        if (!string.IsNullOrEmpty(authUserList))
                        {
                            sheetInfo.AuthorizedUsers = authUserList.Split(',').ToList();
                        }
                        return(sheetInfo);
                    }
                }
            }
            catch (Exception exc)
            {
                _logger.LogError($"Exception getting HomeSheet: {exc.Message}");
                return(null);
            }
            return(null);
        }
Пример #3
0
        private string SubmitTeamLink(string eventName, string teamlink, SocketMessage message)
        {
            var         sheetsService = _sheetService.AuthorizeGoogleSheets();
            ColumnInput input;
            string      response  = Refs.DMBotSubmitTeamHint;
            HomeSheet   homeSheet = _sheetService.GetHomeSheet(eventName);

            if (homeSheet == null)
            {
                return(response);
            }
            if (eventName == "weekly-dice-arena")
            {
                input = new ColumnInput()
                {
                    Column1Value = DateTime.Now.ToString(),
                    Column2Value = message.Author.Username,
                    Column3Value = teamlink
                };
                response = _sheetService.SendLinkToGoogle(sheetsService, message, _sheetService.WDASheetId, homeSheet.SheetName, input);
            }
            else if (eventName == "dice-fight")
            {
                string winName = _sheetService.GetWINName(sheetsService, _sheetService.DiceFightSheetId, message.Author.Username);
                input = new ColumnInput()
                {
                    Column1Value = DateTime.Now.ToString(),
                    Column2Value = message.Author.Username,
                    Column3Value = teamlink,
                    Column4Value = winName
                };
                response = _sheetService.SendLinkToGoogle(sheetsService, message, _sheetService.DiceFightSheetId, homeSheet.SheetName, input);
                if (string.IsNullOrWhiteSpace(winName))
                {
                    message.Author.SendMessageAsync(Refs.DiceFightAskForWin);
                }
            }
            else if (eventName == Refs.EVENT_ONEOFF)
            {
                //string winName = _sheetService.GetWINName(sheetsService, _sheetService.OneOffSheetId, message.Author.Username);
                input = new ColumnInput()
                {
                    Column1Value = DateTime.Now.ToString(),
                    Column2Value = message.Author.Username,
                    Column3Value = teamlink
                };
                response = _sheetService.SendLinkToGoogle(sheetsService, message, _sheetService.OneOffSheetId, homeSheet.SheetName, input);
                //if (string.IsNullOrWhiteSpace(winName))
                //{
                //    message.Author.SendMessageAsync(Refs.DiceFightAskForWin);
                //}
            }
            else if (eventName == "team-of-the-month")
            {
                input = new ColumnInput()
                {
                    Column1Value = DateTime.Now.ToString(),
                    Column2Value = message.Author.Username,
                    Column3Value = teamlink
                };
                response = _sheetService.SendLinkToGoogle(sheetsService, message, _sheetService.TotMSheetId, homeSheet.SheetName, input);
            }
            else if (eventName == "monthly-one-shot")
            {
                input = new ColumnInput()
                {
                    Column1Value = message.Author.Username,
                    Column2Value = teamlink
                };
                response = _sheetService.SendLinkToGoogle(sheetsService, message, _sheetService.CRGRM1SSheetId, Refs.CRGRM1SSheetName, input);
            }
            else if (eventName == "TTTD")
            {
                input = new ColumnInput()
                {
                    Column1Value = message.Author.Username,
                    Column2Value = teamlink
                };
                response = _sheetService.SendLinkToGoogle(sheetsService, message, _sheetService.CRGRTTTDSheetId, Refs.CRGRTTTDSheetName, input);
            }
            if (!response.Equals(Refs.DMBotSubmitTeamHint))
            {
                message.Author.SendMessageAsync($"The following team was successfully submitted for {eventName}");
                message.Author.SendMessageAsync(teamlink);
            }
            return(response);
        }