示例#1
0
        public override async Task OnActivateAsync()
        {
            _channelId = this.GetPrimaryKeyString();
            _logger.LogInformation("Activating channel grain {channelId}", _channelId);

            if (!_channelBotState.RecordExists)
            {
                var defaultBotInfo = new BotAccountInfo
                {
                    IsActive  = true,
                    UserId    = _options.TokenInfo.UserId,
                    UserLogin = _options.TokenInfo.Login,
                };
                _channelBotState.State.AllowedBotAccounts.Add(defaultBotInfo);
                _channelBotState.State.Commands = new Dictionary <Guid, Conceptoire.Twitch.Commands.CommandOptions>();
            }
            else
            {
                // Temps: fix existing ids
                foreach ((var id, var command) in _channelBotState.State.Commands)
                {
                    command.Id = id;
                    if (command.Type == "MessageTracer")
                    {
                        command.Type = "Logger";
                    }
                }
                // Activate bot if it is supposed to be running
                if (_channelBotState.State.IsActive)
                {
                    await RegisterEventSubSubscriptions(CancellationToken.None);
                    await StartBot(_channelState.State.BroadcasterToken);
                }
            }

            await base.OnActivateAsync();

            _channelInfo = await _appClient.GetChannelInfoAsync(_channelId);
            await OnChannelUpdate(_channelInfo);
        }
示例#2
0
 async Task IChannelGrain.AllowBotAccount(BotAccountInfo botAccount)
 {
     _channelBotState.State.AllowedBotAccounts.Add(botAccount);
     await _channelBotState.WriteStateAsync();
 }