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


C# IUserMessage类代码示例

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


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

示例1: Placelist

            public async Task Placelist(IUserMessage imsg)
            {
                var channel = (ITextChannel)imsg.Channel;

                await channel.SendMessageAsync(typesStr)
                             .ConfigureAwait(false);
            }
开发者ID:Chewsterchew,项目名称:NadekoBot,代码行数:7,代码来源:PlaceCommands.cs

示例2: Flip

 public async Task Flip(IUserMessage imsg, int count = 1)
 {
     var channel = (ITextChannel)imsg.Channel;
     if (count == 1)
     {
         if (rng.Next(0, 2) == 1)
             await channel.SendFileAsync(headsPath, $"{imsg.Author.Mention} rolled " + Format.Code("Heads") + ".").ConfigureAwait(false);
         else
             await channel.SendFileAsync(tailsPath, $"{imsg.Author.Mention} rolled " + Format.Code("Tails") + ".").ConfigureAwait(false);
         return;
     }
     if (count > 10 || count < 1)
     {
         await channel.SendMessageAsync("`Invalid number specified. You can flip 1 to 10 coins.`");
         return;
     }
     var imgs = new Image[count];
     for (var i = 0; i < count; i++)
     {
         imgs[i] = rng.Next(0, 10) < 5 ?
                     new Image(File.OpenRead(headsPath)) :
                     new Image(File.OpenRead(tailsPath));
     }
     await channel.SendFileAsync(imgs.Merge().ToStream(), $"{count} coins.png").ConfigureAwait(false);
 }
开发者ID:Chewsterchew,项目名称:NadekoBot,代码行数:25,代码来源:FlipCoinCommand.cs

示例3: Draw

            public async Task Draw(IUserMessage msg, int num = 1)
            {
                var channel = (ITextChannel)msg.Channel;
                var cards = AllDecks.GetOrAdd(channel.Guild, (s) => new Cards());
                var images = new List<Image>();
                var cardObjects = new List<Cards.Card>();
                if (num > 5) num = 5;
                for (var i = 0; i < num; i++)
                {
                    if (cards.CardPool.Count == 0 && i != 0)
                    {
                        try { await channel.SendMessageAsync("No more cards in a deck.").ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); }
                        break;
                    }
                    var currentCard = cards.DrawACard();
                    cardObjects.Add(currentCard);
                    using (var stream = File.OpenRead(Path.Combine(cardsPath, currentCard.ToString().ToLowerInvariant()+ ".jpg").Replace(' ','_')))
                        images.Add(new Image(stream));
                }
                MemoryStream bitmapStream = new MemoryStream();
                images.Merge().SaveAsPng(bitmapStream);
                bitmapStream.Position = 0;
                //todo CARD NAMES?
                var toSend = $"{msg.Author.Mention}";
                if (cardObjects.Count == 5)
                    toSend += $" drew `{Cards.GetHandValue(cardObjects)}`";

                await channel.SendFileAsync(bitmapStream, images.Count + " cards.jpg", toSend).ConfigureAwait(false);
            }
开发者ID:Chewsterchew,项目名称:NadekoBot,代码行数:29,代码来源:DrawCommand.cs

示例4: InRole

 public async Task InRole(IUserMessage umsg, [Remainder] string roles)
 {
     if (string.IsNullOrWhiteSpace(roles))
         return;
     var channel = (ITextChannel)umsg.Channel;
     var arg = roles.Split(',').Select(r => r.Trim().ToUpperInvariant());
     string send = _l["ℹ️ **Here is a list of users in a specfic role:**"];
     foreach (var roleStr in arg.Where(str => !string.IsNullOrWhiteSpace(str) && str != "@EVERYONE" && str != "EVERYONE"))
     {
         var role = channel.Guild.Roles.Where(r => r.Name.ToUpperInvariant() == roleStr).FirstOrDefault();
         if (role == null) continue;
         send += $"```css\n[{role.Name}]\n";
         send += string.Join(", ", channel.Guild.GetUsers().Where(u => u.Roles.Contains(role)).Select(u => u.ToString()));
         send += $"\n```";
     }
     var usr = umsg.Author as IGuildUser;
     while (send.Length > 2000)
     {
         if (!usr.GetPermissions(channel).ManageMessages)
         {
             await channel.SendMessageAsync($"⚠️ {usr.Mention} **you are not allowed to use this command on roles with a lot of users in them to prevent abuse.**").ConfigureAwait(false);
             return;
         }
         var curstr = send.Substring(0, 2000);
         await channel.SendMessageAsync(curstr.Substring(0,
                 curstr.LastIndexOf(", ", StringComparison.Ordinal) + 1)).ConfigureAwait(false);
         send = curstr.Substring(curstr.LastIndexOf(", ", StringComparison.Ordinal) + 1) +
                send.Substring(2000);
     }
     await channel.SendMessageAsync(send).ConfigureAwait(false);
 }
