-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
231 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System; | ||
using System.IO; | ||
using System.Web.Script.Serialization; | ||
using System.Xml; | ||
using System.Xml.Serialization; | ||
|
||
namespace SteamChatBot | ||
{ | ||
public static class Parser | ||
{ | ||
private static JavaScriptSerializer json; | ||
private static JavaScriptSerializer JSON | ||
{ | ||
get | ||
{ | ||
return json ?? (json = new JavaScriptSerializer()); | ||
} | ||
} | ||
|
||
public static Stream ToStream(this string @this) | ||
{ | ||
MemoryStream stream = new MemoryStream(); | ||
StreamWriter writer = new StreamWriter(stream); | ||
writer.Write(@this); | ||
writer.Flush(); | ||
stream.Position = 0; | ||
return stream; | ||
} | ||
|
||
public static T ParseXML<T>(this string @this) where T : class | ||
{ | ||
XmlRootAttribute root = new XmlRootAttribute(); | ||
root.ElementName = "profile"; | ||
root.IsNullable = true; | ||
|
||
var reader = XmlReader.Create(@this.Trim().ToStream(), new XmlReaderSettings() | ||
{ | ||
ConformanceLevel = ConformanceLevel.Document | ||
}); | ||
return new XmlSerializer(typeof(T), root).Deserialize(reader) as T; | ||
} | ||
|
||
public static T ParseJSON<T>(this string @this) where T : class | ||
{ | ||
return JSON.Deserialize<T>(@this.Trim()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using SteamChatBot.Triggers.TriggerOptions; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using SteamKit2; | ||
|
||
namespace SteamChatBot.Triggers | ||
{ | ||
public class ChooseTrigger : BaseTrigger | ||
{ | ||
public ChooseTrigger(TriggerType type, string name, TriggerOptionsBase options) : base(type, name, options) | ||
{ } | ||
|
||
public override bool respondToChatMessage(SteamID roomID, SteamID chatterId, string message) | ||
{ | ||
return Respond(roomID, chatterId, message, true); | ||
} | ||
|
||
public override bool respondToFriendMessage(SteamID userID, string message) | ||
{ | ||
return Respond(userID, userID, message, false); | ||
} | ||
|
||
private bool Respond(SteamID toID, SteamID userID, string message, bool room) | ||
{ | ||
string[] query = StripCommand(message, Options.ChatCommand.Command); | ||
if(query != null && query.Length > 2) | ||
{ | ||
List<string> removed = new List<string>(); | ||
for (int i = 1; i < query.Length; i++) | ||
{ | ||
removed.Add(query[i]); | ||
} | ||
Random rng = new Random(); | ||
string choice = removed[rng.Next(0, removed.Count)]; | ||
SendMessageAfterDelay(toID, "I have chosen " + choice, room); | ||
return true; | ||
} | ||
return false; | ||
} | ||
} | ||
} |
Oops, something went wrong.