Skip to content

Commit

Permalink
Various Bot Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
postworthy committed Aug 24, 2013
1 parent a2390d7 commit 5153815
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -39,4 +39,5 @@ Postworthy.Web.Publish.xml
Postworthy.Publish.xml
*.pubxml
*.pubxml.user
PublishProfiles
PublishProfiles
*.Test.cs
2 changes: 1 addition & 1 deletion Postworthy.Models/Account/UsersCollection.cs
Expand Up @@ -45,7 +45,7 @@ private static List<PostworthyUser> All(bool force = false)
{
if (force) HttpRuntime.Cache.Remove("PostworthyUsers");
var model = HttpRuntime.Cache["PostworthyUsers"] as List<PostworthyUser>;
if (model == null)
if (model == null || model.Count > 0)
{
lock (locker)
{
Expand Down
5 changes: 5 additions & 0 deletions Postworthy.Models/Communication/CommandListener.cs
Expand Up @@ -21,6 +21,7 @@ public class CommandListener
try
{
listener = new TcpListener(ip, port);
listener.ExclusiveAddressUse = false;
listener.Server.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, 1);
listener.Server.ReceiveTimeout = timeout;
listener.Start();
Expand Down Expand Up @@ -53,7 +54,11 @@ public class CommandListener
finally
{
if (listener != null)
{
listener.Stop();
if (listener.Server != null)
listener.Server.Dispose();
}
}
return null;
Expand Down
2 changes: 1 addition & 1 deletion Postworthy.Models/Repository/SimpleRepository.cs
Expand Up @@ -41,7 +41,7 @@ public IEnumerable<TYPE> Query(string key, int pageIndex = 0, int pageSize = 100
if (where != null)
objects = objects.Where(where);

return (pageSize > 0 ? objects.Skip(pageIndex).Take((int)pageSize) : objects).ToList();
return (pageSize > 0 ? objects.Skip(pageIndex).Take((int)pageSize) : objects).AsParallel().Where(x => x != null).ToList();
}
else
return null;
Expand Down
4 changes: 2 additions & 2 deletions Postworthy.Models/Twitter/TweetGroup.cs
Expand Up @@ -20,7 +20,7 @@ public TweetGroup()
{
CreatedOn = DateTime.Now;
}
public TweetGroup(IGrouping<Tweet, Tweet> tg)
public TweetGroup(IGrouping<ITweet, ITweet> tg)
{
GroupStatusIDs = tg.Select(g => g.StatusID).ToList();
CreatedOn = DateTime.Now;
Expand All @@ -31,7 +31,7 @@ public TweetGroup(IGrouping<Tweet, Tweet> tg)
RetweetCount = tg.Key.RetweetCount + tg.Where(t => t.User.Name != tg.Key.User.Name).Sum(t => t.RetweetCount);
LinkRetweetCount = tg.SelectMany(x => x.Links).Sum(x => x.UrlTweetCount);
LinkFacebookShareCount = tg.SelectMany(x => x.Links).Sum(x => x.UrlFacebookShareCount);
User = tg.Key.Status.User;
User = tg.Key.User;
Links = tg.Where(t => t.User.Name != tg.Key.User.Name).SelectMany(x => x.Links).ToList();
Links.AddRange(tg.Key.Links.Where(l => l.Image != null || l.Video != null));
}
Expand Down
2 changes: 1 addition & 1 deletion Postworthy.Models/Twitter/TweetProcessor.cs
Expand Up @@ -30,7 +30,7 @@ public TweetProcessor(IEnumerable<Tweet> tweets, bool force = false)

foreach (var t in tweets)
{
if ((t.Status.RetweetCount > RetweetThreshold && t.Links.Count == 0) || force)
if ((t.RetweetCount > RetweetThreshold && t.Links.Count == 0) || force)
ExtractUriTasks(t);
}
}
Expand Down
6 changes: 6 additions & 0 deletions Postworthy.Tasks.Bot/Postworthy.Tasks.Bot.csproj
Expand Up @@ -31,6 +31,9 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<StartupObject>Postworthy.Tasks.Bot.Program</StartupObject>
</PropertyGroup>
<ItemGroup>
<Reference Include="Antlr3.Runtime">
<HintPath>..\packages\WebGrease.1.3.0\lib\Antlr3.Runtime.dll</HintPath>
Expand Down Expand Up @@ -77,6 +80,9 @@
</None>
<None Include="example.app.config" />
<None Include="packages.config" />
<None Include="UsersCollection.config">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Postworthy.Models\Postworthy.Models.csproj">
Expand Down
2 changes: 1 addition & 1 deletion Postworthy.Tasks.Bot/Streaming/TweetBotProcessingStep.cs
Expand Up @@ -189,7 +189,7 @@ private void SendTweets()
RuntimeSettings.TweetOrRetweet = !RuntimeSettings.TweetOrRetweet;
if (potentialTweets.Length >= POTENTIAL_TWEET_BUFFER_MIN ||
//Because we default the LastTweetTime to the max value this will only be used after the tweet buffer initially loads up
(potentialTweets.Length > 0 && DateTime.Now >= RuntimeSettings.LastTweetTime.AddHours(MAX_TIME_BETWEEN_TWEETS)))
(RuntimeSettings.LastTweetTime != DateTime.MaxValue && potentialTweets.Length > 0 && DateTime.Now >= RuntimeSettings.LastTweetTime.AddHours(MAX_TIME_BETWEEN_TWEETS)))
{
var tweet = potentialTweets.OrderByDescending(t => t.TweetRank).First();
var groups = tweeted
Expand Down

0 comments on commit 5153815

Please sign in to comment.