Advertisement
Terrah

host shuffle

Dec 12th, 2014
1,301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.33 KB | None | 0 0
  1. local list = {};
  2.  
  3. table.insert(list,"GreenDudeHC");
  4. table.insert(list,"AngryAA");
  5. table.insert(list,"HegemonyTV");
  6. table.insert(list,"ZiggyDLive");
  7. table.insert(list,"ZenocideGenius");
  8. table.insert(list,"Pohx");
  9. table.insert(list,"nugiyen");
  10. table.insert(list,"BakerLive");
  11. table.insert(list,"LiftingNerdBro");
  12. table.insert(list,"Terrex7");
  13. table.insert(list,"Jmyers123");
  14. table.insert(list,"theuberelite");
  15. table.insert(list,"Havoc616");
  16. table.insert(list,"Helmannn");
  17. table.insert(list,"Mathil1");
  18. table.insert(list,"RaizQT");
  19. table.insert(list,"Etup");
  20. table.insert(list,"RichJMoney");
  21. table.insert(list,"Terrornoid");
  22. table.insert(list,"herpsderpsanon");
  23. table.insert(list,"rbFrosty");
  24. table.insert(list,"Willywonka_HC");
  25. table.insert(list,"Ghazzy");
  26. table.insert(list,"staceily");
  27. table.insert(list,"manocean");
  28. table.insert(list,"PhageTV");
  29. table.insert(list,"Voegelin");
  30. table.insert(list,"hanarashi");
  31. table.insert(list,"namtro");
  32. table.insert(list,"kaamoos");
  33. table.insert(list,"datmodz");
  34. table.insert(list,"cha_siu_bao");
  35. table.insert(list,"mingthemerciless93");
  36. table.insert(list,"nohandsken");
  37. table.insert(list,"christusrex");
  38. table.insert(list,"morikiopa");
  39. table.insert(list,"k0reangamer");
  40. table.insert(list,"nicosuper");
  41. table.insert(list,"sirvenomik");
  42. table.insert(list,"kluffu");
  43. table.insert(list,"unhost");
  44. table.insert(list,"ghudda");
  45. table.insert(list,"mgriff2k4");
  46. table.insert(list,"marthaAPB");
  47. table.insert(list,"MorsRageNG");
  48.  
  49. MOD.nexthost = MOD.nexthost or 1;
  50. MOD.ShuffleNext= MOD.ShuffleNext or 0;
  51. MOD.KillShuffle = MOD.KillShuffle or false;
  52. MOD.ShuffleInterval = MOD.ShuffleInterval or 900;
  53.  
  54. local function IsPlayingPoE(channel)
  55.  
  56.     if type(channel) ~= "string" then
  57.         return false;
  58.     end
  59.  
  60.     local stream = MOD.GetStream(channel);
  61.  
  62.     if type(stream)=="table" and type(stream.game)=="string" and stream.game:lower() == "path of exile" then
  63.         return true;
  64.     end
  65.  
  66.     return false;
  67. end
  68.  
  69. local loops = 0;
  70. local function GetChannelToHost()
  71.  
  72.     local failsafe = 0;
  73.  
  74.     while loops < 2 do
  75.  
  76.         local selected = list[MOD.nexthost];
  77.  
  78.         if selected == nil then
  79.             MOD.nexthost = 1;
  80.             selected = list[MOD.nexthost];
  81.             loops = loops + 1;
  82.         else
  83.             MOD.nexthost = MOD.nexthost + 1;
  84.         end
  85.  
  86.         failsafe = failsafe + 1;
  87.  
  88.         if IsPlayingPoE(selected) then
  89.             loops=0;
  90.             return selected;
  91.         elseif failsafe >= 3 then
  92.             return "";
  93.         end
  94.     end
  95.  
  96.     loops=1;
  97.     return nil;
  98. end
  99.  
  100. MOD.TempHost = function(newchannel,time)
  101.  
  102.     time = time or MOD.ShuffleInterval;
  103.  
  104.     MOD.ShuffleNext = os.time()+time;
  105.  
  106.     if MOD.CurrentHost ~= newchannel then
  107.         MOD.Host(newchannel);
  108.         MOD.CurrentHost = newchannel;
  109.         print( "Swapped host to " .. newchannel );
  110.     else
  111.         print( "Refreshed host on " .. newchannel );
  112.     end
  113.  
  114.     MOD.Save();
  115. end
  116.  
  117. local fails = 0;
  118. MOD.HostShuffle = function()
  119.  
  120.     if MOD.KillShuffle then
  121.         MOD.CurrentHost=nil;
  122.         return;
  123.     end
  124.  
  125.     local tm = os.time();
  126.  
  127.     MOD.Timer("shuffle",60,MOD.HostShuffle);
  128.  
  129.     if type(MOD.CurrentHost)=="string" then
  130.  
  131.         local stream = MOD.GetStream(MOD.CurrentHost);
  132.         if type(stream)~="table" or type(stream.game)~="string" then
  133.             fails = fails + 1;
  134.         elseif fails == 1 or stream.game:lower() ~= "path of exile" then
  135.             MOD.ShuffleNext = 0;
  136.             print(MOD.CurrentHost .. " is no longer playing Path of Exile!");
  137.             fails = 0;
  138.         else
  139.             fails = 0;
  140.         end
  141.     end
  142.  
  143.     if tm > MOD.ShuffleNext then
  144.  
  145.         local newchannel = GetChannelToHost();
  146.  
  147.         if newchannel == nil then
  148.  
  149.             if IsPlayingPoE(MOD.CurrentHost) then
  150.                 MOD.ShuffleNext = os.time()+MOD.ShuffleInterval;
  151.                 print( "No community streamer found online, continuing temporary host " .. MOD.CurrentHost);
  152.             else
  153.                 MOD.Unhost();
  154.                 MOD.CurrentHost = nil;
  155.                 print( "no channel to host found" );
  156.                 MOD.nexthost = 1;
  157.                 loops = 1;
  158.                 MOD.Timer("shuffle",300,MOD.HostShuffle);
  159.             end
  160.         else
  161.  
  162.             if newchannel == "" then
  163.                 MOD.CurrentHost=nil;
  164.                 MOD.Timer("shuffle",0,MOD.HostShuffle);
  165.                 return;
  166.             end
  167.  
  168.             MOD.ShuffleNext = os.time()+MOD.ShuffleInterval;
  169.  
  170.             if MOD.CurrentHost ~= newchannel then
  171.                 MOD.Host(newchannel);
  172.                 MOD.CurrentHost = newchannel;
  173.                 print( "Swapped host to " .. newchannel );
  174.             else
  175.                 print( "Continuing to host " .. newchannel );
  176.             end
  177.         end
  178.  
  179.         MOD.Save();
  180.     else
  181.         --print( tostring(tm) .. " > " ..tostring(MOD.ShuffleNext) );
  182.     end
  183. end
  184.  
  185. --Turn seconds into a span IE "hh:mm:ss"
  186. local SecondToSpan = MOD.SecondToSpan;
  187.  
  188. MOD.HostShuffle();
  189. return function(msg,usr,chan)
  190.  
  191.     if (UserStatus(usr) == 2 or chan:sub(2):lower() == usr:lower() or usr:lower() == "terrahkitsune" or usr:lower() == "pathofexile" or usr:lower() == "kluffu")then
  192.  
  193.         if not msg then msg="";end
  194.  
  195.         print("MOD");
  196.         MOD.ResetCD(usr);
  197.  
  198.         msg = msg:lower();
  199.  
  200.         if msg == "off" then
  201.  
  202.             MOD.KillShuffle = true;
  203.             MOD.Timer("shuffle");
  204.             MOD.Unhost();
  205.             MOD.CurrentHost=nil;
  206.             MOD.ShuffleNext = 0;
  207.             MOD.Save();
  208.             print("Host shuffling turned off!");
  209.             return;
  210.  
  211.         elseif msg == "on" then
  212.  
  213.             MOD.KillShuffle = false;
  214.             MOD.ShuffleNext = 0;
  215.             MOD.HostShuffle();
  216.             MOD.Save();
  217.             print("Host shuffling turned on!");
  218.             return;
  219.         end
  220.  
  221.     end
  222.  
  223.     if MOD.CurrentHost == nil then
  224.         print("Currently hosting nobody");
  225.         return;
  226.     end
  227.  
  228.     print("Currently hosting http://www.twitch.tv/" .. MOD.CurrentHost .. " next host in " .. SecondToSpan(MOD.ShuffleNext-os.time()));
  229. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement