• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Discord.Channel类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



Channel类属于Discord命名空间,在下文中一共展示了Channel类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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(" 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Discord.DiscordClient类代码示例发布时间:2022-05-24
下一篇:
C# Repository.DiscoDataContext类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap