예제 #1
0
        public static async void Run([TimerTrigger("0 15 16 * * 5")] TimerInfo myTimer, ILogger log)
        {
            ChallongeSQLHelper.ChallongeSQLHelperConnectionString = Environment.GetEnvironmentVariable("dbConnection");
            ChallongeApiHelper.HttpHelper.ChallongeHttpHelper.setAuthorizationHeader(Environment.GetEnvironmentVariable("ApiUsername"), Environment.GetEnvironmentVariable("ApiPassword"));

            FrayDbCurrentWeek currentWeek = ChallongeSQLHelper.GetCurrentWeekInfo();

            if (!currentWeek.TournamentId.HasValue)
            {
                return;
            }

            ChallongeHttpHelper.StartTournament(currentWeek.TournamentId.Value);

            var postyBoi = Activity.CreateMessageActivity();

            postyBoi.Text = "Predictions are closed.  Tournament has started.";

            try
            {
                var connectorClient = new ConnectorClient(new Uri(Environment.GetEnvironmentVariable("ServiceUrl"))
                                                          , microsoftAppId: Environment.GetEnvironmentVariable("MicrosoftAppId")
                                                          , microsoftAppPassword: Environment.GetEnvironmentVariable("MicrosoftAppPassword"));
                MicrosoftAppCredentials.TrustServiceUrl(Environment.GetEnvironmentVariable("ServiceUrl"), DateTime.MaxValue);

                var response = await connectorClient.Conversations.ReplyToActivityWithRetriesAsync(currentWeek.ConversationId, "NotActuallyImportant", (Activity)postyBoi);
            }
            catch (Exception ex)
            {
                //figure out what to do with this
            }

            log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
        }
예제 #2
0
        public async Task HandleMessage(ConnectorClient connector, Activity activity)
        {
            ChallongeSQLHelper.ChallongeSQLHelperConnectionString = ConfigurationManager.AppSettings["dbConnection"];
            ChallongeSQLHelper.SetCurrentConversation(activity.Conversation.Id);

            //Activity reply = activity.CreateReply($"{string.Join("\n\n", activity.Properties.Children().Select(x => x.Path))}");

            //Activity reply = activity.CreateReply($"Dead");

            //await connector.Conversations.ReplyToActivityWithRetriesAsync(reply);
        }
예제 #3
0
        public static void Run([TimerTrigger("0 0 12 * * 1")] TimerInfo myTimer, ILogger log)
        {
            log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");

            //Doing this way for now since the new version of the functions doesn't seem to play nice with the configuration manager
            ChallongeApiHelper.HttpHelper.ChallongeHttpHelper.setAuthorizationHeader(Environment.GetEnvironmentVariable("ApiUsername"), Environment.GetEnvironmentVariable("ApiPassword"));

            ChallongeApiHelper.SQLHelper.ChallongeSQLHelper.ChallongeSQLHelperConnectionString = Environment.GetEnvironmentVariable("dbConnection");

            FrayDbCurrentWeek currentWeekInfo = ChallongeApiHelper.SQLHelper.ChallongeSQLHelper.GetCurrentWeekInfo();

            TournamentCreation tournamentToCreate = new TournamentCreation()
            {
                name                   = $"QDAL Friday Fray - Week {currentWeekInfo.CurrentWeekNum.ToString()}",
                url                    = Guid.NewGuid().ToString().Replace("-", ""),
                tournament_type        = TournamentConstants.TournamentType.SingleElimination,
                open_signup            = true,
                hold_third_place_match = false,
                pts_for_game_win       = 0.0m,
                pts_for_game_tie       = 0.0m,
                pts_for_match_win      = 1.0m,
                pts_for_match_tie      = 0.5m,
                pts_for_bye            = 1.0m,
                swiss_rounds           = 0,
                @private               = false,
                ranked_by              = TournamentConstants.RankedBy.MatchWins,
                show_rounds            = true,
                hide_forum             = false,
                sequential_pairings    = false,
                rr_pts_for_game_win    = 0.0m,
                rr_pts_for_game_tie    = 0.0m,
                rr_pts_for_match_win   = 0.0m,
                rr_pts_for_match_tie   = 0.0m,
                prediction_method      = TournamentConstants.PredictionMethod.Exponential,
                game_id                = TournamentConstants.GameId.PingPong
            };

            var createdTournamnet = ChallongeApiHelper.HttpHelper.ChallongeHttpHelper.PostNewTournament(tournamentToCreate);

            ChallongeSQLHelper.SetCurrentSignupUrl(createdTournamnet.sign_up_url);
            ChallongeSQLHelper.SetCurrentTournamnetId(createdTournamnet.id);

            log.LogInformation("Weekly tournament scheduled succesfully");
        }
