当前位置: 首页>>代码示例>>C#>>正文


C# Discord.User类代码示例

本文整理汇总了C#中Discord.User的典型用法代码示例。如果您正苦于以下问题:C# User类的具体用法?C# User怎么用?C# User使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


User类属于Discord命名空间,在下文中一共展示了User类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: MuteUser

        async Task MuteUser(Server server, Channel channel, User user, DateTime expiresOn)
        {
            try
            {
                // TODO: need to check if client has permissions and user is not the owner
                var mutedRole = server.Roles.SingleOrDefault(r => r.Name == "Muted") 
                    ?? await CreateMutedRole(server);

                var punishment = new Punishment
                {
                    Id = Guid.NewGuid(),
                    Server = server,
                    Channel = channel,
                    User = user,
                    RolesBefore = user.Roles,
                    RolesAfter = new List<Role> { mutedRole },
                    ExpiresOn = expiresOn,
                    PunishmentType = PunishmentType.Mute,
                    Actioned = false
                };

                _botServices.Defence.PunishUser(punishment);

                await _client.EditUser(user, null, null, punishment.RolesAfter);
            } 
            catch (Exception ex)
            {
                _botServices.Logging.LogError(string.Format("Failed to add '{0} to the muted role'", user.Name), ex);
                throw;
            }
        }
开发者ID:Yandawl,项目名称:DAX.Discord,代码行数:31,代码来源:DefenceModule.cs

示例2: CanRun

        public bool CanRun(Command command, User user, Channel channel, out string error)
        {
            error = null;

            if (channel.IsPrivate)
                return DefaultPermissionLevel <= DefaultPermChecker.GetPermissionLevel(user, channel);

            DynPermFullData data = DynPerms.GetPerms(channel.Server.Id);

            // apply default perms.
            bool retval = DefaultPermissionLevel <= DefaultPermChecker.GetPermissionLevel(user, channel);

            // if we do not have dynamic perms in place for the user's server, return the default perms.
            if (data == null || (!data.Perms.RolePerms.Any() && !data.Perms.UserPerms.Any()))
                return retval;

            /* 
              Firsly do role checks.
              Lower entries override higher entries. 
              To do that we have to iterate over the dict instead of using roles the user has as keys.
            */

            foreach (var pair in data.Perms.RolePerms)
            {
                if (user.HasRole(pair.Key))
                    retval = EvaluatePerms(pair.Value, command, retval, channel, ref error);
            }

            // users override roles, do them next.
            DynamicPermissionBlock permBlock;
            if (data.Perms.UserPerms.TryGetValue(user.Id, out permBlock))
                retval = EvaluatePerms(permBlock, command, retval, channel, ref error);

            return retval;
        }
开发者ID:SSStormy,项目名称:Stormbot,代码行数:35,代码来源:DynamicPermissionChecker.cs

示例3: Invite

		internal Invite(DiscordClient client, string code, string xkcdPass, string serverId, string inviterId, string channelId)
			: base(client, code)
		{
			XkcdCode = xkcdPass;
			_server = new Reference<Server>(serverId, x =>
			{
				var server = _client.Servers[x];
				if (server == null)
				{
					server = _generatedServer = new Server(client, x);
					server.Cache();
				}
				return server;
			});
			_inviter = new Reference<User>(serverId, x =>
			{
				var inviter = _client.Users[x, _server.Id];
				if (inviter == null)
				{
					inviter = _generatedInviter = new User(client, x, _server.Id);
					inviter.Cache();
				}
				return inviter;
			});
			_channel = new Reference<Channel>(serverId, x =>
			{
				var channel = _client.Channels[x];
				if (channel == null)
				{
					channel = _generatedChannel = new Channel(client, x, _server.Id, null);
					channel.Cache();
				}
				return channel;
			});
		}
开发者ID:hermanocabral,项目名称:Discord.Net,代码行数:35,代码来源:Invite.cs

