Skip to content

Commit

Permalink
New Priority Feature added
Browse files Browse the repository at this point in the history
  • Loading branch information
toxxic407 committed Mar 7, 2021
1 parent fe2b8ee commit aeaea2c
Showing 1 changed file with 42 additions and 10 deletions.
52 changes: 42 additions & 10 deletions Rust Drop Bot/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Runtime.InteropServices;
using System.Diagnostics;
using Newtonsoft.Json;
using System.Collections;

namespace Rust_Drop_Bot
{
Expand Down Expand Up @@ -118,14 +119,15 @@ static void Main()
} while (retry == true);
status_website = status_website.Substring(0, status_website.IndexOf("general-drops"));
stats = update_stats();
bool[] online = OnlineFinder(stats, status_website);
stats = OnlineFinder(stats, status_website);
Current_Stream = 1337;
int highest_Priority = 0;
for (int i = 0; i < stats.Length; i++)
{
if (online[i] == true)
if (stats[i].online == true && (stats[i].Priority > highest_Priority || highest_Priority == 0))
{
highest_Priority = stats[i].Priority;
Current_Stream = i;
break;
}
}
if (Current_Stream == 1337)
Expand Down Expand Up @@ -159,9 +161,27 @@ static void Main()
Console.WriteLine("Could not reach twitch.facepunch.com to update StreamerData (" + e + ") trying again in one Minute");
}
status_website = status_website.Substring(0, status_website.IndexOf("general-drops"));
if (OnlineFinder(stats, status_website)[Current_Stream] == true)

stats = update_stats();
Streamer[] new_stats = OnlineFinder(stats, status_website);
bool has_priority = true;
for (int j = 0; j < stats.Length; j++)
{
if (new_stats[j].Priority > stats[Current_Stream].Priority && new_stats[j].online == true)
{
has_priority = false;
}
}

if (has_priority != true)
{
Console.WriteLine("A Streamer with a higher Priority is now online");
Console.WriteLine("");
break;
}

if (new_stats[Current_Stream].online == true)
{
stats = update_stats();
stats[Current_Stream].Watchtime++;
if(stats[Current_Stream].Completed == true)
{
Expand All @@ -173,6 +193,7 @@ static void Main()
else
{
Console.WriteLine(stats[Current_Stream].Name + " is no longer online");
Console.WriteLine("");
break;
}
}
Expand All @@ -181,6 +202,7 @@ static void Main()
stats[Current_Stream].Completed = true;
Save_progress(stats);
Console.WriteLine("Required Watchtime completed (" + stats[Current_Stream].Name + ")");
Console.WriteLine("");
}
try
{
Expand All @@ -189,27 +211,27 @@ static void Main()
catch (Exception e)
{
Console.WriteLine("Could not close Streamwindow: " + e);
Console.WriteLine("");
}

}
}

public static bool[] OnlineFinder(Streamer[] stats, String website)
public static Streamer[] OnlineFinder(Streamer[] stats, String website)
{
bool[] online = new bool[stats.Length];
for (int i = 0; i < stats.Length; i++)
{
website = website.Substring(website.IndexOf("online-status") + 14);
if (stats[i].Completed == false && website.Substring(0, 7) == "is-live")
{
online[i] = true;
stats[i].online = true;
}
else
{
online[i] = false;
stats[i].online = false;
}
}
return online;
return stats;
}

public static Streamer[] Get_status(string website, int j)
Expand Down Expand Up @@ -278,5 +300,15 @@ public class Streamer
public String Name { get; set; }
public String URL { get; set; }
public bool Completed { get; set; }
public int Priority { get; set; }
public bool online { get; set; }
}

class StreamerComparer : IComparer
{
public int Compare(object x, object y)
{
return (new CaseInsensitiveComparer()).Compare(((Streamer)x).Priority, ((Streamer)y).Priority);
}
}
}

0 comments on commit aeaea2c

Please sign in to comment.