public static async Task SendJoinMessageAsync(GuildMemberlogs g, string?msg, string username, string avatarUrl) { if (DiscordBot.Bot?.Rest is null) { return; } if (g.JoinMessage?.IsEmbed ?? false) { DiscordEmbedBuilder embed = new DiscordEmbedBuilder() { Color = new DiscordColor(CommandModule.Colors[ColorType.Memberlog][0]), Description = msg is null ? "" : msg, Footer = new DiscordEmbedBuilder.EmbedFooter() { IconUrl = avatarUrl, Text = "User Joined" }, Timestamp = DateTime.Now }; try { await DiscordBot.Bot.Rest.CreateMessageAsync(g.MemberlogChannel ?? 0UL, embed); } catch { /* Backgroun task, ignore rest exceptions. */ } // ignore } else if (g.JoinMessage?.IsImage ?? false) { using var stream = await SvgHandler.GetWelcomeImage(true, username, avatarUrl); if (!(stream is null)) { try { await DiscordBot.Bot.Rest.CreateMessageAsync(g.MemberlogChannel ?? 0UL, new DiscordMessageBuilder().WithFile("welcome-message.png", stream)); } catch { /* Backgroun task, ignore rest exceptions. */ } // ignore } } else if (!(msg is null)) { try { await DiscordBot.Bot.Rest.CreateMessageAsync(g.MemberlogChannel ?? 0UL, msg); } catch { /* Backgroun task, ignore rest exceptions. */ } // ignore } }
public static async Task SendLeaveMessageAsync(GuildMemberlogs g, string?msg, string username, string avatarUrl) { if (DiscordBot.Bot?.Rest is null) { return; } if (g.LeaveMessage?.IsEmbed ?? false) { DiscordEmbedBuilder embed = new DiscordEmbedBuilder() { Color = new DiscordColor(CommandModule.Colors[ColorType.Memberlog][1]), Description = msg is null ? "" : msg, Footer = new DiscordEmbedBuilder.EmbedFooter() { IconUrl = avatarUrl, Text = "User Left" }, Timestamp = DateTime.Now }; try { await DiscordBot.Bot.Rest.CreateMessageAsync(g.MemberlogChannel ?? 0UL, embed); } catch { /* Ignore errors from the REST client sening in the backgroung. */ } // ignore } else if (g.LeaveMessage?.IsImage ?? false) { using var stream = await SvgHandler.GetWelcomeImage(false, username, avatarUrl); if (!(stream is null)) { try { await DiscordBot.Bot.Rest.CreateMessageAsync(g.MemberlogChannel ?? 0UL, new DiscordMessageBuilder().WithFile("farewell-message.png", stream)); } catch { /* Ignore errors from the REST client sening in the backgroung. */ } // ignore } } else if (!(g.LeaveMessage?.Message is null)) { try { await DiscordBot.Bot.Rest.CreateMessageAsync(g.MemberlogChannel ?? 0UL, msg); } catch { /* Ignore errors from the REST client sening in the backgroung. */ } // ignore } }