예제 #4
0
        public async Task HandleMessage(ConnectorClient connector, Activity activity)
        {
            var channelThing = activity.GetChannelData <TeamsChannelData>();

            ChallongeSQLHelper.ChallongeSQLHelperConnectionString = ConfigurationManager.AppSettings["dbConnection"];

            FrayDbTeamsUser teamsUser = ChallongeSQLHelper.SqlGetSingleUser(activity.From.Id, channelThing.Channel.Id);

            bool existingUser = teamsUser != null;

            teamsUser = teamsUser ?? new FrayDbTeamsUser()
            {
                UserId = activity.From.Id, UserName = activity.From.Name
            };
            teamsUser.IsTag     = true;
            teamsUser.ChannelId = channelThing.Channel.Id;

            //if(existingUser) { ChallongeSQLHelper.SqlUpdateTeamsUser(activity.From.Id, teamsUser); }
            if (!existingUser)
            {
                ChallongeSQLHelper.SqlInsertTeamsUser(teamsUser);
            }

            Activity reply = activity.CreateReply();

            if (existingUser)
            {
                reply.AddMentionToText(activity.From, MentionTextLocation.AppendText);
            }
            else
            {
                reply.Text = $"Added information for {activity.From.Name}";
            }

            await connector.Conversations.ReplyToActivityWithRetriesAsync(reply);
        }
예제 #5
0
        static void Main(string[] args)
        {
            ChallongeSQLHelper.ChallongeSQLHelperConnectionString = ConfigurationManager.ConnectionStrings["dbConnection"].ConnectionString;

            List <TournamentRetrieval> tournamentList = ChallongeDataHelper.GetAllTournaments();

            tournamentList = tournamentList.Where(x => x.started_at.HasValue).ToList();

            tournamentList = tournamentList.Where(x => x.name.Contains("Week 52")).ToList();

            foreach (TournamentRetrieval tournament in tournamentList)
            {
                Console.WriteLine($"Currently importing {tournament.name}");

                List <MatchRetrieval>       tournamentMatches      = ChallongeDataHelper.GetTournamentMatches(tournament.id);
                List <ParticipantRetrieval> tournamentParticipants = ChallongeDataHelper.GetTournamentParticipants(tournament.id);

                FrayDbTournament dbTournament = new FrayDbTournament()
                {
                    TournamentName = tournament.name,
                    TournamentId   = tournament.id,
                    TournamentDt   = tournament.started_at.Value
                };

                ChallongeSQLHelper.SqlSaveTournament(dbTournament);

                List <FrayDbParticipant> existingParticipants = ChallongeSQLHelper.SqlGetParticipants();
                HashSet <string>         knownParticipants    = new HashSet <string>(existingParticipants.Select(x => x.ChallongeUserName));

                foreach (ParticipantRetrieval retrievedParticipant in tournamentParticipants)
                {
                    if (string.IsNullOrEmpty(retrievedParticipant.challonge_username))
                    {
                        retrievedParticipant.challonge_username = "******";
                    }

                    if (!knownParticipants.Contains(retrievedParticipant.challonge_username))
                    {
                        FrayDbParticipant newParticipant = new FrayDbParticipant()
                        {
                            ChallongeUserName = retrievedParticipant.challonge_username
                        };

                        ChallongeSQLHelper.SqlSaveParticipant(newParticipant);
                    }
                }

                List <FrayDbParticipant> allKnownParticipants = ChallongeSQLHelper.SqlGetParticipants();

                int maxRank = tournamentMatches.Select(x => x.round).Max();

                foreach (MatchRetrieval retrievedMatch in tournamentMatches.Where(x => x.winner_id.HasValue))
                {
                    FrayDbMatch newMatch = new FrayDbMatch();
                    newMatch.MatchId   = retrievedMatch.id;
                    newMatch.MatchRank = retrievedMatch.round.Equals(0)
                        ? 100
                        : maxRank + 1 - retrievedMatch.round;

                    ParticipantRetrieval player1         = tournamentParticipants.First(x => x.id.Equals(retrievedMatch.player1_id));
                    FrayDbParticipant    actuallyPlayer1 = allKnownParticipants.First(x => x.ChallongeUserName.Equals(player1.challonge_username));

                    ParticipantRetrieval player2         = tournamentParticipants.First(x => x.id.Equals(retrievedMatch.player2_id));
                    FrayDbParticipant    actuallyPlayer2 = allKnownParticipants.First(x => x.ChallongeUserName.Equals(player2.challonge_username));

                    newMatch.Player1Id = Convert.ToInt32(actuallyPlayer1.ParticipantId);
                    newMatch.Player2Id = Convert.ToInt32(actuallyPlayer2.ParticipantId);

                    if (retrievedMatch.winner_id.Equals(player1.id))
                    {
                        newMatch.WinnerId = Convert.ToInt32(actuallyPlayer1.ParticipantId);
                        newMatch.LoserId  = Convert.ToInt32(actuallyPlayer2.ParticipantId);
                    }
                    else
                    {
                        newMatch.WinnerId = Convert.ToInt32(actuallyPlayer2.ParticipantId);
                        newMatch.LoserId  = Convert.ToInt32(actuallyPlayer1.ParticipantId);
                    }

                    newMatch.TournamentId = tournament.id;

                    ChallongeSQLHelper.SqlSaveMatch(newMatch);

                    int currentSetNo = 0;

                    foreach (string set in retrievedMatch.scores_csv.Split(','))
                    {
                        currentSetNo++;

                        FrayDbSet newSet = new FrayDbSet();
                        newSet.MatchId = retrievedMatch.id;
                        newSet.SetNo   = currentSetNo;

                        if (set.IndexOf('-') == 0)
                        {
                            int splitMarker = set.IndexOf('-', 1);

                            newSet.Player1Score = int.Parse(set.Substring(0, splitMarker));
                            newSet.Player2Score = int.Parse(set.Substring(splitMarker + 1));
                        }
                        else
                        {
                            int splitMarker = set.IndexOf('-');

                            newSet.Player1Score = int.Parse(set.Substring(0, splitMarker));
                            newSet.Player2Score = int.Parse(set.Substring(splitMarker + 1));
                        }

                        ChallongeSQLHelper.SqlSaveSet(newSet);
                    }
                }
            }
        }
