public async Task Handle(LeaveChannelCommand message, IMessageHandlerContext context)
        {
            var user = await userRepository.GetById(message.RequestedByUserId).ConfigureAwait(false);

            var applicationContext = ApplicatonContext.CreateFromUser(user);

            await chatlistenerService.UnlistenTo(message.ChannelName, applicationContext).ConfigureAwait(false);

            await context.Publish(new LeftChannelEvent(message.ChannelName)).ConfigureAwait(false);
        }
Beispiel #2
0
        public TwitchBot(string username, string oAuth)
        {
            irc = new IRCUtil("irc.twitch.tv", 6667, username, oAuth);
            this.botUsername               = username;
            channels                       = new Dictionary <string, CommandDictionary>();
            Live                           = true;
            globalCommands                 = new CommandDictionary("#GLOBAL#", irc);
            globalCommands["shutdown"]     = new ShutdownCommand(this);
            globalCommands["leaveChannel"] = new LeaveChannelCommand(this, Level.LEVEL_MODERATOR);
            botUsername                    = username;

            this._logger = LogManager.GetCurrentClassLogger();
        }
        public async Task UpdateChannelListenerState(string channelName, bool shouldListen, IApplicationContext context)
        {
            if (!context.User.HasRole(Roles.Admin) && !string.Equals(context.User.TwitchUsername, channelName, StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            if (shouldListen)
            {
                var joinChannelCommand = new JoinChannelCommand {
                    ChannelName = channelName, RequestedByUserId = context.UserId
                };
                await messageDispatcher.Send(joinChannelCommand).ConfigureAwait(false);
            }
            else
            {
                var leaveChannelCommand = new LeaveChannelCommand {
                    ChannelName = channelName, RequestedByUserId = context.UserId
                };
                await messageDispatcher.Send(leaveChannelCommand).ConfigureAwait(false);
            }
        }