开发者ID:Chewsterchew,项目名称:NadekoBot,代码行数:31,代码来源:Utility.cs

示例5: Read

 public override Task<TypeReaderResult> Read(IUserMessage context, string input)
 {
     input = input.ToUpperInvariant();
     switch (input)
     {
         case "1":
         case "T":
         case "TRUE":
         case "ENABLE":
         case "ENABLED":
         case "ALLOW":
         case "PERMIT":
         case "UNBAN":
             return Task.FromResult(TypeReaderResult.FromSuccess(PermissionAction.Enable));
         case "0":
         case "F":
         case "FALSE":
         case "DENY":
         case "DISABLE":
         case "DISABLED":
         case "DISALLOW":
         case "BAN":
             return Task.FromResult(TypeReaderResult.FromSuccess(PermissionAction.Disable));
         default:
             return Task.FromResult(TypeReaderResult.FromError(CommandError.ParseFailed, "Did not receive a valid boolean value"));
     }
 }
开发者ID:Chewsterchew,项目名称:NadekoBot,代码行数:27,代码来源:PermissionActionTypeReader.cs

示例6: ServerInfo

        public async Task ServerInfo(IUserMessage msg, string guild = null)
        {
            var channel = (ITextChannel)msg.Channel;
            guild = guild?.ToUpperInvariant();
            IGuild server;
            if (guild == null)
                server = channel.Guild;
            else
                server = _client.GetGuilds().Where(g => g.Name.ToUpperInvariant() == guild.ToUpperInvariant()).FirstOrDefault();
            if (server == null)
                return;

            var createdAt = new DateTime(2015, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds(server.Id >> 22);
            var sb = new StringBuilder();
            var users = await server.GetUsersAsync();
            sb.AppendLine([email protected]"__`Name:`__ **{server.Name}**
__`Owner:`__ **{await server.GetUserAsync(server.OwnerId)}**
__`ID:`__ **{server.Id}**
__`Icon URL:`__ { server.IconUrl}
__`TextChannels:`__ **{(await server.GetTextChannelsAsync()).Count()}** `VoiceChannels:` **{(await server.GetVoiceChannelsAsync()).Count()}**
__`Members:`__ **{users.Count}** `-` {users.Count(u => u.Status == UserStatus.Online)}💚 {users.Count(u => u.Status == UserStatus.Idle)}🔶 {users.Count(u => u.Status == UserStatus.DoNotDisturb)}🔴 {users.Count(u=> u.Status == UserStatus.Offline || u.Status == UserStatus.Unknown)}⬛️
__`Roles:`__ **{server.Roles.Count()}**
__`Created At:`__ **{createdAt.ToString("dd.MM.yyyy HH:mm")}**
");
            if (server.Emojis.Count() > 0)
                sb.AppendLine($"__`Custom Emojis:`__ *{string.Join(", ", server.Emojis)}*");
            if (server.Features.Count() > 0)
                sb.AppendLine($"__`Features:`__ **{string.Join(", ", server.Features)}**");
            if (!string.IsNullOrWhiteSpace(server.SplashUrl))
                sb.AppendLine($"__`Region:`__ **{server.VoiceRegionId}**");
            await msg.Reply(sb.ToString()).ConfigureAwait(false);
        }
开发者ID:Chewsterchew,项目名称:NadekoBot,代码行数:32,代码来源:InfoCommands.cs

示例7: PermRole

        public async Task PermRole(IUserMessage msg, [Remainder] IRole role = null)
        {
            var channel = (ITextChannel)msg.Channel;
            using (var uow = DbHandler.UnitOfWork())
            {
                var config = uow.GuildConfigs.For(channel.Guild.Id);
                if (role == null)
                {
                    await channel.SendMessageAsync($"ℹ️ Current permission role is **{config.PermissionRole}**.").ConfigureAwait(false);
                    return;
                }
                else {
                    config.PermissionRole = role.Name.Trim();
                    Cache.AddOrUpdate(channel.Guild.Id, new PermissionCache()
                    {
                        PermRole = config.PermissionRole,
                        RootPermission = Permission.GetDefaultRoot(),
                        Verbose = config.VerbosePermissions
                    }, (id, old) => { old.PermRole = role.Name.Trim(); return old; });
                    await uow.CompleteAsync().ConfigureAwait(false);
                }
            }

            await channel.SendMessageAsync($"✅ Users now require **{role.Name}** role in order to edit permissions.").ConfigureAwait(false);
        }
开发者ID:Chewsterchew,项目名称:NadekoBot,代码行数:25,代码来源:Permissions.cs

示例8: CheckPermission

        //null = not applicable
        //true = applicable, allowed
        //false = applicable, not allowed
        public static bool? CheckPermission(this Permission perm, IUserMessage message, string commandName, string moduleName)
        {
            if (!((perm.SecondaryTarget == SecondaryPermissionType.Command &&
                    perm.SecondaryTargetName.ToLowerInvariant() == commandName.ToLowerInvariant()) ||
                (perm.SecondaryTarget == SecondaryPermissionType.Module &&
                    perm.SecondaryTargetName.ToLowerInvariant() == moduleName.ToLowerInvariant()) ||
                    perm.SecondaryTarget == SecondaryPermissionType.AllModules))
                return null;

            var guildUser = message.Author as IGuildUser;

            switch (perm.PrimaryTarget)
            {
                case PrimaryPermissionType.User:
                    if (perm.PrimaryTargetId == message.Author.Id)
                        return perm.State;
                    break;
                case PrimaryPermissionType.Channel:
                    if (perm.PrimaryTargetId == message.Channel.Id)
                        return perm.State;
                    break;
                case PrimaryPermissionType.Role:
                    if (guildUser == null)
                        break;
                    if (guildUser.Roles.Any(r => r.Id == perm.PrimaryTargetId))
                        return perm.State;
                    break;
                case PrimaryPermissionType.Server:
                    if (guildUser == null)
                        break;
                    return perm.State;
            }
            return null;
        }
开发者ID:Chewsterchew,项目名称:NadekoBot,代码行数:37,代码来源:PermissionExtensions.cs

示例9: Asar

            public async Task Asar(IUserMessage umsg, [Remainder] IRole role)
            {
                var channel = (ITextChannel)umsg.Channel;

                IEnumerable<SelfAssignedRole> roles;

                string msg;
                using (var uow = DbHandler.UnitOfWork())
                {
                    roles = uow.SelfAssignedRoles.GetFromGuild(channel.Guild.Id);
                    if (roles.Any(s => s.RoleId == role.Id && s.GuildId == role.GuildId))
                    {
                        msg = $"💢 Role **{role.Name}** is already in the list.";
                    }
                    else
                    {
                        uow.SelfAssignedRoles.Add(new SelfAssignedRole {
                            RoleId = role.Id,
                            GuildId = role.GuildId
                        });
                        await uow.CompleteAsync();
                        msg = $"🆗 Role **{role.Name}** added to the list.";
                    }
                }
                await channel.SendMessageAsync(msg.ToString()).ConfigureAwait(false);
            }
开发者ID:Chewsterchew,项目名称:NadekoBot,代码行数:26,代码来源:SelfAssignedRolesCommand.cs

示例10: Roll

            public async Task Roll(IUserMessage umsg, string arg)
            {
                var channel = (ITextChannel)umsg.Channel;
                if (channel == null)
                    return;

                var ordered = true;
                var rng = new NadekoRandom();
                Match match;
                if ((match = dndRegex.Match(arg)).Length != 0)
                {
                    int n1;
                    int n2;
                    if (int.TryParse(match.Groups["n1"].ToString(), out n1) &&
                        int.TryParse(match.Groups["n2"].ToString(), out n2) &&
                        n1 <= 50 && n2 <= 100000 && n1 > 0 && n2 > 0)
                    {
                        var add = 0;
                        var sub = 0;
                        int.TryParse(match.Groups["add"].Value, out add);
                        int.TryParse(match.Groups["sub"].Value, out sub);

                        var arr = new int[n1];
                        for (int i = 0; i < n1; i++)
                        {
                            arr[i] = rng.Next(1, n2 + 1) + add - sub;
                        }
                        var elemCnt = 0;
                        await channel.SendMessageAsync($"{umsg.Author.Mention} rolled {n1} {(n1 == 1 ? "die" : "dice")} `1 to {n2}` +`{add}` -`{sub}`.\n`Result:` " + string.Join(", ", (ordered ? arr.OrderBy(x => x).AsEnumerable() : arr).Select(x => elemCnt++ % 2 == 0 ? $"**{x}**" : x.ToString()))).ConfigureAwait(false);
                    }
                }
            }
开发者ID:Chewsterchew,项目名称:NadekoBot,代码行数:32,代码来源:DiceRollCommand.cs

示例11: AutoAssignRole

            public async Task AutoAssignRole(IUserMessage umsg, [Remainder] IRole role = null)
            {
                var channel = (ITextChannel)umsg.Channel;

                GuildConfig conf;
                using (var uow = DbHandler.UnitOfWork())
                {
                    conf = uow.GuildConfigs.For(channel.Guild.Id);
                    if (role == null)
                        conf.AutoAssignRoleId = 0;
                    else
                        conf.AutoAssignRoleId = role.Id;

                    uow.GuildConfigs.Update(conf);
                    await uow.CompleteAsync().ConfigureAwait(false);
                }

                if (role == null)
                {
                    await channel.SendMessageAsync("🆗 **Auto assign role** on user join is now **disabled**.").ConfigureAwait(false);
                    return;
                }

                await channel.SendMessageAsync("✅ **Auto assign role** on user join is now **enabled**.").ConfigureAwait(false);
            }
开发者ID:Chewsterchew,项目名称:NadekoBot,代码行数:25,代码来源:AutoAssignRoleCommands.cs

示例12: MigrateData

            public async Task MigrateData(IUserMessage umsg)
            {
                var channel = (ITextChannel)umsg.Channel;

                var version = 0;
                using (var uow = DbHandler.UnitOfWork())
                {
                    version = uow.BotConfig.GetOrCreate().MigrationVersion;
                }
                try
                {
                    for (var i = version; i < CURRENT_VERSION; i++)
                    {
                        switch (i)
                        {
                            case 0:
                                Migrate0_9To1_0();
                                break;
                        }
                    }
                    await umsg.Channel.SendMessageAsync("🆙 **Migration done.**").ConfigureAwait(false);
                }
                catch (Exception ex)
                {
                    _log.Error(ex);
                    await umsg.Channel.SendMessageAsync("⚠️ **Error while migrating, check `logs` for more informations.**").ConfigureAwait(false);
                }
            }
开发者ID:Chewsterchew,项目名称:NadekoBot,代码行数:28,代码来源:Migration.cs

示例13: CreateWar

        public async Task CreateWar(IUserMessage umsg, int size, [Remainder] string enemyClan = null)
        {
            var channel = (ITextChannel)umsg.Channel;

            if (!(umsg.Author as IGuildUser).GuildPermissions.ManageChannels)
                return;

            if (string.IsNullOrWhiteSpace(enemyClan))
                return;

            if (size < 10 || size > 50 || size % 5 != 0)
            {
                await channel.SendMessageAsync("💢🔰 Not a Valid war size").ConfigureAwait(false);
                return;
            }
            List<ClashWar> wars;
            if (!ClashWars.TryGetValue(channel.Guild.Id, out wars))
            {
                wars = new List<ClashWar>();
                if (!ClashWars.TryAdd(channel.Guild.Id, wars))
                    return;
            }


            var cw = await CreateWar(enemyClan, size, channel.Guild.Id, umsg.Channel.Id);

            wars.Add(cw);
            await channel.SendMessageAsync($"❗🔰**CREATED CLAN WAR AGAINST {cw.ShortPrint()}**").ConfigureAwait(false);
        }
开发者ID:Chewsterchew,项目名称:NadekoBot,代码行数:29,代码来源:ClashOfClans.cs

示例14: Hentai

        public async Task Hentai(IUserMessage umsg, [Remainder] string tag = null)
        {
            var channel = (ITextChannel)umsg.Channel;

            tag = tag?.Trim() ?? "";

            tag = "rating%3Aexplicit+" + tag;

            var rng = new NadekoRandom();
            Task<string> provider = Task.FromResult("");
            switch (rng.Next(0,4))
            {
                case 0:
                    provider = GetDanbooruImageLink(tag);
                    break;
                case 1:
                    provider = GetGelbooruImageLink(tag);
                    break;
                case 2:
                    provider = GetKonachanImageLink(tag);
                    break;
                case 3:
                    provider = GetYandereImageLink(tag);
                    break;
                default:
                    break;
            }
            var link = await provider.ConfigureAwait(false);
            if (string.IsNullOrWhiteSpace(link))
                await channel.SendMessageAsync("Search yielded no results ;(").ConfigureAwait(false);
            else
                await channel.SendMessageAsync(link).ConfigureAwait(false);
        }
开发者ID:Chewsterchew,项目名称:NadekoBot,代码行数:33,代码来源:NSFW.cs

示例15: Memelist

        public async Task Memelist(IUserMessage umsg)
        {
            var channel = (ITextChannel)umsg.Channel;
            HttpClientHandler handler = new HttpClientHandler();

            handler.AllowAutoRedirect = false;

            using (var http = new HttpClient(handler))
            {
                http.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
                string rawJson = "";
                try
                {
                    rawJson = await http.GetStringAsync("https://memegen.link/api/templates/").ConfigureAwait(false);                    
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }
                var data = JsonConvert.DeserializeObject<Dictionary<string, string>>(rawJson)
                                          .Select(kvp => Path.GetFileName(kvp.Value));

                await channel.SendTableAsync(data, x => $"{x,-17}", 3);
            }
        }
开发者ID:Chewsterchew,项目名称:NadekoBot,代码行数:25,代码来源:MemegenCommands.cs


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