示例#1
0
		Message CreateMonkeyMessage (User user)
		{
			var msg = messages [messageIndex++];

			if (messageIndex >= messages.Count)
				messageIndex = 0;

			return Message.Create (user.Id, user.DisplayName, msg);
		}
示例#2
0
		public async Task <Message> CreateMessageAsync (User user)
		{
			var rnd = new Random ();
			var choice = rnd.Next () % 3;

			if (choice == 0)
				return CreateMonkeyMessage (user);

			return await CreateOverflowMessageAsync (choice == 2 ? "dogoverflow.com" : "catoverflow.com", user);
		}
示例#3
0
		async Task<Message> CreateOverflowMessageAsync (string source, User user)
		{
			WebClient client = new WebClient ();
			var catUrl = await client.DownloadStringTaskAsync (
				new Uri (string.Format ("http://{0}/api/query?limit=1&order=random", source)));
			
			var data = await client.DownloadDataTaskAsync (catUrl);

			var image = CreateAnimatedImage (data);


			var photoItem = new PhotoMediaItem (image);
			photoItem.AppliesMediaViewMaskAsOutgoing = false;
			return Message.Create (user.Id, user.DisplayName, photoItem);
		}