public void fire_ModeChange(ModeTypes type, string title) { if (ModeChanges != null && type != null && title != null) { logModeChange(type, title); try { ModeChanges.Invoke(this, new ModeEventArgs(type, title)); } catch { } switch (type) { case ModeTypes.Start: fire_ModeStarted(type, title); break; case ModeTypes.Abort: fire_ModeAborted(type, title); break; case ModeTypes.Finish: fire_ModeFinished(type, title); break; default: break; } } }
private void OnModeReceived(object sender, ModeEventArgs e) { var channel = e.Target.ToLowerInvariant(); if (this.watchedChannels.ContainsKey(channel)) { var changes = ModeChanges.FromChangeList(e.Changes); var triggerBotOpped = false; var triggerBotDeOpped = false; this.logger.DebugFormat("Mode change seen on {0}: {1}", channel, string.Join(" ", e.Changes)); lock (this.channelStatus) { if (changes.Ops.Contains(this.ircClient.Nickname)) { triggerBotOpped = true; changes.Ops.Remove(this.ircClient.Nickname); } if (changes.Deops.Contains(this.ircClient.Nickname)) { triggerBotDeOpped = true; changes.Deops.Remove(this.ircClient.Nickname); } this.SyncChangesToChannel(this.channelStatus[channel], changes); } if (triggerBotOpped) { this.logger.InfoFormat("Bot opped on {0}", channel); this.OnBotOpped(channel); } if (triggerBotDeOpped) { this.logger.InfoFormat("Bot deopped on {0}", channel); this.OnBotDeOpped(channel); } if (!changes.IsEmpty()) { this.logger.InfoFormat("Mode change on {0}", channel); this.OnModeChange(channel); } } }
public void ShouldParseRemovalOfParameterisedModes() { var fromChangeList = ModeChanges.FromChangeList(new [] { "+g-icfnt" }); Assert.IsEmpty(fromChangeList.Bans); Assert.IsEmpty(fromChangeList.Quiets); Assert.IsEmpty(fromChangeList.Unbans); Assert.IsEmpty(fromChangeList.Unquiets); Assert.IsEmpty(fromChangeList.Exempts); Assert.IsEmpty(fromChangeList.Unexempts); Assert.IsEmpty(fromChangeList.Ops); Assert.IsEmpty(fromChangeList.Deops); Assert.IsNull(fromChangeList.Moderated); Assert.IsNull(fromChangeList.ReducedModeration); Assert.IsNull(fromChangeList.RegisteredOnly); }
/// <summary> /// Updates the channel status object with the changes. Must be called inside a lock() only. /// </summary> /// <param name="status"></param> /// <param name="modeChanges"></param> private void SyncChangesToChannel(ChannelStatus status, ModeChanges modeChanges) { if (modeChanges.Ops.Contains(this.ircClient.Nickname)) { status.BotOpsHeld = true; status.BotOpsRequested = false; } if (modeChanges.Deops.Contains(this.ircClient.Nickname)) { status.BotOpsHeld = false; } if (modeChanges.ReducedModeration.HasValue) { status.ReducedModeration = modeChanges.ReducedModeration.Value; } if (modeChanges.Moderated.HasValue) { status.Moderated = modeChanges.Moderated.Value; } if (modeChanges.RegisteredOnly.HasValue) { status.RegisteredOnly = modeChanges.RegisteredOnly.Value; } modeChanges.Unbans.ForEach(x => status.Bans.Remove(x)); modeChanges.Unquiets.ForEach(x => status.Quiets.Remove(x)); modeChanges.Unexempts.ForEach(x => status.Exempts.Remove(x)); modeChanges.Bans.ForEach(x => status.Bans.Add(x)); modeChanges.Quiets.ForEach(x => status.Quiets.Add(x)); modeChanges.Exempts.ForEach(x => status.Exempts.Add(x)); }