示例4: CanRun

        public bool CanRun(Command command, User user, Channel channel, out string error) {
            error = null;

            if (channel.IsPrivate)
                return true;

            try {
                //is it a permission command?
                // if it is, check if the user has the correct role
                // if yes return true, if no return false
                if (command.Category == "Permissions")
                    if (user.Server.IsOwner || user.HasRole(PermissionHelper.ValidateRole(user.Server, PermissionsHandler.GetServerPermissionsRoleName(user.Server))))
                        return true;
                    else
                        throw new Exception($"You don't have the necessary role (**{PermissionsHandler._permissionsDict[user.Server].PermissionsControllerRole}**) to change permissions.");

                var permissionType = PermissionsHandler.GetPermissionBanType(command, user, channel);

                string msg;

                switch (permissionType) {
                    case PermissionsHandler.PermissionBanType.None:
                        return true;
                    case PermissionsHandler.PermissionBanType.ServerBanCommand:
                        msg = $"**{command.Text}** command has been banned from use on this **server**.";
                        break;
                    case PermissionsHandler.PermissionBanType.ServerBanModule:
                        msg = $"**{command.Category}** module has been banned from use on this **server**.";
                        break;
                    case PermissionsHandler.PermissionBanType.ChannelBanCommand:
                        msg = $"**{command.Text}** command has been banned from use on this **channel**.";
                        break;
                    case PermissionsHandler.PermissionBanType.ChannelBanModule:
                        msg = $"**{command.Category}** module has been banned from use on this **channel**.";
                        break;
                    case PermissionsHandler.PermissionBanType.RoleBanCommand:
                        msg = $"You do not have a **role** which permits you the usage of **{command.Text}** command.";
                        break;
                    case PermissionsHandler.PermissionBanType.RoleBanModule:
                        msg = $"You do not have a **role** which permits you the usage of **{command.Category}** module.";
                        break;
                    case PermissionsHandler.PermissionBanType.UserBanCommand:
                        msg = $"{user.Mention}, You have been banned from using **{command.Text}** command.";
                        break;
                    case PermissionsHandler.PermissionBanType.UserBanModule:
                        msg = $"{user.Mention}, You have been banned from using **{command.Category}** module.";
                        break;
                    default:
                        return true;
                }
                if (PermissionsHandler._permissionsDict[user.Server].Verbose) //if verbose - print errors
                    Task.Run(() => channel.SendMessage(msg));
                return false;
            } catch (Exception ex) {
                if (PermissionsHandler._permissionsDict[user.Server].Verbose) //if verbose - print errors
                    Task.Run(() => channel.SendMessage(ex.Message));
                return false;
            }
        }
开发者ID:TheFerty7,项目名称:NadekoBot,代码行数:59,代码来源:PermissionChecker.cs

示例5: GetMusic

 internal static bool GetMusic(User user)
 {
     SQLiteDataReader reader = SQL.ExecuteReader("select channel from flags where music = 1");
     List<long> streams = new List<long>();
     while (reader.Read())
         streams.Add(Convert.ToInt64(reader["channel"].ToString()));
     return user.VoiceChannel != null && streams.Contains(user.VoiceChannel.Id);
 }
开发者ID:Lirusaito,项目名称:Nekobot,代码行数:8,代码来源:Flags.cs

示例6: SetChannelPermissions

		public Task SetChannelPermissions(Channel channel, User user, ChannelPermissions allow = null, ChannelPermissions deny = null)
		{
			if (channel == null) throw new ArgumentNullException(nameof(channel));
			if (user == null) throw new ArgumentNullException(nameof(user));
			CheckReady();

			return SetChannelPermissions(channel, user?.Id, PermissionTarget.User, allow, deny);
		}
开发者ID:hermanocabral,项目名称:Discord.Net,代码行数:8,代码来源:DiscordClient.Permissions.cs

