示例#1
0
        private async Task SendChipAsEmbed(SocketMessage message, Chip toSend)
        {
            var embed = new Discord.EmbedBuilder
            {
                Title = toSend.Name
            };

            if (toSend.Type == "Mega")
            {
                embed.Color = new Color(0x90F8F8); //Megachip Blue
            }
            else if (toSend.Type == "Giga")
            {
                embed.Color = new Color(0xF8C8D8);
            }
            MemoryStream imageStream = new MemoryStream();

            ChipImages.Instance.GetElement(toSend.Element).Save(imageStream, System.Drawing.Imaging.ImageFormat.Png);
            //File.WriteAllBytes("./test.png", imageStream.GetBuffer());
            embed.AddField("Element:", String.Join(", ", toSend.Element), true);
            if (toSend.Skill[0] != "--")
            {
                embed.AddField("Skill", String.Join(", ", toSend.Skill), true);
            }
            embed.ThumbnailUrl = "attachment://unknown.png";
            //embed.ThumbnailUrl = ChipImages.fireURL;
            embed.AddField("Range:", toSend.Range, true);
            if (toSend.Damage != "--")
            {
                embed.AddField("Damage:", toSend.Damage, true);
            }
            if (!toSend.Hits.StartsWith('0'))
            {
                embed.AddField("Hits:", toSend.Hits, true);
            }
            //embed.AddField("Description:", toSend.Description);
            embed.WithDescription(toSend.Description);
            embed.WithFooter(toSend.Type);
            var valToSend = embed.Build();

            //Console.WriteLine(imageStream.Position);
            imageStream.Seek(0, SeekOrigin.Begin); //reset to the beginning because apparently not automatic
                                                   //await message.Channel.SendMessageAsync(embed: valToSend);
                                                   //await message.Channel.SendFileAsync(imageStream, "b1nzy.png");
                                                   //embed: new EmbedBuilder {ImageUrl = "attachment://b1nzy.png"}.Build());
            await message.Channel.SendFileAsync(imageStream, "unknown.png", embed : valToSend);

            imageStream.Dispose();
        }
示例#2
0
        private async Task GuildLeaveLog(SocketGuild guild)
        {
            var logChannel = _client.GetChannel(647167484616769566) as SocketTextChannel;

            var embed = new Discord.EmbedBuilder()
            {
                Title = "📤 Left guild 📤",
                Color = Discord.Color.Red
            };

            embed.AddField("Name", guild.Name, true);
            embed.AddField("ID", guild.Id, true);
            embed.WithFooter($"Now in {_client.Guilds.Count.ToString()} guilds.");
            embed.WithCurrentTimestamp();

            //await logChannel.SendMessageAsync($"📤 Left guild \"{guild.Name}\" (`{guild.Id}`). Now in {_client.Guilds.Count.ToString()} guilds.");
            await logChannel.SendMessageAsync("", embed : embed.Build());
        }
        public EmbedBuilder BuildLinesOfOptions(string title, List <string> options, int start = 1, bool isShowCancelCommandHint = true, string prependDescription = null, string appendDescription = null)
        {
            var eB = new Discord.EmbedBuilder();

            eB.Title = title;
            var sB = new StringBuilder();

            if (prependDescription != null)
            {
                sB.Append(prependDescription);
            }

            for (int i = start; i <= options.Count; i++)
            {
                if (start == 0) //zero-based options
                {
                    if (i == options.Count)
                    {
                        break;
                    }
                    sB.AppendLine($"{i}. {options[i]}");
                }
                else
                {
                    sB.AppendLine($"{i}. {options[i - 1]}");
                }
            }

            if (appendDescription != null)
            {
                sB.Append(appendDescription);
            }

            if (isShowCancelCommandHint)
            {
                eB.WithFooter($"取消指令: {string.Join("、", ReponseSvc.Options.CancelKeywords)} ");
            }
            eB.Description = sB.ToString();
            return(eB);
        }
示例#4
0
        public async Task OnCommandExecutedAsync(Optional <CommandInfo> command, ICommandContext context, IResult result)
        {
            if (!string.IsNullOrWhiteSpace(result?.ErrorReason) && result.Error != CommandError.UnknownCommand /*&& result.Error != CommandError.UnmetPrecondition && result.Error != CommandError.ParseFailed && result.Error != CommandError.BadArgCount*/)
            {
                var errorEmbed = new Discord.EmbedBuilder()
                {
                    Title       = "Error",
                    Description = result.ErrorReason,
                    Color       = Discord.Color.Red
                };
                errorEmbed.WithCurrentTimestamp();
                errorEmbed.WithFooter("If you think this is a bug, please report it in the #support channel in our server (~support).");
                await context.Channel.SendMessageAsync("", embed : errorEmbed.Build());
                await Log(new LogMessage(LogSeverity.Error, "Command", $"A command errored. Message: [{context.Message.Content}] | Error reason: [{result.ErrorReason}] | Guild: [{context.Guild.Name} ({context.Guild.Id})]"));

                return;
            }

            var commandName = command.IsSpecified ? command.Value.Name : "Unknown Command";

            await Log(new LogMessage(LogSeverity.Info, "Command", $"A command executed successfully. Message: [{context.Message.Content}] | Command: [{commandName}] | Guild: [{context.Guild.Name} ({context.Guild.Id})]"));
        }