Пример #1
0
        /// <summary>
        /// performs wise heuristics to identify a file (simple version)
        /// </summary>
        public FileIDType IdentifySimple(IdentifyParams p)
        {
            var ret = Identify(p);

            if (ret.ShouldTryDisc)
            {
                return(FileIDType.Disc);
            }
            if (ret.Count == 0)
            {
                return(FileIDType.None);
            }
            else if (ret.Count == 1)
            {
                return(ret[0].FileIDType);
            }
            else if (ret[0].Confidence == ret[1].Confidence)
            {
                return(FileIDType.Multiple);
            }
            else
            {
                return(ret[0].FileIDType);
            }
        }
Пример #2
0
        public async Task SendIdentifyAsync(int largeThreshold = 100, int shardID = 0, int totalShards = 1, bool guildSubscriptions = true, GatewayIntents?gatewayIntents = null, RequestOptions options = null)
        {
            options = RequestOptions.CreateOrClone(options);
            var props = new Dictionary <string, string>
            {
                ["$device"] = "Discord.Net"
            };
            var msg = new IdentifyParams()
            {
                Token          = AuthToken,
                Properties     = props,
                LargeThreshold = largeThreshold
            };

            if (totalShards > 1)
            {
                msg.ShardingParams = new int[] { shardID, totalShards }
            }
            ;

            options.BucketId = GatewayBucket.Get(GatewayBucketType.Identify).Id;

            if (gatewayIntents.HasValue)
            {
                msg.Intents = (int)gatewayIntents.Value;
            }
            else
            {
                msg.GuildSubscriptions = guildSubscriptions;
            }

            await SendGatewayAsync(GatewayOpCode.Identify, msg, options : options).ConfigureAwait(false);
        }
        public async Task SendIdentifyAsync(int largeThreshold = 100, int shardID = 0, int totalShards = 1, bool guildSubscriptions = true, GatewayIntents? gatewayIntents = null, RequestOptions options = null, string browser = "Discord.Net")
        {
            options = RequestOptions.CreateOrClone(options);
            var props = new Dictionary<string, string>
            {
                ["$device"] = "Discord.Net",
                ["$browser"] = browser,
                [$"os"] = Environment.OSVersion.VersionString
            };
            var msg = new IdentifyParams()
            {
                Token = AuthToken,
                Properties = props,
                LargeThreshold = largeThreshold
            };
            if (totalShards > 1)
                msg.ShardingParams = new int[] { shardID, totalShards };

            if (gatewayIntents.HasValue)
                msg.Intents = (int)gatewayIntents.Value;
            else
                msg.GuildSubscriptions = guildSubscriptions;

            await SendGatewayAsync(GatewayOpCode.Identify, msg, options: options).ConfigureAwait(false);
        }
Пример #4
0
        public async Task SendIdentifyAsync(int largeThreshold = 100, int shardID = 0, int totalShards = 1, RequestOptions options = null)
        {
            options = RequestOptions.CreateOrClone(options);
            var props = new Dictionary <string, string>
            {
                ["$device"] = "Discord.Net"
            };
            var msg = new IdentifyParams()
            {
                Token          = AuthToken,
                Properties     = props,
                LargeThreshold = largeThreshold
            };

            if (totalShards > 1)
            {
                msg.ShardingParams = new int[] { shardID, totalShards }
            }
            ;

            await SendGatewayAsync(GatewayOpCode.Identify, msg, options : options).ConfigureAwait(false);
        }
Пример #5
0
        /// <summary>
        /// performs wise heuristics to identify a file.
        /// this will attempt to return early if a confident result can be produced.
        /// </summary>
        public FileIDResults Identify(IdentifyParams p)
        {
            IdentifyJob job = new IdentifyJob()
            {
                Stream = p.SeekableStream,
                Disc   = p.Disc
            };

            //if we have a disc, that's a separate codepath
            if (job.Disc != null)
            {
                return(IdentifyDisc(job));
            }

            FileIDResults ret = new FileIDResults();

            string ext = p.Extension;

            if (ext != null)
            {
                ext           = ext.TrimStart('.').ToUpper();
                job.Extension = ext;
            }

            if (job.Extension == "CUE")
            {
                ret.ShouldTryDisc = true;
                return(ret);
            }

            if (job.Extension != null)
            {
                //first test everything associated with this extension
                ExtensionInfo handler = null;
                if (ExtensionHandlers.TryGetValue(ext, out handler))
                {
                    foreach (var del in handler.Testers)
                    {
                        var fidr = del(job);
                        if (fidr.FileIDType == FileIDType.None)
                        {
                            continue;
                        }
                        ret.Add(fidr);
                    }

                    ret.Sort();

                    //add a low confidence result just based on extension, if it doesnt exist
                    if (ret.Find((x) => x.FileIDType == handler.DefaultForExtension) == null)
                    {
                        var fidr = new FileIDResult(handler.DefaultForExtension, 5);
                        ret.Add(fidr);
                    }
                }
            }

            ret.Sort();

            //if we didnt find anything high confidence, try all the testers (TODO)

            return(ret);
        }