public static async Task SendJoinMessageAsync(GuildMemberlogs g, CommandContext ctx) { if (!(g.MemberlogChannel is null)) { string?msg = null; if (!(g.JoinMessage?.Message is null)) { msg = await ReplaceValues(g.JoinMessage.Message, ctx); } await SendJoinMessageAsync(g, msg, ctx.Member.Username, ctx.Member?.AvatarUrl ?? ""); } }
public static async Task SendJoinMessageAsync(GuildMemberlogs g, GuildMemberAddEventArgs e) { if (!(g.MemberlogChannel is null)) { string?msg = null; if (!(g.JoinMessage?.Message is null)) { msg = await ReplaceValues(g.JoinMessage.Message, e); } await SendJoinMessageAsync(g, msg, e.Member.Username, e.Member?.AvatarUrl ?? ""); } }
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 } }
public static async Task SendJoinDMMessage(GuildMemberlogs g, GuildMemberAddEventArgs e) { if (g.JoinDmMessage is null) { return; } var msg = await ReplaceValues(g.JoinDmMessage, e); try { var dms = await e.Member.CreateDmChannelAsync(); await dms.SendMessageAsync(msg); } catch { /* If it doesnt sent to the user, its most likely because the user has DMs disabled. Ignore. */ } // ignore }
public async Task JoinDmCommandAsync(CommandContext ctx, [Description("Message to send, `info` to see more information about this command, or `disable` to disable the join DMs.")] [RemainingText] string message) { string msg = message?.Trim().ToLower() ?? "info"; if (msg.Equals("info")) { var embed = CommandModule.SuccessBase() .WithTitle("Join DM Message Information") .WithDescription("Certain words wrapped in brackets `{ }` can be used to replace parts of your message progrmatically.\n" + "**```http\n" + "server, guild :: Gets replaced with your server name.\n" + "user, member :: Gets replaced with the name of the user who just joined.\n" + "membercount :: Gets replaced with the total member count at the time.\n" + "```**\n" + "Ex: Welcome to {server}, {member}! You are the {membercount} person to join!"); await ctx.RespondAsync(embed : embed); return; } var guild = this._model.Find <GuildMemberlogs>(ctx.Guild.Id); if (guild is null) { guild = new GuildMemberlogs(ctx.Guild.Id); this._model.Add(guild); } if (msg.Equals("disable")) { guild.JoinDmMessage = null; await RespondBasicSuccessAsync("Disabled Join DMs"); } else { guild.JoinDmMessage = message; await RespondBasicSuccessAsync($"Set the join DM message to: \n```\n{message}```"); } await this._model.SaveChangesAsync(); }
public async Task MemberlogChannelCommandAsync(CommandContext ctx, [Description("The channel memberlog messages are sent in.")] DiscordChannel?channel = null) { var guild = this._model.Find <GuildMemberlogs>(ctx.Guild.Id); if (guild is null) { guild = new GuildMemberlogs(ctx.Guild.Id); await this._model.AddAsync(guild); } Task res; if (channel is null) { // Disable the memberlog guild.MemberlogChannel = null; res = RespondBasicSuccessAsync("Disabled all member logs."); } else { // Enable the selected channel if it has the right permissions for the bot. var pFor = channel.PermissionsFor(ctx.Member); if (!(channel.Type == ChannelType.Text && pFor.HasPermission(Permissions.SendMessages) && pFor.HasPermission(Permissions.EmbedLinks) && pFor.HasPermission(Permissions.AttachFiles))) { await RespondBasicErrorAsync("Missing permissions in channel: Send Messages, Embed Links, Attach Files"); return; } guild.MemberlogChannel = channel.Id; res = RespondBasicSuccessAsync("Memberlogs will be sent in: " + channel.Mention); } await this._model.SaveChangesAsync(); await res; }
public async Task MemberlogMessageTestCommandAsync(CommandContext ctx) { var guild = await this._model.FindAsync <GuildMemberlogs>(ctx.Guild.Id); if (guild is null) { guild = new GuildMemberlogs(ctx.Guild.Id); await this._model.AddAsync(guild); } if (guild.MemberlogChannel is null) { await RespondBasicErrorAsync($"No memberlog channel set. Set one with `{ctx.Prefix}mlchannel <#channel name>`"); return; } if (guild.JoinMessage is null && guild.LeaveMessage is null) { await RespondBasicErrorAsync("No join or leave message set. Set one with `{ctx.Prefix}mlmsg`"); return; } if (!(guild.JoinMessage is null)) { await MemberLogingUtils.SendJoinMessageAsync(guild, ctx); } if (!(guild.LeaveMessage is null)) { await MemberLogingUtils.SendLeaveMessageAsync(guild, ctx); } await RespondBasicSuccessAsync("Test complete."); }
public async Task MemberlogMessageCommandAsync(CommandContext ctx, [Description("For the `join` or `leave` message")] string selection, [Description("The type of message to send. `text`, `embed`, `image`, or `disable` to turn off.")] string type, [Description("The text sent in the message")] [RemainingText] string message) { var s = selection.Trim().ToLower(); if (!new string[] { "join", "leave" }.Contains(s)) { await RespondBasicErrorAsync("Selection must be one of the following: `join` or `leave`"); return; } var t = type.Trim().ToLower(); if (!new string[] { "text", "embed", "image", "disable" }.Contains(t)) { await RespondBasicErrorAsync("Type must be one of the following: `text`, `embed`, `image`, or `disable` to disable."); return; } if (t == "text" && (message is null || message == "")) { await RespondBasicErrorAsync("Type `text` needs a message."); return; } var guild = await this._model.FindAsync <GuildMemberlogs>(ctx.Guild.Id); if (guild is null) { guild = new GuildMemberlogs(ctx.Guild.Id); await this._model.AddAsync(guild); } Task res; if (s == "join") { if (t == "disable") { guild.JoinMessage = null; res = RespondBasicSuccessAsync("Disabled the join message."); } else { guild.JoinMessage = new MemberlogMessage() { Message = message, IsImage = t == "image", IsEmbed = t == "embed", }; res = RespondBasicSuccessAsync("Set the join message."); } } else { if (t == "disable") { guild.LeaveMessage = null; res = RespondBasicSuccessAsync("Disabled the leave message."); } else { guild.LeaveMessage = new MemberlogMessage() { Message = message, IsImage = t == "image", IsEmbed = t == "embed", }; res = RespondBasicSuccessAsync("Set the join message."); } } await this._model.SaveChangesAsync(); }