예제 #6
0
        public static void Run([TimerTrigger("0 0 11 * * 1")] TimerInfo myTimer, ILogger log)
        {
            log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");

            //Doing this way for now since the new version of the functions doesn't seem to play nice with the configuration manager
            ChallongeApiHelper.HttpHelper.ChallongeHttpHelper.setAuthorizationHeader(Environment.GetEnvironmentVariable("ApiUsername"), Environment.GetEnvironmentVariable("ApiPassword"));

            ChallongeSQLHelper.ChallongeSQLHelperConnectionString = Environment.GetEnvironmentVariable("dbConnection");

            List <TournamentRetrieval> tournamentList = ChallongeApiHelper.HttpHelper.ChallongeHttpHelper.GetRecentTournaments();

            FrayDbCurrentWeek currentWeekInfo = ChallongeSQLHelper.GetCurrentWeekInfo();

            tournamentList = tournamentList
                             .Where(x => x.started_at.HasValue)
                             .Where(x => x.name.Contains($"Week {currentWeekInfo.CurrentWeekNum.ToString()}"))
                             .ToList();

            foreach (TournamentRetrieval tournament in tournamentList)
            {
                Console.WriteLine($"Currently importing {tournament.name}");

                List <MatchRetrieval>       tournamentMatches      = ChallongeDataHelper.GetTournamentMatches(tournament.id);
                List <ParticipantRetrieval> tournamentParticipants = ChallongeDataHelper.GetTournamentParticipants(tournament.id);

                FrayDbTournament dbTournament = new FrayDbTournament()
                {
                    TournamentName = tournament.name,
                    TournamentId   = tournament.id,
                    TournamentDt   = tournament.started_at.Value
                };

                ChallongeSQLHelper.SqlSaveTournament(dbTournament);

                List <FrayDbParticipant> existingParticipants = ChallongeSQLHelper.SqlGetParticipants();
                HashSet <string>         knownParticipants    = new HashSet <string>(existingParticipants.Select(x => x.ChallongeUserName));

                foreach (ParticipantRetrieval retrievedParticipant in tournamentParticipants)
                {
                    if (string.IsNullOrEmpty(retrievedParticipant.challonge_username))
                    {
                        retrievedParticipant.challonge_username = "******";
                    }

                    if (!knownParticipants.Contains(retrievedParticipant.challonge_username))
                    {
                        FrayDbParticipant newParticipant = new FrayDbParticipant()
                        {
                            ChallongeUserName = retrievedParticipant.challonge_username
                        };

                        ChallongeSQLHelper.SqlSaveParticipant(newParticipant);
                    }
                }

                List <FrayDbParticipant> allKnownParticipants = ChallongeSQLHelper.SqlGetParticipants();

                int maxRank = tournamentMatches.Select(x => x.round).Max();

                foreach (MatchRetrieval retrievedMatch in tournamentMatches.Where(x => x.winner_id.HasValue))
                {
                    FrayDbMatch newMatch = new FrayDbMatch();
                    newMatch.MatchId   = retrievedMatch.id;
                    newMatch.MatchRank = retrievedMatch.round.Equals(0)
                        ? 100
                        : maxRank + 1 - retrievedMatch.round;

                    ParticipantRetrieval player1         = tournamentParticipants.First(x => x.id.Equals(retrievedMatch.player1_id));
                    FrayDbParticipant    actuallyPlayer1 = allKnownParticipants.First(x => x.ChallongeUserName.Equals(player1.challonge_username));

                    ParticipantRetrieval player2         = tournamentParticipants.First(x => x.id.Equals(retrievedMatch.player2_id));
                    FrayDbParticipant    actuallyPlayer2 = allKnownParticipants.First(x => x.ChallongeUserName.Equals(player2.challonge_username));

                    newMatch.Player1Id = Convert.ToInt32(actuallyPlayer1.ParticipantId);
                    newMatch.Player2Id = Convert.ToInt32(actuallyPlayer2.ParticipantId);

                    if (retrievedMatch.winner_id.Equals(player1.id))
                    {
                        newMatch.WinnerId = Convert.ToInt32(actuallyPlayer1.ParticipantId);
                        newMatch.LoserId  = Convert.ToInt32(actuallyPlayer2.ParticipantId);
                    }
                    else
                    {
                        newMatch.WinnerId = Convert.ToInt32(actuallyPlayer2.ParticipantId);
                        newMatch.LoserId  = Convert.ToInt32(actuallyPlayer1.ParticipantId);
                    }

                    newMatch.TournamentId = tournament.id;

                    ChallongeSQLHelper.SqlSaveMatch(newMatch);

                    int currentSetNo = 0;

                    foreach (string set in retrievedMatch.scores_csv.Split(','))
                    {
                        currentSetNo++;

                        FrayDbSet newSet = new FrayDbSet();
                        newSet.MatchId = retrievedMatch.id;
                        newSet.SetNo   = currentSetNo;

                        if (set.IndexOf('-') == 0)
                        {
                            int splitMarker = set.IndexOf('-', 1);

                            newSet.Player1Score = int.Parse(set.Substring(0, splitMarker));
                            newSet.Player2Score = int.Parse(set.Substring(splitMarker + 1));
                        }
                        else
                        {
                            int splitMarker = set.IndexOf('-');

                            newSet.Player1Score = int.Parse(set.Substring(0, splitMarker));
                            newSet.Player2Score = int.Parse(set.Substring(splitMarker + 1));
                        }

                        ChallongeSQLHelper.SqlSaveSet(newSet);
                    }
                }
            }

            ChallongeSQLHelper.ProgressToWeekNum(currentWeekInfo.CurrentWeekNum + 1);
        }
        public async Task HandleMessage(ConnectorClient connector, Activity activity)
        {
            bool rejected = true;

            ChallongeSQLHelper.ChallongeSQLHelperConnectionString = ConfigurationManager.AppSettings["dbConnection"];
            var channelThing = activity.GetChannelData <TeamsChannelData>();

            FrayDbTeamsTeam existingTeam = ChallongeSQLHelper.SqlGetSingleTeam(channelThing.Team.Id);

            if (existingTeam == null)
            {
                var teamInfo = connector.GetTeamsConnectorClient().Teams.FetchTeamDetails(channelThing.Team.Id);

                var addTeam = new FrayDbTeamsTeam()
                {
                    TeamId   = teamInfo.Id,
                    TeamName = teamInfo.Name
                };

                ChallongeSQLHelper.SqlSaveTeam(addTeam);
                rejected = false;
            }

            //Check to see whether we've already got the channel
            FrayDbTeamsChannel existingChannel = ChallongeSQLHelper.SqlGetSingleChannel(channelThing.Channel.Id, channelThing.Team.Id);

            if (existingChannel == null)
            {
                //If your channel id matches the team id, you're in the autogenerate General
                if (channelThing.Channel.Id.Equals(channelThing.Team.Id))
                {
                    var addChannel = new FrayDbTeamsChannel()
                    {
                        ChannelId   = channelThing.Channel.Id,
                        TeamId      = channelThing.Team.Id,
                        ChannelName = "General",
                        IsPost      = true
                    };

                    ChallongeSQLHelper.SqlSaveChannel(addChannel);
                    rejected = false;
                }
                else
                {
                    //We gotta get the channels and figure out which one we're in
                    var convoList      = connector.GetTeamsConnectorClient().Teams.FetchChannelList(channelThing.Team.Id);
                    var currentChannel = convoList.Conversations.First(x => x.Id.Equals(channelThing.Channel.Id));

                    var addChannel = new FrayDbTeamsChannel()
                    {
                        ChannelId   = currentChannel.Id,
                        TeamId      = channelThing.Team.Id,
                        ChannelName = currentChannel.Name,
                        IsPost      = true
                    };

                    ChallongeSQLHelper.SqlSaveChannel(addChannel);
                    rejected = false;
                }
            }

            Activity reply = null;

            if (rejected)
            {
                reply = activity.CreateReply("That's going to be a hard pass");
            }
            else
            {
                reply = activity.CreateReply("Saved the data");
            }

            await connector.Conversations.ReplyToActivityWithRetriesAsync(reply);
        }
        public static async void Run([TimerTrigger("0 0 15 * * 1")] TimerInfo myTimer, ILogger log)
        {
            ChallongeSQLHelper.ChallongeSQLHelperConnectionString = Environment.GetEnvironmentVariable("dbConnection");
            FrayDbCurrentWeek currentInfo = ChallongeSQLHelper.GetCurrentWeekInfo();
            var postyBoi = Activity.CreateMessageActivity();

            postyBoi.Text = $"Current signup link\n\n[Week {currentInfo.CurrentWeekNum.ToString()} Signup]({currentInfo.SignupUrl})";

            foreach (FrayDbTeamsChannel chan in ChallongeSQLHelper.SqlGetPostChannels())
            {
                try
                {
                    var conversationParameters = new ConversationParameters
                    {
                        IsGroup     = true,
                        ChannelData = new TeamsChannelData
                        {
                            Channel = new ChannelInfo(chan.ChannelId),
                        },
                        Activity = (Activity)postyBoi
                    };

                    var connectorClient = new ConnectorClient(new Uri(Environment.GetEnvironmentVariable("ServiceUrl"))
                                                              , microsoftAppId: Environment.GetEnvironmentVariable("MicrosoftAppId")
                                                              , microsoftAppPassword: Environment.GetEnvironmentVariable("MicrosoftAppPassword"));
                    MicrosoftAppCredentials.TrustServiceUrl(Environment.GetEnvironmentVariable("ServiceUrl"), DateTime.MaxValue);

                    var response = await connectorClient.Conversations.CreateConversationAsync(conversationParameters);

                    List <FrayDbTeamsUser> frayTagUsers = ChallongeSQLHelper.SqlGetTagUsers(chan.ChannelId);

                    var taggingUsers = Activity.CreateMessageActivity();

                    bool first = true;
                    foreach (FrayDbTeamsUser user in frayTagUsers)
                    {
                        if (!first)
                        {
                            taggingUsers.Text += ", ";
                        }
                        taggingUsers.AddMentionToText(new ChannelAccount(user.UserId, user.UserName), MentionTextLocation.AppendText);
                        first = false;
                    }

                    if (string.IsNullOrEmpty(taggingUsers.Text))
                    {
                        taggingUsers.Text = "All dressed up and no one to tag";
                    }

                    await connectorClient.Conversations.ReplyToActivityWithRetriesAsync(response.Id, response.ActivityId, (Activity)taggingUsers);

                    ChallongeSQLHelper.SetCurrentConversation(response.Id);
                }
                catch (Exception ex)
                {
                    //figure out what to do with this
                }
            }

            log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
        }