本文整理汇总了C#中CommandManager.RegisterMain方法的典型用法代码示例。如果您正苦于以下问题:C# CommandManager.RegisterMain方法的具体用法?C# CommandManager.RegisterMain怎么用?C# CommandManager.RegisterMain使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CommandManager
的用法示例。
在下文中一共展示了CommandManager.RegisterMain方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InitializeBot
private bool InitializeBot()
{
// Read Config File
const string configFilePath = "configTS3AudioBot.cfg";
ConfigFile cfgFile = ConfigFile.Open(configFilePath) ?? ConfigFile.Create(configFilePath) ?? ConfigFile.GetDummy();
var afd = cfgFile.GetDataStruct<AudioFrameworkData>(typeof(AudioFramework), true);
var bcd = cfgFile.GetDataStruct<BobControllerData>(typeof(BobController), true);
var qcd = cfgFile.GetDataStruct<QueryConnectionData>(typeof(QueryConnection), true);
var hmd = cfgFile.GetDataStruct<HistoryManagerData>(typeof(HistoryManager), true);
var pmd = cfgFile.GetDataStruct<PluginManagerData>(typeof(PluginManager), true);
var pld = cfgFile.GetDataStruct<PlaylistManagerData>(typeof(PlaylistManager), true);
mainBotData = cfgFile.GetDataStruct<MainBotData>(typeof(MainBot), true);
cfgFile.Close();
if (consoleOutput)
{
Log.RegisterLogger("[%T]%L: %M", "", Console.WriteLine);
}
if (writeLog && !string.IsNullOrEmpty(mainBotData.logFile))
{
var encoding = new UTF8Encoding(false);
logStream = new StreamWriter(File.Open(mainBotData.logFile, FileMode.Append, FileAccess.Write, FileShare.Read), encoding);
Log.RegisterLogger("[%T]%L: %M\n" + (writeLogStack ? "%S\n" : ""), "", (msg) =>
{
if (logStream != null)
try
{
logStream.Write(msg);
logStream.Flush();
}
catch (IOException) { }
});
}
Log.Write(Log.Level.Info, "[============ TS3AudioBot started =============]");
string dateStr = DateTime.Now.ToLongDateString();
Log.Write(Log.Level.Info, "[=== Date: {0}{1} ===]", new string(' ', Math.Max(0, 32 - dateStr.Length)), dateStr);
string timeStr = DateTime.Now.ToLongTimeString();
Log.Write(Log.Level.Info, "[=== Time: {0}{1} ===]", new string(' ', Math.Max(0, 32 - timeStr.Length)), timeStr);
Log.Write(Log.Level.Info, "[==============================================]");
Log.Write(Log.Level.Info, "[============ Initializing Commands ===========]");
CommandManager = new CommandManager();
CommandManager.RegisterMain(this);
Log.Write(Log.Level.Info, "[============ Initializing Modules ============]");
QueryConnection = new QueryConnection(qcd);
var playlistManager = new PlaylistManager(pld);
BobController = new BobController(bcd, QueryConnection);
// old: new VLCConnection(afd.vlcLocation);
// new: BobController
AudioFramework = new AudioFramework(afd, BobController, playlistManager);
SessionManager = new SessionManager();
HistoryManager = new HistoryManager(hmd);
PluginManager = new PluginManager(this, pmd);
Log.Write(Log.Level.Info, "[=========== Initializing Factories ===========]");
FactoryManager = new ResourceFactoryManager(AudioFramework);
FactoryManager.DefaultFactorty = new MediaFactory();
FactoryManager.AddFactory(new YoutubeFactory());
FactoryManager.AddFactory(new SoundcloudFactory());
FactoryManager.AddFactory(new TwitchFactory());
Log.Write(Log.Level.Info, "[=========== Registering callbacks ============]");
// Inform our HistoryManager when a new resource started successfully
AudioFramework.OnResourceStarted += HistoryManager.LogAudioResource;
// Inform the BobClient on start/stop
AudioFramework.OnResourceStarted += BobController.OnResourceStarted;
AudioFramework.OnResourceStopped += BobController.OnResourceStopped;
// In own favor update the own status text to the current song title
AudioFramework.OnResourceStarted += SongUpdateEvent;
// Register callback for all messages happening
QueryConnection.OnMessageReceived += TextCallback;
// Register callback to remove open private sessions, when user disconnects
QueryConnection.OnClientDisconnect += (s, e) => SessionManager.RemoveSession(e.InvokerId);
Log.Write(Log.Level.Info, "[================= Finalizing =================]");
// Create a default session for all users in all chat
SessionManager.DefaultSession = new PublicSession(this);
// Connect the query after everyting is set up
try { QueryConnection.Connect(); }
catch (QueryCommandException qcex)
{
Log.Write(Log.Level.Error, "There is either a problem with your connection configuration, or the query has not all permissions it needs. ({0})", qcex);
return false;
}
Log.Write(Log.Level.Info, "[============== Connected & Done ==============]");
return true;
}