private void CheckModeratorStatus(IrcChannelUser chanUser) { string username = chanUser.User.NickName; bool op = chanUser.Modes.Contains('o'); TwitchUser user = m_data.GetUser(username, op); if (user != null) { if (op) { if (!m_mods.Contains(user)) { OnInformModerator(user, true); m_mods.Add(user); } } else { if (m_mods.Contains(user)) { OnInformModerator(user, false); m_mods.Remove(user); } } } }
/// <summary> /// /// </summary> /// <param name="Message"></param> protected override void HandleAdminMessage(AdminMessage Message) { base.HandleAdminMessage(Message); // no proper message text? if (Message.Message == null || String.Equals(Message.Message, String.Empty)) { return; } // check if irc is available if (IrcClient.IsRegistered && IrcChannel != null) { // IRC does not allow \r \n \0 // so we remove \0 and remove \r\n by splitting up into lines string[] lines = SplitLinebreaks(Message.Message.Replace("\0", String.Empty)); // forward line by line foreach (string line in lines) { // forward this line to each admin foreach (string admin in Config.Admins) { // try get channeluser by name IrcChannelUser usr = GetChannelUser(admin); // online? send! if (usr != null) { IrcClient.LocalUser.SendMessage(admin, line); } } } } }
public ChannelMute(IrcChannelUser ircChannelUser) { channel = ircChannelUser.Channel; this.ircChannelUser = ircChannelUser; hostName = ircChannelUser.User.HostName; channel.UserLeft += ChannelOnUserLeft; }
public void UnmuteUser(IrcChannelUser ircChannelUser) { if (mutes.TryRemove(GetKey(ircChannelUser.Channel, ircChannelUser.User), out var mute)) { mute.Unmute(); irc.Client.LocalUser.SendMessage(ircChannelUser.User, $"You have been unmuted in {ircChannelUser.Channel.Name}."); } }
private void ChannelOnUserLeft(object sender, IrcChannelUserEventArgs e) { if (e.ChannelUser.User == ircChannelUser.User) { channel.UserLeft -= ChannelOnUserLeft; ircChannelUser = null; } }
void ChannelUser_ModesChanged(object sender, EventArgs e) { IrcChannelUser user = sender as IrcChannelUser; if (user != null) { CheckModeratorStatus(user); } }
private bool CheckModeratorStatus(IrcChannelUser chanUser) { if (chanUser.Modes.Contains('o')) { m_chanData.AddModerator(chanUser.User.NickName.ToLower()); return(true); } return(false); }
public void Install(IWindsorContainer container, IConfigurationStore store) { // Facilities container.AddFacility <LoggingFacility>(f => f.LogUsing <Log4netFactory>().WithConfig("log4net.xml")); container.AddFacility <StartableFacility>(f => f.DeferredStart()); container.Install(new WebInstaller()); var ircClientMock = new Mock <IIrcClient>(); ircClientMock.Setup(x => x.ExtBanTypes).Returns("a"); ircClientMock.Setup(x => x.ExtBanDelimiter).Returns("$"); ircClientMock.Setup(x => x.Nickname).Returns("EyeInTheSkyBot"); ircClientMock.Setup(x => x.ClientName).Returns("Freenode"); var ircChannels = new Dictionary <string, IrcChannel>(); var chan = new IrcChannel("##stwalkerster-development"); ircChannels.Add(chan.Name, chan); ircClientMock.Setup(x => x.Channels).Returns(ircChannels); IrcUser user; IrcChannelUser ircChannelUser; user = IrcUser.FromPrefix("stwalkerster!test@user/.", ircClientMock.Object); user.Account = "stwalkerster"; user.SkeletonStatus = IrcUserSkeletonStatus.Full; ircChannelUser = new IrcChannelUser(user, chan.Name); chan.Users.Add(user.Nickname, ircChannelUser); user = IrcUser.FromPrefix("chanmember!test@user/.", ircClientMock.Object); user.Account = "chanmember"; user.SkeletonStatus = IrcUserSkeletonStatus.Full; ircChannelUser = new IrcChannelUser(user, chan.Name); chan.Users.Add(user.Nickname, ircChannelUser); user = IrcUser.FromPrefix("chanop!test@user/.", ircClientMock.Object); user.Account = "chanop"; user.SkeletonStatus = IrcUserSkeletonStatus.Full; ircChannelUser = new IrcChannelUser(user, chan.Name); ircChannelUser.Operator = true; chan.Users.Add(user.Nickname, ircChannelUser); container.Register( // Main application Component.For <IApplication>().ImplementedBy <Launch>(), Classes.FromAssemblyNamed("EyeInTheSky").InNamespace("EyeInTheSky.Services").WithServiceAllInterfaces(), Classes.FromAssemblyNamed("EyeInTheSky").InNamespace("EyeInTheSky.Services.ExternalProviders").WithServiceAllInterfaces(), Classes.FromAssemblyNamed("EyeInTheSky").InNamespace("EyeInTheSky.Services.Email").WithServiceAllInterfaces(), Component.For <IIrcClient>().Instance(ircClientMock.Object) ); container.Install(Configuration.FromXmlFile("alert-templates.xml")); }
/// <summary> /// Invoked when a private message was received. /// Private messages = admin console /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void OnLocalUserMessageReceived(object sender, IrcMessageEventArgs e) { // try get channeluser by name IrcChannelUser usr = GetChannelUser(e.Source.Name); if (usr == null) { return; } // only allow operators if (!usr.Modes.Contains('o')) { return; } // only allow ADMINS from config if (Config.Admins.Contains(e.Source.Name)) { // invalid if (e.Text == null || e.Text == String.Empty) { return; } // get first space in text int firstspace = e.Text.IndexOf(' '); // either use first part up to first space or full text if no space string comtype = (firstspace > 0) ? e.Text.Substring(0, firstspace) : comtype = e.Text; // check if commandtype is allowed if (Config.AdminCommands.Contains(comtype)) { // enqueue it for execution AdminCommandQueue.Enqueue(e.Text); } else { // respond admin he can't use this admincommand IrcClient.LocalUser.SendMessage( e.Source.Name, e.Source.Name + " you can't use the admin command '" + comtype + "'"); } } else { // respond user he can't use this feature IrcClient.LocalUser.SendMessage( e.Source.Name, e.Source.Name + " you can't use the admin console - Only admins allowed."); } }
public void MuteUser(IrcChannelUser ircChannelUser) { var mute = new ChannelMute(ircChannelUser); if (mutes.TryAdd(GetKey(ircChannelUser.Channel, ircChannelUser.User), mute)) { mute.Mute(muteDuration); ReportToIrc($"MUTED {ircChannelUser.User.NickName} ({ircChannelUser.User.HostName}) has been muted for flooding in {ircChannelUser.Channel.Name}"); irc.Client.LocalUser.SendMessage(ircChannelUser.User, $"You have been automatically muted in {ircChannelUser.Channel.Name} for {muteDuration / 1000 / 60} minutes due to too many messages in a short period of time."); } }
/// <summary> /// /// </summary> /// <param name="Message"></param> protected override void HandleAdminMessage(AdminMessage Message) { base.HandleAdminMessage(Message); // no proper message text? if (Message.Message == null || String.Equals(Message.Message, String.Empty)) { return; } // check if irc is available if (IrcClient.IsRegistered && IrcChannel != null) { // IRC does not allow \r \n \0 // so we remove \0 and remove \r\n by splitting up into lines string[] lines = Util.SplitLinebreaks(Message.Message.Replace("\0", String.Empty)); // Only want to send to any admins who've sent a command since last GC. // Other admins don't need to know about GC. List <string> recipients; bool clearRecent = false; if (Util.IsGarbageCollectMessage(lines[0])) { recipients = RecentAdmins; clearRecent = true; } else { recipients = Config.Admins; } // forward line by line foreach (string line in lines) { // forward this line to each admin foreach (string admin in recipients) { // try get channeluser by name IrcChannelUser usr = GetChannelUser(admin); // online? send! if (usr != null) { IrcClient.LocalUser.SendMessage(admin, line); } } } if (clearRecent) { RecentAdmins.Clear(); } } }
public static SRLIRCRights FromIrcChannelUser(IrcChannelUser user) { if (user.Modes.Contains('o')) { return(SRLIRCRights.Operator); } else if (user.Modes.Contains('v')) { return(SRLIRCRights.Voice); } return(SRLIRCRights.Normal); }
protected object Process(ParameterInfo info, IrcChannelUser user) { // TODO: expose user mode? if (info.ParameterType == typeof(IrcChannelUser)) { return(user); } else { return(Process(info, user.Channel) ?? Process(info, user.User)); } }
private void CheckModeratorStatus(IIrcMessageSource msgSource) { IrcUser ircuser = msgSource as IrcUser; if (ircuser != null) { IrcChannelUser chanUser = m_channel.GetChannelUser(ircuser); if (chanUser != null) { CheckModeratorStatus(chanUser); } } }
void OnChannelMessage(object sender, IrcMessageEventArgs e) { if (Config.IgnoredIRCNicks.Contains(((IrcUser)e.Source).NickName) || Config.IgnoredIRCChatRegexes.Any(s => Regex.IsMatch(e.Text, s))) { return; } var ircChannel = ((IrcChannel)e.Targets[0]); var ircUser = (IrcUser)e.Source; if (e.Text.StartsWith(Config.BotPrefix)) { IRCCommands.Execute(e.Text.Substring(Config.BotPrefix.Length), ircUser, (IIrcMessageTarget)sender); } else if (String.Equals(ircChannel.Name, Config.Channel, StringComparison.OrdinalIgnoreCase)) { IrcChannelUser ircChannelUser = ircChannel.GetChannelUser(ircUser); if (!String.IsNullOrEmpty(Config.IRCChatModesRequired) && ircChannelUser != null && !ircChannelUser.Modes.Intersect(Config.IRCChatModesRequired).Any()) { return; } string text = e.Text; text = System.Text.RegularExpressions.Regex.Replace(text, "\u0003[0-9]{1,2}(,[0-9]{1,2})?", ""); text = text.Replace("\u0002", ""); text = text.Replace("\u000f", ""); text = text.Replace("\u001d", ""); text = text.Replace("\u001f", ""); if (text.StartsWith("\u0001ACTION") && text.EndsWith("\u0001")) { if (!String.IsNullOrEmpty(Config.IRCActionMessageFormat)) { TShock.Utils.Broadcast(String.Format(Config.IRCActionMessageFormat, e.Source.Name, text.Substring(8, text.Length - 9)), 205, 133, 63); } } else { if (!String.IsNullOrEmpty(Config.IRCChatMessageFormat)) { Group group = IrcUsers[ircUser]; TShock.Utils.Broadcast(String.Format(Config.IRCChatMessageFormat, group.Prefix, e.Source.Name, text), group.R, group.G, group.B); } } } }
/// <summary> /// Gets the user in the channel. /// </summary> /// <param name="nickname">The nickname.</param> /// <returns>The specified nickname as an <see cref="IrcChannelUser"/> object.</returns> private IrcChannelUser GetUserInChannel(string nickname) { if (_client.Channels.Count == 0) { return(null); } IrcChannelUser user = null; var currentChan = _client.Channels.First().Users; foreach (var u in currentChan.Where(u => u.User.NickName .Equals(nickname, StringComparison.InvariantCultureIgnoreCase))) { user = u; } return(user); }
public void Query(IrcChannelUser user) { IrcQueryViewModel ipcvm = null; foreach (var item in (this.Parent as IrcNetworkViewModel).Items) { if (item.DisplayName == user.User.NickName) { ipcvm = item; } } if (ipcvm == null) { ipcvm = new IrcQueryViewModel(user.User, this.Channel.Client, this.Settings); (this.Parent as IrcNetworkViewModel).Items.Add(ipcvm); } (this.Parent as IrcNetworkViewModel).ActivateItem(ipcvm); }
public static bool IsModerator(this IrcChannelUser ircChannelUser) { return(HasAdminHostname(ircChannelUser.User) || HasAdminUserMode(ircChannelUser)); }
/// <summary> /// The equals. /// </summary> /// <param name="other"> /// The other. /// </param> /// <returns> /// The <see cref="bool"/>. /// </returns> protected bool Equals(IrcChannelUser other) { return object.Equals(this.User, other.User) && string.Equals(this.Channel, other.Channel); }
/// <summary> /// Invoked when a channel message was received /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void OnMessageReceived(object sender, IrcMessageEventArgs e) { // ignore messages without @prefix start or which are only @prefix + @ + space length if (e.Text == null || e.Text.IndexOf("@" + Config.ChatPrefix) != 0 || e.Text.Length <= Config.ChatPrefix.Length + 1 + 1) { return; } // try get channeluser by name IrcChannelUser usr = GetChannelUser(e.Source.Name); if (usr == null) { return; } // only allow operators if (!usr.Modes.Contains('o')) { // respond user he can't use this feature IrcClient.LocalUser.SendMessage( IrcChannel, e.Source.Name + " you can't use this feature. Only operators allowed."); return; } // now remove the @103 start string s = e.Text.Substring(Config.ChatPrefix.Length + 1 + 1); // used delimiter const char delimiter = ' '; // split up into words string[] words = s.Split(delimiter); if (words.Length > 0) { switch (words[0]) { case ChatCommandBroadcast.KEY1: case ChatCommandBroadcast.KEY2: // keep first word s = String.Join(delimiter.ToString(), words, 0, 1); // insert banner + name s += delimiter + Config.Banner; s += e.Source.Name + ": ~n"; // add rest s += String.Join(delimiter.ToString(), words, 1, words.Length - 1); break; case ChatCommandTell.KEY1: case ChatCommandTell.KEY2: // keep first two word s = String.Join(delimiter.ToString(), words, 0, 2); // insert banner + name s += delimiter + Config.Banner; s += e.Source.Name + ": ~n"; // add rest s += String.Join(delimiter.ToString(), words, 2, words.Length - 2); break; } } // enqueue it for execution ChatCommandQueue.Enqueue(s); }
/// <summary> /// Invoked when a channel message was received /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void OnMessageReceived(object sender, IrcMessageEventArgs e) { // Ignore message whose length is just @prefix + @ + space length. if (e.Text == null || e.Text.Length <= Config.ChatPrefix.Length + 1 + 1) { return; } // try get channeluser by name IrcChannelUser usr = GetChannelUser(e.Source.Name); if (usr == null) { return; } string s = String.Empty; string banner = String.Empty; string ignoreSystemRegex = String.Empty; bool relayMsg = false; // Relay messages from allowed chatbots foreach (var relayBot in Config.RelayBots) { if (relayBot.Name.Contains(e.Source.Name)) { // Sanity check for our own name if (e.Source.Name.Equals(Config.NickName)) { return; } // Convert the IRC colors back to server styles/colors. s = IRCChatStyle.CreateChatMessageFromIRCMessage(e.Text); // Ignore any messages containing... if (!String.IsNullOrEmpty(relayBot.IgnoreAllRegex) && (Regex.Match(s, relayBot.IgnoreAllRegex)).Success) { return; } // Banner is the second string in the tuple. banner = relayBot.Banner; ignoreSystemRegex = relayBot.IgnoreSystemRegex; relayMsg = true; break; } } if (!relayMsg) { // Ignore messages without @prefix start. if (!relayMsg && e.Text.IndexOf("@" + Config.ChatPrefix) != 0) { return; } // only allowed users and admins can use the bot if (!(Config.AllowedUsers.Contains(e.Source.Name) || Config.Admins.Contains(e.Source.Name))) { // respond user he can't use this feature IrcClient.LocalUser.SendMessage( IrcChannel, e.Source.Name + " you can't use this feature."); return; } if (!IsUserRegistered(e.Source.Name)) { // Must have registered nickname. IrcClient.LocalUser.SendMessage(IrcChannel, e.Source.Name + " you must register your nickname to use this feature."); return; } // now remove the @103 start s = e.Text.Substring(Config.ChatPrefix.Length + 1 + 1); } // used delimiter const char delimiter = ' '; // split up into words string[] words = s.Split(delimiter); if (words.Length > 0) { if (Util.IsDisallowedDMCommand(words[0])) { IrcClient.LocalUser.SendMessage( IrcChannel, e.Source.Name + " you can't use this feature. This incident has been logged."); foreach (string admin in Config.Admins) { // try get channeluser by name usr = GetChannelUser(admin); // online? send! if (usr != null) { IrcClient.LocalUser.SendMessage(admin, String.Format("IRC User {0} has attempted to use a DM command", e.Source.Name)); } } return; } else if (words.Length > 3 && relayMsg) { // First word is the server's header (e.g. 103:) so don't use it. if (words[1].Contains("[###]")) { // Ignore system messages containing.... if (!String.IsNullOrEmpty(ignoreSystemRegex) && (Regex.Match(s, ignoreSystemRegex)).Success) { return; } // Adjust the color codes to display [###] correctly, drop the // existing [###] and add a fixed one here. Doesn't seem to be // possible to fix the one in the message itself. s = "dm gqemote " + banner + " ~U[###]~n ~U"; s += String.Join(delimiter.ToString(), words, 2, words.Length - 2); } else if ((Regex.Match(s, @"(broadcasts,|teilt allen)")).Success) { // Add server header, echo message. s = "dm gqemote " + banner + " ~n~w"; s += String.Join(delimiter.ToString(), words, 1, words.Length - 1); } else if (words[1].Contains("You") && words[2].Contains("broadcast,")) { // Echo messages that the other bot broadcasts to its server. s = "dm gqemote " + banner + " ~n~wHelp broadcasts,"; s += String.Join(delimiter.ToString(), words, 3, words.Length - 3); } else if (words.Length > 5 && words[1].Contains("Du") && words[3].Contains("allen")) { // German bot broadcasting to its server, echo the German translation. s = "dm gqemote " + banner + " ~n~wHelp teilt allen mit,"; s += String.Join(delimiter.ToString(), words, 5, words.Length - 5); } } else { switch (words[0]) { case ChatCommandBroadcast.KEY1: case ChatCommandBroadcast.KEY2: // keep first word s = String.Join(delimiter.ToString(), words, 0, 1); // insert banner + name s += delimiter + Config.Banner; s += e.Source.Name + ": ~n"; // add rest s += String.Join(delimiter.ToString(), words, 1, words.Length - 1); break; case ChatCommandTell.KEY1: case ChatCommandTell.KEY2: // keep first two word s = String.Join(delimiter.ToString(), words, 0, 2); // insert banner + name s += delimiter + Config.Banner; s += e.Source.Name + ": ~n"; // add rest s += String.Join(delimiter.ToString(), words, 2, words.Length - 2); break; } } } // enqueue it for execution ChatCommandQueue.Enqueue(s); }
public void AddChatMessage(DateTime date, IrcChannel channel, IrcChannelUser user, string message, bool addSender) { RichTextBox chat = null; foreach (var tabobj in ui_TabControl.Items) { if (string.Compare(((TabItem)tabobj).Header.ToString(), channel.Name) == 0) { chat = (RichTextBox)((TabItem)tabobj).Content; break; } } var flowDocument = chat.Document; // #1585b5 Brush nameColor = new SolidColorBrush(Color.FromArgb(0xff, 0x15, 0x85, 0xb5));; if (AccessLevelHelper.GetNick(user.Nick) == Configuration.Nick) { nameColor = new SolidColorBrush(Colors.Orange); } if (flowDocument.Blocks.Count > 0) { if (Configuration.LineSplitMessages || addSender) { var panel = new StackPanel() { Orientation = Orientation.Vertical, Margin = new Thickness(0, 3, 0, 0) }; panel.Children.Add(new Rectangle() { HorizontalAlignment = HorizontalAlignment.Stretch, Fill = new SolidColorBrush(Color.FromArgb(0xff, 70, 70, 70)), Height = 1 }); flowDocument.Blocks.Add(new BlockUIContainer(panel)); } else { flowDocument.Blocks.Add(new BlockUIContainer(new StackPanel() { Margin = new Thickness(0, 5, 0, 0) })); } } var grid = new Grid(); grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(80) }); // nick grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) }); // chat message grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(50) }); // time stamp var textBlock = new TextBlock() { Text = addSender ? AccessLevelHelper.GetNick(user.Nick) : "", FontWeight = FontWeights.Bold, HorizontalAlignment = HorizontalAlignment.Right, Margin = new Thickness(0, 0, 10, 0), TextWrapping = TextWrapping.Wrap }; if (nameColor != null) { textBlock.Foreground = nameColor; } Grid.SetColumn(textBlock, 0); grid.Children.Add(textBlock); textBlock = new TextBlock() { Text = message, TextWrapping = TextWrapping.Wrap }; Grid.SetColumn(textBlock, 1); grid.Children.Add(textBlock); textBlock = new TextBlock() { Text = date.ToString("HH:mm:ss"), HorizontalAlignment = HorizontalAlignment.Right, TextWrapping = TextWrapping.Wrap }; Grid.SetColumn(textBlock, 2); grid.Children.Add(textBlock); flowDocument.Blocks.Add(new BlockUIContainer(grid)); chat.ScrollToEnd(); }
public void WhoIs(IrcChannelUser user) { this.WhoIs(user.User.NickName); }
private static bool HasAdminUserMode(IrcChannelUser ircChannelUser) { return(ircChannelUser.Modes.Intersect(moderatorUserModes).Any()); }
public static int Compare(IrcChannelUser x, IrcChannelUser y) { return(string.Compare(x.User.NickName, y.User.NickName)); }
/// <summary> /// Invoked when a private message was received. /// Private messages = admin console /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void OnLocalUserMessageReceived(object sender, IrcMessageEventArgs e) { // try get channeluser by name IrcChannelUser usr = GetChannelUser(e.Source.Name); if (usr == null) { return; } // only allow ADMINS from config if (!Config.Admins.Contains(e.Source.Name)) { // respond user he can't use this feature IrcClient.LocalUser.SendMessage( e.Source.Name, e.Source.Name + " you can't use the admin console - Only admins allowed."); return; } // Must be registered. if (!IsUserRegistered(e.Source.Name)) { // respond user he can't use this feature IrcClient.LocalUser.SendMessage( e.Source.Name, e.Source.Name + " you can't use the admin console - nickname must be registered."); return; } // invalid if (e.Text == null || e.Text == String.Empty) { return; } Log("ADM", e.Source.Name + " used the command " + e.Text); // Bot admin command? if (e.Text.StartsWith("@")) { // Returns false if nothing handled the admin command. if (!IRCAdminBotCommand.ParseAdminCommand(e.Source.Name, e.Text, this)) { IrcClient.LocalUser.SendMessage(e.Source.Name, "Couldn't find a handler for admin command " + e.Text); } return; } // get first space in text int firstspace = e.Text.IndexOf(' '); // either use first part up to first space or full text if no space string comtype = (firstspace > 0) ? e.Text.Substring(0, firstspace) : comtype = e.Text; // check if commandtype is allowed if (Config.AdminCommands.Contains(comtype)) { // Record this admin as recent. if (!RecentAdmins.Contains(e.Source.Name)) { RecentAdmins.Add(e.Source.Name); } // enqueue it for execution AdminCommandQueue.Enqueue(e.Text); } else { // respond admin he can't use this admincommand IrcClient.LocalUser.SendMessage( e.Source.Name, e.Source.Name + " you can't use the admin command '" + comtype + "'"); } }