///<summary> Checks if the given STEAMID is an admin in the database</summary> public static bool admincheck(SteamID sender) { if (UserDatabase.ContainsKey(sender.ToString())) { //If the STEAMID is in the dictionary string Key = sender.ToString(); EClanPermission UserPermissions = UserDatabase[Key]; //It will get the permissions value if ((UserPermissions & EClanPermission.OwnerOfficerModerator) > 0) //Checks if it has sufficient privilages { return true; //If there's sufficient privilages, it'll return true } } return false; //If there is no entry in the database, or there aren't sufficient privalages, it'll return false }
static public bool checkAdmin(SteamID sid) { if (admins.Contains(sid.ToString())) return true; else steamFriends.SendChatMessage(sid, EChatEntryType.ChatMsg, "You cannot use this command because you're not an admin."); return false; }
/// <summary> /// Declines the invite to a Steam Group /// </summary> /// <param name="group">SteamID of the group to decline the invite from.</param> private void DeclineGroupInvite(SteamID group) { var declineMsg = new ClientMsg<CMsgGroupInviteAction>((int)EMsg.ClientAcknowledgeClanInvite); declineMsg.Body.GroupID = group.ConvertToUInt64(); declineMsg.Body.AcceptInvite = false; SteamClient.Send(declineMsg); Log.Info("Declined group invite to {0}.", group.ToString()); }
/// <summary> /// Accepts the invite to a Steam Group /// </summary> /// <param name="group">SteamID of the group to accept the invite from.</param> private void AcceptGroupInvite(SteamID group) { var acceptMsg = new ClientMsg<CMsgGroupInviteAction>((int)EMsg.ClientAcknowledgeClanInvite); acceptMsg.Body.GroupID = group.ConvertToUInt64(); acceptMsg.Body.AcceptInvite = true; SteamClient.Send(acceptMsg); Log.Success("Accepted group invite to {0}.", group.ToString()); }
/// <summary> /// Initializes a new instance of the <see cref="SteamTrade.Exceptions.InventoryFetchException"/> class. /// </summary> /// <param name='steamId'> /// Steam identifier that caused the fetch exception. /// </param> public InventoryFetchException (SteamID steamId) : base(String.Format("Failed to fetch inventory for: {0}", steamId.ToString())) { FailingSteamId = steamId; }
/// <summary> /// The commands that users can use by msg'ing the system. Returns a string with the appropriate responses /// </summary> /// <param name="chatID">ChatID of the chatroom</param> /// <param name="sender">STEAMID of the sender</param> /// <param name="message">The message sent</param> public static string Chatcommands(SteamID chatID, SteamID sender, string FullMessage, Bot bot) { FullMessage.Replace(@"\s+", " "); string[] Words = FullMessage.Split(' '); string Message = FullMessage.Remove(0, Words[0].Length + (Words.Length > 1).GetHashCode()); ; if (Words.Length > 1) { Message = FullMessage.Remove(Words[0].Length + 1); //TODO GET THIS PART FIXED } //base.OnChatRoomMessage(chatID, sender, message); bool rank = UserDatabaseHandler.admincheck(sender); foreach (KeyValuePair<string, string> Entry in GroupChatHandler.DataLOG) //TODO Disable autocorrections { if (Words[0].StartsWith(Entry.Key, StringComparison.OrdinalIgnoreCase)) { return GroupChatHandler.AdvancedGoogleSearch(Message, Entry.Value, chatID); } } foreach (KeyValuePair<string, string> Entry in GroupChatHandler.InstantReplies) //TODO Disable autocorrections { if (FullMessage.StartsWith(Entry.Key, StringComparison.OrdinalIgnoreCase)) { return Entry.Value; } } if (DoesMessageStartWith(Words[0], ChatCommands["SteamIDCommand"].Item2)) { if (Words.Length > 0) { return GroupChatHandler.GetSteamIDFromUrl(Words[1], true); } else { return "URL is missing, please add a url"; } } if (DoesMessageStartWith(Words[0], ChatCommands["MySteamIDCommand"].Item2)) { return sender.ToString(); } if (DoesMessageStartWith(Words[0], ChatCommands["Rejoin"].Item2)) { bot.SteamFriends.JoinChat(new SteamID(GroupChatHandler.Groupchat)); } if (DoesMessageStartWith(Words[0], ChatCommands["MOTDSetter"].Item2)) { return BackgroundWork.MOTDSetter; } if (DoesMessageStartWith(Words[0], ChatCommands["MOTDTick"].Item2)) { return BackgroundWork.MOTDPosted.ToString(); } if (DoesMessageStartWith(Words[0], ChatCommands["MOTD"].Item2)) { return BackgroundWork.MOTD; } if (DoesMessageStartWith(Words[0], ChatCommands["Sync"].Item2)) { BackgroundWork.SheetSync(true); return null; } if (DoesMessageStartWith(Words[0], ChatCommands["UploadCheckCommand"].Item2)) { if (Words.Length > 0) { return GroupChatHandler.UploadCheck(Words[1]).ToString(); } else { return "No map specified"; } } if (DoesMessageStartWith(Words[0], ChatCommands["DeleteCommands"].Item2)) { if (Words.Length > 2) { string[] Reason = Message.Split(new string[] { Words[1] }, StringSplitOptions.None); Tuple<string, SteamID> removed = ImpMaster.ImpRemove(Words[1], sender, false, Reason[1]); return "Removed map: " + removed.Item1; } else { Tuple<string, SteamID> removed = ImpMaster.ImpRemove(Words[1], sender, false, "(None)"); return "Removed map: " + removed.Item1; } } if (DoesMessageStartWith(Words[0], ChatCommands["ImpCommands"].Item2)) { if (Words.Length == 1) { return "!add <mapname> <url> <notes> is the command. however if the map is uploaded you do not need to include the url"; } int length = (Words.Length > 2).GetHashCode(); //Checks if there are more than 3 or more words int Uploaded = (GroupChatHandler.UploadCheck(Words[1])).GetHashCode(); //Checks if map is uploaded. Crashes if only one word //TODO FIX THAT string UploadStatus = "Uploaded"; //Sets a string, that'll remain unless altered if (length + Uploaded == 0) { //Checks if either test beforehand returned true return "Make sure to include the download URL!"; } else { string[] notes = FullMessage.Split(new string[] { Words[2 - Uploaded] }, StringSplitOptions.None); //Splits by the 2nd word (the uploadurl) but if it's already uploaded, it'll split by the map instead if (Uploaded == 0) //If the map isn't uploaded, it'll set the upload status to the 3rd word (The URL) { UploadStatus = Words[2]; } string status = ImpMaster.ImpEntry(Words[1], UploadStatus, notes[1], sender); //If there are no notes, but a map and url, this will crash. GroupChatHandler.SpreadsheetSync = true; return status; } } if (DoesMessageStartWith(Words[0], ChatCommands["Update"].Item2)) { if (Words.Length <= 2) //Checks if there are less than 2 words, the previous map and map to change { return "!updatemap <PreviousMapName> <NewMapName> <url> <notes> is the command."; } string[] FullMessageCutArray = Words.Skip(2).ToArray(); int length = (FullMessageCutArray.Length > 1).GetHashCode(); //Checks if there are more than 3 or more words int Uploaded = 0; if (Words.Length > 0) { Uploaded = (GroupChatHandler.UploadCheck(FullMessageCutArray[0])).GetHashCode(); } //Log.Interface("Checking if" + UploadCheck(FullMessageCutArray[1]) + "Is uploaded"); //Checks if map is uploaded. Crashes if only one word //TODO FIX THAT string UploadStatus = "Uploaded"; //Sets a string, that'll remain unless altered if (length + Uploaded == 0) { //Checks if either test beforehand returned true return "Make sure to include the download URL!"; } else { string[] notes = FullMessage.Split(new string[] { FullMessageCutArray[1 - Uploaded] }, StringSplitOptions.None); //Splits by the 2nd word (the uploadurl) but if it's already uploaded, it'll split by the map instead if (Uploaded == 0) //If the map isn't uploaded, it'll set the upload status to the 3rd word (The URL) { UploadStatus = FullMessageCutArray[1]; } string status = ImpMaster.ImpEntryUpdate(Words[1], FullMessageCutArray[0], UploadStatus, notes[1], sender); //If there are no notes, but a map and url, this will crash. GroupChatHandler.SpreadsheetSync = true; return status; } } if (DoesMessageStartWith(Words[0], ChatCommands["MapCommands"].Item2)) { Dictionary<string, Tuple<string, SteamID, string, bool>> Maplist = new Dictionary<string, Tuple<string, SteamID, string, bool>>(); if (File.Exists(@MapStoragePath)) { Maplist = new Dictionary<string, Tuple<string, SteamID, string, bool>>(JsonConvert.DeserializeObject<Dictionary<string, Tuple<string, SteamID, string, bool>>>(System.IO.File.ReadAllText(@MapStoragePath))); } else { System.IO.File.WriteAllText(@GroupChatHandler.MapStoragePath, JsonConvert.SerializeObject(Maplist)); } string Maplisting = ""; string DownloadListing = ""; foreach (var item in Maplist) { Maplisting = Maplisting + item.Key + " , "; DownloadListing = DownloadListing + item.Value.Item1 + " , "; } bot.SteamFriends.SendChatMessage(sender, EChatEntryType.ChatMsg, DownloadListing); return Maplisting; } if (DoesMessageStartWith(Words[0], ChatCommands["HelpCommands"].Item2)) { if (Words.Length > 1) { foreach (KeyValuePair<string, Tuple<string, string[]>> Entry in ChatCommands) { if (Entry.Value.Item2.Contains(Words[1])) { return Entry.Key + ": " + Entry.Value.Item1 + " Commands: " + string.Join(", ", Entry.Value.Item2); ; } } } else { return GroupChatHandler.HelpLink; } } foreach (Tuple<string, string, string, Int32> ServerAddress in Servers) { if (Words[0].StartsWith(ServerAddress.Item3, StringComparison.OrdinalIgnoreCase)) { Steam.Query.ServerInfoResult ServerData = SteamBot.BackgroundWork.ServerQuery(System.Net.IPAddress.Parse(ServerAddress.Item2), ServerAddress.Item4); return ServerData.Map + " " + ServerData.Players + "/" + ServerData.MaxPlayers; } } return null; }
/// <summary> /// The commands that users can use by msg'ing the system. Returns a string with the appropriate responses /// </summary> /// <param name="chatID">ChatID of the chatroom</param> /// <param name="message">The message sent</param> public static string admincommands(SteamID sender, string FullMessage , Bot Bot) { FullMessage.Replace(@"\s+", " "); string[] Words = FullMessage.Split(); string Message = FullMessage.Remove(0, Words[0].Length + (Words.Length > 1).GetHashCode()); if (DoesMessageStartWith(Words[0], ChatCommands["Rejoin"].Item2)) if (FullMessage.StartsWith("!ReJoin", StringComparison.OrdinalIgnoreCase)) { Bot.SteamFriends.LeaveChat(new SteamID(GroupChatHandler.Groupchat)); Bot.SteamFriends.JoinChat(new SteamID(GroupChatHandler.Groupchat)); } if (Words[0].StartsWith("!Say", StringComparison.OrdinalIgnoreCase)) { Bot.SteamFriends.SendChatRoomMessage(GroupChatHandler.Groupchat, EChatEntryType.ChatMsg, Message); } if(DoesMessageStartWith(Words[0], ChatCommands["SetMOTD"].Item2)) { if (Message != null) { if (BackgroundWork.MOTD != null) { return "There is currently a MOTD, please remove it first"; } else { BackgroundWork.MOTDSetter = Bot.SteamFriends.GetFriendPersonaName(sender) + " " + sender; BackgroundWork.MOTD = Message; return "MOTD Set to: " + Message; } } else { return "Make sure to include a MOTD to display!"; } } if (Message.StartsWith("Say my name", StringComparison.OrdinalIgnoreCase)) { return Bot.SteamFriends.GetFriendPersonaName(sender); } if(DoesMessageStartWith(Words[0], ChatCommands["RemoveMOTD"].Item2)) { BackgroundWork.MOTD = null; return "Removed MOTD"; } if (DoesMessageStartWith(Words[0], ChatCommands["ClearCommands"].Item2)) { ImpMaster.WipeAllMaps(); return "Wiped all Maps"; } if (DoesMessageStartWith(Words[0], ChatCommands["EnableSync"].Item2)) { GroupChatHandler.OnlineSync = "true"; GroupChatHandler.groupchatsettings.Remove("OnlineSync"); GroupChatHandler.groupchatsettings.Add("OnlineSync", "true"); System.IO.File.WriteAllText(@"ExtraSettings.json", JsonConvert.SerializeObject(GroupChatHandler.ExtraSettingsData)); return "Enabled Sync"; } if (DoesMessageStartWith(Words[0], ChatCommands["DisableSync"].Item2)) { GroupChatHandler.OnlineSync = "false"; GroupChatHandler.groupchatsettings.Remove("OnlineSync"); GroupChatHandler.groupchatsettings.Add("OnlineSync", "false"); System.IO.File.WriteAllText(@"ExtraSettings.json", JsonConvert.SerializeObject(GroupChatHandler.ExtraSettingsData)); return "Disabled Sync"; } if (DoesMessageStartWith(Words[0], ChatCommands["EnableRSS"].Item2)) { GroupChatHandler.EnableRSS = true; return "Enabled RSS"; } if (DoesMessageStartWith(Words[0], ChatCommands["DisableRSS"].Item2)) { GroupChatHandler.EnableRSS = false; return "Disabled RSS"; } if (DoesMessageStartWith(Words[0], ChatCommands["Rejoin"].Item2)) { Bot.SteamFriends.LeaveChat(new SteamID(GroupChatHandler.Groupchat)); Bot.SteamFriends.JoinChat(new SteamID(GroupChatHandler.Groupchat)); } if (DoesMessageStartWith(Words[0], ChatCommands["Unban"].Item2)) { if (Words.Length > 1) ; string Userid = GroupChatHandler.GetSteamIDFromUrl(Words[1], true); if (UserDatabaseHandler.BanList.ContainsKey(Userid.ToString())) { UserDatabaseHandler.BanList.Remove(Userid); return "The ban has now been lifted"; } else { return "User is not banned"; } } if (DoesMessageStartWith(Words[0], ChatCommands["Ban"].Item2)) { if (Words.Length > 3) { string[] Reason = Message.Split(new string[] { " " + Words[2] + " " }, StringSplitOptions.RemoveEmptyEntries); SteamID Userid = new SteamID(GroupChatHandler.GetSteamIDFromUrl(Words[1], true)); if (UserDatabaseHandler.BanList.ContainsKey(Userid.ToString())) { return "This user has already been banned, their ban has " + UserDatabaseHandler.BanList[Userid.ToString()] + " remainig"; } UserDatabaseHandler.BanList.Add(Userid.ToString(), int.Parse(Words[2]) * 24); System.IO.File.WriteAllText(@UserDatabaseHandler.BanListFilePath, JsonConvert.SerializeObject(UserDatabaseHandler.BanList)); Bot.SteamFriends.SendChatMessage(Userid, EChatEntryType.ChatMsg, "You have been banned from using all bot features for " + Words[2] + "days. Reason given: " + Reason[1]); return "Banned user:"******" (" + Bot.SteamFriends.GetFriendPersonaName(Userid).ToString() + ") for: " + Words[2] + " days. Reason given: " + Reason[1]; } else { return "The command is: " + "!Ban" + " <url of user>, Duration in days, Reason"; } } return null; }
/// <summary> /// Updates a map in the maplist, and keeps the position in the array /// </summary> /// <param name="maptochange"></param> /// <param name="map"></param> /// <param name="downloadurl"></param> /// <param name="notes"></param> /// <param name="sender"></param> /// <returns></returns> public string ImpEntryUpdate(string maptochange, string map, string downloadurl, string notes, SteamID sender) { Log.Interface("Reached Here"); if (notes == null) { notes = "No Notes"; } int EntryCount = 0; if (admincheck(sender) == true | sender.Equals(Maplist[maptochange].Item2)) { foreach (KeyValuePair<string, Tuple<string, string, string, bool>> entry in Maplist) { EntryCount = EntryCount + 1; if (entry.Key == maptochange) { UpdateEntryExecute(EntryCount, maptochange, map, downloadurl, notes, sender.ToString()); return "Map has been updated"; } } } return "The entry was not found"; }
/// <summary> /// The method executed upon the bot receiving messages in group chat /// </summary> /// <param name="chatID">The SteamID of the chatroom</param> /// <param name="sender"> The SteamID of the person who sent the msg</param> /// <param name="message">The message</param> public override void OnChatRoomMessage(SteamID chatID, SteamID sender, string message) { GhostCheck = 120; string adminresponse = null; if (admincheck(sender)) { adminresponse = admincommands(sender, message); } string response = null; if (!BanList.ContainsKey(sender.ToString()) || admincheck(sender)) { response = Chatcommands(chatID, sender, message); if (response != null) { Bot.SteamFriends.SendChatRoomMessage(Groupchat, EChatEntryType.ChatMsg, response); } } else { } if (adminresponse != null) { Bot.SteamFriends.SendChatRoomMessage(Groupchat, EChatEntryType.ChatMsg, adminresponse); } }
/// <summary> /// Adds a map to the database /// </summary> public string ImpEntry(string map, string downloadurl, string notes, SteamID sender) { if (notes == null) { notes = "None"; } //Deserialises the current map list string response = "Failed to add the map to the list"; Dictionary<string, Tuple<string, string, string, bool>> entrydata = Maplist; if (Maplist == null) { Log.Interface("There was an error, here is the map file before it's wiped:" + System.IO.File.ReadAllText(@MapStoragePath)); } if (entrydata.ContainsKey(map)) { //if it already exists, it deletes it so it can update the data response = "Error, the entry already exists! Please remove the existing entry"; } else { //Adds the entry entrydata.Add(map, new Tuple<string, string, string, bool>(downloadurl, sender.ToString(), notes, UploadCheck(map))); //Saves the data Maplist = entrydata; response = "Added: " + map; } System.IO.File.WriteAllText(@MapStoragePath, JsonConvert.SerializeObject(entrydata)); SpreadsheetSync = true; return response; }
/// <summary> /// The commands that users can use by msg'ing the system. Returns a string with the appropriate responses /// </summary> /// <param name="chatID">ChatID of the chatroom</param> /// <param name="sender">STEAMID of the sender</param> /// <param name="message">The message sent</param> public string Chatcommands(SteamID chatID, SteamID sender, string FullMessage) { Utilities utilities = new Utilities(); base.OnChatRoomMessage(chatID, sender, FullMessage); bool rank = admincheck(sender); FullMessage.Replace(@"\s+", " "); string[] Words = FullMessage.Split(); string Message = FullMessage.Remove(0, ((Words[0].Length) * (Words.Length > 1).GetHashCode()) + (Words.Length > 1).GetHashCode()); foreach (KeyValuePair<string, string> Entry in DataLOG) //TODO Disable autocorrections { if (Words[0].StartsWith(Entry.Key, StringComparison.OrdinalIgnoreCase)) { return AdvancedGoogleSearch(Message, Entry.Value, chatID); } } if (DoesMessageStartWith(Words[0], ChatCommandsArray["SteamIDCommand"].Item2)) { if (Words.Length > 0) { return GetSteamIDFromUrl(Words[1], true); } else { return "URL is missing, please add a url"; } } if (DoesMessageStartWith(Words[0], ChatCommandsArray["MySteamIDCommand"].Item2)) { return sender.ToString(); } if (DoesMessageStartWith(Words[0], ChatCommandsArray["Rejoin"].Item2)) { Bot.SteamFriends.JoinChat(new SteamID(Groupchat)); } if (DoesMessageStartWith(Words[0], ChatCommandsArray["MOTDSetter"].Item2)) { return MOTDSetter; } if (DoesMessageStartWith(Words[0], ChatCommandsArray["MOTDTick"].Item2)) { return MOTDPosted.ToString(); } if (DoesMessageStartWith(Words[0], ChatCommandsArray["MOTD"].Item2)) { return MOTD; } if (DoesMessageStartWith(Words[0], ChatCommandsArray["Sync"].Item2)) { SheetSync(true); return null; } if (DoesMessageStartWith(Words[0], ChatCommandsArray["UploadCheckCommand"].Item2)) { if (Words.Length > 0) { return UploadCheck(Words[1]).ToString(); } else { return "No map specified"; } } if (DoesMessageStartWith(Words[0], ChatCommandsArray["DeleteCommands"].Item2)) { string[] Reason = Message.Split(new string[] { Words[1] }, StringSplitOptions.None); Tuple<string, SteamID> removed = ImpRemove(Words[1], sender.ToString(), false, Reason[1]); return "Removed map: " + removed.Item1; } if (DoesMessageStartWith(Words[0], ChatCommandsArray["ImpCommands"].Item2)) { if (Words.Length == 1) { return "!add <mapname> <url> <notes> is the command. however if the map is uploaded you do not need to include the url"; } int length = (Words.Length > 2).GetHashCode(); //Checks if there are more than 3 or more words int Uploaded = (UploadCheck(Words[1])).GetHashCode(); //Checks if map is uploaded. Crashes if only one word //TODO FIX THAT string UploadStatus = "Uploaded"; //Sets a string, that'll remain unless altered if (length + Uploaded == 0) { //Checks if either test beforehand returned true return "Make sure to include the download URL!"; } else { string[] notes = FullMessage.Split(new string[] { Words[2 - Uploaded] }, StringSplitOptions.None); //Splits by the 2nd word (the uploadurl) but if it's already uploaded, it'll split by the map instead if (Uploaded == 0) //If the map isn't uploaded, it'll set the upload status to the 3rd word (The URL) { UploadStatus = Words[2]; } string status = ImpEntry(Words[1], UploadStatus, notes[1], sender); //If there are no notes, but a map and url, this will crash. SpreadsheetSync = true; return status; } } if (DoesMessageStartWith(Message, ChatCommandsArray["Update"].Item2)) { if (Words.Length <= 2) //Checks if there are less than 2 words, the previous map and map to change { return "!updatemap <PreviousMapName> <NewMapName> <url> <notes> is the command."; } string[] FullMessageCutArray = Words.Skip(2).ToArray(); int length = (FullMessageCutArray.Length > 1).GetHashCode(); //Checks if there are more than 3 or more words int Uploaded = 0; if (Words.Length > 0) { Uploaded = (UploadCheck(FullMessageCutArray[0])).GetHashCode(); } //Log.Interface("Checking if" + UploadCheck(FullMessageCutArray[1]) + "Is uploaded"); //Checks if map is uploaded. Crashes if only one word //TODO FIX THAT string UploadStatus = "Uploaded"; //Sets a string, that'll remain unless altered if (length + Uploaded == 0) { //Checks if either test beforehand returned true return "Make sure to include the download URL!"; } else { string[] notes = FullMessage.Split(new string[] { FullMessageCutArray[1 - Uploaded] }, StringSplitOptions.None); //Splits by the 2nd word (the uploadurl) but if it's already uploaded, it'll split by the map instead if (Uploaded == 0) //If the map isn't uploaded, it'll set the upload status to the 3rd word (The URL) { UploadStatus = FullMessageCutArray[1]; } string status = ImpEntryUpdate(Words[1], FullMessageCutArray[0], UploadStatus, notes[1], sender); //If there are no notes, but a map and url, this will crash. SpreadsheetSync = true; return status; } } if (DoesMessageStartWith(Words[0], ChatCommandsArray["MapCommands"].Item2)) { string[] MapData = PrintMapList(Maplist); Bot.SteamFriends.SendChatMessage(sender, EChatEntryType.ChatMsg, MapData[1]); return MapData[0]; } foreach (Tuple<string, string, string, Int32> ServerAddress in Servers) { if (Words[0].StartsWith(ServerAddress.Item3, StringComparison.OrdinalIgnoreCase)) { Steam.Query.ServerInfoResult ServerData = ServerQuery(System.Net.IPAddress.Parse(ServerAddress.Item2), ServerAddress.Item4); return String.Format( "{0} {1}/{2} - join at: steam://connect/{3}:{4}", utilities.SanitizeMapName(ServerData.Map), ServerData.Players, ServerData.MaxPlayers, ServerAddress.Item2, ServerAddress.Item4 ); } } if (DoesMessageStartWith(Words[0], ChatCommandsArray["HelpCommands"].Item2)) { if (Words.Length > 1) { foreach (KeyValuePair<string, Tuple<string, List<string>>> Entry in ChatCommandsArray) { if (Entry.Value.Item2.Contains(Words[1], StringComparer.OrdinalIgnoreCase)) { return Entry.Key + ": " + Entry.Value.Item1 + " Commands: " + string.Join(", ", Entry.Value.Item2); ; } } } else { return HelpLink; } } if (DoesMessageStartWith(Words[0], ChatCommandsArray["ReplyCheck"].Item2) & Words.Length > 1) { foreach (KeyValuePair<string, Tuple<string, SteamID>> Entry in InstantChatReplies) { if ((Entry.Key == Words[1])) { return "Set by: " + Entry.Value.Item2.ToString() + " (" + Bot.SteamFriends.GetFriendPersonaName(Entry.Value.Item2) + ")"; } } } foreach (KeyValuePair<string, Tuple<string, SteamID>> Entry in InstantChatReplies) //TODO Disable autocorrections { if (FullMessage.StartsWith(Entry.Key, StringComparison.OrdinalIgnoreCase)) { return Entry.Value.Item1; } } return null; }
/// <summary> /// The commands that users can use by msg'ing the system. Returns a string with the appropriate responses /// </summary> /// <param name="chatID">ChatID of the chatroom</param> /// <param name="message">The message sent</param> public string admincommands(SteamID sender, string FullMessage) { FullMessage.Replace(@"\s+", " "); string[] Words = FullMessage.Split(); string Message = FullMessage.Remove(0, ((Words[0].Length) * (Words.Length > 1).GetHashCode()) + (Words.Length > 1).GetHashCode()); if (Words[0].StartsWith("!OnlineSheetDownload", StringComparison.OrdinalIgnoreCase)) { OAuthUtil.RefreshAccessToken(OauthParameters); string[] MapData = PrintMapList(new SheetService().SheetDownload(IntegrationName, OauthParameters, SpreadSheetURI)); Bot.SteamFriends.SendChatMessage(sender, EChatEntryType.ChatMsg, MapData[1]); return MapData[0]; } if (Words[0].StartsWith("!ForceSync", StringComparison.OrdinalIgnoreCase)) { Synchronise(null); return "Should be synchronised"; } if (Words[0].StartsWith("!FriendMe", StringComparison.OrdinalIgnoreCase)) { Bot.SteamFriends.AddFriend(sender); return "I have sent the request"; } if (DoesMessageStartWith(Words[0], ChatCommandsArray["Rejoin"].Item2)) if (FullMessage.StartsWith("!ReJoin", StringComparison.OrdinalIgnoreCase)) { Bot.SteamFriends.LeaveChat(new SteamID(Groupchat)); Bot.SteamFriends.JoinChat(new SteamID(Groupchat)); } if (Words[0].StartsWith("!Say", StringComparison.OrdinalIgnoreCase)) { Bot.SteamFriends.SendChatRoomMessage(Groupchat, EChatEntryType.ChatMsg, Message); } if (DoesMessageStartWith(Words[0], ChatCommandsArray["SetMOTD"].Item2)) { if (Message != null) { if (MOTD != null) { return "There is currently a MOTD, please remove it first"; } else { MOTDSetter = Bot.SteamFriends.GetFriendPersonaName(sender) + " " + sender; MOTD = Message; return "MOTD Set to: " + Message; } } else { return "Make sure to include a MOTD to display!"; } } if (Message.StartsWith("Say my name", StringComparison.OrdinalIgnoreCase)) { return Bot.SteamFriends.GetFriendPersonaName(sender); } if (DoesMessageStartWith(Words[0], ChatCommandsArray["RemoveMOTD"].Item2)) { MOTD = null; return "Removed MOTD"; } if (DoesMessageStartWith(Words[0], ChatCommandsArray["ClearCommands"].Item2)) { Maplist = new Dictionary<string, Tuple<string, string, string, bool>>(); System.IO.File.WriteAllText(@MapStoragePath, JsonConvert.SerializeObject(Maplist)); SpreadsheetSync = true; return "Wiped all Maps"; } if (DoesMessageStartWith(Words[0], ChatCommandsArray["EnableSync"].Item2)) { OnlineSync = "true"; groupchatsettings.Remove("OnlineSync"); groupchatsettings.Add("OnlineSync", "true"); System.IO.File.WriteAllText(@"ExtraSettings.json", JsonConvert.SerializeObject(ExtraSettingsData)); return "Enabled Sync"; } if (DoesMessageStartWith(Words[0], ChatCommandsArray["DisableSync"].Item2)) { OnlineSync = "false"; groupchatsettings.Remove("OnlineSync"); groupchatsettings.Add("OnlineSync", "false"); System.IO.File.WriteAllText(@"ExtraSettings.json", JsonConvert.SerializeObject(ExtraSettingsData)); return "Disabled Sync"; } if (DoesMessageStartWith(Words[0], ChatCommandsArray["EnableRSS"].Item2)) { EnableRSS = true; return "Enabled RSS"; } if (DoesMessageStartWith(Words[0], ChatCommandsArray["DisableRSS"].Item2)) { EnableRSS = false; return "Disabled RSS"; } if (DoesMessageStartWith(Words[0], ChatCommandsArray["Rejoin"].Item2)) { Bot.SteamFriends.LeaveChat(new SteamID(Groupchat)); Bot.SteamFriends.JoinChat(new SteamID(Groupchat)); } if (DoesMessageStartWith(Words[0], ChatCommandsArray["Unban"].Item2)) { if (Words.Length > 1) ; string Userid = GetSteamIDFromUrl(Words[1], true); if (BanList.ContainsKey(Userid.ToString())) { BanList.Remove(Userid); System.IO.File.WriteAllText(@BanListFilePath, JsonConvert.SerializeObject(BanList)); return "The ban has now been lifted"; } else { return "User is not banned"; } } if (DoesMessageStartWith(Words[0], ChatCommandsArray["AddCommands"].Item2)) { if (Words.Length > 1) { foreach (KeyValuePair<string, Tuple<string, List<string>>> Entry in ChatCommandsArray) { if (Entry.Value.Item2.Contains(Words[1], StringComparer.OrdinalIgnoreCase)) { foreach (KeyValuePair<string, Tuple<string, List<string>>> EntryRecheck in ChatCommandsArray) { if (EntryRecheck.Value.Item2.Contains(Words[2], StringComparer.OrdinalIgnoreCase)) { return "Sorry this command already exists!"; } else { if (Words[2].StartsWith("!")) { Entry.Value.Item2.Add(Words[2]); } else { Entry.Value.Item2.Add("!" + Words[2]); } System.IO.File.WriteAllText(@"ChatCommands.json", JsonConvert.SerializeObject(ChatCommandsArray)); return "Added: " + Words[2] + " to " + Entry.Key; } } return "Command not found"; } } } else { return HelpLink; } } if (DoesMessageStartWith(Words[0], ChatCommandsArray["RemoveCommands"].Item2)) { if (Words.Length > 1) { foreach (KeyValuePair<string, Tuple<string, List<string>>> Entry in ChatCommandsArray) { if (Entry.Value.Item2.Contains(Words[1], StringComparer.OrdinalIgnoreCase)) { Entry.Value.Item2.Remove(Words[1]); System.IO.File.WriteAllText(@"ChatCommands.json", JsonConvert.SerializeObject(ChatCommandsArray)); return "Removed: " + Words[1]; } else { return "Couldn't find command, try again"; } } } else { return HelpLink; } } if (DoesMessageStartWith(Words[0], ChatCommandsArray["Ban"].Item2)) { if (Words.Length > 3) { string[] Reason = Message.Split(new string[] { " " + Words[2] + " " }, StringSplitOptions.RemoveEmptyEntries); SteamID Userid = new SteamID(GetSteamIDFromUrl(Words[1], true)); if (BanList.ContainsKey(Userid.ToString())) { return "This user has already been banned, their ban has " + BanList[Userid.ToString()] + " remainig"; } BanList.Add(Userid.ToString(), int.Parse(Words[2]) * 24); System.IO.File.WriteAllText(@BanListFilePath, JsonConvert.SerializeObject(BanList)); Bot.SteamFriends.SendChatMessage(Userid, EChatEntryType.ChatMsg, "You have been banned from using all bot features for " + Words[2] + "days. Reason given: " + Reason[1]); return "Banned user:"******" (" + Bot.SteamFriends.GetFriendPersonaName(Userid).ToString() + ") for: " + Words[2] + " days. Reason given: " + Reason[1]; } else { return "The command is: " + "!Ban" + " <url of user>, Duration in days, Reason"; } } if (DoesMessageStartWith(Words[0], ChatCommandsArray["RemoveReply"].Item2) & Words.Length > 1) { if (ChatCommandsArray.ContainsKey(Words[1])) { return "Sorry that reply already exists"; } foreach (KeyValuePair<string, Tuple<string, SteamID>> Entry in InstantChatReplies) { if ((Entry.Key == Words[1]) && (sender == Entry.Value.Item2) | admincheck(sender)) { Bot.SteamFriends.SendChatMessage(Entry.Value.Item2, EChatEntryType.ChatMsg, "Hi, your instant reply has been removed."); InstantChatReplies.Remove(Words[1]); System.IO.File.WriteAllText(@InstantRepliesFile, JsonConvert.SerializeObject(InstantChatReplies)); return "The reply has been removed"; } } } if (DoesMessageStartWith(Words[0], ChatCommandsArray["AddReplies"].Item2) & Words.Length > 2) { if (InstantChatReplies.ContainsKey(Words[1])) { return "Sorry that reply already exists"; } else { string Reply = Message.Remove(0, (Words[1].Length + 1)); Tuple<string, SteamID> Data = Tuple.Create<string, SteamID>(Reply, sender); if (Words[1].StartsWith("/")) { InstantChatReplies.Add(Words[1], Data); System.IO.File.WriteAllText(@InstantRepliesFile, JsonConvert.SerializeObject(InstantChatReplies)); } else { InstantChatReplies.Add("/" + Words[1], Data); System.IO.File.WriteAllText(@InstantRepliesFile, JsonConvert.SerializeObject(InstantChatReplies)); } return "Set reply for: " + Words[1] + " which is: " + Reply; } } return null; }
private bool Respond(SteamID toID, SteamID userID, string message) { Dictionary<SteamID, Dictionary<SteamID, int>> groups = Options.AntiSpamTriggerOptions.groups; AntiSpamTriggerOptions options = Options.AntiSpamTriggerOptions; if(!groups.ContainsKey(toID)) { groups[toID] = new Dictionary<SteamID, int>(); } if(!groups[toID].ContainsKey(userID)) { groups[toID][userID] = 0; } groups[toID][userID] += options.msgPenalty; if(groups[toID][userID] >= options.score.warn && groups[toID][userID] <= options.score.warnMax) { Log("warning", userID, toID); SendMessageAfterDelay(userID, options.warnMessage, false); return true; } else if(groups[toID][userID] >= options.score.kick) { Log("kicking", userID, toID); Bot.steamFriends.KickChatMember(toID, userID); return true; } else if (groups[toID][userID] >= options.score.ban) { Log("banning", userID, toID); Timer unban = new Timer(options.timers.unban); unban.Elapsed += new ElapsedEventHandler((sender, e) => Unban_Elapsed(sender, e, toID, userID)); return true; } else if (groups[toID][userID] >= options.score.tattle && groups[toID][userID] <= options.score.tattleMax) { Log("tattling on", userID, toID); foreach(SteamID admin in options.admins) { SendMessageAfterDelay(admin, Bot.steamFriends.GetFriendPersonaName(userID) + " is spamming in https://steamcommunity.com/gid/" + toID.ToString(), false); } return true; } return false; }
/// <summary> /// Logs bot actions to the console /// </summary> /// <param name="prefix">Action that was taken</param> /// <param name="userID">The user to act upon</param> /// <param name="groupID">The group the action is taking place in</param> /// <param name="reason">Reason they had action taken upon them</param> private void Log(string prefix, SteamID userID, SteamID groupID, string reason) { string message = string.Format("{0}/{1}: {2} {3} for spamming in https://steamcommunity.com/gid/{4} to prevent spam ({5})", Bot.username, Name, prefix, Bot.steamFriends.GetFriendPersonaName(userID), groupID.ToString(), reason); SteamChatBot.Log.Instance.Info(message); }