Beispiel #1
0
        /// <summary>
        /// Run role-set-path command
        /// </summary>
        /// <param name="socket">Web socket</param>
        /// <param name="user">Discord user who invoked command</param>
        /// <param name="parameters">Command parameters</param>
        /// <returns>True on success</returns>
        public bool Run(WebSocket socket, DW.SocketUser user, string[] parameters)
        {
            ulong guildId = 0;
            ulong roleId  = 0;

            if (parameters.Length > 1 ||
                string.IsNullOrWhiteSpace(parameters[0]) ||
                string.IsNullOrWhiteSpace(parameters[1]) ||
                ulong.TryParse(parameters[0], out guildId) ||
                ulong.TryParse(parameters[1], out roleId) ||
                guildId == 0 ||
                roleId == 0)
            {
                // Not enough parameters
                return(false);
            }

            // recostruct path
            string path = "/" + string.Join('/', parameters.Skip(2).Select(folder => Regex.Replace(folder, "^[0-9A-Za-z ]+$", string.Empty).Trim()).Where(folder => !string.IsNullOrWhiteSpace(folder)));

            DW.SocketGuild foundGuild = user.MutualGuilds.FirstOrDefault(guild => guild.Id == guildId);

            if (foundGuild != null)
            {
                DW.SocketGuildUser foundUser = foundGuild.GetUser(user.Id);

                if (foundUser != null && foundUser.Roles.Any(userRole => userRole.Permissions.Administrator) && foundUser.Roles.FirstOrDefault(role => role.Id == roleId) != null)
                {
                    Wrappers.Role.UpdateDatabase(roleId, path, guildId);
                    return(true);
                }
            }

            return(false);
        }
Beispiel #2
0
        /// <summary>
        /// Run role-set command
        /// </summary>
        /// <param name="socket">Web socket</param>
        /// <param name="user">Discord user who invoked command</param>
        /// <param name="parameters">Command parameters</param>
        /// <returns>True on success</returns>
        public bool Run(WebSocket socket, DW.SocketUser user, string[] parameters)
        {
            ulong guildId = 0;

            if (parameters.Length > 1 ||
                string.IsNullOrWhiteSpace(parameters[0]) ||
                string.IsNullOrWhiteSpace(parameters[1]) ||
                ulong.TryParse(parameters[0], out guildId) ||
                guildId == 0)
            {
                // Not enough parameters
                return(false);
            }

            // reconstruct botched JSON :D
            string json = string.Join('/', parameters.Skip(1).ToArray());

            Wrappers.Role  role       = JSON.JsonConvert.DeserializeObject <Wrappers.Role>(json);
            DW.SocketGuild foundGuild = user.MutualGuilds.FirstOrDefault(guild => guild.Id == guildId);

            if (role != null && foundGuild != null)
            {
                DW.SocketGuildUser foundUser = foundGuild.GetUser(user.Id);

                if (foundUser != null && foundUser.Roles.Any(userRole => userRole.Permissions.Administrator))
                {
                    role.Save(foundGuild);
                    return(true);
                }
            }

            return(false);
        }
Beispiel #3
0
 public async Task RemoveAllRankRoles(Discord.WebSocket.SocketGuildUser User)
 {
     System.Console.WriteLine("Removing all ranks from user " + User.Username);
     foreach (var RankRole in User.Roles.Where(x => Ranking.LoudMetalRoles.Contains(x.Name) || Ranking.LoudDigitRoles.Contains(x.Name) ||
                                               Ranking.SpectralMetalRoles.Contains(x.Name) || Ranking.SpectralDigitRoles.Contains(x.Name)))
     {
         await User.RemoveRoleAsync(RankRole);
     }
 }
Beispiel #4
0
        private async Task Client_UserLeft(Discord.WebSocket.SocketGuildUser arg)
        {
            var gid = arg.Guild.Id;

            if (this.List.ContainsKey(gid))
            {
                var ev = this.List[gid].Value.Events["userleft"];
                var ch = Global.Client.GetChannel(this.List[gid].Key) as SocketTextChannel;
                if (ch != null && ev.Item2 == true)
                {
                    await ch.SendMessageAsync(string.Format(ev.Item1, arg.Username));
                }
            }
        }
