Skip to content

Commit

Permalink
Annictからハッシュタグ取得機能を追加 silane#7
Browse files Browse the repository at this point in the history
  • Loading branch information
noriokun4649 committed Mar 22, 2021
1 parent 3f57d97 commit 6754e61
Showing 1 changed file with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using TVTComment.Model.ChatCollectServiceEntry;
using TVTComment.Model.NiconicoUtils;
using TVTComment.Model.TwitterUtils;
using TVTComment.Model.TwitterUtils.AnnictUtils;
using static TVTComment.Model.ChatCollectServiceEntry.TwitterLiveChatCollectServiceEntry.ChatCollectServiceCreationOption;

namespace TVTComment.Model.ChatCollectService
Expand All @@ -37,15 +38,16 @@ public ChatPostObject(string text, string suffixtext) : base(text)
private readonly ConcurrentQueue<Status> statusQueue = new ConcurrentQueue<Status>();
private readonly CancellationTokenSource cancel = new CancellationTokenSource();
private readonly ObservableValue<string> SearchWord = new ObservableValue<string>("");
private readonly ObservableValue<string> EventTextWord = new ObservableValue<string>("");
private readonly SearchWordResolver SearchWordResolver;
private readonly ModeSelectMethod ModeSelect;

private readonly AnnictApis Annict;

public TwitterLiveChatCollectService(IChatCollectServiceEntry serviceEntry, string searchWord, ModeSelectMethod modeSelect, SearchWordResolver searchWordResolver, TwitterAuthentication twitter)
{
Twitter = twitter;
ServiceEntry = serviceEntry;
SearchWord.Value = searchWord;
Twitter = twitter;
ModeSelect = modeSelect;
SearchWordResolver = searchWordResolver;
switch (modeSelect)
Expand All @@ -58,6 +60,10 @@ public TwitterLiveChatCollectService(IChatCollectServiceEntry serviceEntry, stri
chatCollectTask = SearchStreamAsync(searchWord, cancel.Token);
break;
}
if (Twitter.AnnictToken != null && !Twitter.AnnictToken.Equals("")) {
Annict = new(Twitter.AnnictToken);
EventTextWord.Where(x => x != null && !x.Equals("")).Subscribe(res => _ = annictSearch(EventTextWord.Value));
}
}

public string GetInformationText()
Expand All @@ -81,11 +87,16 @@ await Task.Run(() =>
}, cancel);
}

private async Task annictSearch(string evetnText)
{
var result = await Annict.GetTwitterHashtagAsync(evetnText);
if (result != null && !result.Equals("")) SearchWord.Value += " OR #" + result;
}

public IEnumerable<Chat> GetChats(ChannelInfo channel,EventInfo events, DateTime time)
{
if (ModeSelect == ModeSelectMethod.Auto)
{

SearchWord.Value = SearchWordResolver.Resolve(channel.NetworkId, channel.ServiceId);
}
if (chatCollectTask != null)
Expand All @@ -100,6 +111,9 @@ public IEnumerable<Chat> GetChats(ChannelInfo channel,EventInfo events, DateTime
}
}

var result = AnnimeTitleGetter.Convert(events.EventName);
if (result != null && !result.Equals("")) EventTextWord.Value = result;

var list = new List<Chat>();
while (statusQueue.TryDequeue(out var status))
{
Expand Down

0 comments on commit 6754e61

Please sign in to comment.