static void Main(string[] args) { //Initilize the client var _client = new DiscordClient(); StreamReader apifile = File.OpenText("api.txt"); SteamConnection.Connect(); Console.WriteLine("Connected to steam."); _client.MessageReceived += (s, e) => { if (e.Message.IsMentioningMe()) { ClientMentioned(s, e); } Command.CommandController(_client, e.Channel, e.Message.RawText, e.User.Id.ToString(), e.User); if (e.Channel.IsPrivate) { if (e.User.Name != "engi_valk") { Console.WriteLine(e.User.Name + ": " + e.Message.RawText); } } }; _client.ExecuteAndWait(async() => { await _client.Connect(apifile.ReadToEnd(), TokenType.Bot); } ); }
public override void OnRun() { if (!this.connection.isRunning) { Program.Instance.Log(new LogMessage(LogSeverity.Info, "SteamCheck", "Steam connection was disconnected. Rebooting...")); connection.Connect(); } }
private async Task MainAsync() { var startupStr = string.Format("Bot starting up. ({0} by Michael Flaherty)", Program.VERSION); await Log(new LogMessage(LogSeverity.Info, "Startup", startupStr)); var socketConfig = new DiscordSocketConfig { WebSocketProvider = WS4NetProvider.Instance, LogLevel = LogSeverity.Verbose }; client = new DiscordSocketClient(socketConfig); commands = new CommandService(); services = new ServiceCollection().BuildServiceProvider(); messageHist = new Dictionary <ulong, List <MsgInfo> >(); triggerMap = new Dictionary <ulong, string>(); markov = new MarkovHandler(); facts = new FactHandler(); random = new Random(); client.Log += Log; client.GuildAvailable += OnGuildAvailable; client.MessageReceived += HandleCommand; await commands.AddModulesAsync(Assembly.GetEntryAssembly()); await client.LoginAsync(TokenType.Bot, config.DiscordBotToken); await client.StartAsync(); // Connect to steam and pump callbacks connection = new SteamConnection(config.SteamUsername, config.SteamPassword); connection.Connect(); if (config.GitHubUpdateRepository.Length != 0 && config.GitHubAuthToken.Length != 0) { ghClient = new GitHubClient(new ProductHeaderValue(Program.config.GitHubUpdateRepository)); ghClient.Credentials = new Credentials(config.GitHubAuthToken); } // Handle Jobs manager = new JobManager(config.JobInterval); // time in seconds to run each job if (config.SelfUpdateListener && config.GitHubAuthToken.Length != 0) { manager.AddJob(new SelfUpdateListener()); } if (config.SteamCheckJob) { manager.AddJob(new SteamCheckJob(connection)); } if (config.AlliedModdersThreadJob) { manager.AddJob(new AlliedModdersThreadJob("https://forums.alliedmods.net/external.php?newpost=true&forumids=108", "sourcemod")); } foreach (uint appid in config.AppIDList) { manager.AddJob(new UpdateJob(appid)); } manager.StartJobs(); await Task.Delay(-1); }
private async Task MainAsync() { try { Config.Load(); } catch (Exception) { Console.WriteLine("Failed to load config from file. Loading default config."); Config.Default(); Console.WriteLine("Please configure Settings.xml! Exiting program..."); Environment.Exit(0); Console.ReadKey(); } Config.Instance.Save(); Console.WriteLine("Using token: " + Config.Instance.DiscordBotToken); client = new DiscordSocketClient(); commands = new CommandService(); client.Log += Log; services = new ServiceCollection().BuildServiceProvider(); await InstallCommands(); await client.LoginAsync(TokenType.Bot, Config.Instance.DiscordBotToken); await client.StartAsync(); // Connect to steam and pump callbacks connection = new SteamConnection(Config.Instance.SteamUsername, Config.Instance.SteamPassword); new Thread(new ThreadStart(() => { connection.Connect(); })).Start(); // Handle Jobs new Thread(new ThreadStart(() => { var manager = new JobManager(25); // seconds to run each job manager.AddJob(new SteamCheckJob(connection)); // job to check steam connection manager.AddJob(new GithubUpdateJob("https://github.com/alliedmodders/sourcemod/commits/master.atom", "sourcemod")); manager.AddJob(new GithubUpdateJob("https://github.com/alliedmodders/ambuild/commits/master.atom", "sourcemod")); manager.AddJob(new GithubUpdateJob("https://github.com/alliedmodders/metamod-source/commits/master.atom", "sourcemod")); manager.AddJob(new GithubUpdateJob("https://github.com/alliedmodders/hl2sdk/commits/sdk2013.atom", "sourcemod")); manager.AddJob(new AlliedModdersThreadJob("", "sourcemod")); // add appids foreach (uint app in Config.Instance.AppIDList) { manager.AddJob(new UpdateJob(app)); } manager.StartJobs(); })).Start(); await Task.Delay(-1); }