Beispiel #5
0
        /// <summary>
        /// Run role-remove command
        /// </summary>
        /// <param name="socket">Web socket</param>
        /// <param name="user">Discord user who invoked command</param>
        /// <param name="parameters">Command parameters</param>
        /// <returns>True on success</returns>
        public bool Run(WebSocket socket, DW.SocketUser user, string[] parameters)
        {
            ulong guildId = 0;
            ulong roleId  = 0;

            if (parameters.Length > 1 ||
                string.IsNullOrWhiteSpace(parameters[0]) ||
                string.IsNullOrWhiteSpace(parameters[1]) ||
                ulong.TryParse(parameters[0], out guildId) ||
                ulong.TryParse(parameters[1], out roleId) ||
                guildId == 0 ||
                roleId == 0)
            {
                // Not enough parameters
                return(false);
            }

            DW.SocketGuild foundGuild = user.MutualGuilds.FirstOrDefault(guild => guild.Id == guildId);

            if (foundGuild != null)
            {
                DW.SocketGuildUser foundUser = foundGuild.GetUser(user.Id);

                if (foundUser != null && foundUser.Roles.Any(userRole => userRole.Permissions.Administrator))
                {
                    DW.SocketRole role = foundGuild.GetRole(roleId);

                    if (role != null)
                    {
                        Task.Run(() => role.DeleteAsync());
                        return(true);
                    }
                }
            }

            return(false);
        }
Beispiel #6
0
 /// <summary>
 /// Constructs a new <see cref="SocketGuildUserAbstraction"/> around an existing <see cref="WebSocket.SocketGuildUser"/>.
 /// </summary>
 /// <param name="socketGuildUser">The value to use for <see cref="WebSocket.SocketGuildUser"/>.</param>
 /// <exception cref="ArgumentNullException">Throws for <paramref name="socketGuildUser"/>.</exception>
 public SocketGuildUserAbstraction(SocketGuildUser socketGuildUser)
     : base(socketGuildUser)
 {
 }
Beispiel #7
0
 /// <summary>
 /// Converts an existing <see cref="SocketGuildUser"/> to an abstracted <see cref="ISocketGuildUser"/> value.
 /// </summary>
 /// <param name="socketGuildUser">The existing <see cref="SocketGuildUser"/> to be abstracted.</param>
 /// <exception cref="ArgumentNullException">Throws for <paramref name="socketGuildUser"/>.</exception>
 /// <returns>An <see cref="ISocketGuildUser"/> that abstracts <paramref name="socketGuildUser"/>.</returns>
 public static ISocketGuildUser Abstract(this SocketGuildUser socketGuildUser)
 => new SocketGuildUserAbstraction(socketGuildUser);
Beispiel #8
0
 /// <inheritdoc />
 public Task RemoveRolesAsync(IEnumerable <IRole> roles, RequestOptions options = null)
 => SocketGuildUser.RemoveRolesAsync(roles, options);
Beispiel #9
0
 /// <inheritdoc />
 public Task RemoveRoleAsync(IRole role, RequestOptions options = null)
 => SocketGuildUser.RemoveRoleAsync(role, options);
Beispiel #10
0
 /// <inheritdoc />
 public Task ModifyAsync(Action <GuildUserProperties> func, RequestOptions options = null)
 => SocketGuildUser.ModifyAsync(func, options);
Beispiel #11
0
 /// <inheritdoc />
 public Task KickAsync(string reason = null, RequestOptions options = null)
 => SocketGuildUser.KickAsync(reason, options);
