示例#1
0
        public static ISavedChannel GetChannel(this ISavedGuild guild, ulong discordID)
        {
            if (guild is null)
            {
                throw new NullReferenceException();
            }
            var channel = guild.Channels.FirstOrDefault(x => x.DiscordID == discordID);

            if (channel is null)
            {
                throw new ProfessorMewException("Failed to get a channel with a given id.");
            }

            return(channel);
        }
示例#2
0
        public static IGuildRole GetRoleToLower(this ISavedGuild guild, string name)
        {
            if (guild is null || guild.Roles is null)
            {
                throw new NullReferenceException();
            }
            var role = guild.Roles.FirstOrDefault(x => x.Name.ToLowerInvariant() == name.ToLowerInvariant());

            if (role is null)
            {
                throw new ProfessorMewException("Failed to get a role with a given name.");
            }

            return(role);
        }
示例#3
0
        public static ISavedChannel GetChannel(this ISavedGuild guild, string name)
        {
            if (guild is null || guild.Channels is null)
            {
                throw new NullReferenceException();
            }
            var channel = guild.Channels.FirstOrDefault(x => x.Name.ToUpperInvariant() == name.ToUpperInvariant());

            if (channel is null)
            {
                throw new ProfessorMewException("Failed to get a channel with a given name.");
            }

            return(channel);
        }
示例#4
0
        public static IRank GetRank(this ISavedGuild guild, int points)
        {
            if (guild is null || guild.Ranks is null)
            {
                throw new NullReferenceException();
            }
            var rank = guild.Ranks.FirstOrDefault(x => points >= x.MinPoints && points <= x.MaxPoints);

            if (rank is null)
            {
                throw new ProfessorMewException("Failed to get a rank with a given points.");
            }

            return(rank);
        }
示例#5
0
        public static IUser GetUser(this ISavedGuild guild, ulong discordID)
        {
            if (guild is null || guild.Users is null)
            {
                throw new NullReferenceException();
            }
            var user = guild.Users.FirstOrDefault(x => x.DiscordID == discordID);

            if (user is null)
            {
                throw new ProfessorMewException("Failed to find user with a given id.");
            }

            return(user);
        }
示例#6
0
        public static ISavedMessage GetMessage(this ISavedGuild guild, string name)
        {
            if (guild is null || guild.Messages is null)
            {
                throw new NullReferenceException();
            }
            var message = guild.Messages.FirstOrDefault(x => x.Name == name);

            if (message is null)
            {
                throw new ProfessorMewException("Failed to get a saved message with a given name.");
            }

            return(message);
        }
示例#7
0
        public static IRank GetDefaultRank(this ISavedGuild guild)
        {
            if (guild is null)
            {
                throw new NullReferenceException();
            }

            var rank = guild.Ranks.FirstOrDefault(X => X.Default);

            if (rank is null)
            {
                throw new ProfessorMewException("Failed to get default rank.");
            }

            return(rank);
        }
示例#8
0
        public static List <IUser> GetUsers(this ISavedGuild guild, params PointDisplay[] pointDisplays)
        {
            if (guild is null || guild.Users is null)
            {
                throw new NullReferenceException();
            }
            if (pointDisplays is null)
            {
                return(guild.Users.ToList());
            }
            var users = guild.Users.Where(x => pointDisplays.Contains(x.PointDisplay));

            if (users is null)
            {
                throw new ProfessorMewException("Failed to get users with given point displays.");
            }

            return(users.ToList());
        }