// false on error, true if successful public static void CheckAndUpgrade(ConfRoot coreConfig, string oldFilename = "configTS3AudioBot.cfg") { if (!File.Exists(oldFilename)) { return; } var oldConfig = ConfigFile.OpenOrCreate(oldFilename); if (oldConfig is null) { Log.Error("Old config file '{0}' found but could not be read", oldFilename); return; } try { Upgrade(oldConfig, coreConfig); } catch (Exception ex) { Log.Error(ex, "Error while upgrading from old config"); return; } try { File.Move(oldFilename, oldFilename + ".old"); } catch (Exception ex) { Log.Error(ex, "Couldn't move the old config file. Remove it manually to prevent this upgrade step and message."); } }
public void TestLangDetector() { var conn_str = ConfRoot.GetSection("DataCyrConnStr").Value; using (var lang_detector = CreateLangDetector()) { var preproc = new CommonEnCyr(lang_detector); preproc.RunAsync((txt_src, pp_item) => { if (pp_item.Lang == LangLabel.NA) { Log($"LANG_DETECT_ERROR>>> {pp_item.Text}"); } //else //Log($"{pp_item.Lang}>>> {pp_item.Text}"); } ); Log($"TEST Process samples ..."); foreach (var keyValue in GetSrcItems(conn_str)) { preproc.Push(keyValue.Value); } } Log($"TEST Done"); }
private E <string> Run(ParameterData setup) { var configResult = ConfRoot.OpenOrCreate(configFilePath); if (!configResult.Ok) { return("Could not create config"); } ConfRoot config = configResult.Value; Config.Deprecated.UpgradeScript.CheckAndUpgrade(config); ConfigUpgrade2.Upgrade(config.Configs.BotsPath.Value); config.Save(); var builder = new DependencyBuilder(injector); builder.AddModule(this); builder.AddModule(config); builder.AddModule(injector); builder.AddModule(config.Db); builder.RequestModule <SystemMonitor>(); builder.RequestModule <DbStore>(); builder.AddModule(config.Plugins); builder.RequestModule <PluginManager>(); builder.AddModule(config.Web); builder.AddModule(config.Web.Interface); builder.AddModule(config.Web.Api); builder.RequestModule <WebServer>(); builder.AddModule(config.Rights); builder.RequestModule <RightsManager>(); builder.RequestModule <BotManager>(); builder.RequestModule <TokenManager>(); builder.RequestModule <CommandManager>(); builder.AddModule(config.Factories); builder.RequestModule <SpotifyApi>(); builder.RequestModule <ResourceResolver>(); builder.RequestModule <Stats>(); builder.AddModule(config.Tools.Librespot); if (!builder.Build()) { Log.Error("Missing core module dependency"); return("Could not load all core modules"); } YoutubeDlHelper.DataObj = config.Tools.YoutubeDl; builder.GetModule <SystemMonitor>().StartTimedSnapshots(); builder.GetModule <CommandManager>().RegisterCollection(MainCommands.Bag); builder.GetModule <RightsManager>().CreateConfigIfNotExists(setup.Interactive); builder.GetModule <BotManager>().RunBots(setup.Interactive); builder.GetModule <WebServer>().StartWebServer(); builder.GetModule <Stats>().StartTimer(setup.SendStats); return(R.Ok); }
public Stats(ConfRoot conf, DbStore database, BotManager botManager) { this.conf = conf; this.database = database; this.botManager = botManager; uploadParamEnabled = true; runtimeLastTrack = Tools.Now; ReadAndUpgradeStats(); }
private E <string> Run(bool interactive = false) { var configResult = ConfRoot.OpenOrCreate(configFilePath); if (!configResult.Ok) { return("Could not create config"); } ConfRoot config = configResult.Value; Config.Deprecated.UpgradeScript.CheckAndUpgrade(config); var injector = new CoreInjector(); injector.RegisterType <Core>(); injector.RegisterType <ConfRoot>(); injector.RegisterType <CoreInjector>(); injector.RegisterType <DbStore>(); injector.RegisterType <PluginManager>(); injector.RegisterType <CommandManager>(); injector.RegisterType <ResourceFactoryManager>(); injector.RegisterType <WebServer>(); injector.RegisterType <RightsManager>(); injector.RegisterType <BotManager>(); injector.RegisterType <TokenManager>(); injector.RegisterModule(this); injector.RegisterModule(config); injector.RegisterModule(injector); injector.RegisterModule(new DbStore(config.Db)); injector.RegisterModule(new PluginManager(config.Plugins)); injector.RegisterModule(new CommandManager(), x => x.Initialize()); injector.RegisterModule(new ResourceFactoryManager(config.Factories), x => x.Initialize()); injector.RegisterModule(new WebServer(config.Web), x => x.Initialize()); injector.RegisterModule(new RightsManager(config.Rights)); injector.RegisterModule(new BotManager()); injector.RegisterModule(new TokenManager(), x => x.Initialize()); if (!injector.AllResolved()) { Log.Debug("Cyclic core module dependency"); injector.ForceCyclicResolve(); if (!injector.AllResolved()) { Log.Error("Missing core module dependency"); return("Could not load all core modules"); } } YoutubeDlHelper.DataObj = config.Tools.YoutubeDl; Bots.RunBots(interactive); return(R.Ok); }
public async Task Run(ParameterData setup) { scheduler.VerifyOwnThread(); AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionHandler; TaskScheduler.UnobservedTaskException += UnobservedTaskExceptionHandler; Console.CancelKeyPress += ConsoleInterruptHandler; var config = ConfRoot.OpenOrCreate(configFilePath); if (config is null) { throw new Exception("Could not create config"); } ConfigUpgrade2.Upgrade(config.Configs.BotsPath.Value); config.Save(); var builder = new DependencyBuilder(injector); injector.AddModule(this); injector.AddModule(scheduler); injector.AddModule(injector); injector.AddModule(config); injector.AddModule(config.Db); injector.AddModule(config.Plugins); injector.AddModule(config.Web); injector.AddModule(config.Web.Interface); injector.AddModule(config.Web.Api); injector.AddModule(config.Rights); injector.AddModule(config.Factories); builder.RequestModule <SystemMonitor>(); builder.RequestModule <DbStore>(); builder.RequestModule <PluginManager>(); builder.RequestModule <WebServer>(); builder.RequestModule <RightsManager>(); builder.RequestModule <BotManager>(); builder.RequestModule <TokenManager>(); builder.RequestModule <CommandManager>(); builder.RequestModule <ResourceResolver>(); builder.RequestModule <Stats>(); if (!builder.Build()) { throw new Exception("Could not load all core modules"); } Upgrader.PerformUpgrades(injector); YoutubeDlHelper.DataObj = config.Tools.YoutubeDl; injector.GetModuleOrThrow <CommandManager>().RegisterCollection(MainCommands.Bag); injector.GetModuleOrThrow <RightsManager>().CreateConfigIfNotExists(setup.Interactive); injector.GetModuleOrThrow <WebServer>().StartWebServer(); injector.GetModuleOrThrow <Stats>().StartTimer(setup.SendStats); await injector.GetModuleOrThrow <BotManager>().RunBots(setup.Interactive); }
private E <string> Run(bool interactive = false) { var configResult = ConfRoot.OpenOrCreate(configFilePath); if (!configResult.Ok) { return("Could not create config"); } ConfRoot config = configResult.Value; Config.Deprecated.UpgradeScript.CheckAndUpgrade(config); ConfigUpgrade2.Upgrade(config.Configs.BotsPath.Value); config.Save(); var builder = new DependencyBuilder(injector); builder.AddModule(this); builder.AddModule(config); builder.AddModule(injector); builder.AddModule(config.Db); builder.RequestModule <SystemMonitor>(); builder.RequestModule <DbStore>(); builder.AddModule(config.Plugins); builder.RequestModule <PluginManager>(); builder.AddModule(config.Web); builder.AddModule(config.Web.Interface); builder.AddModule(config.Web.Api); builder.RequestModule <WebServer>(); builder.AddModule(config.Rights); builder.RequestModule <RightsManager>(); builder.RequestModule <BotManager>(); builder.RequestModule <TokenManager>(); builder.RequestModule <CommandManager>(); builder.AddModule(config.Factories); // TODO fix interaction: rfm needs to be in the same injector as the commandsystem, otherwise duplicate error // Also TODO find solution to move commandsystem to bot, without breaking api builder.RequestModule <ResourceFactory>(); if (!builder.Build()) { Log.Error("Missing core module dependency"); return("Could not load all core modules"); } YoutubeDlHelper.DataObj = config.Tools.YoutubeDl; builder.GetModule <SystemMonitor>().StartTimedSnapshots(); builder.GetModule <CommandManager>().RegisterCollection(MainCommands.Bag); builder.GetModule <RightsManager>().CreateConfigIfNotExists(interactive); builder.GetModule <BotManager>().RunBots(interactive); builder.GetModule <WebServer>().StartWebServer(); return(R.Ok); }
public void ProcRukBuildFull() { var conn_str = ConfRoot.GetSection("DataCyrConnStr").Value; ProcRukFull(conn_str, "StaTransform.db", "AdID:"); SubProcFillEmptyVectDictRND(DBF_W2V_RUK, FTLangLabel.__label__ru); SubProcFillEmptyVectDictRND(DBF_W2V_RUK, FTLangLabel.__label__uk); SubProcFillEmptyVectDictRND(DBF_W2V_RUK, FTLangLabel.__label__en); SubProcBuildResultDict(DBF_RUK_Proc, DBF_W2V_RUK); SubProcInsertPredefinedMacro(DBF_W2V_RUK); }
public void ProcRukBuildFull() { var conn_str = ConfRoot.GetSection("DataCyrConnStr").Value; ProcRukFull(conn_str, "cs", ""); SubProcFillEmptyVectDictRND(DBF_W2V_RUK, LangLabel.NA); SubProcFillEmptyVectDictRND(DBF_W2V_RUK, LangLabel.ru); SubProcFillEmptyVectDictRND(DBF_W2V_RUK, LangLabel.uk); SubProcFillEmptyVectDictRND(DBF_W2V_RUK, LangLabel.en); SubProcBuildResultDict(DBF_RUK_Proc, DBF_W2V_RUK); //SubProcInsertPredefinedMacro(DBF_W2V_RUK); }
public SpotifyStreamAudioProducer(Stream stream, Player player, ConfRoot config) { this.stream = stream; this.player = player; wait = new AutoResetEvent(false); resampledStream = new MemoryStream(); if (resampler == null) { var dll = Path.GetFullPath(Path.Combine(config.Plugins.Path.Value, "lib", "NAudio.dll")); resampler = new Resampler(Assembly.LoadFrom(dll)); } }
public void ProcRuUkFull() { Log("Process Samples ..."); var conn_str = ConfRoot.GetSection("DataCyrConnStr").Value; ProcSrcItems(conn_str, "cs", ""); _lang = LangLabel.ru; SubProcFillEmptyVectDict(FTF_MODEL, DBF_W2V, LANG); _lang = LangLabel.uk; SubProcFillEmptyVectDict(FTF_MODEL, DBF_W2V, LANG); _lang = LangLabel.NA; SubProcFillEmptyVectDictRND(DBF_W2V, LANG); // SubProcBuildResultDict(DBF_RESULT, DBF_W2V); Log("Done (ProcRuUkFull)"); }
/// <summary> /// Texts data source. Rewrite to connect another source. /// </summary> /// <returns>yield key-value pairs</returns> IEnumerable <KeyValuePair <string, string> > GetSrcItems(string conn_str) { using (var cn = new SQLiteConnection(conn_str)) { cn.Open(); var sql = ConfRoot.GetSection("DataCyrSelectSQL").Value; var cmd = new SQLiteCommand(sql, cn); using (var rd = cmd.ExecuteReader()) { while (rd.Read()) { yield return(KeyValuePair.Create(rd.GetString(0), rd.GetString(1))); } } } }
public SpotifyControl(SpotifyPluginConfig config, ConfRoot rootConf) { if (initialized) { return; } _spotifyConfig = config; if (SpotifyAPIWeb == null) { var dll = Path.GetFullPath(Path.Combine(rootConf.Plugins.Path.Value, "lib", "SpotifyAPI.Web.dll")); SpotifyAPIWeb = Assembly.LoadFrom(dll); } if (SpotifyAPIAuth == null) { var dll2 = Path.GetFullPath(Path.Combine(rootConf.Plugins.Path.Value, "lib", "SpotifyAPI.Web.Auth.dll")); SpotifyAPIAuth = Assembly.LoadFrom(dll2); } }
public Player(ConfRoot confRoot, ConfBot config, DedicatedTaskScheduler scheduler, Id id) { this.scheduler = scheduler; FfmpegProducer = new FfmpegProducer(confRoot.Tools.Ffmpeg, scheduler, id); StallCheckPipe = new StallCheckPipe(); VolumePipe = new VolumePipe(); Volume = config.Audio.Volume.Default; EncoderPipe = new EncoderPipe(SendCodec) { Bitrate = ScaleBitrate(config.Audio.Bitrate) }; TimePipe = new PreciseTimedPipe(EncoderPipe, id) { ReadBufferSize = EncoderPipe.PacketSize }; MergePipe = new PassiveMergePipe(); config.Audio.Bitrate.Changed += (s, e) => EncoderPipe.Bitrate = ScaleBitrate(e.NewValue); MergePipe.Into(TimePipe).Chain <CheckActivePipe>().Chain(StallCheckPipe).Chain(VolumePipe).Chain(EncoderPipe); }
public Stats(ConfRoot conf, DbStore database, BotManager botManager, DedicatedTaskScheduler scheduler) { this.conf = conf; this.database = database; this.botManager = botManager; uploadParamEnabled = true; runtimeLastTrack = Tools.Now; ticker = scheduler.CreateTimer(TrackPoint, CheckInterval, false); meta = database.GetMetaData(StatsTable); trackEntries = database.GetCollection <StatsData>(StatsTable); trackEntries.EnsureIndex(x => x.Id, true); trackEntries.EnsureIndex(x => x.Time); accEntries = database.GetCollection <StatsData>(StatsTableAcc); accEntries.EnsureIndex(x => x.Id, true); if (meta.Version != StatsVersion || meta.CustomData is null) { statsPoints = new StatsMeta { LastSend = Tools.Now, }; meta.Version = StatsVersion; UpdateMeta(); } else { statsPoints = JsonConvert.DeserializeObject <StatsMeta>(meta.CustomData, JsonSettings) ?? new StatsMeta(); // Upgrade steps here } overallStats = accEntries.FindById(OverallId) ?? new StatsData { Id = OverallId }; }
public BotManager(ConfRoot confRoot, CoreInjector coreInjector) { this.confRoot = confRoot; this.coreInjector = coreInjector; }
public SpotifyApi(ConfRoot rootConfig) { config = rootConfig.Tools.Spotify; this.rootConfig = rootConfig; if ( string.IsNullOrWhiteSpace(config.SpotifyAccessToken) && string.IsNullOrWhiteSpace(config.SpotifyRefreshToken) ) { // Get new spotify access and refresh tokens. if (string.IsNullOrWhiteSpace(config.SpotifyAPIClientId) || string.IsNullOrWhiteSpace(config.SpotifyAPIClientSecret)) { Log.Error("Failed to setup spotify API: Invalid user input for client ID or secret."); return; } var loginRequest = new LoginRequest( CallbackUrl, config.SpotifyAPIClientId, LoginRequest.ResponseType.Code ) { Scope = new[] { Scopes.UserReadPlaybackState, Scopes.UserModifyPlaybackState, Scopes.UserReadPrivate } }; Console.WriteLine(strings.login_to_spotify_using_this_url, loginRequest.ToUri()); Console.Write(strings.copy_redirect_url_here); var resultUrl = Console.ReadLine(); if (string.IsNullOrWhiteSpace(resultUrl)) { Log.Error("Failed to setup spotify API: Invalid user input for the callback URL."); return; } var match = SpotifyCallbackCodeMatcher.Match(resultUrl); if (!match.Success) { Log.Error("Failed to setup spotify API: Code not found in callback URL."); return; } var tokenRequestTask = new OAuthClient().RequestToken( new AuthorizationCodeTokenRequest( config.SpotifyAPIClientId, config.SpotifyAPIClientSecret, match.Groups[1].Value, CallbackUrl ) ); var result = ResolveRequestTask(tokenRequestTask, false); if (!result.Ok) { Log.Error("Failed to setup spotify API: Code to token translation failed."); return; } if (tokenRequestTask.IsFaulted) { Log.Error("Failed to setup spotify API: Code to token translation failed."); return; } if ( config.SpotifyAccessToken == null || config.SpotifyRefreshToken == null ) { Log.Error("Failed to setup spotify API: Token config entries are invalid."); return; } config.SpotifyAccessToken.Value = tokenRequestTask.Result.AccessToken; config.SpotifyRefreshToken.Value = tokenRequestTask.Result.RefreshToken; rootConfig.Save(); } // Create spotify client. Client = new SpotifyClient(config.SpotifyAccessToken); // Get the market of the bot. var userData = Request(() => Client.UserProfile.Current()); if (!userData.Ok) { Log.Error($"Failed to setup spotify API: Could not get user data ({userData.Error})."); Client = null; return; } // Reshaper is lying, it is null if the user-read-private permission is missing. // ReSharper disable once ConditionIsAlwaysTrueOrFalse // ReSharper disable once HeuristicUnreachableCode if (userData.Value.Country == null) { // ReSharper disable once HeuristicUnreachableCode Log.Error("Failed to setup spotify API: Country of the spotify user is invalid."); // Reset access and refresh token as they are using the wrong permissions. config.SpotifyAccessToken.Value = ""; config.SpotifyRefreshToken.Value = ""; rootConfig.Save(); Client = null; return; } market = userData.Value.Country; }
// false on error, true if successful private static void Upgrade(ConfigFile from, ConfRoot to) { // Read old data var web = from.GetDataStruct <WebData>("WebData", true); var rmd = from.GetDataStruct <RightsManagerData>("RightsManager", true); var ytd = from.GetDataStruct <YoutubeFactoryData>("YoutubeFactory", true); var pmd = from.GetDataStruct <PluginManagerData>("PluginManager", true); var mfd = from.GetDataStruct <MediaFactoryData>("MediaFactory", true); var mbd = from.GetDataStruct <MainBotData>("MainBot", true); var hmd = from.GetDataStruct <HistoryManagerData>("HistoryManager", true); var pld = from.GetDataStruct <PlaylistManagerData>("PlaylistManager", true); var afd = from.GetDataStruct <AudioFrameworkData>("AudioFramework", true); var qcd = from.GetDataStruct <Ts3FullClientData>("QueryConnection", true); // Get all root stuff and save it to.Web.Hosts.Value = web.HostAddress.Split(' '); to.Web.Port.Value = web.Port; to.Web.Api.Enabled.Value = web.EnableApi; to.Web.Interface.Enabled.Value = web.EnableWebinterface; to.Web.Interface.Path.Value = web.WebinterfaceHostPath; to.Rights.Path.Value = rmd.RightsFile; to.Tools.YoutubeDl.Path.Value = ytd.YoutubedlPath; to.Tools.Ffmpeg.Path.Value = qcd.FfmpegPath; to.Plugins.Path.Value = pmd.PluginPath; to.Plugins.WriteStatusFiles.Value = pmd.WriteStatusFiles; to.Factories.Media.Path.Value = mfd.DefaultPath; to.Db.Path.Value = hmd.HistoryFile; to.Save(); // Create a default client for all bot instance relate stuff and save var bot = to.CreateBot(); bot.Run.Value = true; bot.Language.Value = mbd.Language; bot.BotGroupId.Value = mbd.BotGroupId; bot.GenerateStatusAvatar.Value = mbd.GenerateStatusAvatar; bot.Commands.Matcher.Value = mbd.CommandMatching; bot.History.Enabled.Value = hmd.EnableHistory; bot.History.FillDeletedIds.Value = hmd.FillDeletedIds; bot.Playlists.Path.Value = pld.PlaylistPath; bot.Audio.Volume.Default.Value = afd.DefaultVolume; bot.Audio.MaxUserVolume.Value = afd.MaxUserVolume; bot.Audio.SendMode.Value = afd.AudioMode; bot.Audio.Bitrate.Value = qcd.AudioBitrate; bot.Connect.Address.Value = qcd.Address; bot.Connect.Identity.PrivateKey.Value = qcd.Identity; bot.Connect.Identity.Level.Value = qcd.IdentityLevel == "auto" ? -1 : int.Parse(qcd.IdentityLevel); bot.Connect.Identity.Offset.Value = qcd.IdentityOffset; bot.Connect.ServerPassword.Password.Value = qcd.ServerPassword; bot.Connect.ServerPassword.AutoHash.Value = qcd.ServerPasswordAutoHash; bot.Connect.ServerPassword.Hashed.Value = qcd.ServerPasswordIsHashed; if (!string.IsNullOrEmpty(qcd.ClientVersion)) { var clientVersion = qcd.ClientVersion.Split('|'); bot.Connect.ClientVersion.Build.Value = clientVersion[0]; bot.Connect.ClientVersion.Platform.Value = clientVersion[1]; bot.Connect.ClientVersion.Sign.Value = clientVersion[2]; } bot.Connect.Name.Value = qcd.DefaultNickname; bot.Connect.Channel.Value = qcd.DefaultChannel; bot.Connect.ChannelPassword.Password.Value = qcd.DefaultChannelPassword; bot.Connect.Badges.Value = qcd.ClientBadges == "overwolf=0:badges=" ? "" : qcd.ClientBadges; bot.SaveNew(ConfigHelper.DefaultBotName); }
public BotManager(ConfRoot confRoot, CoreInjector coreInjector) { Util.Init(out activeBots); this.confRoot = confRoot; this.coreInjector = coreInjector; }