private void ReplyToCommand(string message, bool notice) { switch (CommandType) { case ECommandType.IRC: var isChannelMessage = IRC.IsRecipientChannel(Recipient); string recipient = Recipient; if (isChannelMessage) { if (!notice) { message = string.Format("{0}{1}{2}: {3}", Colors.LIGHTGRAY, SenderIdentity.Nickname, Colors.NORMAL, message); } else { recipient = SenderIdentity.Nickname.ToString(); } } else { recipient = SenderIdentity.Nickname.ToString(); } IRC.Instance.SendReply(recipient, message, notice); break; case ECommandType.SteamChatRoom: if (!Steam.Instance.Client.IsConnected) { break; } Steam.Instance.Friends.SendChatRoomMessage( ChatRoomID, EChatEntryType.ChatMsg, string.Format("{0}: {1}", Steam.Instance.Friends.GetFriendPersonaName(SenderID), Colors.StripColors(message)) ); break; case ECommandType.SteamIndividual: if (!Steam.Instance.Client.IsConnected) { break; } Steam.Instance.Friends.SendChatMessage( SenderID, EChatEntryType.ChatMsg, Colors.StripColors(message) ); break; } }
private void ReplyToCommand(string message, bool notice) { switch (CommandType) { case ECommandType.IRC: var isChannelMessage = IRC.IsRecipientChannel(Recipient); var recipient = Recipient; if (isChannelMessage) { if (!notice) { message = $"{Nickname}: {message}"; } else { recipient = SenderIdentity.Nickname.ToString(); } } else { recipient = SenderIdentity.Nickname.ToString(); } IRC.Instance.SendReply(recipient, message, notice); break; case ECommandType.SteamIndividual: if (!Steam.Instance.Client.IsConnected) { break; } Steam.Instance.Friends.SendChatMessage( SenderID, EChatEntryType.ChatMsg, Colors.StripColors(message) ); break; } }
public void OnIRCMessage(object sender, ChatMessageEventArgs e) { var commandData = new CommandArguments { CommandType = ECommandType.IRC, SenderIdentity = e.Sender, Nickname = e.Sender.Nickname.ToString(), Recipient = e.Recipient, Message = e.Message }; if (commandData.SenderIdentity.Hostname == "steamdb/discord-relay") { var match = DiscordRelayMessageRegex.Match(commandData.Message); if (!match.Success) { return; } // Remove IRC colors, remove control characters, remove zero width space, add @ and a space commandData.Nickname = $"@{Utils.RemoveControlCharacters(Colors.StripColors(match.Groups["name"].Value.Replace("\u200B", "")))} "; commandData.Message = match.Groups["message"].Value; } if (commandData.Message[0] != Settings.Current.IRC.CommandPrefix) { return; } var message = commandData.Message; var messageArray = message.Split(' '); var trigger = messageArray[0]; if (trigger.Length < 2) { return; } trigger = trigger.Substring(1); var command = RegisteredCommands.Find(cmd => cmd.Trigger == trigger); if (command == null) { return; } commandData.Message = message.Substring(messageArray[0].Length).Trim(); if (command.IsSteamCommand && !Steam.Instance.Client.IsConnected) { commandData.Reply("Not connected to Steam."); return; } var ident = $"{e.Sender.Username}@{e.Sender.Hostname}"; commandData.IsUserAdmin = Settings.Current.IRC.Admins.Contains(ident); if (command.IsAdminCommand && !commandData.IsUserAdmin) { return; } Log.WriteInfo(nameof(CommandHandler), $"Handling IRC command \"{Utils.RemoveControlCharacters(Colors.StripColors(message))}\" for {commandData}"); TryCommand(command, commandData); }
public void OnMessage(CommandArguments command) { var matches = SteamLinkMatch.Matches(command.Message); foreach (Match match in matches) { var page = match.Groups["page"].Value; // Ignore sub pages, easier to do it here rather than in regex if (!string.IsNullOrEmpty(page)) { continue; } var appType = string.Empty; var id = uint.Parse(match.Groups["id"].Value); var isPackage = match.Groups["type"].Value == "sub"; string name; if (isPackage) { name = Steam.GetPackageName(id); } else { App data; using (var db = Database.GetConnection()) { data = db.Query <App>("SELECT `AppID`, `Apps`.`Name`, `LastKnownName`, `AppsTypes`.`DisplayName` as `AppTypeString` FROM `Apps` JOIN `AppsTypes` ON `Apps`.`AppType` = `AppsTypes`.`AppType` WHERE `AppID` = @AppID", new { AppID = id }).SingleOrDefault(); } if (data.AppID == 0) { continue; } name = string.IsNullOrEmpty(data.LastKnownName) ? data.Name : data.LastKnownName; name = Utils.RemoveControlCharacters(name); appType = data.AppTypeString; } if (command.Message.IndexOf(name, StringComparison.CurrentCultureIgnoreCase) >= 0) { continue; } string priceInfo = isPackage ? string.Empty : GetFormattedPrices(id); if (command.CommandType == ECommandType.SteamChatRoom) { Steam.Instance.Friends.SendChatRoomMessage(command.ChatRoomID, EChatEntryType.ChatMsg, string.Format("» {0} {1} — {2}{3}", isPackage ? "Package" : "App", id, Colors.StripColors(name), priceInfo)); continue; } if (!isPackage && command.Recipient == "#steamlug" && (appType == "Game" || appType == "Application")) { using (var db = Database.GetConnection()) { var status = db.ExecuteScalar <string>("SELECT `Status` FROM `LinuxSupport` WHERE `AppID` = @AppID", new { AppID = id }); switch (status) { case "working": priceInfo += " (✓ Confirmed for Linux)"; break; case "beta": priceInfo += " (Has a public Linux βeta)"; break; default: priceInfo += " (✘ Unknown Linux status)"; break; } } } IRC.Instance.SendReply(command.Recipient, string.Format("{0}» {1}{2} {3} —{4} {5}{6}{7}", Colors.OLIVE, Colors.NORMAL, isPackage ? "Package" : appType, id, Colors.BLUE, name, Colors.LIGHTGRAY, priceInfo ), false ); } }
public void OnMessage(CommandArguments command) { var matches = SteamLinkMatch.Matches(command.Message); foreach (Match match in matches) { var page = match.Groups["page"].Value; // Ignore sub pages, easier to do it here rather than in regex if (!string.IsNullOrEmpty(page)) { continue; } var id = uint.Parse(match.Groups["id"].Value); var isPackage = match.Groups["type"].Value == "sub"; var name = isPackage ? Steam.GetPackageName(id) : Steam.GetAppName(id); if (command.Message.Contains(name)) { continue; } string priceInfo = string.Empty; if (!isPackage) { List <Price> prices; using (var db = Database.GetConnection()) { prices = db.Query <Price>("SELECT `Country`, `PriceFinal`, `PriceDiscount` FROM `Store` WHERE `AppID` = @AppID AND `Country` IN ('us', 'uk', 'it')", new { AppID = id }).ToList(); } if (prices.Any()) { priceInfo = string.Format(" ({0})", string.Join(" / ", prices.Select(x => x.Format()))); } } if (command.CommandType == ECommandType.SteamChatRoom) { Steam.Instance.Friends.SendChatRoomMessage(command.ChatRoomID, EChatEntryType.ChatMsg, string.Format("» {0} {1} — {2}{3}", isPackage ? "Package" : "App", id, Colors.StripColors(name), priceInfo)); } else { IRC.Instance.SendReply(command.Recipient, string.Format("{0}» {1}{2} {3} —{4} {5}{6}{7}", Colors.OLIVE, Colors.NORMAL, isPackage ? "Package" : "App", id, Colors.BLUE, name, Colors.LIGHTGRAY, priceInfo ), false ); } } }
private static void ReplyToCommand(CommandArguments command, string message, bool notice) { switch (command.CommandType) { case ECommandType.IRC: var isChannelMessage = IRC.IsRecipientChannel(command.Recipient); bool shouldReplyAsNotice = false; string recipient = command.Recipient; if (isChannelMessage) { shouldReplyAsNotice = notice || command.ReplyAsNotice; if (!shouldReplyAsNotice) { message = string.Format("{0}{1}{2}: {3}", Colors.LIGHTGRAY, command.SenderIdentity.Nickname, Colors.NORMAL, message); } else { recipient = command.SenderIdentity.Nickname.ToString(); } } else { recipient = command.SenderIdentity.Nickname.ToString(); } IRC.Instance.SendReply(recipient, message, shouldReplyAsNotice); break; case ECommandType.SteamChatRoom: if (!Steam.Instance.Client.IsConnected) { break; } Steam.Instance.Friends.SendChatRoomMessage(command.ChatRoomID, EChatEntryType.ChatMsg, string.Format("{0}: {1}", Steam.Instance.Friends.GetFriendPersonaName(command.SenderID), Colors.StripColors(message))); break; case ECommandType.SteamIndividual: if (!Steam.Instance.Client.IsConnected) { break; } Steam.Instance.Friends.SendChatMessage(command.SenderID, EChatEntryType.ChatMsg, Colors.StripColors(message)); break; } }
public void OnMessage(CommandArguments command) { var matches = SteamLinkMatch.Matches(command.Message); foreach (Match match in matches) { var page = match.Groups["page"].Value; // Ignore sub pages, easier to do it here rather than in regex if (!string.IsNullOrEmpty(page)) { continue; } var appType = string.Empty; var id = uint.Parse(match.Groups["id"].Value); var isPackage = match.Groups["type"].Value == "sub"; var name = isPackage ? Steam.GetPackageName(id) : Steam.GetAppName(id, out appType); if (command.Message.Contains(name)) { continue; } string priceInfo = isPackage ? string.Empty : GetFormattedPrices(id); if (command.CommandType == ECommandType.SteamChatRoom) { Steam.Instance.Friends.SendChatRoomMessage(command.ChatRoomID, EChatEntryType.ChatMsg, string.Format("» {0} {1} — {2}{3}", isPackage ? "Package" : "App", id, Colors.StripColors(name), priceInfo)); continue; } if (!isPackage && command.Recipient == "#steamlug" && (appType == "Game" || appType == "Application")) { using (var db = Database.GetConnection()) { var status = db.ExecuteScalar <string>("SELECT `Status` FROM `LinuxSupport` WHERE `AppID` = @AppID", new { AppID = id }); switch (status) { case "working": priceInfo += " (✓ Confirmed for Linux)"; break; case "beta": priceInfo += " (Has a public Linux βeta)"; break; default: priceInfo += " (✘ Unknown Linux status)"; break; } } } IRC.Instance.SendReply(command.Recipient, string.Format("{0}» {1}{2} {3} —{4} {5}{6}{7}", Colors.OLIVE, Colors.NORMAL, isPackage ? "Package" : "App", id, Colors.BLUE, name, Colors.LIGHTGRAY, priceInfo ), false ); } }
public static void ReplyToCommand(CommandArguments command, string message, params object[] args) { if (command.IsChatRoomCommand) { Steam.Instance.Friends.SendChatRoomMessage(command.ChatRoomID, EChatEntryType.ChatMsg, string.Format(":dsham: {0}", Colors.StripColors(string.Format(message, args)))); } else { IRC.Instance.Client.SendMessage(SendType.Message, command.Channel, string.Format(message, args), Priority.High); } }