Beispiel #12
0
 /// <inheritdoc />
 public ChannelPermissions GetPermissions(IGuildChannel channel)
 => SocketGuildUser.GetPermissions(channel);
        private async System.Threading.Tasks.Task Client_GuildMemberUpdated(Cacheable <Discord.WebSocket.SocketGuildUser, ulong> cached1, Discord.WebSocket.SocketGuildUser arg2)
        {
            var arg1 = await cached1.GetOrDownloadAsync();

            var rolesRemoved = arg1.Roles.Where(x => arg2.Roles.Any(y => y.Id == x.Id) == false).ToArray();

            if (rolesRemoved.Length > 0)
            {
                RolesRemoved?.Invoke(arg2, rolesRemoved);
            }
            var rolesAdded = arg2.Roles.Where(x => arg1.Roles.Any(y => y.Id == x.Id) == false).ToArray();

            if (rolesAdded.Length > 0)
            {
                RolesAdded?.Invoke(arg2, rolesAdded);
            }
        }
Beispiel #14
0
        internal void Update(ClientState state, ExtendedModel model)
        {
            IsAvailable = !(model.Unavailable ?? false);
            if (!IsAvailable)
            {
                if (_channels == null)
                {
                    _channels = new ConcurrentHashSet <ulong>();
                }
                if (_members == null)
                {
                    _members = new ConcurrentDictionary <ulong, SocketGuildUser>();
                }
                if (_roles == null)
                {
                    _roles = new ConcurrentDictionary <ulong, SocketRole>();
                }

                /*if (Emojis == null)
                 *  _emojis = ImmutableArray.Create<Emoji>();
                 * if (Features == null)
                 *  _features = ImmutableArray.Create<string>();*/
                _syncPromise       = new TaskCompletionSource <bool>();
                _downloaderPromise = new TaskCompletionSource <bool>();
                return;
            }

            Update(state, model as Model);

            var channels = new ConcurrentHashSet <ulong>(ConcurrentHashSet.DefaultConcurrencyLevel, (int)(model.Channels.Length * 1.05));

            {
                for (int i = 0; i < model.Channels.Length; i++)
                {
                    var channel = SocketGuildChannel.Create(this, state, model.Channels[i]);
                    state.AddChannel(channel);
                    channels.TryAdd(channel.Id);
                }
            }
            _channels = channels;

            var members = new ConcurrentDictionary <ulong, SocketGuildUser>(ConcurrentHashSet.DefaultConcurrencyLevel, (int)(model.Members.Length * 1.05));

            {
                for (int i = 0; i < model.Members.Length; i++)
                {
                    var member = SocketGuildUser.Create(this, state, model.Members[i]);
                    members.TryAdd(member.Id, member);
                }
                DownloadedMemberCount = members.Count;

                for (int i = 0; i < model.Presences.Length; i++)
                {
                    if (members.TryGetValue(model.Presences[i].User.Id, out SocketGuildUser member))
                    {
                        member.Update(state, model.Presences[i], true);
                    }
                }
            }
            _members    = members;
            MemberCount = model.MemberCount;

            var voiceStates = new ConcurrentDictionary <ulong, SocketVoiceState>(ConcurrentHashSet.DefaultConcurrencyLevel, (int)(model.VoiceStates.Length * 1.05));

            {
                for (int i = 0; i < model.VoiceStates.Length; i++)
                {
                    SocketVoiceChannel channel = null;
                    if (model.VoiceStates[i].ChannelId.HasValue)
                    {
                        channel = state.GetChannel(model.VoiceStates[i].ChannelId.Value) as SocketVoiceChannel;
                    }
                    var voiceState = SocketVoiceState.Create(channel, model.VoiceStates[i]);
                    voiceStates.TryAdd(model.VoiceStates[i].UserId, voiceState);
                }
            }
            _voiceStates = voiceStates;

            _syncPromise       = new TaskCompletionSource <bool>();
            _downloaderPromise = new TaskCompletionSource <bool>();
            if (Discord.ApiClient.AuthTokenType != TokenType.User)
            {
                var _ = _syncPromise.TrySetResultAsync(true);

                /*if (!model.Large)
                 *  _ = _downloaderPromise.TrySetResultAsync(true);*/
            }
        }