示例7: RemoveChannelPermissions

		public Task RemoveChannelPermissions(Channel channel, User user)
		{
			if (channel == null) throw new ArgumentNullException(nameof(channel));
			if (user == null) throw new ArgumentNullException(nameof(user));
			CheckReady();

			return RemoveChannelPermissions(channel, user?.Id, PermissionTarget.User);
		}
开发者ID:hermanocabral,项目名称:Discord.Net,代码行数:8,代码来源:DiscordClient.Permissions.cs

示例8: GetWarningsCount

 public int GetWarningsCount(User user)
 {
     if (_warnings.ContainsKey(user))
     {
         return _warnings[user];
     }
     return 0;
 }
开发者ID:Yandawl,项目名称:DAX.Discord,代码行数:8,代码来源:DefenceService.cs

示例9: CanRun

 public bool CanRun(Command command, User user, Channel channel, out string error)
 {
     error = string.Empty;
     if (user.ServerPermissions.ManageRoles)
         return true;
     error = "You do not have a permission to manage roles.";
     return false;
 }
开发者ID:Ryonez,项目名称:Lucy,代码行数:8,代码来源:SimpleCheckers.cs

示例10: Ban

		/// <summary> Bans a user from the provided server. </summary>
		public Task Ban(User user)
		{
			if (user == null) throw new ArgumentNullException(nameof(user));
			if (user.Server == null) throw new ArgumentException("Unable to ban a user in a private chat.");
			CheckReady();

			return _api.BanUser(user.Server.Id, user.Id);
		}
开发者ID:hermanocabral,项目名称:Discord.Net,代码行数:9,代码来源:DiscordClient.Bans.cs

示例11: AddWarning

        public void AddWarning(Channel channel, User user)
        {
            if (!_warnings.ContainsKey(user))
            {
                _warnings.Add(user, 0);
            }
            _warnings[user]++;

            NotifyUserWarned(new UserWarnedEventArgs { Channel = channel, User = user, WarningCount = _warnings[user] });
        }
开发者ID:Yandawl,项目名称:DAX.Discord,代码行数:10,代码来源:DefenceService.cs

示例12: HasNeko

 static bool HasNeko(ref string msg, User user)
 {
     string neko = user.Name;
     string nekonick = user.Nickname;
     if (HasNekoEmojiOrNot(ref msg, neko)) // Have we been mentioned by our actual name?
     {
         HasNekoNick(ref msg, nekonick); // Strip nick, too, just in case.
         return true;
     }
     return HasNekoNick(ref msg, nekonick); // Have we been mentioned by our nick?
 }
开发者ID:Kusoneko,项目名称:Nekobot,代码行数:11,代码来源:Chatbot.cs

示例13: CanRun

 public bool CanRun(Command command, User user, Channel channel, out string error)
 {
     if (user.IsPrivate)
     {
         error = "This command can't be run in n a private chat.";
         return false;
     }
     else
     {
         error = null;
         return true;
     }
 }
开发者ID:Lirusaito,项目名称:Nekobot,代码行数:13,代码来源:PublicChecker.cs

示例14: CanRun

 public bool CanRun(Command command, User user, Channel channel, out string error)
 {
     if (user.Server != null)
     {
         error = "This command may only be run in a private chat.";
         return false;
     }
     else
     {
         error = null;
         return true;
     }
 }
开发者ID:Kusoneko,项目名称:Nekobot,代码行数:13,代码来源:PrivateChecker.cs

示例15: AddEvent

        public void AddEvent(Server server, Channel channel, User user, EventType eventType)
        {
            var eventToSave = new Event
            {
                Id = Guid.NewGuid(),
                User = user,
                Server = server,
                Channel = channel,
                EventType = eventType,
                OccuredOn = DateTime.Now
            };

            _eventRepository.Insert(eventToSave);
        }
开发者ID:Yandawl,项目名称:DAX.Discord,代码行数:14,代码来源:EventService.cs


注:本文中的Discord.User类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。