private async Task ChannelDestroyed(SocketChannel arg) { if (arg.GetType() == typeof(SocketTextChannel)) { SocketTextChannel destroyedchannel = (SocketTextChannel)arg; RemoveRelayChannel(destroyedchannel.Name); } }
private async Task ChannelCreated(SocketChannel arg) { if (arg.GetType() == typeof(SocketTextChannel) && Regex.Match(((SocketTextChannel)arg).Name.ToLower(), @"stream_").Success) { SocketTextChannel createdchannel = (SocketTextChannel)arg; AddRelayChannel(createdchannel.Name); } }
public async Task UserDMCommand(string Token, [Remainder] string Message) { ModMail ModMail = ModMailDB.ModMail.Find(Token); IUser User = null; if (ModMail != null) { User = DiscordSocketClient.GetUser(ModMail.UserID); } if (ModMail == null || User == null) { await BuildEmbed(EmojiEnum.Annoyed) .WithTitle("Could Not Find Token!") .WithDescription("Haiya! I couldn't find the modmail for the given token. Are you sure this exists in the database? " + "The token should be given as the footer of the embed. Make sure this is the token and not the modmail number.") .WithCurrentTimestamp() .SendEmbed(Context.Channel); } else { SocketChannel SocketChannel = DiscordSocketClient.GetChannel(ModerationConfiguration.ModMailChannelID); if (SocketChannel is SocketTextChannel TextChannel) { IMessage MailMessage = await TextChannel.GetMessageAsync(ModMail.MessageID); if (MailMessage is IUserMessage MailMSG) { try { await MailMSG.ModifyAsync(MailMSGs => MailMSGs.Embed = MailMessage.Embeds.FirstOrDefault().ToEmbedBuilder() .WithColor(Color.Green) .AddField($"Replied By: {Context.User.Username}", Message.Length > 300 ? $"{Message.Substring(0, 300)} ..." : Message) .Build() ); } catch (InvalidOperationException) { IMessage Messaged = await MailMSG.Channel.SendMessageAsync(embed : MailMSG.Embeds.FirstOrDefault().ToEmbedBuilder().Build()); ModMail.MessageID = Messaged.Id; ModMailDB.SaveChanges(); } } else { throw new Exception($"Woa, this is strange! The message required isn't a socket user message! Are you sure this message exists? ModMail Type: {MailMessage.GetType()}"); } } else { throw new Exception($"Eek! The given channel of {SocketChannel} turned out *not* to be an instance of SocketTextChannel, rather {SocketChannel.GetType().Name}!"); } await BuildEmbed(EmojiEnum.Love) .WithTitle("Modmail User DM") .WithDescription(Message) .AddField("Sent By", Context.User.GetUserInformation()) .SendDMAttachedEmbed(Context.Channel, BotConfiguration, User, BuildEmbed(EmojiEnum.Unknown) .WithTitle($"Modmail From {Context.Guild.Name}") .WithDescription(Message) .WithCurrentTimestamp() .WithFooter(Token) ); } }
/// <summary> /// The Create Or Get Webhook finds the given channel and, when provided a name, attempts to find a webhook /// with that said name. If the webhook can not be found, it creates a new webhook in the channel with the set name. /// </summary> /// <param name="ChannelID">The Channel ID is the snowflake ID of the channel which you wish the webhook to be made in.</param> /// <param name="WebhookName">The Webhook Name is the identifier of the webhook, and is what the webhook will be called.</param> /// <returns>The DiscordWebhookClient of the webhook that has been gotten or created.</returns> public async Task <DiscordWebhookClient> CreateOrGetWebhook(ulong ChannelID, string WebhookName) { if (ChannelID > 0) { try { SocketChannel Channel = DiscordSocketClient.GetChannel(ChannelID); if (Channel is SocketTextChannel TextChannel) { foreach (RestWebhook RestWebhook in await TextChannel.GetWebhooksAsync()) { if (RestWebhook.Name.Equals(WebhookName)) { return(new DiscordWebhookClient(RestWebhook.Id, RestWebhook.Token)); } } RestWebhook Webhook = await TextChannel.CreateWebhookAsync(WebhookName, ProfileService.GetRandomPFP()); return(new DiscordWebhookClient(Webhook.Id, Webhook.Token)); } throw new Exception($"The webhook {WebhookName} could not be initialized in the given channel {Channel} due to it being of type {Channel.GetType().Name}."); } catch (HttpException) { } } return(null); }
public async Task SetWelcomeChannel([Remainder] SocketChannel channel) { SocketGuildUser GuildUser = Context.Guild.GetUser(Context.User.Id); if (GuildUser.GuildPermissions.ManageChannels || Global.DevUIDs.Contains(Context.Message.Author.Id)) { if (channel.GetType() == typeof(SocketVoiceChannel)) { EmbedBuilder eb = new EmbedBuilder(); eb.WithTitle("Error setting welcome channel"); eb.WithDescription($"The welcome channel type must be a text channel!"); eb.WithColor(Color.Red); eb.WithAuthor(Context.Message.Author); eb.WithCurrentTimestamp(); await Context.Message.ReplyAsync("", false, eb.Build()); return; } MongoClient mongoClient = new MongoClient(Global.Mongoconnstr); IMongoDatabase database = mongoClient.GetDatabase("finlay"); IMongoCollection <BsonDocument> collection = database.GetCollection <BsonDocument>("guilds"); ulong _id = Context.Guild.Id; BsonDocument guildDocument = await MongoHandler.FindById(collection, _id); if (guildDocument == null) { MongoHandler.InsertGuild(_id); } BsonDocument guild = await collection.Find(Builders <BsonDocument> .Filter.Eq("_id", _id)).FirstOrDefaultAsync(); ulong _chanId = channel.Id; if (guild == null) { BsonDocument document = new BsonDocument { { "_id", (decimal)_id }, { "welcomechannel", (decimal)_chanId } }; collection.InsertOne(document); } else { collection.UpdateOne(Builders <BsonDocument> .Filter.Eq("_id", _id), Builders <BsonDocument> .Update.Set("welcomechannel", _chanId)); } EmbedBuilder embed = new EmbedBuilder(); embed.WithTitle("Success"); embed.WithDescription($"Successfully set the welcome channel to <#{_chanId}>!"); embed.WithColor(Color.Green); embed.WithAuthor(Context.Message.Author); embed.WithCurrentTimestamp(); await Context.Message.ReplyAsync("", false, embed.Build()); } else { await Context.Channel.TriggerTypingAsync(); await Context.Message.Channel.SendMessageAsync("", false, new EmbedBuilder() { Color = Color.LightOrange, Title = "You don't have Permission!", Description = $"Sorry, {Context.Message.Author.Mention} but you do not have permission to use this command.", Author = new EmbedAuthorBuilder() { Name = Context.Message.Author.ToString(), IconUrl = Context.Message.Author.GetAvatarUrl() ?? Context.User.GetDefaultAvatarUrl(), Url = Context.Message.GetJumpUrl() } }.Build()); } }