public async Task Connect() { JObject config = _configReader.GetConfig(); string slackKey = config["slack"].Value <string>("apiToken"); var connector = new SlackConnector.SlackConnector(); _connection = await connector.Connect(slackKey); _connection.OnMessageReceived += MessageReceived; _connection.OnDisconnect += OnDisconnect; Console.WriteLine("Connected!"); Console.WriteLine($"Bots Name: {_connection.Self.Name}"); Console.WriteLine($"Team Name: {_connection.Team.Name}"); }
private IEnumerable <ResponseMessage> FlickrHandler(IncomingMessage message, string matchedHandle) { string searchTerm = message.TargetedText.Substring(matchedHandle.Length).Trim(); if (string.IsNullOrEmpty(searchTerm)) { yield return(message.ReplyToChannel($"Please give me something to search, e.g. {matchedHandle} trains")); } else { yield return(message.IndicateTypingOnChannel()); string apiKey = _configReader.GetConfig()["flickr"].Value <string>("apiKey"); if (string.IsNullOrEmpty(apiKey)) { _statsPlugin.IncrementState("Flickr:Failed"); yield return(message.ReplyToChannel("Woops, looks like a Flickr API Key has not been entered. Please ask the admin to fix this")); } else { var flickr = new Flickr(apiKey); var options = new PhotoSearchOptions { Tags = searchTerm, PerPage = 50, Page = 1 }; PhotoCollection photos = flickr.PhotosSearch(options); if (photos.Any()) { _statsPlugin.IncrementState("Flickr:Sent"); int i = new Random().Next(0, photos.Count); Photo photo = photos[i]; var attachment = new Attachment { AuthorName = photo.OwnerName, Fallback = photo.Description, ImageUrl = photo.LargeUrl, ThumbUrl = photo.ThumbnailUrl }; yield return(message.ReplyToChannel($"Here is your picture about '{searchTerm}'", attachment)); } else { _statsPlugin.IncrementState("Flickr:Failed"); yield return(message.ReplyToChannel($"Sorry @{message.Username}, I couldn't find anything about {searchTerm}")); } } } }
public void Start() { JObject config = _configReader.GetConfig(); _adminPin = config.Value <int?>("adminPin"); if (_adminPin.HasValue) { Console.WriteLine($"Admin pin is '{_adminPin.Value}'"); } else { Console.WriteLine("No admin pin detected. Admin mode deactivated."); } }
private TextWriter TryGetLogWriter() { try { string logFile = Path.Combine(Environment.CurrentDirectory, _configReader.GetConfig().Value <string>("logFile")); if (File.Exists(logFile)) { File.Delete(logFile); } var logStream = new FileStream(logFile, FileMode.OpenOrCreate, FileAccess.Write); var fileWriter = new StreamWriter(logStream) { AutoFlush = true }; return(fileWriter); } catch (Exception) { Console.WriteLine("Unable to write to log file, THIS IS NOT LOGGING TO FILE"); return(null); } }