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


C# Discord.Channel类代码示例

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


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

示例1: GetMessages

        /// <summary>
        /// Get a number of messages from a channel.
        /// </summary>
        /// <param name="c">The channel</param>
        /// <param name="numReq">The number of messages requested</param>
        /// <returns></returns>
        public static async Task<IEnumerable<Message>> GetMessages(Channel c, int numReq)
        {
            int currentCount = 0;
            int numToGetThisLoop = 100;
            int newMsgCount = 100;
            ulong lastMsgId;
            IEnumerable<Message> allMsgs = new List<Message>();
            IEnumerable<Message> newMsgs = new List<Message>();
            if (numReq <= 0) return null;                                         //Quit on bad request

            lastMsgId = (await c.DownloadMessages(1))[0].Id;                        //Start from last message (will be excluded)

            while (currentCount < numReq && newMsgCount == numToGetThisLoop)      //Keep going while we don't have enough, and haven't reached end of channel
            {
                if (numReq - currentCount < 100)                                  //If we need less than 100 to achieve required number
                    numToGetThisLoop = numReq - currentCount;                     //Reduce number to get this loop

                newMsgs = await c.DownloadMessages(numToGetThisLoop, lastMsgId, Relative.Before, false);    //Get N messages before that id
                newMsgCount = newMsgs.Count();                                      //Get the count we downloaded, usually 100
                currentCount += newMsgCount;                                        //Add new messages to count
                lastMsgId = newMsgs.Last().Id;                                      //Get the id to start from on next iteration
                allMsgs = allMsgs.Concat(newMsgs);                                  //Add messages to the list
            }

            return allMsgs;
        }
开发者ID:Cappucirno,项目名称:moetron,代码行数:32,代码来源:MessageUtil.cs

示例2: 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

示例3: CleanUserMentions

 internal static string CleanUserMentions(Channel channel, string text, List<User> users = null)
 {
     ulong id;
     text = _userNicknameRegex.Replace(text, new MatchEvaluator(e =>
     {
         if (e.Value.Substring(3, e.Value.Length - 4).TryToId(out id))
         {
             var user = channel.GetUserFast(id);
             if (user != null)
             {
                 if (users != null)
                     users.Add(user);
                 return '@' + user.Nickname;
             }
         }
         return e.Value; //User not found or parse failed
     }));
     return _userRegex.Replace(text, new MatchEvaluator(e =>
     {
         if (e.Value.Substring(2, e.Value.Length - 3).TryToId(out id))
         {
             var user = channel.GetUserFast(id);
             if (user != null)
             {
                 if (users != null)
                     users.Add(user);
                 return '@' + user.Name;
             }
         }
         return e.Value; //User not found or parse failed
     }));
 }
开发者ID:Carbonitex,项目名称:Discord.Net,代码行数:32,代码来源:Message.cs

示例4: 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

示例5: StopPoll

        public async Task StopPoll(Channel ch) {
            NadekoBot.client.MessageReceived -= Vote;
            Poll throwaway;
            PollCommand.ActivePolls.TryRemove(e.Server, out throwaway);
            try {
                var results = participants.GroupBy(kvp => kvp.Value)
                                .ToDictionary(x => x.Key, x => x.Sum(kvp => 1))
                                .OrderBy(kvp => kvp.Value);

                int totalVotesCast = results.Sum(kvp => kvp.Value);
                if (totalVotesCast == 0) {
                    await ch.SendMessage("📄 **No votes have been cast.**");
                    return;
                }
                var closeMessage = $"--------------**POLL CLOSED**--------------\n" +
                                   $"📄 , here are the results:\n";
                foreach (var kvp in results) {
                    closeMessage += $"`{kvp.Key}.` **[{answers[kvp.Key - 1]}]** has {kvp.Value} votes.({kvp.Value * 1.0f / totalVotesCast * 100}%)\n";
                }

                await ch.SendMessage($"📄 **Total votes cast**: {totalVotesCast}\n{closeMessage}");
            } catch (Exception ex) {
                Console.WriteLine($"Error in poll game {ex}");
            }
        }
开发者ID:ZR2,项目名称:l,代码行数:25,代码来源:PollCommand.cs

示例6: 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

示例7: 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

示例8: 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

示例9: Help

 public Task<Message[]> Help(Channel channel)
 {
     return client.SendMessage(channel,
         "List of commands:\n" +
         "・basics\n・birthday\n・music\n・picture\n・quote(wip)\n・timezone(wip)\n・game(wip)\n・feature request\n" +
         "Type !help <command> to learn more about the command"
     );
 }
开发者ID:auchiyam,项目名称:MikuBot,代码行数:8,代码来源:BotCommands.cs

示例10: 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

示例11: ExecuteCommand

 public  async void ExecuteCommand(Channel channel, Message message)
 {
     await channel.SendIsTyping();
     Thread.Sleep(5000);
     await
         channel.SendMessage(
             "What the fuck did you just fucking say about me, you little bitch? I’ll have you know I graduated top of my class in the Navy Seals, and I’ve been involved in numerous secret raids on Al-Quaeda, and I have over 300 confirmed kills. I am trained in gorilla warfare and I’m the top sniper in the entire US armed forces. You are nothing to me but just another target. I will wipe you the fuck out with precision the likes of which has never been seen before on this Earth, mark my fucking words. You think you can get away with saying that shit to me over the Internet? Think again, fucker. As we speak I am contacting my secret network of spies across the USA and your IP is being traced right now so you better prepare for the storm, maggot. The storm that wipes out the pathetic little thing you call your life. You’re fucking dead, kid. I can be anywhere, anytime, and I can kill you in over seven hundred ways, and that’s just with my bare hands. Not only am I extensively trained in unarmed combat, but I have access to the entire arsenal of the United States Marine Corps and I will use it to its full extent to wipe your miserable ass off the face of the continent, you little shit. If only you could have known what unholy retribution your little “clever” comment was about to bring down upon you, maybe you would have held your fucking tongue. But you couldn’t, you didn’t, and now you’re paying the price, you goddamn idiot. I will shit fury all over you and you will drown in it. You’re fucking dead, kiddo.");
 }
开发者ID:msciotti,项目名称:Discord-Bot,代码行数:8,代码来源:MasonCommand.cs

示例12: MusicControls

 public MusicControls(Channel voiceChannel, CommandEventArgs e, float? vol) : this() {
     if (voiceChannel == null)
         throw new ArgumentNullException(nameof(voiceChannel));
     if (vol != null)
         Volume = (float)vol;
     VoiceChannel = voiceChannel;
     _e = e;
 }
开发者ID:Daedren,项目名称:NadekoBot,代码行数:8,代码来源:MusicControls.cs

示例13: 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

示例14: GetNsfw

 internal static bool GetNsfw(Channel chan)
 {
     SQLiteDataReader reader = SQL.ExecuteReader("select nsfw from flags where channel = '" + chan.Id + "'");
     while (reader.Read())
         if (int.Parse(reader["nsfw"].ToString()) == 1)
             return true;
     return false;
 }
开发者ID:Lirusaito,项目名称:Nekobot,代码行数:8,代码来源:Flags.cs

示例15: MoveToVoice

 private async Task MoveToVoice(Channel voiceChannel, params User[] users)
 {
     foreach (User user in users.Where(user => user.Status == UserStatus.Online ||
                                               user.Status == UserStatus.Idle))
     {
         await user.Edit(voiceChannel: voiceChannel);
     }
 }
开发者ID:SSStormy,项目名称:Stormbot,代码行数:8,代码来源:PersonalModule.cs


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