public static async void GetChatHighlights(string twitchID, double timeframe) { string url = "https://api.twitch.tv/v5/videos/" + twitchID + "/comments"; List <TwitchChat> chats = new List <TwitchChat>(); TwitchChat chat = new TwitchChat(); bool firstRoll = true; using (var client = new WebClient()) { client.Headers.Add(HttpRequestHeader.Accept, "application/vnd.twitchtv.v5+json"); client.Headers.Add("Client-ID", "jzkbprff40iqj646a697cyrvl0zt2m6"); while (chat.Next != null && (chat.Next.Length > 0 || firstRoll)) { string requestUrl = url + (firstRoll ? "?content_offset_seconds=0" : "?cursor=" + chat.Next); string json = await client.DownloadStringTaskAsync(new Uri(requestUrl)); chat = new TwitchChat().FromJson(json); chats.Add(chat); if (firstRoll) { firstRoll = false; } } RequestedHighlights.Add(twitchID, chats); QueuedRequests[twitchID] = true; } }
protected override void OnEnd() { Started = false; if (Main.netMode == NetmodeID.MultiplayerClient) { return; } if (rand.elements.Count == 0) { //TwitchChat.Send("No one was selected to become chat boss"); //TwitchBoss.Boss = string.Empty; //TwitchChat.Post("No one...", Color.White); return; } var t = rand.Get(); TwitchBoss.Boss = t; assignTime = DateTimeOffset.Now; TwitchChat.Post($"New boss is @[c/{TwitchChat.TwitchColor}:{TwitchBoss.Boss}]", Color.White); if (Main.netMode != NetmodeID.MultiplayerClient) { TwitchChat.Send(EndString + $" @{TwitchBoss.Boss} you can use " + $"{string.Join(" ", (from s in TwitchBoss.Commands select s.Key))}"); } TwitchChat.Instance.Irc.ChannelMessage -= Handle; }
protected override void OnEnd() { TwitchChat.Instance.Irc.ChannelMessage -= CountVote; if (VoteMode != VoteMode.EndAction || Main.netMode == NetmodeID.MultiplayerClient) { return; } var votesCount = new SortedDictionary <string, int>(); foreach (KeyValuePair <string, string> it in Votes) { if (votesCount.ContainsKey(it.Value)) { votesCount[it.Value]++; } else { votesCount.Add(it.Value, 1); } } var bigger = 0; string index = "", draftIndex = ""; foreach (KeyValuePair <string, int> it in votesCount) { if (it.Value > bigger) { bigger = it.Value; index = it.Key; draftIndex = ""; } else if (it.Value == bigger) { draftIndex = it.Key; } } if (index == draftIndex && index != "") { var rand = new WeightedRandom <string>(); rand.Add(index); rand.Add(draftIndex); index = rand.Get(); } if (index != string.Empty) { VoteSuggestion[index].Invoke(null); } else { TwitchChat.Send("No votes..."); } }
// Use this for initialization void Start() { twitchChat = GetComponent <TwitchChat>(); // Adding hardcoded commands to the adminCommands adminCommands.Add("!admin"); adminCommands.Add("!blacklist"); }
// Start is called before the first frame update void Start() { ConfigInfo config = ConfigInfo.GetInstance(); permissionList = config.permissionList; twitchChat = GameObject.Find("TwitchChat").GetComponent <TwitchChat>(); }
//protected override void OnTick() //{ // base.OnTick(); //} public override void OnWaveChange() { switch (Main.invasionProgressWave) { case 1: TwitchChat.Post("Vortex tower was awoken!", Color.ForestGreen); EventPlayer.LunarSky = LunarSkies.Vortex; if (Main.netMode != 1) { GlobalSpawnOverride.OverrideItemPool(InvadersDrop); } break; case 2: TwitchChat.Post("Vortex tower was defeated!", Color.ForestGreen); TwitchChat.Post("Solar tower was awoken!", Color.Orange); EventPlayer.LunarSky = LunarSkies.Solar; if (Main.netMode != 1) { GlobalSpawnOverride.OverrideItemPool(InvadersDrop); } break; case 3: TwitchChat.Post("Solar tower was defeated!", Color.Orange); TwitchChat.Post("Stardust tower was awoken!", Color.AliceBlue); EventPlayer.LunarSky = LunarSkies.Stardust; if (Main.netMode != 1) { GlobalSpawnOverride.OverrideItemPool(InvadersDrop); } break; case 4: TwitchChat.Post("Stardust tower was defeated!", Color.AliceBlue); TwitchChat.Post("Nebula tower was awoken!", Color.Violet); EventPlayer.LunarSky = LunarSkies.Nebula; if (Main.netMode != 1) { GlobalSpawnOverride.OverrideItemPool(InvadersDrop); } break; case 5: TwitchChat.Post("Nebula tower was defeated!", Color.Violet); TwitchChat.Post("Impeting doom approach...", Color.PaleGreen); EventPlayer.LunarSky = LunarSkies.None; if (Main.netMode != 1) { NPC.NewNPC(Main.spawnTileX, Main.spawnTileY, NPCID.MoonLordCore); GlobalSpawnOverride.OverrideItemPool(InvadersDrop); } break; } }
void m_CommandsBehaviour_onReceived(TwitchChat twitchChat, CommandsArgs commandsArgs) { if (commandsArgs.IsCommand(m_SpawnCommand)) { if (m_Viewers.ContainsKey(commandsArgs.nick)) { Viewer viewer = m_Viewers[commandsArgs.nick]; viewer.accoladesUI.playingImage.color = Color.green; viewer.isPlaying = true; } } }
void InboundsBehaviour_OnGreeted(TwitchChat twitchIRC, InboundsArgs obj) { if (!m_Viewers.ContainsKey(obj.nick)) { Viewer viewer = new Viewer(obj.nick, m_StatusItem, twitchIRC.messenger.channel); viewer.lifeTime = 0.0f; m_Viewers.Add(obj.nick, viewer); } else { m_Viewers[obj.nick].lifeTime = 0.0f; } StartCoroutine(CheckForFollowers(new[] { obj.nick })); }
protected override void OnStart() { Votes.Clear(); if (Main.netMode != NetmodeID.MultiplayerClient) { TwitchChat.Instance.Irc.ChannelMessage += CountVote; var commands = ""; foreach (KeyValuePair <string, Action <ChannelMessageEventArgs> > it in VoteSuggestion) { commands += it.Key + ", "; } commands = commands.Substring(0, commands.Length - 2); TwitchChat.Send($"{Description}. Available commands: {commands}"); } }
protected override void OnStart() { if (Main.netMode == NetmodeID.MultiplayerClient) { return; } rand.Clear(); Part.Clear(); Started = true; TwitchChat.Instance.Irc.ChannelMessage += Handle; TwitchChat.Send(StartString + " Quick write \"boss\" in chat!"); TwitchChat.Post(StartString, Color.White); }
void TwitchConnect_OnRefreshed(TwitchChat twitchIRC, TwitchTv.TMI twitchTvTMI) { if (twitchTvTMI == null) { Debug.LogFormat("twitchTvTMI is still null {0}", DateTime.Now); } //string moderators = string.Join(", ", twitchTvTMI.chatters.moderators); //string viewers = string.Join(", ", twitchTvTMI.chatters.viewers); //Debug.LogFormat("moderators:{0} viewers:{1} > {2}", moderators, viewers, DateTime.Now); foreach (var item in twitchTvTMI.chatters.viewers.Concat(twitchTvTMI.chatters.moderators)) { if (m_Viewers.ContainsKey(item)) { m_Viewers[item].lifeTime = 0.0f; } } StartCoroutine(CheckForFollowers(twitchTvTMI.chatters.viewers.Concat(twitchTvTMI.chatters.moderators).ToArray())); }
public void EventEnd(EventWorld world, TwitchChat mod) { if (Main.netMode == NetmodeID.Server) // Server { NetMessage.BroadcastChatMessage(NetworkText.FromKey(LanguageManager.Instance.GetTextValue(EndString)), StartColor); } else if (Main.netMode == NetmodeID.SinglePlayer) // Single Player { Main.NewText(Language.GetTextValue(LanguageManager.Instance.GetTextValue(EndString)), StartColor); } GlobalSpawnOverride.EndOverride(); GlobalSpawnOverride.DisablePoolOverride(); GlobalSpawnOverride.DisableItemPool(); if (Type == InvasionType.Invasion) { Main.invasionSize = 0; Main.invasionSizeStart = Main.invasionSize; Main.invasionProgress = 0; Main.invasionX = Main.spawnTileX; Main.invasionProgressIcon = 0; Main.invasionProgressWave = 0; Main.invasionProgressMax = Main.invasionSizeStart; Main.invasionWarn = 0; Main.invasionType = 0; Main.invasionDelay = 0; numPlayers = 0; } OnEnd(); if (Main.netMode == 2) { ModPacket netMessage = mod.GetPacket(); netMessage.Write((byte)NetPacketType.EventEnded); netMessage.Write(GetType().Name); netMessage.Send(); } }
void CreateEditorsIfNeeded() { m_TwitchChat = m_UniTwitchIRCBehaviours.GetComponentInChildren <TwitchChat>(); if (m_TwitchChat) { if (m_TwitchChatEditor == null) { m_TwitchChatEditor = Editor.CreateEditor(m_TwitchChat, typeof(TwitchChatEditor)) as TwitchChatEditor; } m_ChannelProperty = m_TwitchChatEditor.serializedObject.FindProperty("m_Channel"); m_OpenOnRunProperty = serializedObject.FindProperty("m_OpenOnRun"); } m_TwitchConnect = m_UniTwitchIRCBehaviours.GetComponentInChildren <TwitchConnect>(); if (m_TwitchConnect) { if (m_TwitchConnectEditor == null) { m_TwitchConnectEditor = Editor.CreateEditor(m_TwitchConnect) as TwitchConnectEditor; } } }
void CommandsBehaviour_OnCommandsReceived(TwitchChat twitchChat, CommandsArgs commandsArgs) { if (commandsArgs.IsCommand(m_HelpCommand)) { string message = string.Concat( m_InboundBuilder.ToString().Trim(new char[] { ',', ' ' }), " - ", m_CommandsBuilder.ToString().Trim(new char[] { ',', ' ' })); twitchChat.SendChatMessage(message); } else if (commandsArgs.IsCommand(m_CommandHelp)) { if (m_HelpDescriptions.ContainsKey(commandsArgs.argument)) { string message = string.Concat("Help for ", commandsArgs.argument, ": ", m_HelpDescriptions[commandsArgs.argument]); twitchChat.SendChatMessage(message); } } }
public void SetTwitchChat(TwitchChat tc) { this.twitchChat = tc; }
void Awake() { _instance = this; DontDestroyOnLoad(this); }
/// <summary> /// Used by mod internally! Better use <see cref="EventWorld.StartWorldEvent(WorldEvent)" /> to start events! Use only /// if you KNOW what you do!! /// Start event starting sequence, and send event data for all players. Can break things if called outside /// <see cref="EventWorld" />! /// </summary> /// <param name="world"></param> /// <param name="mod"></param> internal void EventStart(EventWorld world, TwitchChat mod) { if (Main.netMode == NetmodeID.Server) // Server { NetMessage.BroadcastChatMessage(NetworkText.FromKey(LanguageManager.Instance.GetTextValue(StartString)), StartColor); } else if (Main.netMode == NetmodeID.SinglePlayer) // Single Player { Main.NewText(Language.GetTextValue(LanguageManager.Instance.GetTextValue(StartString)), StartColor); } //Post(Language.GetTextValue(LanguageManager.Instance.GetTextValue(StartString)), StartColor); started = true; TimeLeft = Length; //timeStart = Main.time; //Count Players for (var i = 0; i < 255; i++) { if (Main.player[i] != null && Main.player[i].active && Main.player[i].statLifeMax >= 200) { numPlayers++; } } if (Type == InvasionType.Invasion) { Main.invasionSize = MultiplyByPlayers ? InvasionSize * numPlayers : InvasionSize; Main.invasionProgressDisplayLeft = Main.invasionSize - Main.invasionProgress; Main.invasionSizeStart = Main.invasionSize; TimeLeft = Main.invasionSize; Main.invasionProgressWave = 1; Main.invasionProgress = 0; Main.invasionX = Main.spawnTileX; Main.invasionProgressIcon = 0 + 8; Main.invasionProgressMax = Main.invasionSizeStart; Main.invasionType = -1; OnWaveChange(); } OnStart(); if (Main.netMode != 1) //If we NOT the server client { GlobalSpawnOverride.StartOverrideSpawnRate(SpawnRateMul, MaxSpawnMul); if (Type == InvasionType.WorldEvent && Invaders != null) { GlobalSpawnOverride.OverridePool(Invaders, DisableOthers, true); } else { if (InvasionList != null && InvasionList.Count != 0) { GlobalSpawnOverride.OverridePool(GetListForCurWave, DisableOthers, true); } } if (InvadersDrop != null) { GlobalSpawnOverride.OverrideItemPool(InvadersDrop); } } if (Main.netMode == 2) { ModPacket netMessage = mod.GetPacket(); netMessage.Write((byte)NetPacketType.EventWasStarted); netMessage.Write(GetType().Name); netMessage.Write(TimeLeft); netMessage.Write((byte)Type); if (Type == InvasionType.Invasion) { WriteWaveData(ref netMessage); } netMessage.Send(); } }
public override void Action(CommandCaller caller, string input, string[] args) { if (args.Length > 0) { switch (args[0].ToLower()) { case "c": case "connect": if (Mod.OldConfig.Get <string>(TwitchCfg.OAToken) != "https://twitchapps.com/tmi/" && Mod.OldConfig.Get <string>(TwitchCfg.Username) != "missingno") { Mod.Irc.Username = Mod.OldConfig.Get <string>(TwitchCfg.Username); Mod.Irc.AuthToken = Mod.OldConfig.Get <string>(TwitchCfg.OAToken); Mod.Irc.Connect(); } else { caller.Reply("You missed username or token in settings. Type /t s to open settings file and /t r to reload mod"); } break; case "dc": case "disconnect": Mod.Irc.Disconnect(); break; case "r": case "reload": Mod.Unload(); Mod.Load(); caller.Reply("Reloading mod...."); break; case "s": case "settings": Mod.Storage.OpenFileExternally(Mod.Storage.GetFullPath("Twitch.ini")); break; case "o": case "open": Mod.Storage.OpenInNativeExplorer(); break; case "m": case "message": var a = new List <string>(); for (var i = 1; i < args.Length; i++) { a.Add(args[i]); } var text = string.Join(" ", a); TwitchChat.Send(text); caller.Reply($"[c/{TwitchChat.TwitchColor}:<-- To Twitch:] {text}"); break; default: caller.Reply(Usage); return; } } else { caller.Reply(Usage); } }
public void PerformTick(EventWorld world, TwitchChat mod) { if (Main.invasionProgress >= 100) { if (Main.invasionProgressWave >= InvasionList.Count) { if (Main.netMode != 1) { EventEnd(world, mod); world.CurrentEvent = null; } Main.invasionProgressDisplayLeft = 20; return; } if (Main.netMode != 1) { if (Main.invasionProgressWave == 0) { return; } Main.invasionProgressWave++; Main.invasionProgress = 0; OnWaveChange(); Main.invasionSize = MultiplyByPlayers ? InvasionSize * numPlayers : InvasionSize; Main.invasionSizeStart = Main.invasionSize; tLeft = Main.invasionSize; GlobalSpawnOverride.OverridePool(GetListForCurWave, DisableOthers, true); if (Main.netMode == 2) { ModPacket netMessage = mod.GetPacket(); netMessage.Write((byte)NetPacketType.EventWaveUpdated); netMessage.Write(GetType().Name); netMessage.Write(TimeLeft); netMessage.Write((byte)Type); if (Type == InvasionType.Invasion) { WriteWaveData(ref netMessage); } netMessage.Send(); } } } else if (Type == InvasionType.Invasion) { if (Main.netMode == 2) { if (TimeLeft != oldProgressData) { ModPacket netMessage = mod.GetPacket(); netMessage.Write((byte)NetPacketType.EventWaveUpdated); netMessage.Write(GetType().Name); netMessage.Write(TimeLeft); netMessage.Write((byte)Type); if (Type == InvasionType.Invasion) { WriteWaveData(ref netMessage); } netMessage.Send(); } oldProgressData = TimeLeft; } Main.invasionProgress = (int)(100 * ((float)(Main.invasionSize - TimeLeft) / Main.invasionSize)); Main.invasionProgressDisplayLeft = 1000; } OnTick(); }