Пример #1
0
        private Task HandleJoinVoiceChat(DiscordGuild guild, DiscordUser user, DiscordChannel channel)
        {
            return(Task.Run(async() => {
                await Task.Delay(TimeSpan.FromSeconds(10));
                if (!channel.Users.Any())
                {
                    return;
                }

                // Check only certain categories:
                if (!channel.ParentId.HasValue || this._config.VoiceNotificationCategories.Contains(channel.ParentId.Value))
                {
                    return;
                }
                // Only alert for users who have VC notifications enabled themselves:
                var userConfig = this._settings.GetVoiceSettings(guild.Id, user.Id);
                if (userConfig == null)
                {
                    return;
                }
                userConfig.IsInTimeout = true;
                var voiceUsers = this._settings.GetVoiceUsers(guild.Id);
                foreach (var user in voiceUsers.Where(y => y.UserId != user.Id && y.CheckFilter(user.Id)))
                {
                    try {
                        var member = guild.Members[user.UserId];
                        var matchingStatus = member?.Presence != null && member.Presence.Status.MatchesAvailability(user.TargetStatus);
                        if (!matchingStatus)
                        {
                            continue;
                        }
                        await member.SendMessageAsync($"A user just joined the {channel.Name} voice channel in ${guild.Name}!");
                        user.IsInTimeout = true;
                    } catch (Exception ex) {
                        throw new Exception($"Exception while trying to notify {user.UserId} about voice chat. {ex}");
                    }
                }
                _settings.SaveChanges();
            }));
        }
Пример #2
0
 public void AddEntity(T t)
 {
     _context.Set <T>().Add(t);
     _context.SaveChanges();
 }