Created
January 2, 2020 20:58
-
-
Save Taifunov/0ae73a7a3eaedcaf2d0bc2fd1874e67e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
internal async Task PostPhotoAsync(Photo instance) | |
{ | |
try | |
{ | |
var getById = _parser.GetById(); | |
var descrs = _parser.GetDescription(); | |
for (var i = 0; i < getById.Count && i < descrs.Count; i++) | |
{ | |
string photo = getById[i]; | |
var descr = descrs[i]; | |
using (var source = new CancellationTokenSource(7000)) | |
using (var resp = await _client.GetStreamAsync(photo)) | |
{ | |
var msg = await _bot.SendPhotoAsync( | |
chatId: ChannelId, | |
photo: new InputOnlineFile(resp, "lol-community.jpg"), | |
replyMarkup: new InlineKeyboardMarkup(new[] { | |
new[] { | |
new InlineKeyboardButton {Text = "๐ 0", CallbackData = "post_id like"}, | |
new InlineKeyboardButton {Text = "๐ 0", CallbackData = "post_id dislike"}, | |
}, | |
}), | |
caption: descr, | |
cancellationToken: new CancellationTokenSource().Token); | |
var postData = new PostData() { | |
Post_url = photo, | |
PostId = instance.PostId, | |
MessageId = msg.MessageId, | |
Likes = 0, | |
DisLikes = 0 | |
}; | |
_context.Posts.Add(postData); | |
_context.SaveChanges(); | |
} | |
} | |
} | |
catch (Exception e) | |
{ | |
_logger.LogError(e.ToString()); | |
} | |
} | |
internal async Task PostVideoAsync(Video instance) | |
{ | |
try | |
{ | |
var descrs = _parser.GetVideoDescriptionList(); | |
var urls = _parser.GetVideoUrl(); | |
for (int i = 0; i < urls.Count; i++) | |
{ | |
var descr = descrs[i]; | |
var video = urls[i]; | |
var uri = new Uri(video); | |
if (uri.Host == "www.youtube.com" || uri.Host == "www.youtu.be") | |
{ | |
var newUri = | |
$"https://youtube.com/watch?v={uri.LocalPath.Split('/')[2]}"; | |
var msg = await _bot.SendTextMessageAsync( | |
chatId: ChannelId, | |
parseMode: ParseMode.Html, | |
text: "๐ฌ " + $"<b>{descr}*</b>" + Environment.NewLine + | |
newUri, // made escape | |
replyMarkup: new InlineKeyboardMarkup(new[] { | |
new[] { | |
new InlineKeyboardButton { | |
Text = "๐", CallbackData = "post_id like" | |
}, | |
new InlineKeyboardButton { | |
Text = "๐", CallbackData = "post_id dislike" | |
}, | |
}, | |
}), | |
cancellationToken: new CancellationTokenSource().Token); | |
var videoData = new PostData() | |
{ | |
Post_url = video, | |
PostId = instance.Id, | |
MessageId = msg.MessageId, | |
Likes = 0, | |
DisLikes = 0 | |
}; | |
using (_context) | |
{ | |
_context.Posts.Add(videoData); | |
_context.SaveChanges(); | |
} | |
} | |
} | |
} catch (Exception e) | |
{ | |
_logger.LogError(e.ToString()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment