Esempio n. 1
0
        public async Task <RuntimeResult> DeregisterGeneralManager([Remainder] string teamName)
        {
            logger.Debug($"Attemping to deregister GM from {teamName}");
            ehmBotSettings = Program.EhmBotSettings;
            await Task.Delay(0);

            var team = TeamList.GetTeam(teamName);

            if (team == null)
            {
                return new BotResult(CommandError.Unsuccessful, "Unrecognized team")
                       {
                           Action = EAction.Deregister, ResultTime = DateTime.Now
                       }
            }
            ;
            var             generalManager        = ehmBotSettings.GetGmByTeam(team);
            SocketGuildUser waitingGeneralManager = null;

            if (!string.IsNullOrWhiteSpace(generalManager.WaitingDiscordId))
            {
                waitingGeneralManager = Context.Guild.GetUser(Convert.ToUInt64(generalManager.WaitingDiscordId));
            }
            DeregisterGeneralManager(generalManager);
            ehmBotSettings.Save(settingsPath);
            var nickName = Context.Guild.GetUser(Context.User.Id).Nickname;

            logger.Debug($"Deregistered GM from {teamName} {(waitingGeneralManager != null ? $" Replaced with {waitingGeneralManager.Nickname ?? waitingGeneralManager.Username}" : string.Empty)}");
            return(new BotResult(null, $"Deregistered {nickName} from {team.FullName}" +
                                 $"{(waitingGeneralManager != null ? $" Replaced with {waitingGeneralManager.Nickname ?? waitingGeneralManager.Username}" : string.Empty)}")
            {
                Action = EAction.Deregister,
                ResultTime = DateTime.Now
            });
        }
Esempio n. 2
0
        public async Task <RuntimeResult> RegisterGeneralManager([Remainder] string teamName)
        {
            logger.Debug($"Attemping to register GM to {teamName}");
            ehmBotSettings = Program.EhmBotSettings;
            await Task.Delay(0);

            var team = TeamList.GetTeam(teamName);

            if (team == null)
            {
                return new BotResult(CommandError.Unsuccessful, "Unrecognized team")
                       {
                           Action = EAction.Register, ResultTime = DateTime.Now
                       }
            }
            ;
            var generalManager        = ehmBotSettings.GetGmByTeam(team);
            var currentGeneralManager = ehmBotSettings.GetGmById(Context.User.Id.ToString());
            var nickName = Context.Guild.GetUser(Context.User.Id).Nickname;

            if (string.IsNullOrWhiteSpace(generalManager.DiscordId) || generalManager.DiscordId == Context.User.Id.ToString())
            {
                generalManager.DiscordId = Context.User.Id.ToString();

                if (currentGeneralManager != null)
                {
                    DeregisterGeneralManager(currentGeneralManager);
                }
                ehmBotSettings.Save(settingsPath);
                logger.Debug($"Registered GM {nickName} to {teamName}");
                return(new BotResult(null, $"Registered {nickName} as {team.FullName}")
                {
                    Action = EAction.Register, ResultTime = DateTime.Now
                });
            }
            var currentUserOnTeam = Context.Guild.GetUser(Convert.ToUInt64(generalManager.DiscordId));

            if (currentUserOnTeam == null)
            {
                generalManager.DiscordId = Context.User.Id.ToString();
                if (currentGeneralManager != null)
                {
                    DeregisterGeneralManager(currentGeneralManager);
                }
                ehmBotSettings.Save(settingsPath);
                logger.Debug($"Registered GM {nickName} to {teamName}");
                return(new BotResult(null, $"Registered {nickName} as {team.FullName}")
                {
                    Action = EAction.Register, ResultTime = DateTime.Now
                });
            }
            generalManager.WaitingDiscordId = Context.User.Id.ToString();
            ehmBotSettings.Save(settingsPath);
            logger.Debug($"Set GM {nickName} in waiting list for {teamName}");
            return(new BotResult(null, $"{nickName} will be registered as {team.FullName} when {currentUserOnTeam.Nickname ?? currentUserOnTeam.Nickname} registers as another team or deregisters.")
            {
                Action = EAction.Register,
                ResultTime = DateTime.Now
            });
        }