Example #1
0
        private async Task OnReactionAdded(Cacheable <IUserMessage, ulong> cache, ISocketMessageChannel ch, SocketReaction reaction)
        {
            var                 dlTasks = new List <Task>();
            IUserMessage        msg     = null;
            Task <IUserMessage> msgTask = null;

            if (cache.HasValue)
            {
                msg = cache.Value;
            }
            else
            {
                msgTask = cache.DownloadAsync();
                dlTasks.Add(msgTask);
            }

            IGuildUser   user     = null;
            Task <IUser> userTask = null;

            if (reaction.User.IsSpecified)
            {
                user = reaction.User.Value as IGuildUser;
            }
            else
            {
                userTask = ch.GetUserAsync(reaction.UserId);
                dlTasks.Add(userTask);
            }
            await Task.WhenAll(dlTasks);

            if (msg == null)
            {
                msg = await msgTask;
            }
            if (user == null)
            {
                user = await userTask as IGuildUser;
            }

            // Don't process bot reaction
            if (user.IsBot || user.IsWebhook)
            {
                return;
            }

            try{
                _logger.LogDebug($"{user.Username}#{user.Discriminator}> reaction {reaction.Emote.Name}");
                var code = _automuteService.GetVCLinkedGameCode(user.VoiceChannel);
                if (code is null)
                {
                    return;
                }
                await _automuteService.OnReactionAdded(msg, user, reaction, code);
            }catch (Exception e) {
                _logger.LogDebug($"{e.GetType()} -- {e.Message}");
                using (_logger.BeginScope("")){ _logger.LogDebug(e.StackTrace); }
            }
        }
Example #2
0
        public async Task UnlinkAsync([Summary("User index")] int index)
        {
            if (Context.IsPrivate)
            {
                await ReplyAsync("Cannot be used with DM.");

                return;
            }

            var user = Context.Message.Author as SocketGuildUser;

            if (user?.VoiceChannel == null)
            {
                await ReplyAsync($"{Context.User.Mention} Please join the voice chat on this server.");

                return;
            }
            if (index <= 0)
            {
                await ReplyAsync("Enter a value greater than or equal to `1`.");

                return;
            }

            // Search game
            var code = _automuteService.GetVCLinkedGameCode(user.VoiceChannel);

            if (code != null)
            {
                try
                {
                    if (!_automuteService.UnlinkUserAndPlayer(code, user, index - 1))
                    {
                        _logger.LogInformation("unlink failed.");
                    }
                }
                catch (Exception e)
                {
                    _logger.LogError($"{e.GetType()} -- {e.Message}");
                    using (_logger.BeginScope("err"))
                    {
                        _logger.LogError(e.StackTrace);
                    }
                }
                return;
            }
            await ReplyAsync($":speaker: \"{user.VoiceChannel.Name}\" > There are no games to pair with.");
        }
Example #3
0
        public async Task RefreshAsync()
        {
            if (Context.IsPrivate)
            {
                await ReplyAsync("Cannot be used with DM.");

                return;
            }

            var user = Context.Message.Author as SocketGuildUser;

            if (user?.VoiceChannel == null)
            {
                await ReplyAsync($"{Context.User.Mention} Please join the voice chat on this server.");

                return;
            }

            // Search game
            var code = _automuteService.GetVCLinkedGameCode(user.VoiceChannel);

            if (code != null)
            {
                try
                {
                    if (!_automuteService.RefreshEmbed(code))
                    {
                        _logger.LogInformation("refresh failed.");
                    }
                }
                catch (Exception e)
                {
                    _logger.LogCritical(e.Message);
                    using (_logger.BeginScope("err"))
                    {
                        _logger.LogCritical(e.StackTrace);
                    }
                }
                return;
            }
            await ReplyAsync($":speaker: \"{user.VoiceChannel.Name}\" > There are no games to pair with.");
        }