Пример #1
0
 public void InviteDeleted(DiscordServer server, DiscordInvite invite)
 {
     foreach (var e in this.invite)
     {
         e.InviteDeleted(server, invite);
     }
 }
Пример #2
0
#pragma warning restore IDE1006


        public Joiner(JoinRequest request)
        {
            Attack = new Attack(this)
            {
                Type = "Joiner", Bots = Server.Bots.Count
            };

            Threads = request.Threads;
            try
            {
                _invite = new DiscordClient().GetInvite(request.Invite.Split('/').Last());
            }
            catch (DiscordHttpException e)
            {
                if (e.Code == DiscordError.UnknownInvite)
                {
                    Console.WriteLine($"[FATAL] {request.Invite} is invalid");

                    throw new CheckException("Invalid invite");
                }
                else
                {
                    Console.WriteLine($"[ERROR] Unknown: {e.Code} | {e.ErrorMessage}");

                    throw new CheckException($"Code: {e.Code}");
                }
            }
        }
Пример #3
0
        public static async Task <bool> IsWhitelistedAsync(DiscordInvite invite)
        {
            var code = string.IsNullOrWhiteSpace(invite.Code) ? null : invite.Code;
            var name = string.IsNullOrWhiteSpace(invite.Guild.Name) ? null : invite.Guild.Name;

            await using var db = new BotDb();
            var whitelistedInvite = await db.WhitelistedInvites.FirstOrDefaultAsync(i => i.GuildId == invite.Guild.Id);

            if (whitelistedInvite == null)
            {
                return(false);
            }

            if (name != null && name != whitelistedInvite.Name)
            {
                whitelistedInvite.Name = invite.Guild.Name;
            }
            if (string.IsNullOrEmpty(whitelistedInvite.InviteCode) && code != null)
            {
                whitelistedInvite.InviteCode = code;
            }
            await db.SaveChangesAsync().ConfigureAwait(false);

            return(true);
        }
Пример #4
0
            public async Task Gibinvite(CommandContext ctx, int max_uses = 1, int age = 0)
            {
                DiscordChannel channel = await ctx.Client.GetChannelAsync(230004550973521932);

                DiscordInvite inv = await channel.CreateInviteAsync(age, max_uses, false, true, $"gibinvite command used in {ctx.Channel.Id}");

                DiscordDmChannel chan = await ctx.Member.CreateDmChannelAsync();

                await chan.SendMessageAsync($"Here's the invite you asked for: https://discord.gg/{inv.Code}");

                await ctx.Channel.SendMessageAsync($"{Program.cfgjson.Emoji.Check} I've DMed you an invite to **Erisa's Corner** with `{max_uses}` use(s) and an age of `{age}`!");
            }
Пример #5
0
        public static async Task <bool> AddAsync(DiscordInvite invite)
        {
            if (await IsWhitelistedAsync(invite).ConfigureAwait(false))
            {
                return(false);
            }

            var code = invite.IsRevoked || string.IsNullOrWhiteSpace(invite.Code) ? null : invite.Code;
            var name = string.IsNullOrWhiteSpace(invite.Guild.Name) ? null : invite.Guild.Name;

            await using var db = new BotDb();
            await db.WhitelistedInvites.AddAsync(new WhitelistedInvite { GuildId = invite.Guild.Id, Name = name, InviteCode = code }).ConfigureAwait(false);

            await db.SaveChangesAsync().ConfigureAwait(false);

            return(true);
        }
Пример #6
0
        public async Task GetInstantInviteAsync(CommandContext ctx)
        {
            IReadOnlyList <DiscordInvite> invites = await ctx.Guild.GetInvitesAsync();

            IEnumerable <DiscordInvite> permanent = invites.Where(inv => !inv.IsTemporary);

            if (permanent.Any())
            {
                await ctx.RespondAsync(permanent.First().ToString());
            }
            else
            {
                DiscordInvite invite = await ctx.Channel.CreateInviteAsync(max_age : 3600, temporary : true, reason : ctx.BuildInvocationDetailsString());

                await ctx.RespondAsync($"{invite} {Formatter.Italic("(This invite will expire in one hour!)")}");
            }
        }
Пример #7
0
        //TODO needs thorough testing
        async Task AttemptInformPermittedMembersDirectly(DiscordMember channelCreator, DiscordChannel createdVoiceChannel, IEnumerable <DiscordMember> permittedAndAuthorizedMembers)
        {
            DiscordInvite newInvite = await createdVoiceChannel.CreateInviteAsync();

            foreach (DiscordMember member in permittedAndAuthorizedMembers)
            {
                DiscordDmChannel currentMemberDm;
                try { currentMemberDm = await member.CreateDmChannelAsync(); }
                catch (Exception) { continue; }

                if (currentMemberDm is null)
                {
                    continue;
                }

                await currentMemberDm.SendMessageAsync($"You were whitelisted to join a VC by {channelCreator.Nickname ?? channelCreator.DisplayName} in {createdVoiceChannel.Guild.Name}. Click this link to immediately join the channel: {newInvite}");
            }
        }
Пример #8
0
        internal override async Task Execute(CommandObjects CommandObject)
        {
            string[] msgs = CommandObject.CommandArgs.Remove(0);

            if (msgs.Length == 0)
            {
                Log.Debug("Channel is null");

                DiscordChannel DefaultChannel = CommandObject.Guild.GetDefaultChannel();
                Console.WriteLine(DefaultChannel.Name);
                DiscordInvite Invite = await DefaultChannel.CreateInviteAsync();

                string InviteUrl = "https://discord.gg/" + Invite.Code;
                string Message   = string.Format(CommandObject.Language.InviteResult, InviteUrl);
                await CommandObject.Message.Channel.SendMessageAsync(Message);

                return;
            }

            string InviteText     = msgs[0];
            string InviteIDString = InviteText.TrimStart('<', '#').TrimEnd('>');

            if (!ulong.TryParse(InviteIDString, out ulong InviteID))
            {
                await CommandObject.Message.Channel.SendMessageAsync(CommandObject.Language.InviteChannelNotFound);

                return;
            }

            try {
                DiscordChannel GetChannel = CommandObject.Guild.GetChannel(InviteID);
                DiscordInvite  Invite     = await GetChannel.CreateInviteAsync();

                string InviteUrl = "https://discord.gg/" + Invite.Code;
                string Message   = string.Format(CommandObject.Language.InviteResult, InviteUrl);
                await CommandObject.Message.Channel.SendMessageAsync(Message);
            }
            catch (NullReferenceException) {
                Log.Warning("Channel ID is not found");
                await CommandObject.Message.Channel.SendMessageAsync(CommandObject.Language.InviteChannelIdNotFound);
            }
        }
Пример #9
0
        public async Task KickInvite(CommandContext ctx, DiscordMember user)
        {
            var           roles   = user.Roles;
            var           invites = ctx.Guild.GetInvitesAsync().Result;
            DiscordInvite invitex = null;

            foreach (var invite in invites)
            {
                if (invite.MaxAge == 0 && invite.MaxUses == 0)
                {
                    invitex = invite;
                    break;
                }
            }
            await user.SendMessageAsync(invitex.ToString());

            await user.RemoveAsync();

            esperandoporcargo.Add(user, roles);
        }
Пример #10
0
 /// <summary>
 /// Returns the full invite url of an invite. e.g. https://discord.gg/2jk86sa8
 /// </summary>
 /// <param name="invite">The invite object to get the invite code from.</param>
 /// <returns></returns>
 public static string GetFullUrl(this DiscordInvite invite)
 {
     return($"https://discord.gg/{invite.Code} "); //that space at the end is very important!
 }