Exemplo n.º 1
0
 public PluginBase LoadPlugin(string dllPath, VtuberBotObserver observer)
 {
     try
     {
         if (!File.Exists(dllPath))
         {
             return(null);
         }
         var bytes      = File.ReadAllBytes(dllPath);
         var assembly   = Assembly.Load(bytes);
         var pluginMain = assembly.GetExportedTypes().FirstOrDefault(v => v.BaseType == typeof(PluginBase));
         if (pluginMain == null)
         {
             return(null);
         }
         var plugin = Activator.CreateInstance(pluginMain) as PluginBase;
         plugin.Observer = observer;
         plugin.DllPath  = dllPath;
         plugin.OnLoad();
         Plugins.Add(plugin);
         return(plugin);
     }
     catch (Exception ex)
     {
         LogHelper.Error("Cannot load plugin " + dllPath, true, ex);
         return(null);
     }
 }
Exemplo n.º 2
0
 public void LoadPlugins(string path, VtuberBotObserver observer)
 {
     if (!Directory.Exists(path))
     {
         return;
     }
     if (Directory.Exists(Path.Combine(path, "Assembly")))
     {
         foreach (var lib in Directory.GetFiles(Path.Combine(path, "Assembly")).Where(v => Path.GetExtension(v) == ".dll"))
         {
             LogHelper.Info("Load library: " + lib);
             var bytes = File.ReadAllBytes(lib);
             Assembly.Load(bytes);
         }
     }
     foreach (var file in Directory.GetFiles(path))
     {
         if (Path.GetExtension(file) != ".dll")
         {
             continue;
         }
         var plugin = LoadPlugin(file, observer);
         if (plugin == null)
         {
             LogHelper.Error("Cannot load plugin " + file);
         }
         else
         {
             LogHelper.Info("Loaded plugin: " + plugin.PluginName);
         }
     }
 }
Exemplo n.º 3
0
 public GroupController(VtuberBotObserver observer)
 {
     _observer           = observer;
     _vtuberCollection   = observer.Database.GetCollection <VtuberEntity>("vtubers");
     _liveFileCollection = observer.Database.GetCollection <YoutubeLiveFile>("youtube-live-files");
     _liveInfoCollection = observer.Database.GetCollection <YoutubeLiveInfo>("youtube-live-details");
 }
Exemplo n.º 4
0
        public void LoadPlugins(VtuberBotObserver observer)
        {
            var pluginPath = Path.Combine(Directory.GetCurrentDirectory(), "Plugins");

            if (!Directory.Exists(pluginPath))
            {
                Directory.CreateDirectory(pluginPath);
            }
            LoadPlugins(pluginPath, observer);
        }
Exemplo n.º 5
0
 public WebController(VtuberBotObserver observer)
 {
     _observer                   = observer;
     _vtuberCollection           = observer.Database.GetCollection <VtuberEntity>("vtubers");
     _liveFileCollection         = observer.Database.GetCollection <YoutubeLiveFile>("youtube-live-files");
     _liveInfoCollection         = observer.Database.GetCollection <YoutubeLiveInfo>("youtube-live-details");
     _liveChatCollection         = observer.Database.GetCollection <YoutubeLiveChat>("youtube-live-chats");
     _webLiveChatCollection      = observer.Database.GetCollection <YoutubeWebLiveChat>("youtube-web-live-chats");
     _tweetsCollection           = observer.Database.GetCollection <TweetInfo>("tweet-details");
     _bilibiliCommentsCollection = observer.Database.GetCollection <BilibiliCommentInfo>("bili-live-comments");
 }
 public SpiderCallbackController(VtuberBotObserver observer) => Observer = observer;
Exemplo n.º 7
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
            var database = new MongoClient(Config.DefaultConfig.DatabaseUrl).GetDatabase("vtuber-bot-data");
            var observer = new VtuberBotObserver(database);

            foreach (var client in Config.DefaultConfig.Clients)
            {
                LogHelper.Info("正在初始化Bot " + client.ClientId);
                var bot = new Bot.VtuberBot {
                    BotName = client.ClientId
                };
                foreach (var config in client.Services)
                {
                    var service = ServiceDispatcher.SearchBotService(config.ServiceType);
                    if (service == null)
                    {
                        LogHelper.Error("未找到服务类型 " + config.ServiceType);
                        continue;
                    }

                    service.ListenUrl    = config.ListenUrl;
                    service.AccessToken  = config.AccessToken;
                    service.ListenPort   = config.ListenPort;
                    service.Level        = config.Level;
                    service.WebsocketUrl = config.WsUrl;
                    service.Load();
                    bot.Services.Add(service);
                }
                bot.Init();
                observer.AddBot(bot);
                LogHelper.Info($"初始化 Bot {bot.BotName} 完成..");
            }
            observer.Processors.Add(new HelpProcessor()); //HELP
            observer.Processors.Add(new LiveProcessor());
            observer.Processors.Add(new VtuberProcessor());
            observer.Processors.Add(new SubscribeProcessor());
            observer.Processors.Add(new PluginProcessor());
            services.AddSingleton(serviceProvider => database);
            services.AddSingleton(serviceProvider => observer);
            services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(
                JwtBearerDefaults.AuthenticationScheme,
                options =>
            {
                options.RequireHttpsMetadata      = false;
                options.TokenValidationParameters = new TokenValidationParameters()
                {
                    ValidateIssuer = true,
                    ValidIssuer    = "http://api.bot.vtb.wiki",

                    ValidateIssuerSigningKey = true,
                    IssuerSigningKey         = BotJwt.IssuerSigningKey,

                    ValidateAudience = false,
                    ValidateLifetime = true,
                };
                options.SaveToken = true;
            });
            services.AddCors(option =>
            {
                option.AddPolicy("Any", policy => policy.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod());
            });
            PluginManager.Manager.LoadPlugins(observer);
        }