From 5cd113ac3411d7f34502130fef85c7aad7e082e8 Mon Sep 17 00:00:00 2001 From: Toyz Date: Tue, 17 Mar 2015 13:27:49 -0700 Subject: [PATCH 01/40] Added appdomain stuff but breaks on complie @Matt can you look at the code and if you can't fix it, this is all we need to have working so we can have dynamic loading and unloading plugins --- Spiffbot/Spiff.IRC/API/PluginLoader.cs | 20 ++++++++++++++++++-- Spiffbot/Spiff.IRC/Spiff.Core.csproj | 2 ++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/Spiffbot/Spiff.IRC/API/PluginLoader.cs b/Spiffbot/Spiff.IRC/API/PluginLoader.cs index dc02fb6..8b3a9b7 100644 --- a/Spiffbot/Spiff.IRC/API/PluginLoader.cs +++ b/Spiffbot/Spiff.IRC/API/PluginLoader.cs @@ -14,7 +14,7 @@ public class PluginLoader private readonly string _directory; public List LoadedPlugins { get; private set; } public Dictionary LoadedAssemblies { get; private set; } - + public Dictionary LoadedAppDomains { get; private set; } public PluginLoader(string directory) { @@ -22,6 +22,7 @@ public PluginLoader(string directory) LoadedPlugins = new List(); LoadedAssemblies = new Dictionary(); + LoadedAppDomains = new Dictionary(); } public void LoadPlugins() @@ -30,8 +31,15 @@ public void LoadPlugins() var assembly in Directory.GetFiles( _directory, - "*.dll").Select(Assembly.LoadFile)) + "*.dll").Select(Assembly.LoadFile())) { + + //Doesn't allow cross plugin which is a major bug that I can't solve, maybe you can + //bug does not load cross plugin + /*AppDomainSetup domainSetup = new AppDomainSetup { PrivateBinPath = assembly }; + var newDomain = AppDomain.CreateDomain(Path.GetFileNameWithoutExtension(assembly), null, domainSetup); + ProxyClass c = (ProxyClass)(newDomain.CreateInstanceFromAndUnwrap(assembly, typeof(ProxyClass).FullName)); + var asm = c.LoadAssembly(assembly);*/ AddAssembly(assembly); LoadPlugin(assembly); } @@ -81,5 +89,13 @@ public void StartPlugins() plugin.Start(); } } + + public class ProxyClass : MarshalByRefObject + { + public Assembly LoadAssembly(string path) + { + return Assembly.LoadFile(path); + } + } } } diff --git a/Spiffbot/Spiff.IRC/Spiff.Core.csproj b/Spiffbot/Spiff.IRC/Spiff.Core.csproj index 3dd6403..a0973fc 100644 --- a/Spiffbot/Spiff.IRC/Spiff.Core.csproj +++ b/Spiffbot/Spiff.IRC/Spiff.Core.csproj @@ -36,6 +36,7 @@ + @@ -46,6 +47,7 @@ + From 2002b505127e81f6832a6bdb11a1edc384dc3350 Mon Sep 17 00:00:00 2001 From: Toyz Date: Tue, 17 Mar 2015 17:03:38 -0700 Subject: [PATCH 02/40] Fixed a bug in plugin loader --- .gitignore | 3 +++ Spiffbot/Spiff.IRC/API/PluginLoader.cs | 4 ++-- Spiffbot/Spiffbot/Program.cs | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 48ba856..c0b6ff4 100644 --- a/.gitignore +++ b/.gitignore @@ -72,3 +72,6 @@ Icon Network Trash Folder Temporary Items .apdisk + +*.suo +Spiffbot/Spiffbot.v12.suo \ No newline at end of file diff --git a/Spiffbot/Spiff.IRC/API/PluginLoader.cs b/Spiffbot/Spiff.IRC/API/PluginLoader.cs index 8b3a9b7..b66ffe9 100644 --- a/Spiffbot/Spiff.IRC/API/PluginLoader.cs +++ b/Spiffbot/Spiff.IRC/API/PluginLoader.cs @@ -3,7 +3,6 @@ using System.IO; using System.Linq; using System.Reflection; -using System.Text; using Spiff.Core.Extensions; using Spiff.Core.Utils; @@ -31,7 +30,7 @@ public void LoadPlugins() var assembly in Directory.GetFiles( _directory, - "*.dll").Select(Assembly.LoadFile())) + "*.dll").Select(Assembly.LoadFile)) { //Doesn't allow cross plugin which is a major bug that I can't solve, maybe you can @@ -90,6 +89,7 @@ public void StartPlugins() } } + //TODO: Fix me so we can use this to load plugins! public class ProxyClass : MarshalByRefObject { public Assembly LoadAssembly(string path) diff --git a/Spiffbot/Spiffbot/Program.cs b/Spiffbot/Spiffbot/Program.cs index 004aa46..60f17f2 100644 --- a/Spiffbot/Spiffbot/Program.cs +++ b/Spiffbot/Spiffbot/Program.cs @@ -71,7 +71,7 @@ private static void IrcClientOnOnTwitchDataDebugOut(object sender, TwitchEvent t if (ConfigFile.GetValue("adv", "debug", false)) { Logger.Debug(twitchEvent.Payload, "Debug"); - } + } } private static void TitleUpdater() From d042dc97c6e526f277ac1853e0503dda2801a5dc Mon Sep 17 00:00:00 2001 From: Toyz Date: Tue, 17 Mar 2015 17:09:15 -0700 Subject: [PATCH 03/40] Fixed the title from SpiffBaot to SpiffBot... Yaaaaaa for bad spelling! --- Spiffbot/Spiffbot/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Spiffbot/Spiffbot/Program.cs b/Spiffbot/Spiffbot/Program.cs index 60f17f2..61cfd0a 100644 --- a/Spiffbot/Spiffbot/Program.cs +++ b/Spiffbot/Spiffbot/Program.cs @@ -80,7 +80,7 @@ private static void TitleUpdater() { var viewers = SiteApi.GetChatters(SpiffCore.Instance.Channel).Count; - Console.Title = string.Format("Spiffbaot - Viewers: {0}", viewers); + Console.Title = string.Format("Spiffbot - Viewers: {0}", viewers); Thread.Sleep(1000); } From f93de38c10bb09750d6745ed732929ae36cacdea Mon Sep 17 00:00:00 2001 From: Toyz Date: Tue, 17 Mar 2015 18:46:38 -0700 Subject: [PATCH 04/40] Added Win32 blocking API idk which one is which :panda_face: --- Spiffbot/Win32API/Invoke.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Spiffbot/Win32API/Invoke.cs b/Spiffbot/Win32API/Invoke.cs index a3cb522..a2efe55 100644 --- a/Spiffbot/Win32API/Invoke.cs +++ b/Spiffbot/Win32API/Invoke.cs @@ -26,5 +26,11 @@ public struct POINT [DllImport("user32.dll")] private static extern int SendMessage(int hWnd, int hMsg, int wParam, int lParam); + + [DllImport("user32.dll")] + static extern bool UnBlockInput(bool fBlockIt); + + [DllImport("user32.dll")] + static extern bool BlockInput(bool fBlockIt); } } From 29d30eb918cb22bf2015c334323cecfc480dd567 Mon Sep 17 00:00:00 2001 From: Toyz Date: Tue, 17 Mar 2015 18:49:08 -0700 Subject: [PATCH 05/40] Fixed a private to public in Win32 plugin --- Spiffbot/Win32API/Invoke.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Spiffbot/Win32API/Invoke.cs b/Spiffbot/Win32API/Invoke.cs index a2efe55..2d09f32 100644 --- a/Spiffbot/Win32API/Invoke.cs +++ b/Spiffbot/Win32API/Invoke.cs @@ -25,7 +25,7 @@ public struct POINT public static int SC_MONITORPOWER = 0xF170; [DllImport("user32.dll")] - private static extern int SendMessage(int hWnd, int hMsg, int wParam, int lParam); + public static extern int SendMessage(int hWnd, int hMsg, int wParam, int lParam); [DllImport("user32.dll")] static extern bool UnBlockInput(bool fBlockIt); From 83e744690c36319bb9e61538e232fa8349d64843 Mon Sep 17 00:00:00 2001 From: Toyz Date: Tue, 17 Mar 2015 21:13:04 -0700 Subject: [PATCH 06/40] Added Managers to handle Viewers Will add more for Chat, commands and others to make it better to use then before --- Spiffbot/CustomCommands/CustomCommands.cs | 4 +- .../DefaultCommands/Commands/AllCommands.cs | 2 +- Spiffbot/DefaultCommands/DefaultCommands.cs | 6 +- Spiffbot/QuizBotPlugin/QuizMaster.cs | 44 ++++++------ Spiffbot/Spiff.IRC/API/Commands/Command.cs | 9 ++- .../Spiff.IRC/API/EventArgs/OnChatEvent.cs | 8 ++- Spiffbot/Spiff.IRC/API/Plugin.cs | 5 ++ Spiffbot/Spiff.IRC/API/Twitch/SiteAPI.cs | 20 ++---- Spiffbot/Spiff.IRC/Managers/Viewers/Viewer.cs | 67 ++++++++++++++++++ .../Managers/Viewers/ViewerManager.cs | 64 +++++++++++++++++ Spiffbot/Spiff.IRC/Spiff.Core.csproj | 2 + Spiffbot/Spiff.IRC/SpiffCore.cs | 61 ++++++++-------- Spiffbot/Spiffbot.v12.suo | Bin 149504 -> 167936 bytes Spiffbot/Spiffbot/Program.cs | 2 +- vjoy/XInputView.source/MainForm.cs | 11 +-- vjoy/XInputView.source/XInputView.csproj | 6 ++ 16 files changed, 224 insertions(+), 87 deletions(-) create mode 100644 Spiffbot/Spiff.IRC/Managers/Viewers/Viewer.cs create mode 100644 Spiffbot/Spiff.IRC/Managers/Viewers/ViewerManager.cs diff --git a/Spiffbot/CustomCommands/CustomCommands.cs b/Spiffbot/CustomCommands/CustomCommands.cs index e61fa1c..727010d 100644 --- a/Spiffbot/CustomCommands/CustomCommands.cs +++ b/Spiffbot/CustomCommands/CustomCommands.cs @@ -9,7 +9,7 @@ public class CustomCommands : Plugin { public override string Name { - get { return "Custom Commands"; } + get { return "Custom LoadedCommands"; } } public override string Author @@ -37,7 +37,7 @@ public override void Start() ConfigSettings.Flush(); } - Logger.Debug("Is Default Plugin Set: " + ((DefaultCommands.DefaultCommands)GetPlugin("Default Commands") != null), Name); + Logger.Debug("Is Default Plugin Set: " + ((DefaultCommands.DefaultCommands)GetPlugin("Default LoadedCommands") != null), Name); RegisterCommand(new SourceCommand()); RegisterCommand(new SongCommand()); RegisterCommand(new ReloadConfigSettings()); diff --git a/Spiffbot/DefaultCommands/Commands/AllCommands.cs b/Spiffbot/DefaultCommands/Commands/AllCommands.cs index d39fab6..e27bf9c 100644 --- a/Spiffbot/DefaultCommands/Commands/AllCommands.cs +++ b/Spiffbot/DefaultCommands/Commands/AllCommands.cs @@ -19,7 +19,7 @@ public override void Run(string[] parts, string complete, string channel, string { var commands = string.Join(", ", SpiffCore.Instance.AllCommands().Keys); - Boardcast("All Commands: " + commands); + Boardcast("All LoadedCommands: " + commands); } } } diff --git a/Spiffbot/DefaultCommands/DefaultCommands.cs b/Spiffbot/DefaultCommands/DefaultCommands.cs index 72995f6..421b427 100644 --- a/Spiffbot/DefaultCommands/DefaultCommands.cs +++ b/Spiffbot/DefaultCommands/DefaultCommands.cs @@ -8,7 +8,7 @@ public class DefaultCommands : Plugin { public override string Name { - get { return "Default Commands"; } + get { return "Default LoadedCommands"; } } public override string Author @@ -28,7 +28,7 @@ public override int Version public override void Start() { - Logger.Write("Loading Plugin Commands", Name); + Logger.Write("Loading Plugin LoadedCommands", Name); RegisterCommand(new AllCommands()); RegisterCommand(new HelpCommand()); RegisterCommand(new GameCommand()); @@ -38,7 +38,7 @@ public override void Start() public override void Destory() { - Logger.Write("[Default Commands]Stopping", Name); + Logger.Write("[Default LoadedCommands]Stopping", Name); } } } diff --git a/Spiffbot/QuizBotPlugin/QuizMaster.cs b/Spiffbot/QuizBotPlugin/QuizMaster.cs index 7f7584e..9605ce6 100644 --- a/Spiffbot/QuizBotPlugin/QuizMaster.cs +++ b/Spiffbot/QuizBotPlugin/QuizMaster.cs @@ -1,12 +1,9 @@ using System; using System.Collections.Generic; using System.IO; -using System.Linq; -using System.Text; using System.Timers; using QuizBotPlugin.ListItems; using Spiff.Core; -using Spiff.Core.API.Commands; using Spiff.Core.API.EventArgs; using Spiff.Core.Utils; @@ -15,44 +12,43 @@ namespace QuizBotPlugin public class QuizMaster { private readonly string _file; - private readonly Command _comm; - private List _quizItems; + private readonly List _quizItems; private QuizItem _currentItem; - private Timer Timer; - private int _id = 0; - private bool NoPost = false; + private Timer _timer; + private int _id; + public bool NoPost; public QuizMaster(string file) { _file = file; - + NoPost = false; _quizItems = Utils.DeserializeFromXml>( File.ReadAllText(Path.Combine(QuizBot.BotInstance.PluginDirectory, file))); - Timer = new Timer {Interval = 60000}; - Timer.Elapsed += TimerOnTick; + _timer = new Timer {Interval = 60000}; + _timer.Elapsed += TimerOnTick; _currentItem = getQuizItem(); - SpiffCore.Instance.OnChatHandler += InstanceOnOnChatHandler; + SpiffCore.Instance.OnChatEvent += InstanceOnOnChatEvent; - Timer.Start(); + _timer.Start(); } - private void InstanceOnOnChatHandler(object sender, OnChatEvent onChatEvent) + private void InstanceOnOnChatEvent(object sender, OnChatEvent onChatEvent) { //Logger.Debug("Fired Message Event:" + onChatEvent.Message, QuizBot.BotInstance.Name); if (onChatEvent.Message.Trim().Equals(_currentItem.Anwser)) { //NoPost = true; - Timer.Stop(); + _timer.Stop(); //NoPost = false; - SpiffCore.Instance.WriteOut.SendMessage(onChatEvent.User + " got the anwser correct!"); + SpiffCore.Instance.WriteOut.SendMessage(onChatEvent.User.Username + " got the anwser correct!"); _currentItem = getQuizItem(); - if(Timer != null) - Timer.Start(); + if(_timer != null) + _timer.Start(); } } @@ -66,8 +62,8 @@ private void TimerOnTick(object sender, EventArgs eventArgs) //if (NoPost) return; SpiffCore.Instance.WriteOut.SendMessage("The anwser for the question was: " + _currentItem.Anwser); _currentItem = getQuizItem(); - if(Timer != null) - Timer.Start(); + if(_timer != null) + _timer.Start(); } private QuizItem getQuizItem() @@ -75,11 +71,11 @@ private QuizItem getQuizItem() if (_id > _quizItems.Count - 1) { _id = 0; - SpiffCore.Instance.OnChatHandler -= InstanceOnOnChatHandler; + SpiffCore.Instance.OnChatEvent -= InstanceOnOnChatEvent; SpiffCore.Instance.WriteOut.SendMessage("Game Over... Maybe I will load another :D"); - Timer.Elapsed -= TimerOnTick; - Timer.Dispose(); - Timer = null; + _timer.Elapsed -= TimerOnTick; + _timer.Dispose(); + _timer = null; return null; } var item = _quizItems[_id]; diff --git a/Spiffbot/Spiff.IRC/API/Commands/Command.cs b/Spiffbot/Spiff.IRC/API/Commands/Command.cs index 3ddf065..bfb494c 100644 --- a/Spiffbot/Spiff.IRC/API/Commands/Command.cs +++ b/Spiffbot/Spiff.IRC/API/Commands/Command.cs @@ -1,5 +1,6 @@ using System.Linq; using Spiff.Core.API.Twitch; +using Spiff.Core.Managers.Viewers; namespace Spiff.Core.API.Commands { @@ -9,7 +10,7 @@ public abstract class Command public abstract string CommandInfo { get; } //Methods - public abstract void Run(string[] parts, string complete, string channel, string nick); + public abstract void Run(string[] parts, string complete, string channel, Viewer nick); protected bool IsMod(string nick) { @@ -24,11 +25,9 @@ protected bool IsOwner(string nick) return SpiffCore.Instance.Channel.ToLower().Equals(nick.ToLower()); } - protected SiteApi.Viewer GetViewer(string nick) + protected Viewer GetViewer(string nick) { - var users = SiteApi.GetChatters(SpiffCore.Instance.Channel); - - return (from s in users where s.Username.ToLower().Equals(nick.ToLower()) select s).FirstOrDefault(); + return SpiffCore.Instance.ViewerManager.GetViewer(nick); } protected void Boardcast(string message) diff --git a/Spiffbot/Spiff.IRC/API/EventArgs/OnChatEvent.cs b/Spiffbot/Spiff.IRC/API/EventArgs/OnChatEvent.cs index 13caf40..b07877b 100644 --- a/Spiffbot/Spiff.IRC/API/EventArgs/OnChatEvent.cs +++ b/Spiffbot/Spiff.IRC/API/EventArgs/OnChatEvent.cs @@ -1,12 +1,14 @@ -namespace Spiff.Core.API.EventArgs +using Spiff.Core.Managers.Viewers; + +namespace Spiff.Core.API.EventArgs { public class OnChatEvent : System.EventArgs { public string Channel { get; private set; } - public string User { get; private set; } + public Viewer User { get; private set; } public string Message { get; private set; } - public OnChatEvent(string channel, string user, string message) + public OnChatEvent(string channel, Viewer user, string message) { Channel = channel; User = user; diff --git a/Spiffbot/Spiff.IRC/API/Plugin.cs b/Spiffbot/Spiff.IRC/API/Plugin.cs index 1f59aa7..bda794e 100644 --- a/Spiffbot/Spiff.IRC/API/Plugin.cs +++ b/Spiffbot/Spiff.IRC/API/Plugin.cs @@ -1,6 +1,7 @@ using System.IO; using System.Linq; using Spiff.Core.API.Commands; +using Spiff.Core.Managers.Viewers; using Spiff.Core.Utils; namespace Spiff.Core.API @@ -46,6 +47,10 @@ public OutUtils Writer { get { return SpiffCore.WriteOut; } } + public ViewerManager ViewerManager + { + get { return SpiffCore.ViewerManager; } + } public string PluginDirectory { diff --git a/Spiffbot/Spiff.IRC/API/Twitch/SiteAPI.cs b/Spiffbot/Spiff.IRC/API/Twitch/SiteAPI.cs index ec45c21..7500d26 100644 --- a/Spiffbot/Spiff.IRC/API/Twitch/SiteAPI.cs +++ b/Spiffbot/Spiff.IRC/API/Twitch/SiteAPI.cs @@ -4,6 +4,7 @@ using System.Net; using Newtonsoft.Json; using Newtonsoft.Json.Linq; +using Spiff.Core.Managers.Viewers; namespace Spiff.Core.API.Twitch { @@ -60,18 +61,6 @@ public class RootObject public static class SiteApi { - public class Viewer - { - public bool IsMod { get; private set; } - public string Username { get; private set; } - - public Viewer(string username, bool isMod) - { - IsMod = isMod; - Username = username; - } - } - public static string GetGame(string streamer) { using (var client = new WebClient()) @@ -90,6 +79,9 @@ public static string GetGame(string streamer) } } + + //Kinda pointless now that the new system is in place for the viewer managers but ehhh :] we wll remove later or just depricate it + [Obsolete("User ViewerManager.Viewers for this information")] public static List GetChatters(string streamer) { var users = new List(); @@ -103,8 +95,8 @@ public static List GetChatters(string streamer) client.DownloadString(string.Format("https://tmi.twitch.tv/group/user/{0}/chatters", streamer))); - users.AddRange(json["chatters"]["viewers"].Select(viewer => new Viewer((string) viewer, false))); - users.AddRange(json["chatters"]["moderators"].Select(viewer => new Viewer((string) viewer, true))); + users.AddRange(json["chatters"]["viewers"].Select(viewer => new Viewer((string) viewer, false, DateTime.Now))); + users.AddRange(json["chatters"]["moderators"].Select(viewer => new Viewer((string)viewer, true, DateTime.Now))); } catch (Exception e) { diff --git a/Spiffbot/Spiff.IRC/Managers/Viewers/Viewer.cs b/Spiffbot/Spiff.IRC/Managers/Viewers/Viewer.cs new file mode 100644 index 0000000..7f59853 --- /dev/null +++ b/Spiffbot/Spiff.IRC/Managers/Viewers/Viewer.cs @@ -0,0 +1,67 @@ +using System; + +namespace Spiff.Core.Managers.Viewers +{ + public class Viewer + { + protected bool Equals(Viewer other) + { + return IsMod.Equals(other.IsMod) && string.Equals(Username, other.Username) && JoinedTime.Equals(other.JoinedTime); + } + + public override int GetHashCode() + { + unchecked + { + var hashCode = IsMod.GetHashCode(); + hashCode = (hashCode*397) ^ (Username != null ? Username.GetHashCode() : 0); + hashCode = (hashCode*397) ^ JoinedTime.GetHashCode(); + return hashCode; + } + } + + public bool IsMod { get; set; } + public string Username { get; set; } + public DateTime JoinedTime { get; set; } + + public Viewer(string username, bool isMod, DateTime joinTime) + { + IsMod = isMod; + Username = username; + JoinedTime = joinTime; + } + + public Viewer(Viewer viewer) + { + IsMod = viewer.IsMod; + Username = viewer.Username; + } + + public void Kick(int timeout = 600) + { + SpiffCore.Instance.WriteOut.TimeoutUser(Username, timeout); + } + + public void Ban() + { + SpiffCore.Instance.WriteOut.BanUser(Username); + } + + public void Unban() + { + SpiffCore.Instance.WriteOut.UnbanUser(Username); + } + + public override string ToString() + { + return string.Format("Nick: {0} - Joined: {1} - IsMod: {2}", Username, JoinedTime, IsMod); + } + + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + if (ReferenceEquals(this, obj)) return true; + return obj.GetType() == GetType() && Equals((Viewer) obj); + } + } +} diff --git a/Spiffbot/Spiff.IRC/Managers/Viewers/ViewerManager.cs b/Spiffbot/Spiff.IRC/Managers/Viewers/ViewerManager.cs new file mode 100644 index 0000000..76a0940 --- /dev/null +++ b/Spiffbot/Spiff.IRC/Managers/Viewers/ViewerManager.cs @@ -0,0 +1,64 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Spiff.Core.API.EventArgs; + +namespace Spiff.Core.Managers.Viewers +{ + public class ViewerManager + { + private readonly SpiffCore _spiffCore; + public List AllViewers { get; private set; } + + public ViewerManager(SpiffCore spiffCore) + { + _spiffCore = spiffCore; + AllViewers = new List(); + + _spiffCore.OnUserJoinEvent += SpiffCoreOnOnUserJoinEvent; + _spiffCore.OnUserLeftEvent += SpiffCoreOnOnUserLeftEvent; + } + + private void SpiffCoreOnOnUserLeftEvent(object sender, OnUserLeftEvent onUserLeftEvent) + { + var viewer = (from s in AllViewers where s.Username == onUserLeftEvent.Nick select s).FirstOrDefault(); + + if (viewer == null) return; + AllViewers.Remove(viewer); + } + + private void SpiffCoreOnOnUserJoinEvent(object sender, OnUserJoinEvent onUserJoinEvent) + { + var viewer = (from s in AllViewers where s.Username == _spiffCore.BotName select s).FirstOrDefault(); + + if (viewer != null) return; + var owner = onUserJoinEvent.Nick.ToLower().Equals(onUserJoinEvent.Channel.Replace("#", "").ToLower()); + AllViewers.Add(new Viewer(onUserJoinEvent.Nick, owner, DateTime.Now)); + } + + public void SetMod(string nick) + { + var viewer = (from s in AllViewers where String.Equals(s.Username, nick, StringComparison.CurrentCultureIgnoreCase) select s).FirstOrDefault(); + + if (viewer != null) + { + viewer.IsMod = true; + } + } + + public void RemoveMod(string nick) + { + var viewer = (from s in AllViewers where String.Equals(s.Username, nick, StringComparison.CurrentCultureIgnoreCase) select s).FirstOrDefault(); + + if (viewer != null) + { + viewer.IsMod = false; + } + } + + public Viewer GetViewer(string nick) + { + return (from s in AllViewers where String.Equals(s.Username, nick, StringComparison.CurrentCultureIgnoreCase) select s).FirstOrDefault(); + } + } +} diff --git a/Spiffbot/Spiff.IRC/Spiff.Core.csproj b/Spiffbot/Spiff.IRC/Spiff.Core.csproj index a0973fc..5449ef0 100644 --- a/Spiffbot/Spiff.IRC/Spiff.Core.csproj +++ b/Spiffbot/Spiff.IRC/Spiff.Core.csproj @@ -49,6 +49,8 @@ + + diff --git a/Spiffbot/Spiff.IRC/SpiffCore.cs b/Spiffbot/Spiff.IRC/SpiffCore.cs index be67d89..4ade8a4 100644 --- a/Spiffbot/Spiff.IRC/SpiffCore.cs +++ b/Spiffbot/Spiff.IRC/SpiffCore.cs @@ -5,6 +5,7 @@ using Spiff.Core.API.Commands; using Spiff.Core.API.EventArgs; using Spiff.Core.IRC; +using Spiff.Core.Managers.Viewers; using Spiff.Core.Utils; namespace Spiff.Core @@ -19,14 +20,18 @@ public class SpiffCore public OutUtils WriteOut { get; set; } //event Args - public event EventHandler OnUserJoinHandler; - public event EventHandler OnUserLeftHandler; - public event EventHandler OnChatHandler; - public event EventHandler OnCommandHandler; + public event EventHandler OnUserJoinEvent; + public event EventHandler OnUserLeftEvent; + public event EventHandler OnChatEvent; + public event EventHandler OnCommandEvent; //Command List - public Dictionary Commands {get; private set; } + public Dictionary LoadedCommands {get; private set; } public PluginLoader PluginLoader { get; private set; } + + //Viewer Managers + public ViewerManager ViewerManager { get; private set; } + //Instance public static SpiffCore Instance { get; private set; } @@ -38,16 +43,14 @@ public SpiffCore(string channel, string botName, string outh, string pluginDirec Channel = channel; BotName = botName; PluginLoader = new PluginLoader(pluginDirectory); - - Commands = new Dictionary(); - - Instance = this; - + LoadedCommands = new Dictionary(); IrcClient = new IRCClient(channel, botName, outh, this); - IrcClient.OnTwitchEvent += IrcClientOnOnTwitchEvent; - AppDomain.CurrentDomain.AssemblyResolve += CurrentDomainOnAssemblyResolve; + + ViewerManager = new ViewerManager(this); + + Instance = this; } private Assembly CurrentDomainOnAssemblyResolve(object sender, ResolveEventArgs args) @@ -60,39 +63,39 @@ private Assembly CurrentDomainOnAssemblyResolve(object sender, ResolveEventArgs public void AddCommand(Command command) { Command outcommand; - Commands.TryGetValue("!" + command.CommandName, out outcommand); + LoadedCommands.TryGetValue("!" + command.CommandName, out outcommand); if (outcommand == null) { - Commands.Add("!" + command.CommandName, command); + LoadedCommands.Add("!" + command.CommandName, command); } } public void RemoveCommand(Command command) { Command outcommand; - Commands.TryGetValue("!" + command.CommandName, out outcommand); + LoadedCommands.TryGetValue("!" + command.CommandName, out outcommand); if (outcommand == null) { - Commands.Remove("!" + command.CommandName); + LoadedCommands.Remove("!" + command.CommandName); } } public void RemoveCommand(string command) { Command outcommand; - Commands.TryGetValue("!" + command, out outcommand); + LoadedCommands.TryGetValue("!" + command, out outcommand); if (outcommand == null) { - Commands.Remove("!" + command); + LoadedCommands.Remove("!" + command); } } public Dictionary AllCommands() { - return Commands; + return LoadedCommands; } #endregion @@ -131,20 +134,20 @@ private void IrcClientOnOnTwitchEvent(object sender, TwitchEvent twitchEvent) { case "PRIVMSG": if (channel.StartsWith("#")) - if (OnChatHandler != null) - OnChatHandler(this, new OnChatEvent(channel, nick, message)); + if (OnChatEvent != null) + OnChatEvent(this, new OnChatEvent(channel, ViewerManager.GetViewer(nick), message)); Logger.Info(string.Format("{0} -> {1}", nick, message), "Chat"); break; case "JOIN": if (channel.StartsWith("#")) - if (OnUserJoinHandler != null) - OnUserJoinHandler(this, new OnUserJoinEvent(nick, channel)); + if (OnUserJoinEvent != null) + OnUserJoinEvent(this, new OnUserJoinEvent(nick, channel)); Logger.Info(string.Format("{0} has joined the chat", nick), "Joined Chat"); break; case "PART": if (channel.StartsWith("#")) - if (OnUserLeftHandler != null) - OnUserLeftHandler(this, new OnUserLeftEvent(nick, channel)); + if (OnUserLeftEvent != null) + OnUserLeftEvent(this, new OnUserLeftEvent(nick, channel)); Logger.Info(string.Format("{0} has left the chat", nick), "Left Chat"); break; } @@ -152,17 +155,17 @@ private void IrcClientOnOnTwitchEvent(object sender, TwitchEvent twitchEvent) if (message.StartsWith("!")) { Command command; - Commands.TryGetValue(message.Split(' ')[0], out command); + LoadedCommands.TryGetValue(message.Split(' ')[0], out command); if (command != null) { var args = message.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); //try //{ - if (OnCommandHandler != null) - OnCommandHandler(this, new OnCommandEvent(command, args, message)); + if (OnCommandEvent != null) + OnCommandEvent(this, new OnCommandEvent(command, args, message)); - command.Run(args, message, channel.TrimStart('#'), nick); + command.Run(args, message, channel.TrimStart('#'), ViewerManager.GetViewer(nick)); /*} catch (Exception ex) { diff --git a/Spiffbot/Spiffbot.v12.suo b/Spiffbot/Spiffbot.v12.suo index 866e45a9f88e3b2096d3236da669ec06830d8468..f16d65ef6dbfdaa66920664a6e5ec87bfd75b18d 100644 GIT binary patch delta 5049 zcmb_g3s98T75>jjqF3R1zEA8dqG&BCo)r)(2ut zr`Av_dmC>?V@qkH&6LboHtA;ak|;@?OeQgzX(nysOecM$Ni&U|(#*sr(sTaZl}Ct~ zJTCL?J@=e*&pr3vbI$+&^q)}n52;R+XKt1xNrAXAIXQ`)1c>hZ4%!dQ?CR!^5bP$e&VhOjh$4- zL6Lh1SDH-15%r{*hnN=`6OURpj_-`{ZpVIEgeF(lMrb4UYtY~DjLFFr5xyzXNBOll zE=JH6vm`0$=7bbv*7NMx)I*tQCLc$O5Hu|fd)+kC_eA)1rGb{~8n@AEY! zEI>{HY5DT`#JnX<kry6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iuxc<}LOG^C++|j@_zTkGxYA?s5g2ZynS;~7rk%kJ>m7wQHnkMi zL(fiwwnx&Xt{Je6``@E$8)-uUB9_S{93!L4)2CKMR@6 zP0Wl9J&Hy^ua8EqU%mrWYfL%BcOqUST39?+%-K-m4Hh%1S^uF#rmX?;)ev1Hsxgc5 zI_qg~WYOvxYZg~xi0W?#7JSh?khl`wfp4isYLLBX71b2ZYjG{Ax))^#2_tn#J+c$^ z`%vy@XSSahNW7c5;Q%QgjeAm+L=UjgWc8{hIhoR|SXNg+4x^z4$!E=VS6VA1OO~XD zU!uc9_Ti&cn?9+ZJbn&%@K2Cf;#EmMf2)YK2@7RaE-?v_b<^I|d8 z-}$CjHSQ0>lF4X}!dUUB?>V5xhypPu-}V|D*Jn=`fieFI1Z|_f=YgiXK^iUF0F?XM z;VSwVvp#Zs_rx3=Q}|~;K!_h+gcP6u6g+(FDrD04Ai&4c(81!BMSN}%6#mn1;4wyK zAZFr;WoTs!U$~7fiTbEkHCZpdYyCcXlAw7V-w^B)w!m zd7UJQhba#{1+Xe%6Tf#B|F)D+FVypWCG;F*xZFGxM?}>cT)#fpP}Z7QksJ##}g8yWm?JA9jomQ6DgVnBU?oyuD<}TbF`!Y diff --git a/Spiffbot/Spiffbot/Program.cs b/Spiffbot/Spiffbot/Program.cs index 61cfd0a..3fd16e9 100644 --- a/Spiffbot/Spiffbot/Program.cs +++ b/Spiffbot/Spiffbot/Program.cs @@ -78,7 +78,7 @@ private static void TitleUpdater() { while (!Stopping) { - var viewers = SiteApi.GetChatters(SpiffCore.Instance.Channel).Count; + var viewers = SpiffCore.Instance.ViewerManager.AllViewers.Count; Console.Title = string.Format("Spiffbot - Viewers: {0}", viewers); diff --git a/vjoy/XInputView.source/MainForm.cs b/vjoy/XInputView.source/MainForm.cs index 2d165bd..756ef72 100644 --- a/vjoy/XInputView.source/MainForm.cs +++ b/vjoy/XInputView.source/MainForm.cs @@ -72,6 +72,7 @@ public class MainForm : System.Windows.Forms.Form private string path; public MainForm() { + InitializeComponent(); // Create one joystick object and a position structure. joystick = new vJoy(); iReport = new vJoy.JoystickState(); @@ -263,7 +264,7 @@ private void InitializeComponent() this.iconsToolStripMenuItem, this.exitToolStripMenuItem}); this.contextMenuStrip1.Name = "contextMenuStrip1"; - this.contextMenuStrip1.Size = new System.Drawing.Size(158, 136); + this.contextMenuStrip1.Size = new System.Drawing.Size(158, 114); this.contextMenuStrip1.Opening += new System.ComponentModel.CancelEventHandler(this.contextMenuStrip1_Opening); // // setBackgroundToolStripMenuItem @@ -377,7 +378,7 @@ private void InitializeComponent() // this.basicGreenToolStripMenuItem.CheckOnClick = true; this.basicGreenToolStripMenuItem.Name = "basicGreenToolStripMenuItem"; - this.basicGreenToolStripMenuItem.Size = new System.Drawing.Size(152, 22); + this.basicGreenToolStripMenuItem.Size = new System.Drawing.Size(144, 22); this.basicGreenToolStripMenuItem.Text = "Simple Green"; this.basicGreenToolStripMenuItem.Click += new System.EventHandler(this.basicGreenToolStripMenuItem_Click); // @@ -385,7 +386,7 @@ private void InitializeComponent() // this.basicBlueToolStripMenuItem.CheckOnClick = true; this.basicBlueToolStripMenuItem.Name = "basicBlueToolStripMenuItem"; - this.basicBlueToolStripMenuItem.Size = new System.Drawing.Size(152, 22); + this.basicBlueToolStripMenuItem.Size = new System.Drawing.Size(144, 22); this.basicBlueToolStripMenuItem.Text = "Simple Blue"; this.basicBlueToolStripMenuItem.Click += new System.EventHandler(this.basicBlueToolStripMenuItem_Click); // @@ -393,7 +394,7 @@ private void InitializeComponent() // this.basicRedToolStripMenuItem.CheckOnClick = true; this.basicRedToolStripMenuItem.Name = "basicRedToolStripMenuItem"; - this.basicRedToolStripMenuItem.Size = new System.Drawing.Size(152, 22); + this.basicRedToolStripMenuItem.Size = new System.Drawing.Size(144, 22); this.basicRedToolStripMenuItem.Text = "Simple Red"; this.basicRedToolStripMenuItem.Click += new System.EventHandler(this.basicRedToolStripMenuItem_Click); // @@ -401,7 +402,7 @@ private void InitializeComponent() // this.customToolStripMenuItem.CheckOnClick = true; this.customToolStripMenuItem.Name = "customToolStripMenuItem"; - this.customToolStripMenuItem.Size = new System.Drawing.Size(152, 22); + this.customToolStripMenuItem.Size = new System.Drawing.Size(144, 22); this.customToolStripMenuItem.Text = "Custom"; this.customToolStripMenuItem.Click += new System.EventHandler(this.customToolStripMenuItem_Click); // diff --git a/vjoy/XInputView.source/XInputView.csproj b/vjoy/XInputView.source/XInputView.csproj index 15a68c8..6fb28a1 100644 --- a/vjoy/XInputView.source/XInputView.csproj +++ b/vjoy/XInputView.source/XInputView.csproj @@ -119,6 +119,12 @@ Always + + PreserveNewest + + + PreserveNewest + From ac3bf094bda58af0ac08e74f667d2fae1504d5a4 Mon Sep 17 00:00:00 2001 From: Toyz Date: Tue, 17 Mar 2015 21:44:20 -0700 Subject: [PATCH 07/40] Added Managers for Users and Commands Also removed SUO, working on a Plugin Manager next --- .gitignore | 1 + .../Commands/MouseMouseCommand.cs | 5 +- .../Commands/ReloadConfigSettings.cs | 5 +- .../CustomCommands/Commands/SongCommand.cs | 5 +- .../CustomCommands/Commands/SourceCommand.cs | 5 +- .../DefaultCommands/Commands/AllCommands.cs | 8 +- .../DefaultCommands/Commands/GameCommand.cs | 3 +- .../DefaultCommands/Commands/HelpCommand.cs | 7 +- .../Commands/PluginsCommand.cs | 3 +- .../DefaultCommands/Commands/RandomViewer.cs | 3 +- .../Commands/EditorInterfaceCommand.cs | 5 +- .../Commands/StartQuizCommand.cs | 5 +- .../Spiff.IRC/API/EventArgs/OnCommandEvent.cs | 9 ++- Spiffbot/Spiff.IRC/API/Plugin.cs | 2 +- .../Managers/Commands/CommandManager.cs | 53 +++++++++++++ .../Managers/Commands/CommandObject.cs | 21 ++++++ .../Managers/Viewers/ViewerManager.cs | 10 ++- Spiffbot/Spiff.IRC/Spiff.Core.csproj | 2 + Spiffbot/Spiff.IRC/SpiffCore.cs | 70 ++---------------- Spiffbot/Spiffbot.v12.suo | Bin 167936 -> 0 bytes 20 files changed, 132 insertions(+), 90 deletions(-) create mode 100644 Spiffbot/Spiff.IRC/Managers/Commands/CommandManager.cs create mode 100644 Spiffbot/Spiff.IRC/Managers/Commands/CommandObject.cs delete mode 100644 Spiffbot/Spiffbot.v12.suo diff --git a/.gitignore b/.gitignore index c0b6ff4..ac0a4e6 100644 --- a/.gitignore +++ b/.gitignore @@ -74,4 +74,5 @@ Temporary Items .apdisk *.suo +Spiffbot/Spiffbot.v12.suo Spiffbot/Spiffbot.v12.suo \ No newline at end of file diff --git a/Spiffbot/CustomCommands/Commands/MouseMouseCommand.cs b/Spiffbot/CustomCommands/Commands/MouseMouseCommand.cs index aeba03b..16de1ab 100644 --- a/Spiffbot/CustomCommands/Commands/MouseMouseCommand.cs +++ b/Spiffbot/CustomCommands/Commands/MouseMouseCommand.cs @@ -1,4 +1,5 @@ using Spiff.Core.API.Commands; +using Spiff.Core.Managers.Viewers; using Win32API; namespace CustomCommands.Commands @@ -15,9 +16,9 @@ public override string CommandInfo get { return "Set the mouse's current location on the screen"; } } - public override void Run(string[] parts, string complete, string channel, string nick) + public override void Run(string[] parts, string complete, string channel, Viewer nick) { - if (IsOwner(nick)) + if (IsOwner(nick.Username)) { if (parts.Length < 3) return; diff --git a/Spiffbot/CustomCommands/Commands/ReloadConfigSettings.cs b/Spiffbot/CustomCommands/Commands/ReloadConfigSettings.cs index 149acb1..affc645 100644 --- a/Spiffbot/CustomCommands/Commands/ReloadConfigSettings.cs +++ b/Spiffbot/CustomCommands/Commands/ReloadConfigSettings.cs @@ -1,4 +1,5 @@ using Spiff.Core.API.Commands; +using Spiff.Core.Managers.Viewers; namespace CustomCommands.Commands { @@ -14,9 +15,9 @@ public override string CommandInfo get { return "Reload the config for the song"; } } - public override void Run(string[] parts, string complete, string channel, string nick) + public override void Run(string[] parts, string complete, string channel, Viewer nick) { - if (IsOwner(nick)) + if (IsOwner(nick.Username)) { CustomCommands.ConfigSettings.Refresh(); Boardcast(nick + " has reloaded the config"); diff --git a/Spiffbot/CustomCommands/Commands/SongCommand.cs b/Spiffbot/CustomCommands/Commands/SongCommand.cs index b387dee..0f82350 100644 --- a/Spiffbot/CustomCommands/Commands/SongCommand.cs +++ b/Spiffbot/CustomCommands/Commands/SongCommand.cs @@ -1,5 +1,6 @@ using System.IO; using Spiff.Core.API.Commands; +using Spiff.Core.Managers.Viewers; namespace CustomCommands.Commands { @@ -15,13 +16,13 @@ public override string CommandInfo get { return "Get the current playing song"; } } - public override void Run(string[] parts, string complete, string channel, string nick) + public override void Run(string[] parts, string complete, string channel, Viewer nick) { var file = CustomCommands.ConfigSettings.GetValue("config", "Song_File", "c:\\Path\\To\\Song"); if (File.Exists(file)) { - Boardcast(string.Format("Hey, {0} the current song is: {1}", nick, File.ReadAllText(file))); + Boardcast(string.Format("Hey, {0} the current song is: {1}", nick.Username, File.ReadAllText(file))); } } } diff --git a/Spiffbot/CustomCommands/Commands/SourceCommand.cs b/Spiffbot/CustomCommands/Commands/SourceCommand.cs index 77fdc65..4239598 100644 --- a/Spiffbot/CustomCommands/Commands/SourceCommand.cs +++ b/Spiffbot/CustomCommands/Commands/SourceCommand.cs @@ -1,4 +1,5 @@ using Spiff.Core.API.Commands; +using Spiff.Core.Managers.Viewers; namespace CustomCommands.Commands { @@ -14,9 +15,9 @@ public override string CommandInfo get { return "This is a link to the source code on github"; } } - public override void Run(string[] parts, string complete, string channel, string nick) + public override void Run(string[] parts, string complete, string channel, Viewer nick) { - Boardcast(string.Format("Hey, {0} here is a link to the code: https://github.com/Toyz/SpiffBot/tree/master/Spiffbot", nick)); + Boardcast(string.Format("Hey, {0} here is a link to the code: https://github.com/Toyz/SpiffBot/tree/master/Spiffbot", nick.Username)); } } } diff --git a/Spiffbot/DefaultCommands/Commands/AllCommands.cs b/Spiffbot/DefaultCommands/Commands/AllCommands.cs index e27bf9c..2896c0b 100644 --- a/Spiffbot/DefaultCommands/Commands/AllCommands.cs +++ b/Spiffbot/DefaultCommands/Commands/AllCommands.cs @@ -1,5 +1,7 @@ -using Spiff.Core; +using System.Linq; +using Spiff.Core; using Spiff.Core.API.Commands; +using Spiff.Core.Managers.Viewers; namespace DefaultCommands.Commands { @@ -15,9 +17,9 @@ public override string CommandInfo get { return "Returns a list of all possible commands"; } } - public override void Run(string[] parts, string complete, string channel, string nick) + public override void Run(string[] parts, string complete, string channel, Viewer nick) { - var commands = string.Join(", ", SpiffCore.Instance.AllCommands().Keys); + var commands = string.Join(", ", SpiffCore.Instance.CommandManager.CommandObjects.Select(s => s.CommandName)); Boardcast("All LoadedCommands: " + commands); } diff --git a/Spiffbot/DefaultCommands/Commands/GameCommand.cs b/Spiffbot/DefaultCommands/Commands/GameCommand.cs index ebf8827..ed5a5e0 100644 --- a/Spiffbot/DefaultCommands/Commands/GameCommand.cs +++ b/Spiffbot/DefaultCommands/Commands/GameCommand.cs @@ -1,6 +1,7 @@ using Spiff.Core; using Spiff.Core.API.Commands; using Spiff.Core.API.Twitch; +using Spiff.Core.Managers.Viewers; namespace DefaultCommands.Commands { @@ -16,7 +17,7 @@ public override string CommandInfo get { return "Get's the current game I am playing"; } } - public override void Run(string[] parts, string complete, string channel, string nick) + public override void Run(string[] parts, string complete, string channel, Viewer nick) { var game = SiteApi.GetGame(channel); diff --git a/Spiffbot/DefaultCommands/Commands/HelpCommand.cs b/Spiffbot/DefaultCommands/Commands/HelpCommand.cs index c3ee39d..7ee1ad1 100644 --- a/Spiffbot/DefaultCommands/Commands/HelpCommand.cs +++ b/Spiffbot/DefaultCommands/Commands/HelpCommand.cs @@ -1,5 +1,6 @@ using Spiff.Core; using Spiff.Core.API.Commands; +using Spiff.Core.Managers.Viewers; namespace DefaultCommands.Commands { @@ -15,7 +16,7 @@ public override string CommandInfo get { return "Get the help info for a given command name"; } } - public override void Run(string[] parts, string complete, string channel, string nick) + public override void Run(string[] parts, string complete, string channel, Viewer nick) { if (parts.Length < 2) { @@ -23,9 +24,7 @@ public override void Run(string[] parts, string complete, string channel, string return; } - Command command; - - SpiffCore.Instance.AllCommands().TryGetValue("!" + parts[1], out command); + var command = SpiffCore.Instance.CommandManager.GetCommandObject(CommandName).Command; if (command == null) Boardcast("Command does not exist"); diff --git a/Spiffbot/DefaultCommands/Commands/PluginsCommand.cs b/Spiffbot/DefaultCommands/Commands/PluginsCommand.cs index 9e37dba..9313614 100644 --- a/Spiffbot/DefaultCommands/Commands/PluginsCommand.cs +++ b/Spiffbot/DefaultCommands/Commands/PluginsCommand.cs @@ -2,6 +2,7 @@ using System.Linq; using Spiff.Core; using Spiff.Core.API.Commands; +using Spiff.Core.Managers.Viewers; namespace DefaultCommands.Commands { @@ -17,7 +18,7 @@ public override string CommandInfo get { return "A list of all loaded plugins"; } } - public override void Run(string[] parts, string complete, string channel, string nick) + public override void Run(string[] parts, string complete, string channel, Viewer nick) { List pluginNames = SpiffCore.Instance.PluginLoader.LoadedPlugins.Select(plugin => plugin.Name).ToList(); diff --git a/Spiffbot/DefaultCommands/Commands/RandomViewer.cs b/Spiffbot/DefaultCommands/Commands/RandomViewer.cs index 48f80f4..f22a4f7 100644 --- a/Spiffbot/DefaultCommands/Commands/RandomViewer.cs +++ b/Spiffbot/DefaultCommands/Commands/RandomViewer.cs @@ -2,6 +2,7 @@ using Spiff.Core.API.Commands; using Spiff.Core.API.Twitch; using Spiff.Core.Extensions; +using Spiff.Core.Managers.Viewers; namespace DefaultCommands.Commands { @@ -17,7 +18,7 @@ public override string CommandInfo get { return "Return a random viewer fom the chat"; } } - public override void Run(string[] parts, string complete, string channel, string nick) + public override void Run(string[] parts, string complete, string channel, Viewer nick) { var viewers = SiteApi.GetChatters(channel); diff --git a/Spiffbot/QuizBotPlugin/Commands/EditorInterfaceCommand.cs b/Spiffbot/QuizBotPlugin/Commands/EditorInterfaceCommand.cs index 58e495c..a31860e 100644 --- a/Spiffbot/QuizBotPlugin/Commands/EditorInterfaceCommand.cs +++ b/Spiffbot/QuizBotPlugin/Commands/EditorInterfaceCommand.cs @@ -2,6 +2,7 @@ using System.Windows.Forms; using QuizBotPlugin.Forms; using Spiff.Core.API.Commands; +using Spiff.Core.Managers.Viewers; namespace QuizBotPlugin.Commands { @@ -17,9 +18,9 @@ public override string CommandInfo get { return "This allows the chat owner to add custom quiz/edit current ones"; } } - public override void Run(string[] parts, string complete, string channel, string nick) + public override void Run(string[] parts, string complete, string channel, Viewer nick) { - if (IsOwner(nick)) + if (IsOwner(nick.Username)) { var t = new Thread(() => { Application.Run(new QuizBuilder()); }); diff --git a/Spiffbot/QuizBotPlugin/Commands/StartQuizCommand.cs b/Spiffbot/QuizBotPlugin/Commands/StartQuizCommand.cs index 7ef3e6a..68757b8 100644 --- a/Spiffbot/QuizBotPlugin/Commands/StartQuizCommand.cs +++ b/Spiffbot/QuizBotPlugin/Commands/StartQuizCommand.cs @@ -1,4 +1,5 @@ using Spiff.Core.API.Commands; +using Spiff.Core.Managers.Viewers; namespace QuizBotPlugin.Commands { @@ -14,9 +15,9 @@ public override string CommandInfo get { return "Command to start a give quiz"; } } - public override void Run(string[] parts, string complete, string channel, string nick) + public override void Run(string[] parts, string complete, string channel, Viewer nick) { - if (IsOwner(nick)) + if (IsOwner(nick.Username)) { new QuizMaster(parts[1] + ".xml"); } diff --git a/Spiffbot/Spiff.IRC/API/EventArgs/OnCommandEvent.cs b/Spiffbot/Spiff.IRC/API/EventArgs/OnCommandEvent.cs index f94276c..00e160b 100644 --- a/Spiffbot/Spiff.IRC/API/EventArgs/OnCommandEvent.cs +++ b/Spiffbot/Spiff.IRC/API/EventArgs/OnCommandEvent.cs @@ -1,18 +1,21 @@ using Spiff.Core.API.Commands; +using Spiff.Core.Managers.Viewers; namespace Spiff.Core.API.EventArgs { public class OnCommandEvent : System.EventArgs { - public Command Command { get; private set; } + public string CommandName { get; private set; } public string[] Args { get; private set; } public string Complete { get; private set; } + public Viewer Nick { get; private set; } - public OnCommandEvent(Command command, string[] args, string complete) + public OnCommandEvent(string commandName, string[] args, string complete, Viewer viewer) { - Command = command; + CommandName = commandName; Args = args; Complete = complete; + Nick = viewer; } } diff --git a/Spiffbot/Spiff.IRC/API/Plugin.cs b/Spiffbot/Spiff.IRC/API/Plugin.cs index bda794e..71a1a1a 100644 --- a/Spiffbot/Spiff.IRC/API/Plugin.cs +++ b/Spiffbot/Spiff.IRC/API/Plugin.cs @@ -66,7 +66,7 @@ public string PluginDirectory protected void RegisterCommand(Command command) { - SpiffCore.Instance.AddCommand(command); + SpiffCore.Instance.CommandManager.RegisterCommand(command); } protected Plugin GetPlugin(string name) diff --git a/Spiffbot/Spiff.IRC/Managers/Commands/CommandManager.cs b/Spiffbot/Spiff.IRC/Managers/Commands/CommandManager.cs new file mode 100644 index 0000000..09938eb --- /dev/null +++ b/Spiffbot/Spiff.IRC/Managers/Commands/CommandManager.cs @@ -0,0 +1,53 @@ +using System.Collections.Generic; +using System.Linq; +using Spiff.Core.API.EventArgs; +using Spiff.Core.Managers.Command; +using Spiff.Core.Utils; + +namespace Spiff.Core.Managers.Commands +{ + public class CommandManager + { + private readonly SpiffCore _spiffCore; + public List CommandObjects { get; private set; } + + public CommandManager(SpiffCore spiffCore) + { + _spiffCore = spiffCore; + CommandObjects = new List(); + + _spiffCore.OnCommandEvent += SpiffCoreOnOnCommandEvent; + } + + private void SpiffCoreOnOnCommandEvent(object sender, OnCommandEvent onCommandEvent) + { + var command = (from s in CommandObjects where s.CommandName == onCommandEvent.CommandName.TrimStart('!') select s).FirstOrDefault(); + + if (command != null) + { + command.Command.Run(onCommandEvent.Args, onCommandEvent.Complete, _spiffCore.Channel, onCommandEvent.Nick); + } + } + + public CommandObject GetCommandObject(string command) + { + return (from s in CommandObjects where s.CommandName == command.TrimStart('!') select s).FirstOrDefault(); + } + + public void RegisterCommand(API.Commands.Command command) + { + var cmd = (from s in CommandObjects where s.CommandName == command.CommandName select s).FirstOrDefault(); + + if (cmd == null) + CommandObjects.Add(new CommandObject(command)); + } + + public void DeregisterCommand(API.Commands.Command command) + { + var cmd = (from s in CommandObjects where s.CommandName == command.CommandName select s).FirstOrDefault(); + + if(cmd != null) + CommandObjects.Remove(cmd); + } + } +} diff --git a/Spiffbot/Spiff.IRC/Managers/Commands/CommandObject.cs b/Spiffbot/Spiff.IRC/Managers/Commands/CommandObject.cs new file mode 100644 index 0000000..21bf019 --- /dev/null +++ b/Spiffbot/Spiff.IRC/Managers/Commands/CommandObject.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Spiff.Core.Managers.Command +{ + public class CommandObject + { + public string CommandName { get; set; } + public string CommandInfo { get; set; } + public API.Commands.Command Command { get; set; } + + public CommandObject(API.Commands.Command command) + { + CommandName = command.CommandName; + CommandInfo = command.CommandInfo; + Command = command; + } + } +} diff --git a/Spiffbot/Spiff.IRC/Managers/Viewers/ViewerManager.cs b/Spiffbot/Spiff.IRC/Managers/Viewers/ViewerManager.cs index 76a0940..4caf8ff 100644 --- a/Spiffbot/Spiff.IRC/Managers/Viewers/ViewerManager.cs +++ b/Spiffbot/Spiff.IRC/Managers/Viewers/ViewerManager.cs @@ -58,7 +58,15 @@ public void RemoveMod(string nick) public Viewer GetViewer(string nick) { - return (from s in AllViewers where String.Equals(s.Username, nick, StringComparison.CurrentCultureIgnoreCase) select s).FirstOrDefault(); + var viewer = (from s in AllViewers where String.Equals(s.Username, nick, StringComparison.CurrentCultureIgnoreCase) select s).FirstOrDefault(); + + if (viewer == null) + { + viewer = new Viewer(nick, false, DateTime.Now); + AllViewers.Add(viewer); + } + + return viewer; } } } diff --git a/Spiffbot/Spiff.IRC/Spiff.Core.csproj b/Spiffbot/Spiff.IRC/Spiff.Core.csproj index 5449ef0..1aaeedf 100644 --- a/Spiffbot/Spiff.IRC/Spiff.Core.csproj +++ b/Spiffbot/Spiff.IRC/Spiff.Core.csproj @@ -49,6 +49,8 @@ + + diff --git a/Spiffbot/Spiff.IRC/SpiffCore.cs b/Spiffbot/Spiff.IRC/SpiffCore.cs index 4ade8a4..a562d24 100644 --- a/Spiffbot/Spiff.IRC/SpiffCore.cs +++ b/Spiffbot/Spiff.IRC/SpiffCore.cs @@ -5,6 +5,7 @@ using Spiff.Core.API.Commands; using Spiff.Core.API.EventArgs; using Spiff.Core.IRC; +using Spiff.Core.Managers.Commands; using Spiff.Core.Managers.Viewers; using Spiff.Core.Utils; @@ -26,11 +27,11 @@ public class SpiffCore public event EventHandler OnCommandEvent; //Command List - public Dictionary LoadedCommands {get; private set; } public PluginLoader PluginLoader { get; private set; } - //Viewer Managers + //Managers public ViewerManager ViewerManager { get; private set; } + public CommandManager CommandManager { get; private set; } //Instance public static SpiffCore Instance { get; private set; } @@ -43,12 +44,12 @@ public SpiffCore(string channel, string botName, string outh, string pluginDirec Channel = channel; BotName = botName; PluginLoader = new PluginLoader(pluginDirectory); - LoadedCommands = new Dictionary(); IrcClient = new IRCClient(channel, botName, outh, this); IrcClient.OnTwitchEvent += IrcClientOnOnTwitchEvent; AppDomain.CurrentDomain.AssemblyResolve += CurrentDomainOnAssemblyResolve; ViewerManager = new ViewerManager(this); + CommandManager = new CommandManager(this); Instance = this; } @@ -59,47 +60,6 @@ private Assembly CurrentDomainOnAssemblyResolve(object sender, ResolveEventArgs return PluginLoader.GetAsm(args.Name); } - #region Publics - public void AddCommand(Command command) - { - Command outcommand; - LoadedCommands.TryGetValue("!" + command.CommandName, out outcommand); - - if (outcommand == null) - { - LoadedCommands.Add("!" + command.CommandName, command); - } - } - - public void RemoveCommand(Command command) - { - Command outcommand; - LoadedCommands.TryGetValue("!" + command.CommandName, out outcommand); - - if (outcommand == null) - { - LoadedCommands.Remove("!" + command.CommandName); - } - } - - public void RemoveCommand(string command) - { - Command outcommand; - LoadedCommands.TryGetValue("!" + command, out outcommand); - - if (outcommand == null) - { - LoadedCommands.Remove("!" + command); - } - } - - public Dictionary AllCommands() - { - return LoadedCommands; - } - - #endregion - #region Privates private void IrcClientOnOnTwitchEvent(object sender, TwitchEvent twitchEvent) { @@ -154,25 +114,9 @@ private void IrcClientOnOnTwitchEvent(object sender, TwitchEvent twitchEvent) if (message.StartsWith("!")) { - Command command; - LoadedCommands.TryGetValue(message.Split(' ')[0], out command); - - if (command != null) - { - var args = message.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); - //try - //{ - if (OnCommandEvent != null) - OnCommandEvent(this, new OnCommandEvent(command, args, message)); - - command.Run(args, message, channel.TrimStart('#'), ViewerManager.GetViewer(nick)); - /*} - catch (Exception ex) - { - RemoveCommand(command); - Logger.Error("Error in Running Command: " + ex, "Plugin Command Error"); - }*/ - } + var args = message.Split(new[] {' '}, StringSplitOptions.RemoveEmptyEntries); + if (OnCommandEvent != null) + OnCommandEvent(this, new OnCommandEvent(message.Split(' ')[0], args, message, ViewerManager.GetViewer(nick))); } } } diff --git a/Spiffbot/Spiffbot.v12.suo b/Spiffbot/Spiffbot.v12.suo deleted file mode 100644 index f16d65ef6dbfdaa66920664a6e5ec87bfd75b18d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 167936 zcmeHQ31C#!)qVj%78g`h6vd#ppiY`)5)wdRGD#o`vIG$8s7zJ{vYDBH2w1g?OVPG! z)grF7)>?~eU2v(j?zJxcYpeck)xTQ1sCB8w#Z;}qq~xZerz-|gGC^Hl-h z6u_wfJn~!~U|_M*g}<0msMIQ*@OzYXs6F>?A7w;eT_5i7+3cg=xu-b%LcwVWH#;l> zFGPx6$||KEskh>)Ryo5V7W3)TzIeKQdp+(;0L;q)hIf17dcNUahTjiy9)af*wRd~NFEpfclJ-1^ zXJfQ$ejCuPtKrw+-O=#pY0uaW>a^?S@M{1;z@dPd03)7cKCJxx5Ox>9$$$xfy#T~F zVIQO!#(g883D68^0ki_z04o6zz$yUijP0fa&1xy!F zs`;=_S-f3`z?tm-`y$$@DWrb}(&uV*#~*0Dyg&{oe-|4Pg9pHJ{fD4A;Cj zx`lYR2(TE?09XQ83Rng>5wHu9U^gM|v2rs(-Hy zq=(ad`g#E>`)D6!-h#DB3^X3s zr3}emt~P|5j`b(YO`6Yb`8mJH?`sfm6ULwpE#?!|QK%VD*CGd9NGX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PMTtGs-rZAYyl0&=~~nTT5CPLwS0dHdL-tV+xR}&Q{FETH|$M%~86P zYGO4*WEC|g*thUn(vME13;wghw78=30ofss@|}mf3oNMw zCF6H~S{RIHBWE@?1M<~NQ71DEk0E-XOabH!KPMA>X$#{iX;qS4o=zIDm<_e0UW&@w zQH`f$3e6TqNKYQXxUDO3NE%P+2Nn};tJY>D7Hg~&4Up%?Q_{hfG!0vmiAapN z<+T{B5}%rlf5gAvG4HKp2UD^CEwM%p|Ji`-YOppzfib`J|Ff%YoqPJ&UyY zf0JncTiU{Qg3h}el22Q;jMtZqk9u&cejr71>h_(e3L z6bm=Dw~(DbhSpH)!c8&H{x_A$n^iS?&;B>hhU>;0Xgt7E*a{ga``=wXJ1>KfJX+`| z>?3!Fds=$NrDFeU>?o_YUN7UCV$l)mjqzWYrvAm2G`~;B{>@U*4)P$;1u%gT!wG)! ziKw-|JhQ&+`S26oUev$nnU|r=<@$ZwzMnX@4pm{7L&& z=JrmbALb_lm!AFaka9X&SwuM#cF>A&tZoNJi*)UOtM>igSyZVSUm7!pTVk9~ouR^(SFMeySn%wBqZP)mFVU;~ EKMI>eq5uE@ From 69e8be5d3ec45410f0a6c14a331e6d1e2f3fd589 Mon Sep 17 00:00:00 2001 From: Toyz Date: Tue, 17 Mar 2015 21:57:31 -0700 Subject: [PATCH 08/40] Fixed the test plugin for cross plugin loading --- Spiffbot/CustomCommands/CustomCommands.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Spiffbot/CustomCommands/CustomCommands.cs b/Spiffbot/CustomCommands/CustomCommands.cs index 727010d..4a0b8c3 100644 --- a/Spiffbot/CustomCommands/CustomCommands.cs +++ b/Spiffbot/CustomCommands/CustomCommands.cs @@ -37,7 +37,7 @@ public override void Start() ConfigSettings.Flush(); } - Logger.Debug("Is Default Plugin Set: " + ((DefaultCommands.DefaultCommands)GetPlugin("Default LoadedCommands") != null), Name); + Logger.Debug("Is Default Plugin Set: " + ((DefaultCommands.DefaultCommands)GetPlugin("Default Commands") != null), Name); RegisterCommand(new SourceCommand()); RegisterCommand(new SongCommand()); RegisterCommand(new ReloadConfigSettings()); From 4a667f042de6205419a080ffe2926a6a428269dd Mon Sep 17 00:00:00 2001 From: Toyz Date: Tue, 17 Mar 2015 23:56:55 -0700 Subject: [PATCH 09/40] Added basic scareystuff plugin Changed a few things in IRC also --- .../ScareyStuff/Commands/ReloadCommand.cs | 32 ++++++++++ Spiffbot/ScareyStuff/Commands/SoundCommand.cs | 49 +++++++++++++++ .../ScareyStuff/Properties/AssemblyInfo.cs | 36 +++++++++++ Spiffbot/ScareyStuff/ScareyStuff.cs | 51 +++++++++++++++ Spiffbot/ScareyStuff/ScareyStuff.csproj | 62 +++++++++++++++++++ Spiffbot/ScareyStuff/Utils.cs | 30 +++++++++ Spiffbot/Spiff.IRC/IRC/IRCClient.cs | 12 ++-- .../IRC/{TwitchEvent.cs => IrcDataEvent.cs} | 4 +- Spiffbot/Spiff.IRC/Spiff.Core.csproj | 4 +- Spiffbot/Spiff.IRC/SpiffCore.cs | 26 ++++---- Spiffbot/Spiffbot.sln | 9 +++ Spiffbot/Spiffbot/Program.cs | 4 +- 12 files changed, 295 insertions(+), 24 deletions(-) create mode 100644 Spiffbot/ScareyStuff/Commands/ReloadCommand.cs create mode 100644 Spiffbot/ScareyStuff/Commands/SoundCommand.cs create mode 100644 Spiffbot/ScareyStuff/Properties/AssemblyInfo.cs create mode 100644 Spiffbot/ScareyStuff/ScareyStuff.cs create mode 100644 Spiffbot/ScareyStuff/ScareyStuff.csproj create mode 100644 Spiffbot/ScareyStuff/Utils.cs rename Spiffbot/Spiff.IRC/IRC/{TwitchEvent.cs => IrcDataEvent.cs} (65%) diff --git a/Spiffbot/ScareyStuff/Commands/ReloadCommand.cs b/Spiffbot/ScareyStuff/Commands/ReloadCommand.cs new file mode 100644 index 0000000..60e397c --- /dev/null +++ b/Spiffbot/ScareyStuff/Commands/ReloadCommand.cs @@ -0,0 +1,32 @@ +using Spiff.Core.API.Commands; +using Spiff.Core.Managers.Viewers; + +namespace ScareyStuff.Commands +{ + public class ReloadCommand : Command + { + private readonly ScareyStuff _scareyStuff; + + public override string CommandName + { + get { return "ssreload"; } + } + + public override string CommandInfo + { + get { return "Reload the configs for ScareyStuff"; } + } + + public ReloadCommand(ScareyStuff scareyStuff) + { + _scareyStuff = scareyStuff; + } + + public override void Run(string[] parts, string complete, string channel, Viewer nick) + { + if (!IsOwner(nick.Username)) return; + _scareyStuff.ScareySounds.Refresh(); + Boardcast("Reloaded Scarey Sounds"); + } + } +} diff --git a/Spiffbot/ScareyStuff/Commands/SoundCommand.cs b/Spiffbot/ScareyStuff/Commands/SoundCommand.cs new file mode 100644 index 0000000..dd05a3d --- /dev/null +++ b/Spiffbot/ScareyStuff/Commands/SoundCommand.cs @@ -0,0 +1,49 @@ +using System.IO; +using Spiff.Core.API.Commands; +using Spiff.Core.Managers.Viewers; + +namespace ScareyStuff.Commands +{ + public class SoundCommand : Command + { + private readonly ScareyStuff _scareyStuff; + + public override string CommandName + { + get { return "ssound"; } + } + + public override string CommandInfo + { + get { return "Play a scarey sound!"; } + } + + public SoundCommand(ScareyStuff scareyStuff) + { + _scareyStuff = scareyStuff; + } + + public override void Run(string[] parts, string complete, string channel, Viewer nick) + { + if (parts.Length < 2) + { + Boardcast("Usage: !ssound name"); + return; + } + + var sound = _scareyStuff.ScareySounds.GetValue("Sound", parts[1], string.Empty); + + if (string.IsNullOrEmpty(sound)) + { + Boardcast("Sound does not exist"); + return; + } + + if (File.Exists(Path.Combine(_scareyStuff.PluginDirectory, sound))) + { + Utils u = new Utils(Path.Combine(_scareyStuff.PluginDirectory, sound)); + u.Play(); + } + } + } +} diff --git a/Spiffbot/ScareyStuff/Properties/AssemblyInfo.cs b/Spiffbot/ScareyStuff/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..491275a --- /dev/null +++ b/Spiffbot/ScareyStuff/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("ScareyStuff")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("ScareyStuff")] +[assembly: AssemblyCopyright("Copyright © 2015")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("354d378b-ddbd-4daf-8ebf-bb413d7e5121")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Spiffbot/ScareyStuff/ScareyStuff.cs b/Spiffbot/ScareyStuff/ScareyStuff.cs new file mode 100644 index 0000000..ad90682 --- /dev/null +++ b/Spiffbot/ScareyStuff/ScareyStuff.cs @@ -0,0 +1,51 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using ScareyStuff.Commands; +using Spiff.Core.API; +using Spiff.Core.Utils; + +namespace ScareyStuff +{ + public class ScareyStuff : Plugin + { + public override string Name + { + get { return "ScareyStuff"; } + } + + public override string Author + { + get { return "Toyz"; } + } + + public override string Description + { + get { return "A list of scarey triggers for SpiffBot"; } + } + + public override int Version + { + get { return 1; } + } + + private Ini _scareySounds; + public Ini ScareySounds + { + get { return _scareySounds; } + } + public override void Start() + { + _scareySounds = new Ini(Path.Combine(PluginDirectory, "Sounds.ini")); + RegisterCommand(new ReloadCommand(this)); + RegisterCommand(new SoundCommand(this)); + } + + public override void Destory() + { + Logger.Info("Going offline now D:", Name); + } + } +} diff --git a/Spiffbot/ScareyStuff/ScareyStuff.csproj b/Spiffbot/ScareyStuff/ScareyStuff.csproj new file mode 100644 index 0000000..3c0fbb0 --- /dev/null +++ b/Spiffbot/ScareyStuff/ScareyStuff.csproj @@ -0,0 +1,62 @@ + + + + + Debug + AnyCPU + {C5760B4A-7D47-4BDE-B751-7290873C95C0} + Library + Properties + ScareyStuff + ScareyStuff + v4.0 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + {5FBAAAEE-E98C-46BB-AF7C-01C8540ECFF2} + Spiff.Core + + + + + \ No newline at end of file diff --git a/Spiffbot/ScareyStuff/Utils.cs b/Spiffbot/ScareyStuff/Utils.cs new file mode 100644 index 0000000..2565c22 --- /dev/null +++ b/Spiffbot/ScareyStuff/Utils.cs @@ -0,0 +1,30 @@ +using System; +using System.Runtime.InteropServices; +using System.Text; + +namespace ScareyStuff +{ + public class Utils + { + [DllImport("winmm.dll")] + private static extern int mciSendString(string mciCommand, StringBuilder buffer, int bufferSize, IntPtr callback); + + private readonly string _fileName; + + public void Send(string mciCommand) + { + mciSendString(mciCommand, null, 0, IntPtr.Zero); + } + + public Utils(string fileLocation) + { + _fileName = fileLocation; + Send("open " + _fileName); + } + + public void Play() + { + Send("play " + _fileName); + } + } +} diff --git a/Spiffbot/Spiff.IRC/IRC/IRCClient.cs b/Spiffbot/Spiff.IRC/IRC/IRCClient.cs index 5b6da56..2cffa07 100644 --- a/Spiffbot/Spiff.IRC/IRC/IRCClient.cs +++ b/Spiffbot/Spiff.IRC/IRC/IRCClient.cs @@ -7,7 +7,7 @@ namespace Spiff.Core.IRC { - public class IRCClient + public class IrcClient { private readonly string _channel; private readonly string _user; @@ -18,10 +18,10 @@ public class IRCClient private StreamReader _reader; private StreamWriter _streamWriter; - public event EventHandler OnTwitchEvent; - public event EventHandler OnTwitchDataDebugOut; + public event EventHandler OnTwitchEvent; + public event EventHandler OnTwitchDataDebugOut; - public IRCClient(string channel, string user, string oauth, SpiffCore twitch) + public IrcClient(string channel, string user, string oauth, SpiffCore twitch) { _channel = channel; _user = user; @@ -81,10 +81,10 @@ private void Listener() } if(OnTwitchEvent != null) - OnTwitchEvent(this, new TwitchEvent(data)); + OnTwitchEvent(this, new IrcDataEvent(data)); if (OnTwitchDataDebugOut != null) - OnTwitchDataDebugOut(this, new TwitchEvent(data)); + OnTwitchDataDebugOut(this, new IrcDataEvent(data)); } } } diff --git a/Spiffbot/Spiff.IRC/IRC/TwitchEvent.cs b/Spiffbot/Spiff.IRC/IRC/IrcDataEvent.cs similarity index 65% rename from Spiffbot/Spiff.IRC/IRC/TwitchEvent.cs rename to Spiffbot/Spiff.IRC/IRC/IrcDataEvent.cs index cee58fb..4816705 100644 --- a/Spiffbot/Spiff.IRC/IRC/TwitchEvent.cs +++ b/Spiffbot/Spiff.IRC/IRC/IrcDataEvent.cs @@ -2,11 +2,11 @@ namespace Spiff.Core.IRC { - public class TwitchEvent : EventArgs + public class IrcDataEvent : EventArgs { public string Payload { get; private set; } - public TwitchEvent(string payload) + public IrcDataEvent(string payload) { Payload = payload; } diff --git a/Spiffbot/Spiff.IRC/Spiff.Core.csproj b/Spiffbot/Spiff.IRC/Spiff.Core.csproj index 1aaeedf..0a8f813 100644 --- a/Spiffbot/Spiff.IRC/Spiff.Core.csproj +++ b/Spiffbot/Spiff.IRC/Spiff.Core.csproj @@ -60,8 +60,8 @@ - - + + diff --git a/Spiffbot/Spiff.IRC/SpiffCore.cs b/Spiffbot/Spiff.IRC/SpiffCore.cs index a562d24..96fd01e 100644 --- a/Spiffbot/Spiff.IRC/SpiffCore.cs +++ b/Spiffbot/Spiff.IRC/SpiffCore.cs @@ -1,8 +1,6 @@ using System; -using System.Collections.Generic; using System.Reflection; using Spiff.Core.API; -using Spiff.Core.API.Commands; using Spiff.Core.API.EventArgs; using Spiff.Core.IRC; using Spiff.Core.Managers.Commands; @@ -37,14 +35,14 @@ public class SpiffCore public static SpiffCore Instance { get; private set; } //Server IRC stuff - public IRCClient IrcClient; + public IrcClient IrcClient; public SpiffCore(string channel, string botName, string outh, string pluginDirectory) { Channel = channel; BotName = botName; PluginLoader = new PluginLoader(pluginDirectory); - IrcClient = new IRCClient(channel, botName, outh, this); + IrcClient = new IrcClient(channel, botName, outh, this); IrcClient.OnTwitchEvent += IrcClientOnOnTwitchEvent; AppDomain.CurrentDomain.AssemblyResolve += CurrentDomainOnAssemblyResolve; @@ -61,9 +59,9 @@ private Assembly CurrentDomainOnAssemblyResolve(object sender, ResolveEventArgs } #region Privates - private void IrcClientOnOnTwitchEvent(object sender, TwitchEvent twitchEvent) + private void IrcClientOnOnTwitchEvent(object sender, IrcDataEvent ircDataEvent) { - var data = twitchEvent.Payload; + var data = ircDataEvent.Payload; var message = ""; var split1 = data.Split(':'); @@ -110,14 +108,18 @@ private void IrcClientOnOnTwitchEvent(object sender, TwitchEvent twitchEvent) OnUserLeftEvent(this, new OnUserLeftEvent(nick, channel)); Logger.Info(string.Format("{0} has left the chat", nick), "Left Chat"); break; + case "QUIT": + if (channel.StartsWith("#")) + if (OnUserLeftEvent != null) + OnUserLeftEvent(this, new OnUserLeftEvent(nick, channel)); + Logger.Info(string.Format("{0} has left the chat", nick), "Left Chat"); + break; } - if (message.StartsWith("!")) - { - var args = message.Split(new[] {' '}, StringSplitOptions.RemoveEmptyEntries); - if (OnCommandEvent != null) - OnCommandEvent(this, new OnCommandEvent(message.Split(' ')[0], args, message, ViewerManager.GetViewer(nick))); - } + if (!message.StartsWith("!")) return; + var args = message.Split(new[] {' '}, StringSplitOptions.RemoveEmptyEntries); + if (OnCommandEvent != null) + OnCommandEvent(this, new OnCommandEvent(message.Split(' ')[0], args, message, ViewerManager.GetViewer(nick))); } } #endregion diff --git a/Spiffbot/Spiffbot.sln b/Spiffbot/Spiffbot.sln index 58e63f9..d8b3fd5 100644 --- a/Spiffbot/Spiffbot.sln +++ b/Spiffbot/Spiffbot.sln @@ -19,6 +19,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "QuizBot", "QuizBot", "{E603 EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QuizBotPlugin", "QuizBotPlugin\QuizBotPlugin.csproj", "{49C769A1-613B-4DDD-AF87-5F02518CBD7C}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Spiff Plugins", "Spiff Plugins", "{5D2FA251-DD06-4130-BE4B-1F01028E3769}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ScareyStuff", "ScareyStuff\ScareyStuff.csproj", "{C5760B4A-7D47-4BDE-B751-7290873C95C0}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -49,6 +53,10 @@ Global {49C769A1-613B-4DDD-AF87-5F02518CBD7C}.Debug|Any CPU.Build.0 = Debug|Any CPU {49C769A1-613B-4DDD-AF87-5F02518CBD7C}.Release|Any CPU.ActiveCfg = Release|Any CPU {49C769A1-613B-4DDD-AF87-5F02518CBD7C}.Release|Any CPU.Build.0 = Release|Any CPU + {C5760B4A-7D47-4BDE-B751-7290873C95C0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C5760B4A-7D47-4BDE-B751-7290873C95C0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C5760B4A-7D47-4BDE-B751-7290873C95C0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C5760B4A-7D47-4BDE-B751-7290873C95C0}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -59,5 +67,6 @@ Global {44219821-25D1-4165-85D6-B793237E74BA} = {FDF62C49-7D07-4B2E-B0A6-6D8B243AB8FA} {E60366F1-423A-4DAE-937B-AAFA1BDA0CDA} = {FDF62C49-7D07-4B2E-B0A6-6D8B243AB8FA} {49C769A1-613B-4DDD-AF87-5F02518CBD7C} = {E60366F1-423A-4DAE-937B-AAFA1BDA0CDA} + {C5760B4A-7D47-4BDE-B751-7290873C95C0} = {5D2FA251-DD06-4130-BE4B-1F01028E3769} EndGlobalSection EndGlobal diff --git a/Spiffbot/Spiffbot/Program.cs b/Spiffbot/Spiffbot/Program.cs index 3fd16e9..3a61919 100644 --- a/Spiffbot/Spiffbot/Program.cs +++ b/Spiffbot/Spiffbot/Program.cs @@ -66,11 +66,11 @@ private static void ConsoleOnCancelKeyPress(object sender, ConsoleCancelEventArg SpiffCore.Instance.IrcClient.ServerThread().Abort(); } - private static void IrcClientOnOnTwitchDataDebugOut(object sender, TwitchEvent twitchEvent) + private static void IrcClientOnOnTwitchDataDebugOut(object sender, IrcDataEvent ircDataEvent) { if (ConfigFile.GetValue("adv", "debug", false)) { - Logger.Debug(twitchEvent.Payload, "Debug"); + Logger.Debug(ircDataEvent.Payload, "Debug"); } } From 06b0f7f02e879860f206a6c606876e320c9ca62e Mon Sep 17 00:00:00 2001 From: Toyz Date: Wed, 18 Mar 2015 10:15:40 -0700 Subject: [PATCH 10/40] Put events in a task factory This should speed up the server thread as events that have long running parts can lock out the thread --- .../API/EventArgs/OnUserJoinEvent.cs | 8 ++-- .../API/EventArgs/OnUserLeftEvent.cs | 8 ++-- .../Managers/Commands/CommandManager.cs | 27 +++++------- .../Managers/Viewers/ViewerManager.cs | 44 +++++++++++-------- Spiffbot/Spiff.IRC/SpiffCore.cs | 27 +++++++++--- 5 files changed, 70 insertions(+), 44 deletions(-) diff --git a/Spiffbot/Spiff.IRC/API/EventArgs/OnUserJoinEvent.cs b/Spiffbot/Spiff.IRC/API/EventArgs/OnUserJoinEvent.cs index 1c155bb..82f265a 100644 --- a/Spiffbot/Spiff.IRC/API/EventArgs/OnUserJoinEvent.cs +++ b/Spiffbot/Spiff.IRC/API/EventArgs/OnUserJoinEvent.cs @@ -1,11 +1,13 @@ -namespace Spiff.Core.API.EventArgs +using Spiff.Core.Managers.Viewers; + +namespace Spiff.Core.API.EventArgs { public class OnUserJoinEvent : System.EventArgs { - public string Nick { get; private set; } + public Viewer Nick { get; private set; } public string Channel { get; private set; } - public OnUserJoinEvent(string nick, string channel) + public OnUserJoinEvent(Viewer nick, string channel) { Nick = nick; Channel = channel; diff --git a/Spiffbot/Spiff.IRC/API/EventArgs/OnUserLeftEvent.cs b/Spiffbot/Spiff.IRC/API/EventArgs/OnUserLeftEvent.cs index aa4f331..915de3e 100644 --- a/Spiffbot/Spiff.IRC/API/EventArgs/OnUserLeftEvent.cs +++ b/Spiffbot/Spiff.IRC/API/EventArgs/OnUserLeftEvent.cs @@ -1,11 +1,13 @@ -namespace Spiff.Core.API.EventArgs +using Spiff.Core.Managers.Viewers; + +namespace Spiff.Core.API.EventArgs { public class OnUserLeftEvent : System.EventArgs { public string Channel { get; private set; } - public string Nick { get; private set; } + public Viewer Nick { get; private set; } - public OnUserLeftEvent(string nick, string channel) + public OnUserLeftEvent(Viewer nick, string channel) { Channel = channel; Nick = nick; diff --git a/Spiffbot/Spiff.IRC/Managers/Commands/CommandManager.cs b/Spiffbot/Spiff.IRC/Managers/Commands/CommandManager.cs index 09938eb..7caad08 100644 --- a/Spiffbot/Spiff.IRC/Managers/Commands/CommandManager.cs +++ b/Spiffbot/Spiff.IRC/Managers/Commands/CommandManager.cs @@ -1,8 +1,7 @@ using System.Collections.Generic; using System.Linq; -using Spiff.Core.API.EventArgs; using Spiff.Core.Managers.Command; -using Spiff.Core.Utils; +using Spiff.Core.Managers.Viewers; namespace Spiff.Core.Managers.Commands { @@ -15,23 +14,11 @@ public CommandManager(SpiffCore spiffCore) { _spiffCore = spiffCore; CommandObjects = new List(); - - _spiffCore.OnCommandEvent += SpiffCoreOnOnCommandEvent; - } - - private void SpiffCoreOnOnCommandEvent(object sender, OnCommandEvent onCommandEvent) - { - var command = (from s in CommandObjects where s.CommandName == onCommandEvent.CommandName.TrimStart('!') select s).FirstOrDefault(); - - if (command != null) - { - command.Command.Run(onCommandEvent.Args, onCommandEvent.Complete, _spiffCore.Channel, onCommandEvent.Nick); - } } public CommandObject GetCommandObject(string command) { - return (from s in CommandObjects where s.CommandName == command.TrimStart('!') select s).FirstOrDefault(); + return (from s in CommandObjects where Equals(s.CommandName.ToLower(), command.ToLower().TrimStart('!')) select s).FirstOrDefault(); } public void RegisterCommand(API.Commands.Command command) @@ -49,5 +36,15 @@ public void DeregisterCommand(API.Commands.Command command) if(cmd != null) CommandObjects.Remove(cmd); } + + public void RunCommand(string commandName, string[] args, string message, Viewer getViewer) + { + var command = (from s in CommandObjects where Equals(s.CommandName.ToLower(), commandName.ToLower().TrimStart('!')) select s).FirstOrDefault(); + + if (command != null) + { + command.Command.Run(args, message, _spiffCore.Channel, getViewer); + } + } } } diff --git a/Spiffbot/Spiff.IRC/Managers/Viewers/ViewerManager.cs b/Spiffbot/Spiff.IRC/Managers/Viewers/ViewerManager.cs index 4caf8ff..016b256 100644 --- a/Spiffbot/Spiff.IRC/Managers/Viewers/ViewerManager.cs +++ b/Spiffbot/Spiff.IRC/Managers/Viewers/ViewerManager.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using Spiff.Core.API.EventArgs; namespace Spiff.Core.Managers.Viewers { @@ -14,26 +13,40 @@ public ViewerManager(SpiffCore spiffCore) { _spiffCore = spiffCore; AllViewers = new List(); + } + + public Viewer AddViewer(string nick) + { + var viewer = (from s in AllViewers where s.Username == _spiffCore.BotName select s).FirstOrDefault(); + + if (viewer != null) return null; + var owner = nick.ToLower().Equals(_spiffCore.Channel.Replace("#", "").ToLower()); - _spiffCore.OnUserJoinEvent += SpiffCoreOnOnUserJoinEvent; - _spiffCore.OnUserLeftEvent += SpiffCoreOnOnUserLeftEvent; + viewer = new Viewer(nick, owner, DateTime.Now); + AllViewers.Add(viewer); + + return viewer; } - private void SpiffCoreOnOnUserLeftEvent(object sender, OnUserLeftEvent onUserLeftEvent) + public Viewer AddViewer(Viewer viewer) { - var viewer = (from s in AllViewers where s.Username == onUserLeftEvent.Nick select s).FirstOrDefault(); + if (AllViewers.Contains(viewer)) return null; + AllViewers.Add(viewer); + return viewer; + } + + public void RemoveViewer(string nick) + { + var viewer = (from s in AllViewers where String.Equals(s.Username, nick, StringComparison.CurrentCultureIgnoreCase) select s).FirstOrDefault(); if (viewer == null) return; AllViewers.Remove(viewer); } - private void SpiffCoreOnOnUserJoinEvent(object sender, OnUserJoinEvent onUserJoinEvent) + public void RemoveViewer(Viewer viewer) { - var viewer = (from s in AllViewers where s.Username == _spiffCore.BotName select s).FirstOrDefault(); - - if (viewer != null) return; - var owner = onUserJoinEvent.Nick.ToLower().Equals(onUserJoinEvent.Channel.Replace("#", "").ToLower()); - AllViewers.Add(new Viewer(onUserJoinEvent.Nick, owner, DateTime.Now)); + if (AllViewers.Contains(viewer)) return; + AllViewers.Remove(viewer); } public void SetMod(string nick) @@ -58,13 +71,8 @@ public void RemoveMod(string nick) public Viewer GetViewer(string nick) { - var viewer = (from s in AllViewers where String.Equals(s.Username, nick, StringComparison.CurrentCultureIgnoreCase) select s).FirstOrDefault(); - - if (viewer == null) - { - viewer = new Viewer(nick, false, DateTime.Now); - AllViewers.Add(viewer); - } + var viewer = (from s in AllViewers where String.Equals(s.Username, nick, StringComparison.CurrentCultureIgnoreCase) select s).FirstOrDefault() ?? + AddViewer(nick); return viewer; } diff --git a/Spiffbot/Spiff.IRC/SpiffCore.cs b/Spiffbot/Spiff.IRC/SpiffCore.cs index 96fd01e..60fbfaf 100644 --- a/Spiffbot/Spiff.IRC/SpiffCore.cs +++ b/Spiffbot/Spiff.IRC/SpiffCore.cs @@ -1,5 +1,6 @@ using System; using System.Reflection; +using System.Threading.Tasks; using Spiff.Core.API; using Spiff.Core.API.EventArgs; using Spiff.Core.IRC; @@ -88,30 +89,44 @@ private void IrcClientOnOnTwitchEvent(object sender, IrcDataEvent ircDataEvent) } } + Viewer viewer; switch (type) { case "PRIVMSG": if (channel.StartsWith("#")) if (OnChatEvent != null) - OnChatEvent(this, new OnChatEvent(channel, ViewerManager.GetViewer(nick), message)); + { + Task.Factory.StartNew(() => OnChatEvent(this, new OnChatEvent(channel, ViewerManager.GetViewer(nick), message))); + } Logger.Info(string.Format("{0} -> {1}", nick, message), "Chat"); break; case "JOIN": + viewer = ViewerManager.AddViewer(nick); if (channel.StartsWith("#")) if (OnUserJoinEvent != null) - OnUserJoinEvent(this, new OnUserJoinEvent(nick, channel)); + { + Task.Factory.StartNew(() => OnUserJoinEvent(this, new OnUserJoinEvent(viewer, channel))); + } Logger.Info(string.Format("{0} has joined the chat", nick), "Joined Chat"); break; case "PART": + viewer = ViewerManager.GetViewer(nick); if (channel.StartsWith("#")) if (OnUserLeftEvent != null) - OnUserLeftEvent(this, new OnUserLeftEvent(nick, channel)); + { + Task.Factory.StartNew(() => OnUserLeftEvent(this, new OnUserLeftEvent(viewer, channel))); + } + ViewerManager.RemoveViewer(nick); Logger.Info(string.Format("{0} has left the chat", nick), "Left Chat"); break; case "QUIT": + viewer = ViewerManager.GetViewer(nick); if (channel.StartsWith("#")) if (OnUserLeftEvent != null) - OnUserLeftEvent(this, new OnUserLeftEvent(nick, channel)); + { + Task.Factory.StartNew(() => OnUserLeftEvent(this, new OnUserLeftEvent(viewer, channel))); + } + ViewerManager.RemoveViewer(nick); Logger.Info(string.Format("{0} has left the chat", nick), "Left Chat"); break; } @@ -119,7 +134,9 @@ private void IrcClientOnOnTwitchEvent(object sender, IrcDataEvent ircDataEvent) if (!message.StartsWith("!")) return; var args = message.Split(new[] {' '}, StringSplitOptions.RemoveEmptyEntries); if (OnCommandEvent != null) - OnCommandEvent(this, new OnCommandEvent(message.Split(' ')[0], args, message, ViewerManager.GetViewer(nick))); + Task.Factory.StartNew(() => OnCommandEvent(this, new OnCommandEvent(message.Split(' ')[0], args, message, ViewerManager.GetViewer(nick)))); + + CommandManager.RunCommand(message.Split(' ')[0], args, message, ViewerManager.GetViewer(nick)); } } #endregion From ba2a05e07d3831572709f466a3c9774fe5be63a1 Mon Sep 17 00:00:00 2001 From: Toyz Date: Wed, 18 Mar 2015 10:28:09 -0700 Subject: [PATCH 11/40] Slight tweak to move certain calls about events xD --- Spiffbot/Spiff.IRC/SpiffCore.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Spiffbot/Spiff.IRC/SpiffCore.cs b/Spiffbot/Spiff.IRC/SpiffCore.cs index 60fbfaf..ebcdaf7 100644 --- a/Spiffbot/Spiff.IRC/SpiffCore.cs +++ b/Spiffbot/Spiff.IRC/SpiffCore.cs @@ -111,32 +111,32 @@ private void IrcClientOnOnTwitchEvent(object sender, IrcDataEvent ircDataEvent) break; case "PART": viewer = ViewerManager.GetViewer(nick); + ViewerManager.RemoveViewer(nick); if (channel.StartsWith("#")) if (OnUserLeftEvent != null) { Task.Factory.StartNew(() => OnUserLeftEvent(this, new OnUserLeftEvent(viewer, channel))); } - ViewerManager.RemoveViewer(nick); Logger.Info(string.Format("{0} has left the chat", nick), "Left Chat"); break; case "QUIT": viewer = ViewerManager.GetViewer(nick); + ViewerManager.RemoveViewer(nick); if (channel.StartsWith("#")) if (OnUserLeftEvent != null) { Task.Factory.StartNew(() => OnUserLeftEvent(this, new OnUserLeftEvent(viewer, channel))); } - ViewerManager.RemoveViewer(nick); Logger.Info(string.Format("{0} has left the chat", nick), "Left Chat"); break; } if (!message.StartsWith("!")) return; var args = message.Split(new[] {' '}, StringSplitOptions.RemoveEmptyEntries); + CommandManager.RunCommand(message.Split(' ')[0], args, message, ViewerManager.GetViewer(nick)); if (OnCommandEvent != null) Task.Factory.StartNew(() => OnCommandEvent(this, new OnCommandEvent(message.Split(' ')[0], args, message, ViewerManager.GetViewer(nick)))); - CommandManager.RunCommand(message.Split(' ')[0], args, message, ViewerManager.GetViewer(nick)); } } #endregion From 80ded870e6f0a10f7a41c1a071c787aeb53873c9 Mon Sep 17 00:00:00 2001 From: Toyz Date: Wed, 18 Mar 2015 10:36:43 -0700 Subject: [PATCH 12/40] Fixed null error in HelpCommand --- Spiffbot/DefaultCommands/Commands/HelpCommand.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Spiffbot/DefaultCommands/Commands/HelpCommand.cs b/Spiffbot/DefaultCommands/Commands/HelpCommand.cs index 7ee1ad1..0add465 100644 --- a/Spiffbot/DefaultCommands/Commands/HelpCommand.cs +++ b/Spiffbot/DefaultCommands/Commands/HelpCommand.cs @@ -24,7 +24,7 @@ public override void Run(string[] parts, string complete, string channel, Viewer return; } - var command = SpiffCore.Instance.CommandManager.GetCommandObject(CommandName).Command; + var command = SpiffCore.Instance.CommandManager.GetCommandObject(parts[1]); if (command == null) Boardcast("Command does not exist"); From 58d50c5e09e704745dc3d182f1df01fbca0fd796 Mon Sep 17 00:00:00 2001 From: Toyz Date: Wed, 18 Mar 2015 21:46:51 -0700 Subject: [PATCH 13/40] Added Default Commands to the program !help, !allcmd, !plugins are all default commands in the server now --- Spiffbot/DefaultCommands/DefaultCommands.cs | 3 --- .../DefaultCommands/DefaultCommands.csproj | 3 --- .../Defaults}/Commands/AllCommands.cs | 3 +-- .../Defaults}/Commands/HelpCommand.cs | 5 ++--- .../Defaults}/Commands/PluginsCommand.cs | 3 +-- .../Spiff.IRC/Defaults/DefaultsMananger.cs | 20 +++++++++++++++++++ Spiffbot/Spiff.IRC/Managers/Viewers/Viewer.cs | 1 + Spiffbot/Spiff.IRC/Spiff.Core.csproj | 5 +++++ Spiffbot/Spiff.IRC/SpiffCore.cs | 8 +++++++- 9 files changed, 37 insertions(+), 14 deletions(-) rename Spiffbot/{DefaultCommands => Spiff.IRC/Defaults}/Commands/AllCommands.cs (92%) rename Spiffbot/{DefaultCommands => Spiff.IRC/Defaults}/Commands/HelpCommand.cs (90%) rename Spiffbot/{DefaultCommands => Spiff.IRC/Defaults}/Commands/PluginsCommand.cs (93%) create mode 100644 Spiffbot/Spiff.IRC/Defaults/DefaultsMananger.cs diff --git a/Spiffbot/DefaultCommands/DefaultCommands.cs b/Spiffbot/DefaultCommands/DefaultCommands.cs index 421b427..3d0048a 100644 --- a/Spiffbot/DefaultCommands/DefaultCommands.cs +++ b/Spiffbot/DefaultCommands/DefaultCommands.cs @@ -29,11 +29,8 @@ public override int Version public override void Start() { Logger.Write("Loading Plugin LoadedCommands", Name); - RegisterCommand(new AllCommands()); - RegisterCommand(new HelpCommand()); RegisterCommand(new GameCommand()); RegisterCommand(new RandomViewer()); - RegisterCommand(new PluginsCommand()); } public override void Destory() diff --git a/Spiffbot/DefaultCommands/DefaultCommands.csproj b/Spiffbot/DefaultCommands/DefaultCommands.csproj index f5926fc..1ebad54 100644 --- a/Spiffbot/DefaultCommands/DefaultCommands.csproj +++ b/Spiffbot/DefaultCommands/DefaultCommands.csproj @@ -39,10 +39,7 @@ - - - diff --git a/Spiffbot/DefaultCommands/Commands/AllCommands.cs b/Spiffbot/Spiff.IRC/Defaults/Commands/AllCommands.cs similarity index 92% rename from Spiffbot/DefaultCommands/Commands/AllCommands.cs rename to Spiffbot/Spiff.IRC/Defaults/Commands/AllCommands.cs index 2896c0b..e562447 100644 --- a/Spiffbot/DefaultCommands/Commands/AllCommands.cs +++ b/Spiffbot/Spiff.IRC/Defaults/Commands/AllCommands.cs @@ -1,9 +1,8 @@ using System.Linq; -using Spiff.Core; using Spiff.Core.API.Commands; using Spiff.Core.Managers.Viewers; -namespace DefaultCommands.Commands +namespace Spiff.Core.Defaults.Commands { public class AllCommands : Command { diff --git a/Spiffbot/DefaultCommands/Commands/HelpCommand.cs b/Spiffbot/Spiff.IRC/Defaults/Commands/HelpCommand.cs similarity index 90% rename from Spiffbot/DefaultCommands/Commands/HelpCommand.cs rename to Spiffbot/Spiff.IRC/Defaults/Commands/HelpCommand.cs index 0add465..bf38feb 100644 --- a/Spiffbot/DefaultCommands/Commands/HelpCommand.cs +++ b/Spiffbot/Spiff.IRC/Defaults/Commands/HelpCommand.cs @@ -1,8 +1,7 @@ -using Spiff.Core; -using Spiff.Core.API.Commands; +using Spiff.Core.API.Commands; using Spiff.Core.Managers.Viewers; -namespace DefaultCommands.Commands +namespace Spiff.Core.Defaults.Commands { public class HelpCommand : Command { diff --git a/Spiffbot/DefaultCommands/Commands/PluginsCommand.cs b/Spiffbot/Spiff.IRC/Defaults/Commands/PluginsCommand.cs similarity index 93% rename from Spiffbot/DefaultCommands/Commands/PluginsCommand.cs rename to Spiffbot/Spiff.IRC/Defaults/Commands/PluginsCommand.cs index 9313614..54e481b 100644 --- a/Spiffbot/DefaultCommands/Commands/PluginsCommand.cs +++ b/Spiffbot/Spiff.IRC/Defaults/Commands/PluginsCommand.cs @@ -1,10 +1,9 @@ using System.Collections.Generic; using System.Linq; -using Spiff.Core; using Spiff.Core.API.Commands; using Spiff.Core.Managers.Viewers; -namespace DefaultCommands.Commands +namespace Spiff.Core.Defaults.Commands { public class PluginsCommand : Command { diff --git a/Spiffbot/Spiff.IRC/Defaults/DefaultsMananger.cs b/Spiffbot/Spiff.IRC/Defaults/DefaultsMananger.cs new file mode 100644 index 0000000..5c87676 --- /dev/null +++ b/Spiffbot/Spiff.IRC/Defaults/DefaultsMananger.cs @@ -0,0 +1,20 @@ +using Spiff.Core.Defaults.Commands; + +namespace Spiff.Core.Defaults +{ + public class DefaultsMananger + { + private readonly SpiffCore _spiffCore; + public DefaultsMananger(SpiffCore spiffCore) + { + _spiffCore = spiffCore; + } + + public void AddCommands() + { + _spiffCore.CommandManager.RegisterCommand(new AllCommands()); + _spiffCore.CommandManager.RegisterCommand(new HelpCommand()); + _spiffCore.CommandManager.RegisterCommand(new PluginsCommand()); + } + } +} diff --git a/Spiffbot/Spiff.IRC/Managers/Viewers/Viewer.cs b/Spiffbot/Spiff.IRC/Managers/Viewers/Viewer.cs index 7f59853..4d8ca8a 100644 --- a/Spiffbot/Spiff.IRC/Managers/Viewers/Viewer.cs +++ b/Spiffbot/Spiff.IRC/Managers/Viewers/Viewer.cs @@ -35,6 +35,7 @@ public Viewer(Viewer viewer) { IsMod = viewer.IsMod; Username = viewer.Username; + JoinedTime = viewer.JoinedTime; } public void Kick(int timeout = 600) diff --git a/Spiffbot/Spiff.IRC/Spiff.Core.csproj b/Spiffbot/Spiff.IRC/Spiff.Core.csproj index 0a8f813..d5a0c1c 100644 --- a/Spiffbot/Spiff.IRC/Spiff.Core.csproj +++ b/Spiffbot/Spiff.IRC/Spiff.Core.csproj @@ -49,6 +49,10 @@ + + + + @@ -71,6 +75,7 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Spiffbot/Spiffbot/Spiffbot.csproj b/Spiffbot/Spiffbot/Spiffbot.csproj index 3c3b8dd..a815b50 100644 --- a/Spiffbot/Spiffbot/Spiffbot.csproj +++ b/Spiffbot/Spiffbot/Spiffbot.csproj @@ -34,6 +34,8 @@ + + @@ -43,6 +45,12 @@ + + Form + + + ServerGUI.cs + @@ -50,6 +58,11 @@ Spiff.Core + + + ServerGUI.cs + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file From 0554ccb15a84ba663236818c28af7cb06bc3b9bd Mon Sep 17 00:00:00 2001 From: Toyz Date: Sat, 21 Mar 2015 16:01:01 -0700 Subject: [PATCH 30/40] Minor updates --- Spiffbot/Spiff.IRC/IRC/IRCClient.cs | 8 +++- Spiffbot/Spiff.IRC/IRC/IrcDataEvent.cs | 4 +- Spiffbot/Spiff.IRC/IRC/IrcReader.cs | 49 +++++++++++++++++++++++ Spiffbot/Spiff.IRC/Spiff.Core.csproj | 1 + Spiffbot/Spiff.IRC/SpiffCore.cs | 55 +++++++++++++++++++++++++- Spiffbot/Spiff.IRC/Utils/Logger.cs | 3 +- 6 files changed, 114 insertions(+), 6 deletions(-) create mode 100644 Spiffbot/Spiff.IRC/IRC/IrcReader.cs diff --git a/Spiffbot/Spiff.IRC/IRC/IRCClient.cs b/Spiffbot/Spiff.IRC/IRC/IRCClient.cs index dc65ba6..4b67506 100644 --- a/Spiffbot/Spiff.IRC/IRC/IRCClient.cs +++ b/Spiffbot/Spiff.IRC/IRC/IRCClient.cs @@ -90,13 +90,17 @@ private void Listener() } var data1 = data; + + //Logger.Debug(); + + var packet = IrcReader.ParseIrcMessageWithRegex(data); new Task(() => { if (OnTwitchDataEvent != null) - OnTwitchDataEvent(this, new IrcDataEvent(data1)); + OnTwitchDataEvent(this, new IrcDataEvent(data1, packet)); if (OnTwitchDebugEvent != null) - OnTwitchDebugEvent(this, new IrcDataEvent(data1)); + OnTwitchDebugEvent(this, new IrcDataEvent(data1, packet)); }).Start(); } } diff --git a/Spiffbot/Spiff.IRC/IRC/IrcDataEvent.cs b/Spiffbot/Spiff.IRC/IRC/IrcDataEvent.cs index d9f73ea..edf66fb 100644 --- a/Spiffbot/Spiff.IRC/IRC/IrcDataEvent.cs +++ b/Spiffbot/Spiff.IRC/IRC/IrcDataEvent.cs @@ -4,11 +4,13 @@ namespace Spiff.Core.IRC { public class IrcDataEvent : EventArgs { - public IrcDataEvent(string payload) + public IrcDataEvent(string payload, IrcReader packet) { Payload = payload; + Packet = packet; } public string Payload { get; private set; } + public IrcReader Packet { get; private set; } } } \ No newline at end of file diff --git a/Spiffbot/Spiff.IRC/IRC/IrcReader.cs b/Spiffbot/Spiff.IRC/IRC/IrcReader.cs new file mode 100644 index 0000000..d79e20c --- /dev/null +++ b/Spiffbot/Spiff.IRC/IRC/IrcReader.cs @@ -0,0 +1,49 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; + +namespace Spiff.Core.IRC +{ + public class IrcReader + { + public string Nick { get; set; } + public string Prefix { get; set; } + public string Command { get; set; } + public string[] Parameters { get; set; } + public string Tailing { get; set; } + + public IrcReader(string prefix, string command, string[] @params, string tailing) + { + Nick = prefix.Contains('!') ? prefix.Split('!')[0] : prefix; + Command = command; + Parameters = @params; + Tailing = tailing; + } + + public override string ToString() + { + return string.Format("Nick: {0}, Command: {1}, Params: {2}, Trailing: {3}", Nick, Command, + string.Join(",", Parameters), Tailing); + } + + public static IrcReader ParseIrcMessageWithRegex(string message) + { + Regex parsingRegex = new Regex(@"^(:(?\S+) )?(?\S+)( (?!:)(?.+?))?( :(?.+))?$", RegexOptions.Compiled | RegexOptions.ExplicitCapture); + Match messageMatch = parsingRegex.Match(message); + + if (messageMatch.Success) + { + var prefix = messageMatch.Groups["prefix"].Value; + var command = messageMatch.Groups["command"].Value; + var parameters = messageMatch.Groups["params"].Value.Split(' '); + var trailing = messageMatch.Groups["trail"].Value; + + return new IrcReader(prefix, command, parameters, trailing); + } + + return null; + } + } +} diff --git a/Spiffbot/Spiff.IRC/Spiff.Core.csproj b/Spiffbot/Spiff.IRC/Spiff.Core.csproj index 07a1a88..3673b82 100644 --- a/Spiffbot/Spiff.IRC/Spiff.Core.csproj +++ b/Spiffbot/Spiff.IRC/Spiff.Core.csproj @@ -57,6 +57,7 @@ + diff --git a/Spiffbot/Spiff.IRC/SpiffCore.cs b/Spiffbot/Spiff.IRC/SpiffCore.cs index 6a94aa1..ee2f418 100644 --- a/Spiffbot/Spiff.IRC/SpiffCore.cs +++ b/Spiffbot/Spiff.IRC/SpiffCore.cs @@ -68,7 +68,58 @@ private Assembly CurrentDomainOnAssemblyResolve(object sender, ResolveEventArgs private void IrcClientOnOnTwitchDataEvent(object sender, IrcDataEvent ircDataEvent) { - var data = ircDataEvent.Payload; + var packet = ircDataEvent.Packet; + Viewer viewer; + switch (packet.Command) + { + case "PRIVMSG": + viewer = ViewerManager.GetViewer(packet.Nick) ?? ViewerManager.AddViewer(packet.Nick); + if (OnChatEvent != null) + { + Task.Factory.StartNew( + () => + OnChatEvent(this, + new OnChatEvent(packet.Parameters[0], viewer, packet.Tailing))); + } + Logger.Info(string.Format("{0} -> {1}", packet.Nick, packet.Tailing), "Chat"); + break; + case "JOIN": + ViewerManager.AddViewer(packet.Nick); + if (OnUserJoinEvent != null) + { + new Task(() => OnUserJoinEvent(this, new OnUserJoinEvent(ViewerManager.AddViewer(packet.Nick), packet.Parameters[0]))).Start(); + } + Logger.Info(string.Format("{0} has joined the chat", packet.Nick), "Joined Chat"); + break; + case "QUIT": + case "PART": + viewer = (Viewer)ViewerManager.AddViewer(packet.Nick).Clone(); + if (packet.Parameters[0].StartsWith("#")) + if (OnUserLeftEvent != null) + { + new Task(() => OnUserLeftEvent(this, new OnUserLeftEvent(viewer, packet.Parameters[0]))).Start(); + } + ViewerManager.RemoveViewer(packet.Nick); + Logger.Info(string.Format("{0} has left the chat", packet.Nick), "Left Chat"); + break; + case "MODE": + string mode = packet.Parameters[1]; + if(mode.Equals("+o")) + ViewerManager.SetMod(packet.Nick); + break; + } + + if (packet.Tailing.StartsWith("!")) + { + var args = packet.Tailing.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); + CommandManager.RunCommand(packet.Tailing.Split(' ')[0], args, packet.Tailing, ViewerManager.GetViewer(packet.Nick)); + if (OnCommandEvent != null) + new Task( + () => + OnCommandEvent(this, + new OnCommandEvent(packet.Tailing.Split(' ')[0], args, packet.Tailing, ViewerManager.GetViewer(packet.Nick)))).Start(); + } + /*var data = ircDataEvent.Payload; var message = ""; var split1 = data.Split(':'); @@ -159,7 +210,7 @@ private void IrcClientOnOnTwitchDataEvent(object sender, IrcDataEvent ircDataEve () => OnCommandEvent(this, new OnCommandEvent(message.Split(' ')[0], args, message, ViewerManager.GetViewer(nick)))).Start(); - } + }*/ } #endregion diff --git a/Spiffbot/Spiff.IRC/Utils/Logger.cs b/Spiffbot/Spiff.IRC/Utils/Logger.cs index c0b00f4..7d4af9f 100644 --- a/Spiffbot/Spiff.IRC/Utils/Logger.cs +++ b/Spiffbot/Spiff.IRC/Utils/Logger.cs @@ -47,7 +47,8 @@ public static void Write(Object write, string from = "") private static void WriteLogFile(string text) { if (ConfigFile.GetValue("adv", "log", true)) - File.AppendAllText(LogFile, string.Format("[{0}]{1}{2}", DateTime.Now, text, Environment.NewLine)); + return; + //File.AppendAllText(LogFile, string.Format("[{0}]{1}{2}", DateTime.Now, text, Environment.NewLine)); } } } \ No newline at end of file From 27c29acc222b1cbdf92ddf68b82751b0b2933000 Mon Sep 17 00:00:00 2001 From: Toyz Date: Sat, 21 Mar 2015 17:04:59 -0700 Subject: [PATCH 31/40] Revert "Minor updates" This reverts commit 0554ccb15a84ba663236818c28af7cb06bc3b9bd. --- Spiffbot/Spiff.IRC/IRC/IRCClient.cs | 8 +--- Spiffbot/Spiff.IRC/IRC/IrcDataEvent.cs | 4 +- Spiffbot/Spiff.IRC/IRC/IrcReader.cs | 49 ----------------------- Spiffbot/Spiff.IRC/Spiff.Core.csproj | 1 - Spiffbot/Spiff.IRC/SpiffCore.cs | 55 +------------------------- Spiffbot/Spiff.IRC/Utils/Logger.cs | 3 +- 6 files changed, 6 insertions(+), 114 deletions(-) delete mode 100644 Spiffbot/Spiff.IRC/IRC/IrcReader.cs diff --git a/Spiffbot/Spiff.IRC/IRC/IRCClient.cs b/Spiffbot/Spiff.IRC/IRC/IRCClient.cs index 4b67506..dc65ba6 100644 --- a/Spiffbot/Spiff.IRC/IRC/IRCClient.cs +++ b/Spiffbot/Spiff.IRC/IRC/IRCClient.cs @@ -90,17 +90,13 @@ private void Listener() } var data1 = data; - - //Logger.Debug(); - - var packet = IrcReader.ParseIrcMessageWithRegex(data); new Task(() => { if (OnTwitchDataEvent != null) - OnTwitchDataEvent(this, new IrcDataEvent(data1, packet)); + OnTwitchDataEvent(this, new IrcDataEvent(data1)); if (OnTwitchDebugEvent != null) - OnTwitchDebugEvent(this, new IrcDataEvent(data1, packet)); + OnTwitchDebugEvent(this, new IrcDataEvent(data1)); }).Start(); } } diff --git a/Spiffbot/Spiff.IRC/IRC/IrcDataEvent.cs b/Spiffbot/Spiff.IRC/IRC/IrcDataEvent.cs index edf66fb..d9f73ea 100644 --- a/Spiffbot/Spiff.IRC/IRC/IrcDataEvent.cs +++ b/Spiffbot/Spiff.IRC/IRC/IrcDataEvent.cs @@ -4,13 +4,11 @@ namespace Spiff.Core.IRC { public class IrcDataEvent : EventArgs { - public IrcDataEvent(string payload, IrcReader packet) + public IrcDataEvent(string payload) { Payload = payload; - Packet = packet; } public string Payload { get; private set; } - public IrcReader Packet { get; private set; } } } \ No newline at end of file diff --git a/Spiffbot/Spiff.IRC/IRC/IrcReader.cs b/Spiffbot/Spiff.IRC/IRC/IrcReader.cs deleted file mode 100644 index d79e20c..0000000 --- a/Spiffbot/Spiff.IRC/IRC/IrcReader.cs +++ /dev/null @@ -1,49 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Text.RegularExpressions; - -namespace Spiff.Core.IRC -{ - public class IrcReader - { - public string Nick { get; set; } - public string Prefix { get; set; } - public string Command { get; set; } - public string[] Parameters { get; set; } - public string Tailing { get; set; } - - public IrcReader(string prefix, string command, string[] @params, string tailing) - { - Nick = prefix.Contains('!') ? prefix.Split('!')[0] : prefix; - Command = command; - Parameters = @params; - Tailing = tailing; - } - - public override string ToString() - { - return string.Format("Nick: {0}, Command: {1}, Params: {2}, Trailing: {3}", Nick, Command, - string.Join(",", Parameters), Tailing); - } - - public static IrcReader ParseIrcMessageWithRegex(string message) - { - Regex parsingRegex = new Regex(@"^(:(?\S+) )?(?\S+)( (?!:)(?.+?))?( :(?.+))?$", RegexOptions.Compiled | RegexOptions.ExplicitCapture); - Match messageMatch = parsingRegex.Match(message); - - if (messageMatch.Success) - { - var prefix = messageMatch.Groups["prefix"].Value; - var command = messageMatch.Groups["command"].Value; - var parameters = messageMatch.Groups["params"].Value.Split(' '); - var trailing = messageMatch.Groups["trail"].Value; - - return new IrcReader(prefix, command, parameters, trailing); - } - - return null; - } - } -} diff --git a/Spiffbot/Spiff.IRC/Spiff.Core.csproj b/Spiffbot/Spiff.IRC/Spiff.Core.csproj index 3673b82..07a1a88 100644 --- a/Spiffbot/Spiff.IRC/Spiff.Core.csproj +++ b/Spiffbot/Spiff.IRC/Spiff.Core.csproj @@ -57,7 +57,6 @@ - diff --git a/Spiffbot/Spiff.IRC/SpiffCore.cs b/Spiffbot/Spiff.IRC/SpiffCore.cs index ee2f418..6a94aa1 100644 --- a/Spiffbot/Spiff.IRC/SpiffCore.cs +++ b/Spiffbot/Spiff.IRC/SpiffCore.cs @@ -68,58 +68,7 @@ private Assembly CurrentDomainOnAssemblyResolve(object sender, ResolveEventArgs private void IrcClientOnOnTwitchDataEvent(object sender, IrcDataEvent ircDataEvent) { - var packet = ircDataEvent.Packet; - Viewer viewer; - switch (packet.Command) - { - case "PRIVMSG": - viewer = ViewerManager.GetViewer(packet.Nick) ?? ViewerManager.AddViewer(packet.Nick); - if (OnChatEvent != null) - { - Task.Factory.StartNew( - () => - OnChatEvent(this, - new OnChatEvent(packet.Parameters[0], viewer, packet.Tailing))); - } - Logger.Info(string.Format("{0} -> {1}", packet.Nick, packet.Tailing), "Chat"); - break; - case "JOIN": - ViewerManager.AddViewer(packet.Nick); - if (OnUserJoinEvent != null) - { - new Task(() => OnUserJoinEvent(this, new OnUserJoinEvent(ViewerManager.AddViewer(packet.Nick), packet.Parameters[0]))).Start(); - } - Logger.Info(string.Format("{0} has joined the chat", packet.Nick), "Joined Chat"); - break; - case "QUIT": - case "PART": - viewer = (Viewer)ViewerManager.AddViewer(packet.Nick).Clone(); - if (packet.Parameters[0].StartsWith("#")) - if (OnUserLeftEvent != null) - { - new Task(() => OnUserLeftEvent(this, new OnUserLeftEvent(viewer, packet.Parameters[0]))).Start(); - } - ViewerManager.RemoveViewer(packet.Nick); - Logger.Info(string.Format("{0} has left the chat", packet.Nick), "Left Chat"); - break; - case "MODE": - string mode = packet.Parameters[1]; - if(mode.Equals("+o")) - ViewerManager.SetMod(packet.Nick); - break; - } - - if (packet.Tailing.StartsWith("!")) - { - var args = packet.Tailing.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); - CommandManager.RunCommand(packet.Tailing.Split(' ')[0], args, packet.Tailing, ViewerManager.GetViewer(packet.Nick)); - if (OnCommandEvent != null) - new Task( - () => - OnCommandEvent(this, - new OnCommandEvent(packet.Tailing.Split(' ')[0], args, packet.Tailing, ViewerManager.GetViewer(packet.Nick)))).Start(); - } - /*var data = ircDataEvent.Payload; + var data = ircDataEvent.Payload; var message = ""; var split1 = data.Split(':'); @@ -210,7 +159,7 @@ private void IrcClientOnOnTwitchDataEvent(object sender, IrcDataEvent ircDataEve () => OnCommandEvent(this, new OnCommandEvent(message.Split(' ')[0], args, message, ViewerManager.GetViewer(nick)))).Start(); - }*/ + } } #endregion diff --git a/Spiffbot/Spiff.IRC/Utils/Logger.cs b/Spiffbot/Spiff.IRC/Utils/Logger.cs index 7d4af9f..c0b00f4 100644 --- a/Spiffbot/Spiff.IRC/Utils/Logger.cs +++ b/Spiffbot/Spiff.IRC/Utils/Logger.cs @@ -47,8 +47,7 @@ public static void Write(Object write, string from = "") private static void WriteLogFile(string text) { if (ConfigFile.GetValue("adv", "log", true)) - return; - //File.AppendAllText(LogFile, string.Format("[{0}]{1}{2}", DateTime.Now, text, Environment.NewLine)); + File.AppendAllText(LogFile, string.Format("[{0}]{1}{2}", DateTime.Now, text, Environment.NewLine)); } } } \ No newline at end of file From 93a955b1e342139664fd6a53e3bcc8cb70b45425 Mon Sep 17 00:00:00 2001 From: Toyz Date: Sat, 21 Mar 2015 17:32:17 -0700 Subject: [PATCH 32/40] Fixed code errors --- Spiffbot/Spiff.IRC/IRC/IRCClient.cs | 5 +- Spiffbot/Spiff.IRC/IRC/IrcDataEvent.cs | 4 +- Spiffbot/Spiff.IRC/IRC/IrcReader.cs | 50 ++++++++++++ Spiffbot/Spiff.IRC/Spiff.Core.csproj | 1 + Spiffbot/Spiff.IRC/SpiffCore.cs | 101 ++++++++----------------- Spiffbot/Spiffbot/ServerGUI.cs | 3 + 6 files changed, 90 insertions(+), 74 deletions(-) create mode 100644 Spiffbot/Spiff.IRC/IRC/IrcReader.cs diff --git a/Spiffbot/Spiff.IRC/IRC/IRCClient.cs b/Spiffbot/Spiff.IRC/IRC/IRCClient.cs index dc65ba6..db4d694 100644 --- a/Spiffbot/Spiff.IRC/IRC/IRCClient.cs +++ b/Spiffbot/Spiff.IRC/IRC/IRCClient.cs @@ -90,13 +90,14 @@ private void Listener() } var data1 = data; + var ircData = IrcReader.ParseIrcMessageWithRegex(data); new Task(() => { if (OnTwitchDataEvent != null) - OnTwitchDataEvent(this, new IrcDataEvent(data1)); + OnTwitchDataEvent(this, new IrcDataEvent(data1, ircData)); if (OnTwitchDebugEvent != null) - OnTwitchDebugEvent(this, new IrcDataEvent(data1)); + OnTwitchDebugEvent(this, new IrcDataEvent(data1, ircData)); }).Start(); } } diff --git a/Spiffbot/Spiff.IRC/IRC/IrcDataEvent.cs b/Spiffbot/Spiff.IRC/IRC/IrcDataEvent.cs index d9f73ea..b8b13cc 100644 --- a/Spiffbot/Spiff.IRC/IRC/IrcDataEvent.cs +++ b/Spiffbot/Spiff.IRC/IRC/IrcDataEvent.cs @@ -4,11 +4,13 @@ namespace Spiff.Core.IRC { public class IrcDataEvent : EventArgs { - public IrcDataEvent(string payload) + public IrcDataEvent(string payload, IrcReader packet) { Payload = payload; + Packet = packet; } public string Payload { get; private set; } + public IrcReader Packet { get; set; } } } \ No newline at end of file diff --git a/Spiffbot/Spiff.IRC/IRC/IrcReader.cs b/Spiffbot/Spiff.IRC/IRC/IrcReader.cs new file mode 100644 index 0000000..9786f8e --- /dev/null +++ b/Spiffbot/Spiff.IRC/IRC/IrcReader.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; + +namespace Spiff.Core.IRC +{ + public class IrcReader + { + public string Nick { get; set; } + public string Prefix { get; set; } + public string Command { get; set; } + public string[] Parameters { get; set; } + public string Tailing { get; set; } + + public IrcReader(string prefix, string command, string[] @params, string tailing) + { + Nick = prefix.Contains('!') ? prefix.Split('!')[0] : prefix; + Command = command; + Parameters = @params; + Tailing = tailing; + } + + public override string ToString() + { + return string.Format("Nick: {0}, Command: {1}, Params: {2}, Trailing: {3}", Nick, Command, + string.Join(",", Parameters), Tailing); + } + + public static IrcReader ParseIrcMessageWithRegex(string message) + { + Regex parsingRegex = new Regex(@"^(:(?\S+) )?(?\S+)( (?!:)(?.+?))?( :(?.+))?$", RegexOptions.Compiled | RegexOptions.ExplicitCapture); + Match messageMatch = parsingRegex.Match(message); + + if (messageMatch.Success) + { + string prefix = messageMatch.Groups["prefix"].Value; + string command = messageMatch.Groups["command"].Value; + string[] parameters = messageMatch.Groups["params"].Value.Split(' '); + string trailing = messageMatch.Groups["trail"].Value; + + //if (!String.IsNullOrEmpty(trailing)) + return new IrcReader(prefix, command, parameters, trailing); + } + + return null; + } + } +} diff --git a/Spiffbot/Spiff.IRC/Spiff.Core.csproj b/Spiffbot/Spiff.IRC/Spiff.Core.csproj index 07a1a88..3673b82 100644 --- a/Spiffbot/Spiff.IRC/Spiff.Core.csproj +++ b/Spiffbot/Spiff.IRC/Spiff.Core.csproj @@ -57,6 +57,7 @@ + diff --git a/Spiffbot/Spiff.IRC/SpiffCore.cs b/Spiffbot/Spiff.IRC/SpiffCore.cs index 6a94aa1..ee8ba3b 100644 --- a/Spiffbot/Spiff.IRC/SpiffCore.cs +++ b/Spiffbot/Spiff.IRC/SpiffCore.cs @@ -68,97 +68,56 @@ private Assembly CurrentDomainOnAssemblyResolve(object sender, ResolveEventArgs private void IrcClientOnOnTwitchDataEvent(object sender, IrcDataEvent ircDataEvent) { - var data = ircDataEvent.Payload; - var message = ""; - - var split1 = data.Split(':'); - if (split1.Length <= 1) return; - - //Splitting nick, type, chan and message - var split2 = split1[1].Split(' '); - - //Nick consists of various things - we only want the nick itself - var nick = split2[0]; - nick = nick.Split('!')[0]; - - //Type = PRIVMSG for normal messages. Only thing we need - var type = split2[1]; - - //Channel posted to - var channel = split2[2]; - - if (split1.Length > 2) - { - for (var i = 2; i < split1.Length; i++) - { - message += split1[i] + " "; - } - } - + var packet = ircDataEvent.Packet; Viewer viewer; - switch (type) + switch (packet.Command) { case "PRIVMSG": - viewer = ViewerManager.GetViewer(nick) ?? ViewerManager.AddViewer(nick); - - if (channel.StartsWith("#")) - if (OnChatEvent != null) - { - Task.Factory.StartNew( - () => - OnChatEvent(this, - new OnChatEvent(channel, viewer, message))); - } - Logger.Info(string.Format("{0} -> {1}", nick, message), "Chat"); + viewer = ViewerManager.GetViewer(packet.Nick) ?? ViewerManager.AddViewer(packet.Nick); + if (OnChatEvent != null) + { + Task.Factory.StartNew( + () => + OnChatEvent(this, + new OnChatEvent(packet.Parameters[0], viewer, packet.Tailing))); + } + Logger.Info(string.Format("{0} -> {1}", packet.Nick, packet.Tailing), "Chat"); break; case "JOIN": - ViewerManager.AddViewer(nick); - if (channel.StartsWith("#")) - if (OnUserJoinEvent != null) - { - new Task(() => OnUserJoinEvent(this, new OnUserJoinEvent(ViewerManager.AddViewer(nick), channel))).Start(); - } - Logger.Info(string.Format("{0} has joined the chat", nick), "Joined Chat"); - break; - case "PART": - viewer = (Viewer)ViewerManager.AddViewer(nick).Clone(); - if (channel.StartsWith("#")) - if (OnUserLeftEvent != null) - { - new Task(() => OnUserLeftEvent(this, new OnUserLeftEvent(viewer, channel))).Start(); - } - ViewerManager.RemoveViewer(nick); - Logger.Info(string.Format("{0} has left the chat", nick), "Left Chat"); + ViewerManager.AddViewer(packet.Nick); + if (OnUserJoinEvent != null) + { + new Task(() => OnUserJoinEvent(this, new OnUserJoinEvent(ViewerManager.AddViewer(packet.Nick), packet.Parameters[0]))).Start(); + } + Logger.Info(string.Format("{0} has joined the chat", packet.Nick), "Joined Chat"); break; case "QUIT": - viewer = (Viewer) ViewerManager.AddViewer(nick).Clone(); - if (channel.StartsWith("#")) + case "PART": + viewer = (Viewer)ViewerManager.AddViewer(packet.Nick).Clone(); + if (packet.Parameters[0].StartsWith("#")) if (OnUserLeftEvent != null) { - new Task(() => OnUserLeftEvent(this, new OnUserLeftEvent(viewer, channel))).Start(); + new Task(() => OnUserLeftEvent(this, new OnUserLeftEvent(viewer, packet.Parameters[0]))).Start(); } - ViewerManager.RemoveViewer(nick); - Logger.Info(string.Format("{0} has left the chat", nick), "Left Chat"); + ViewerManager.RemoveViewer(packet.Nick); + Logger.Info(string.Format("{0} has left the chat", packet.Nick), "Left Chat"); break; case "MODE": - var d = data.Split(new[] {' '}, StringSplitOptions.RemoveEmptyEntries); - var n = d[d.Length - 1]; - var o = d[d.Length - 2]; - - if(o == "+o") - ViewerManager.SetMod(n); + string mode = packet.Parameters[1]; + if (mode.Equals("+o")) + ViewerManager.SetMod(packet.Nick); break; } - if (message.StartsWith("!")) + if (packet.Tailing.StartsWith("!")) { - var args = message.Split(new[] {' '}, StringSplitOptions.RemoveEmptyEntries); - CommandManager.RunCommand(message.Split(' ')[0], args, message, ViewerManager.GetViewer(nick)); + var args = packet.Tailing.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); + CommandManager.RunCommand(packet.Tailing.Split(' ')[0], args, packet.Tailing, ViewerManager.GetViewer(packet.Nick)); if (OnCommandEvent != null) new Task( () => OnCommandEvent(this, - new OnCommandEvent(message.Split(' ')[0], args, message, ViewerManager.GetViewer(nick)))).Start(); + new OnCommandEvent(packet.Tailing.Split(' ')[0], args, packet.Tailing, ViewerManager.GetViewer(packet.Nick)))).Start(); } } diff --git a/Spiffbot/Spiffbot/ServerGUI.cs b/Spiffbot/Spiffbot/ServerGUI.cs index 13b0b82..9b9128e 100644 --- a/Spiffbot/Spiffbot/ServerGUI.cs +++ b/Spiffbot/Spiffbot/ServerGUI.cs @@ -21,6 +21,7 @@ public ServerGui() private void InstanceOnOnChatEvent(object sender, OnChatEvent onChatEvent) { + if (IsDisposed) return; Invoke(new Action(() => { string name = string.Format("[{0}]", onChatEvent.User.Username); @@ -38,6 +39,7 @@ private void InstanceOnOnChatEvent(object sender, OnChatEvent onChatEvent) private void InstanceOnOnUserLeftEvent(object sender, OnUserLeftEvent onUserLeftEvent) { + if (IsDisposed) return; Invoke(new Action(() => { CurrrentUsers.Items.Remove(onUserLeftEvent.Nick.Username); })); @@ -45,6 +47,7 @@ private void InstanceOnOnUserLeftEvent(object sender, OnUserLeftEvent onUserLeft private void InstanceOnOnUserJoinEvent(object sender, OnUserJoinEvent onUserJoinEvent) { + if (IsDisposed) return; Invoke(new Action(() => { if (!CurrrentUsers.Items.Contains(onUserJoinEvent.Nick.Username)) From 8d11c757b1e52a4153e9ea41f202d81418541d26 Mon Sep 17 00:00:00 2001 From: Toyz Date: Sat, 21 Mar 2015 19:38:07 -0700 Subject: [PATCH 33/40] Added new basic plugin Also fixed commands in the IrcWritter --- Spiffbot/Spiff.IRC/IRC/IrcWritter.cs | 12 ++-- Spiffbot/Spiffbot.sln | 9 +++ Spiffbot/WordFilter/Censor.cs | 53 +++++++++++++++ .../WordFilter/Properties/AssemblyInfo.cs | 36 ++++++++++ Spiffbot/WordFilter/WordFilter.cs | 66 +++++++++++++++++++ Spiffbot/WordFilter/WordFilter.csproj | 60 +++++++++++++++++ 6 files changed, 230 insertions(+), 6 deletions(-) create mode 100644 Spiffbot/WordFilter/Censor.cs create mode 100644 Spiffbot/WordFilter/Properties/AssemblyInfo.cs create mode 100644 Spiffbot/WordFilter/WordFilter.cs create mode 100644 Spiffbot/WordFilter/WordFilter.csproj diff --git a/Spiffbot/Spiff.IRC/IRC/IrcWritter.cs b/Spiffbot/Spiff.IRC/IRC/IrcWritter.cs index 58be9f3..d8b4d0f 100644 --- a/Spiffbot/Spiff.IRC/IRC/IrcWritter.cs +++ b/Spiffbot/Spiff.IRC/IRC/IrcWritter.cs @@ -58,30 +58,30 @@ public void TimeoutUser(string user, int timeout, bool bypass = false) { if (bypass) { - WriteDirect(string.Format("/timeout {0} {1}", user, timeout)); + SendMessage(string.Format("/timeout {0} {1}", user, timeout), true); return; } - _queue.Enqueue(string.Format("/timeout {0} {1}", user, timeout)); + SendMessage(string.Format("/timeout {0} {1}", user, timeout)); } public void BanUser(string user, bool bypass = false) { if (bypass) { - WriteDirect(string.Format("/ban {0}", user)); + SendMessage(string.Format("/ban {0}", user), true); return; } - _queue.Enqueue(string.Format("/ban {0}", user)); + SendMessage(string.Format("/ban {0}", user)); } public void UnbanUser(string user, bool bypass = false) { if (bypass) { - WriteDirect(string.Format("/unban {0}", user)); + SendMessage(string.Format("/unban {0}", user), true); return; } - _queue.Enqueue(string.Format("/unban {0}", user)); + SendMessage(string.Format("/unban {0}", user)); } public void SendCustom(string command, bool bypass = false) diff --git a/Spiffbot/Spiffbot.sln b/Spiffbot/Spiffbot.sln index d8b3fd5..e3f0dd2 100644 --- a/Spiffbot/Spiffbot.sln +++ b/Spiffbot/Spiffbot.sln @@ -23,6 +23,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Spiff Plugins", "Spiff Plug EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ScareyStuff", "ScareyStuff\ScareyStuff.csproj", "{C5760B4A-7D47-4BDE-B751-7290873C95C0}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Danger Plugins", "Danger Plugins", "{8DA8EF15-1C2F-49A0-9818-534981509DEA}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WordFilter", "WordFilter\WordFilter.csproj", "{8E0E9F7C-2EFF-40E1-A955-968890633850}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -57,6 +61,10 @@ Global {C5760B4A-7D47-4BDE-B751-7290873C95C0}.Debug|Any CPU.Build.0 = Debug|Any CPU {C5760B4A-7D47-4BDE-B751-7290873C95C0}.Release|Any CPU.ActiveCfg = Release|Any CPU {C5760B4A-7D47-4BDE-B751-7290873C95C0}.Release|Any CPU.Build.0 = Release|Any CPU + {8E0E9F7C-2EFF-40E1-A955-968890633850}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8E0E9F7C-2EFF-40E1-A955-968890633850}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8E0E9F7C-2EFF-40E1-A955-968890633850}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8E0E9F7C-2EFF-40E1-A955-968890633850}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -68,5 +76,6 @@ Global {E60366F1-423A-4DAE-937B-AAFA1BDA0CDA} = {FDF62C49-7D07-4B2E-B0A6-6D8B243AB8FA} {49C769A1-613B-4DDD-AF87-5F02518CBD7C} = {E60366F1-423A-4DAE-937B-AAFA1BDA0CDA} {C5760B4A-7D47-4BDE-B751-7290873C95C0} = {5D2FA251-DD06-4130-BE4B-1F01028E3769} + {8E0E9F7C-2EFF-40E1-A955-968890633850} = {8DA8EF15-1C2F-49A0-9818-534981509DEA} EndGlobalSection EndGlobal diff --git a/Spiffbot/WordFilter/Censor.cs b/Spiffbot/WordFilter/Censor.cs new file mode 100644 index 0000000..fdc4b0e --- /dev/null +++ b/Spiffbot/WordFilter/Censor.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text.RegularExpressions; + +namespace WordFilter +{ + public class Censor + { + public IList CensoredWords { get; private set; } + + public Censor(IEnumerable censoredWords) + { + if (censoredWords == null) + throw new ArgumentNullException("censoredWords"); + + CensoredWords = new List(censoredWords); + } + + public string CensorText(string text) + { + if (text == null) + throw new ArgumentNullException("text"); + + return CensoredWords.Select(ToRegexPattern).Aggregate(text, (current, regularExpression) => Regex.Replace(current, regularExpression, StarCensoredMatch, RegexOptions.IgnoreCase | RegexOptions.CultureInvariant)); + } + + private static string StarCensoredMatch(Match m) + { + string word = m.Captures[0].Value; + + return new string('*', word.Length); + } + + private string ToRegexPattern(string wildcardSearch) + { + string regexPattern = Regex.Escape(wildcardSearch); + + regexPattern = regexPattern.Replace(@"\*", ".*?"); + regexPattern = regexPattern.Replace(@"\?", "."); + + if (regexPattern.StartsWith(".*?")) + { + regexPattern = regexPattern.Substring(3); + regexPattern = @"(^\b)*?" + regexPattern; + } + + regexPattern = @"\b" + regexPattern + @"\b"; + + return regexPattern; + } + } +} diff --git a/Spiffbot/WordFilter/Properties/AssemblyInfo.cs b/Spiffbot/WordFilter/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..97450a5 --- /dev/null +++ b/Spiffbot/WordFilter/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("WordFilter")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("WordFilter")] +[assembly: AssemblyCopyright("Copyright © 2015")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("7a11afbe-ff00-45f4-a41d-94bb6aead9d8")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Spiffbot/WordFilter/WordFilter.cs b/Spiffbot/WordFilter/WordFilter.cs new file mode 100644 index 0000000..82a25bc --- /dev/null +++ b/Spiffbot/WordFilter/WordFilter.cs @@ -0,0 +1,66 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using Spiff.Core; +using Spiff.Core.API; +using Spiff.Core.API.EventArgs; + +namespace WordFilter +{ + public class WordFilter : Plugin + { + public override string Name + { + get { return "Badword filter"; } + } + + public override string Author + { + get { return "Toyz"; } + } + + public override string Description + { + get { return "Simple badword Filter"; } + } + + public override int Version + { + get { return 1; } + } + + private string _wordFile = ""; + private List _words; + private Censor _censor; + public override void Start() + { + _wordFile = Path.Combine(PluginDirectory, "Words.txt"); + + _words = new List(); + if (File.Exists(_wordFile)) + _words = File.ReadAllLines(_wordFile).ToList(); + + _censor = new Censor(_words); + SpiffCore.OnChatEvent += SpiffCoreOnOnChatEvent; + } + + private void SpiffCoreOnOnChatEvent(object sender, OnChatEvent onChatEvent) + { + if (onChatEvent.User.IsMod) return; + var orginal = onChatEvent.Message; + var changes = _censor.CensorText(onChatEvent.Message); + + if (!orginal.Equals(changes)) + { + onChatEvent.User.Kick(1); + } + } + + public override void Destory() + { + //nothing to kill + } + } +} diff --git a/Spiffbot/WordFilter/WordFilter.csproj b/Spiffbot/WordFilter/WordFilter.csproj new file mode 100644 index 0000000..99c122c --- /dev/null +++ b/Spiffbot/WordFilter/WordFilter.csproj @@ -0,0 +1,60 @@ + + + + + Debug + AnyCPU + {8E0E9F7C-2EFF-40E1-A955-968890633850} + Library + Properties + WordFilter + WordFilter + v4.0 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + {5FBAAAEE-E98C-46BB-AF7C-01C8540ECFF2} + Spiff.Core + + + + + \ No newline at end of file From fe33581c06df7868ff8056eae5ea3af7364b590d Mon Sep 17 00:00:00 2001 From: Toyz Date: Sat, 21 Mar 2015 21:06:12 -0700 Subject: [PATCH 34/40] Added power to see total seen for censor And changed Kick to timeout --- Spiffbot/Spiff.IRC/Managers/Viewers/Viewer.cs | 6 ++++ Spiffbot/WordFilter/Censor.cs | 31 +++++++++++++++++-- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/Spiffbot/Spiff.IRC/Managers/Viewers/Viewer.cs b/Spiffbot/Spiff.IRC/Managers/Viewers/Viewer.cs index 5906aa1..6f6e487 100644 --- a/Spiffbot/Spiff.IRC/Managers/Viewers/Viewer.cs +++ b/Spiffbot/Spiff.IRC/Managers/Viewers/Viewer.cs @@ -44,11 +44,17 @@ public object Clone() return new Viewer(this); } + [Obsolete("Use timeout instead")] public void Kick(int timeout = 600) { SpiffCore.Instance.WriteOut.TimeoutUser(Username, timeout, true); } + public void Timeout(int timeout = 600) + { + SpiffCore.Instance.WriteOut.TimeoutUser(Username, timeout, true); + } + public void Ban() { SpiffCore.Instance.WriteOut.BanUser(Username, true); diff --git a/Spiffbot/WordFilter/Censor.cs b/Spiffbot/WordFilter/Censor.cs index fdc4b0e..1d34fb4 100644 --- a/Spiffbot/WordFilter/Censor.cs +++ b/Spiffbot/WordFilter/Censor.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; using System.Text.RegularExpressions; namespace WordFilter @@ -22,9 +21,37 @@ public string CensorText(string text) if (text == null) throw new ArgumentNullException("text"); - return CensoredWords.Select(ToRegexPattern).Aggregate(text, (current, regularExpression) => Regex.Replace(current, regularExpression, StarCensoredMatch, RegexOptions.IgnoreCase | RegexOptions.CultureInvariant)); + string censoredText = text; + + foreach (string censoredWord in CensoredWords) + { + string regularExpression = ToRegexPattern(censoredWord); + + censoredText = Regex.Replace(censoredText, regularExpression, StarCensoredMatch, + RegexOptions.IgnoreCase | RegexOptions.CultureInvariant); + } + + return censoredText; } + public List TotalSeen(string text) + { + List seen = new List(); + string censoredText = text; + + foreach (string censoredWord in CensoredWords) + { + string regularExpression = ToRegexPattern(censoredWord); + + censoredText = Regex.Replace(censoredText, regularExpression, StarCensoredMatch, + RegexOptions.IgnoreCase | RegexOptions.CultureInvariant); + + if(censoredWord != text) seen.Add(true); + } + + return seen; + } + private static string StarCensoredMatch(Match m) { string word = m.Captures[0].Value; From 3e79f6dc10f294488027a28230b89dcba930d812 Mon Sep 17 00:00:00 2001 From: Toyz Date: Sat, 21 Mar 2015 22:39:22 -0700 Subject: [PATCH 35/40] Changed stupid things --- Spiffbot/Spiffbot/ServerGUI.Designer.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Spiffbot/Spiffbot/ServerGUI.Designer.cs b/Spiffbot/Spiffbot/ServerGUI.Designer.cs index 252cebb..539ce39 100644 --- a/Spiffbot/Spiffbot/ServerGUI.Designer.cs +++ b/Spiffbot/Spiffbot/ServerGUI.Designer.cs @@ -109,7 +109,7 @@ private void InitializeComponent() this.tabPage2.Padding = new System.Windows.Forms.Padding(3); this.tabPage2.Size = new System.Drawing.Size(369, 276); this.tabPage2.TabIndex = 1; - this.tabPage2.Text = "Bot Config"; + this.tabPage2.Text = "Plugins & Commands"; this.tabPage2.UseVisualStyleBackColor = true; // // label2 @@ -155,26 +155,26 @@ private void InitializeComponent() this.banToolStripMenuItem, this.warningToolStripMenuItem}); this.BanKickControl.Name = "BanKickControl"; - this.BanKickControl.Size = new System.Drawing.Size(153, 92); + this.BanKickControl.Size = new System.Drawing.Size(120, 70); // // kickToolStripMenuItem // this.kickToolStripMenuItem.Name = "kickToolStripMenuItem"; - this.kickToolStripMenuItem.Size = new System.Drawing.Size(152, 22); - this.kickToolStripMenuItem.Text = "Kick"; + this.kickToolStripMenuItem.Size = new System.Drawing.Size(119, 22); + this.kickToolStripMenuItem.Text = "Timeout"; this.kickToolStripMenuItem.Click += new System.EventHandler(this.kickToolStripMenuItem_Click); // // banToolStripMenuItem // this.banToolStripMenuItem.Name = "banToolStripMenuItem"; - this.banToolStripMenuItem.Size = new System.Drawing.Size(152, 22); + this.banToolStripMenuItem.Size = new System.Drawing.Size(119, 22); this.banToolStripMenuItem.Text = "Ban"; this.banToolStripMenuItem.Click += new System.EventHandler(this.banToolStripMenuItem_Click); // // warningToolStripMenuItem // this.warningToolStripMenuItem.Name = "warningToolStripMenuItem"; - this.warningToolStripMenuItem.Size = new System.Drawing.Size(152, 22); + this.warningToolStripMenuItem.Size = new System.Drawing.Size(119, 22); this.warningToolStripMenuItem.Text = "Warning"; this.warningToolStripMenuItem.Click += new System.EventHandler(this.warningToolStripMenuItem_Click); // From fbb30556717ec3dbba727781fb7507fe6069744b Mon Sep 17 00:00:00 2001 From: Toyz Date: Sun, 22 Mar 2015 12:18:20 -0700 Subject: [PATCH 36/40] Made logging to file multi threaded --- Spiffbot/Spiff.IRC/Spiff.Core.csproj | 1 + Spiffbot/Spiff.IRC/Utils/Logger.cs | 44 +++++++------ Spiffbot/Spiff.IRC/Utils/LoggerTask.cs | 85 ++++++++++++++++++++++++++ Spiffbot/Spiffbot/Program.cs | 1 + 4 files changed, 113 insertions(+), 18 deletions(-) create mode 100644 Spiffbot/Spiff.IRC/Utils/LoggerTask.cs diff --git a/Spiffbot/Spiff.IRC/Spiff.Core.csproj b/Spiffbot/Spiff.IRC/Spiff.Core.csproj index 3673b82..fafce58 100644 --- a/Spiffbot/Spiff.IRC/Spiff.Core.csproj +++ b/Spiffbot/Spiff.IRC/Spiff.Core.csproj @@ -76,6 +76,7 @@ + diff --git a/Spiffbot/Spiff.IRC/Utils/Logger.cs b/Spiffbot/Spiff.IRC/Utils/Logger.cs index c0b00f4..a5c59a0 100644 --- a/Spiffbot/Spiff.IRC/Utils/Logger.cs +++ b/Spiffbot/Spiff.IRC/Utils/Logger.cs @@ -7,47 +7,55 @@ namespace Spiff.Core.Utils public static class Logger { private static readonly string LogFile; + private static readonly LoggerTask LoggerTask; static Logger() { if(string.IsNullOrEmpty(LogFile)) LogFile = Path.Combine("Logs", string.Format("{0:yyyy-MM-dd_hh-mm-ss-tt}.log", DateTime.Now)); + + if (LoggerTask == null) + { + LoggerTask = new LoggerTask(LogFile); + } } public static Ini ConfigFile { get; set; } public static void Error(Object error, string from = "") { - Console.WriteLine(string.IsNullOrWhiteSpace(from) ? error : string.Format("[{0}]".Bold().Red() + "{1}".Red(), @from, error)); - string text = (string) (string.IsNullOrWhiteSpace(@from) ? error : string.Format("[{0}]" + "{1}", @from, error)); - WriteLogFile(string.Format("[{0}]{1}", DateTime.Now, text)); + LoggerTask.Add(new LoggerTask.WritterObject + { + ConsoleText = (string)(string.IsNullOrWhiteSpace(from) ? error : string.Format("[{0}]".Bold().Red() + "{1}".Red(), @from, error)), + FileText = (string)(string.IsNullOrWhiteSpace(@from) ? error : string.Format("[{0}]" + "{1}", @from, error)) + }); } public static void Info(Object info, string from = "") { - Console.WriteLine(string.IsNullOrWhiteSpace(from) ? info : string.Format("[{0}]".Bold().Cyan() + "{1}".Cyan(), @from, info)); - string text = (string)(string.IsNullOrWhiteSpace(@from) ? info : string.Format("[{0}]" + "{1}", @from, info)); - WriteLogFile(text); + LoggerTask.Add(new LoggerTask.WritterObject + { + ConsoleText = (string)(string.IsNullOrWhiteSpace(from) ? info : string.Format("[{0}]".Bold().Blue() + "{1}".Blue(), @from, info)), + FileText = (string)(string.IsNullOrWhiteSpace(@from) ? info : string.Format("[{0}]" + "{1}", @from, info)) + }); } public static void Debug(Object debug, string from = "") { - Console.WriteLine(string.IsNullOrWhiteSpace(from) ? debug : string.Format("[{0}]".Bold().Yellow() + "{1}".Yellow(), @from, debug)); - string text = (string)(string.IsNullOrWhiteSpace(@from) ? debug : string.Format("[{0}]" + "{1}", @from, debug)); - WriteLogFile(string.Format("[{0}]{1}", DateTime.Now, text)); + LoggerTask.Add(new LoggerTask.WritterObject + { + ConsoleText = (string)(string.IsNullOrWhiteSpace(from) ? debug : string.Format("[{0}]".Bold().Yellow() + "{1}".Yellow(), @from, debug)), + FileText = (string)(string.IsNullOrWhiteSpace(@from) ? debug : string.Format("[{0}]" + "{1}", @from, debug)) + }); } public static void Write(Object write, string from = "") { - Console.WriteLine(string.IsNullOrWhiteSpace(from) ? write : string.Format("[{0}]{1}", @from, write)); - string text = (string)(string.IsNullOrWhiteSpace(@from) ? write : string.Format("[{0}]" + "{1}", @from, write)); - WriteLogFile(string.Format("[{0}]{1}", DateTime.Now, text)); - } - - private static void WriteLogFile(string text) - { - if (ConfigFile.GetValue("adv", "log", true)) - File.AppendAllText(LogFile, string.Format("[{0}]{1}{2}", DateTime.Now, text, Environment.NewLine)); + LoggerTask.Add(new LoggerTask.WritterObject + { + ConsoleText = (string)(string.IsNullOrWhiteSpace(from) ? write : string.Format("[{0}]".Bold().White() + "{1}".White(), @from, write)), + FileText = (string)(string.IsNullOrWhiteSpace(@from) ? write : string.Format("[{0}]" + "{1}", @from, write)) + }); } } } \ No newline at end of file diff --git a/Spiffbot/Spiff.IRC/Utils/LoggerTask.cs b/Spiffbot/Spiff.IRC/Utils/LoggerTask.cs new file mode 100644 index 0000000..a43027c --- /dev/null +++ b/Spiffbot/Spiff.IRC/Utils/LoggerTask.cs @@ -0,0 +1,85 @@ +using System; +using System.Collections.Concurrent; +using System.Drawing.Imaging; +using System.IO; +using System.Threading; +using System.Timers; +using Timer = System.Timers.Timer; + +namespace Spiff.Core.Utils +{ + public class LoggerTask + { + public class WritterObject + { + public string ConsoleText { get; set; } + public string FileText { get; set; } + } + + private readonly string _file; + public ConcurrentQueue ContentWriter = new ConcurrentQueue(); + + public LoggerTask(string file) + { + _file = file; + + var timer = new Timer(); + timer.Elapsed += TimerOnElapsed; + timer.Interval = 10; + timer.Enabled = true; + } + + public bool IsEmpty() + { + return ContentWriter.IsEmpty; + } + + public void Add(WritterObject txt) + { + ContentWriter.Enqueue(txt); + } + + private void TimerOnElapsed(object sender, ElapsedEventArgs elapsedEventArgs) + { + if (ContentWriter.IsEmpty) return; + + WritterObject txt; + ContentWriter.TryDequeue(out txt); + + if (txt != null) + { + if(Logger.ConfigFile.GetValue("adv", "log", true)) + WriteToFile(txt.FileText); + WriteToConsole(txt.ConsoleText); + } + } + + private static readonly ReaderWriterLockSlim ReadWriteLock = new ReaderWriterLockSlim(); + + private void WriteToFile(string txt) + { + //File.AppendAllText(_file, string.Format("[{0}]{1}{2}", DateTime.Now, txt, Environment.NewLine)); + //ReadWriteLock.EnterWriteLock(); + try + { + // Append text to the file + using (StreamWriter sw = File.AppendText(_file)) + { + sw.WriteLine("[{0}]{1}", DateTime.Now, txt); + sw.Close(); + } + } + catch(Exception e) + { + Logger.Error("File in use: " + e.Message + " - " + e.StackTrace, "WriteToFileFail"); + // Release lock + //ReadWriteLock.ExitWriteLock(); + } + } + + private void WriteToConsole(string txt) + { + Console.WriteLine(txt); + } + } +} diff --git a/Spiffbot/Spiffbot/Program.cs b/Spiffbot/Spiffbot/Program.cs index ea9266e..c348de6 100644 --- a/Spiffbot/Spiffbot/Program.cs +++ b/Spiffbot/Spiffbot/Program.cs @@ -22,6 +22,7 @@ static void Main(string[] args) EscapeSequencer.Install(); EscapeSequencer.Bold = true; + Logger.ConfigFile = ConfigFile; if (!Directory.Exists("Plugins")) Directory.CreateDirectory("Plugins"); From d69b4c34dce5c8f7f2bb8067e69b741fa0d5423d Mon Sep 17 00:00:00 2001 From: Toyz Date: Fri, 27 Mar 2015 09:55:08 -0700 Subject: [PATCH 37/40] Minor patches to code --- Spiffbot/Spiff.IRC/Utils/Ini.cs | 116 ++++++++++++------------- Spiffbot/Spiff.IRC/Utils/LoggerTask.cs | 7 +- Spiffbot/Spiffbot/ServerGUI.cs | 9 +- 3 files changed, 60 insertions(+), 72 deletions(-) diff --git a/Spiffbot/Spiff.IRC/Utils/Ini.cs b/Spiffbot/Spiff.IRC/Utils/Ini.cs index b5f0655..dfbbc48 100644 --- a/Spiffbot/Spiff.IRC/Utils/Ini.cs +++ b/Spiffbot/Spiff.IRC/Utils/Ini.cs @@ -159,111 +159,109 @@ public void Flush() } } - protected virtual void PerformFlush() + private void PerformFlush() { // *** If local cache was not modified, exit *** if (!_mCacheModified) return; _mCacheModified = false; // *** Check if original file exists *** - var OriginalFileExists = File.Exists(FileName); + var originalFileExists = File.Exists(FileName); // *** Get temporary file name *** - var TmpFileName = Path.ChangeExtension(FileName, "$n$"); + var tmpFileName = Path.ChangeExtension(FileName, "$n$"); // *** Copy content of original file to temporary file, replace modified values *** - StreamWriter sw = null; // *** Create the temporary file *** - sw = new StreamWriter(TmpFileName); + var sw = new StreamWriter(tmpFileName); try { - Dictionary CurrentSection = null; - if (OriginalFileExists) + Dictionary currentSection = null; + if (originalFileExists) { StreamReader sr = null; + string value = null; + var reading = true; + string key = null; try { // *** Open the original file *** sr = new StreamReader(FileName); // *** Read the file original content, replace changes with local cache values *** - string s; - string SectionName; - string Key = null; - string Value = null; - bool Unmodified; - var Reading = true; - while (Reading) + while (reading) { - s = sr.ReadLine(); - Reading = (s != null); + var s = sr.ReadLine(); + reading = (s != null); // *** Check for end of file *** - if (Reading) + string sectionName; + bool unmodified; + if (reading) { - Unmodified = true; + unmodified = true; s = s.Trim(); - SectionName = ParseSectionName(s); + sectionName = ParseSectionName(s); } else { - Unmodified = false; - SectionName = null; + unmodified = false; + sectionName = null; } // *** Check for section names *** - if ((SectionName != null) || (!Reading)) + if ((sectionName != null) || (!reading)) { - if (CurrentSection != null) + if (currentSection != null) { // *** Write all remaining modified values before leaving a section **** - if (CurrentSection.Count > 0) + if (currentSection.Count > 0) { - foreach (var fkey in CurrentSection.Keys) + foreach (var fkey in currentSection.Keys) { - if (CurrentSection.TryGetValue(fkey, out Value)) + if (currentSection.TryGetValue(fkey, out value)) { sw.Write(fkey); sw.Write('='); - sw.WriteLine(Value); + sw.WriteLine(value); } } sw.WriteLine(); - CurrentSection.Clear(); + currentSection.Clear(); } } - if (Reading) + if (reading) { // *** Check if current section is in local modified cache *** - if (!_mModified.TryGetValue(SectionName, out CurrentSection)) + if (!_mModified.TryGetValue(sectionName, out currentSection)) { - CurrentSection = null; + currentSection = null; } } } - else if (CurrentSection != null) + else if (currentSection != null) { // *** Check for key+value pair *** - if (ParseKeyValuePair(s, ref Key, ref Value)) + if (ParseKeyValuePair(s, ref key, ref value)) { - if (CurrentSection.TryGetValue(Key, out Value)) + if (currentSection.TryGetValue(key, out value)) { // *** Write modified value to temporary file *** - Unmodified = false; - CurrentSection.Remove(Key); + unmodified = false; + currentSection.Remove(key); - sw.Write(Key); + sw.Write(key); sw.Write('='); - sw.WriteLine(Value); + sw.WriteLine(value); } } } // *** Write unmodified lines from the original file *** - if (Unmodified) + if (unmodified) { sw.WriteLine(s); } @@ -277,33 +275,30 @@ protected virtual void PerformFlush() { // *** Cleanup: close files *** if (sr != null) sr.Close(); - sr = null; } } // *** Cycle on all remaining modified values *** - foreach (var SectionPair in _mModified) + foreach (var sectionPair in _mModified) { - CurrentSection = SectionPair.Value; - if (CurrentSection.Count > 0) - { - sw.WriteLine(); + currentSection = sectionPair.Value; + if (currentSection.Count <= 0) continue; + sw.WriteLine(); - // *** Write the section name *** - sw.Write('['); - sw.Write(SectionPair.Key); - sw.WriteLine(']'); + // *** Write the section name *** + sw.Write('['); + sw.Write(sectionPair.Key); + sw.WriteLine(']'); - // *** Cycle on all key+value pairs in the section *** - foreach (var ValuePair in CurrentSection) - { - // *** Write the key+value pair *** - sw.Write(ValuePair.Key); - sw.Write('='); - sw.WriteLine(ValuePair.Value); - } - CurrentSection.Clear(); + // *** Cycle on all key+value pairs in the section *** + foreach (var valuePair in currentSection) + { + // *** Write the key+value pair *** + sw.Write(valuePair.Key); + sw.Write('='); + sw.WriteLine(valuePair.Value); } + currentSection.Clear(); } _mModified.Clear(); @@ -312,16 +307,15 @@ protected virtual void PerformFlush() sw = null; // *** Rename the temporary file *** - File.Copy(TmpFileName, FileName, true); + File.Copy(tmpFileName, FileName, true); // *** Delete the temporary file *** - File.Delete(TmpFileName); + File.Delete(tmpFileName); } finally { // *** Cleanup: close files *** if (sw != null) sw.Close(); - sw = null; } } diff --git a/Spiffbot/Spiff.IRC/Utils/LoggerTask.cs b/Spiffbot/Spiff.IRC/Utils/LoggerTask.cs index a43027c..7fee8ec 100644 --- a/Spiffbot/Spiff.IRC/Utils/LoggerTask.cs +++ b/Spiffbot/Spiff.IRC/Utils/LoggerTask.cs @@ -1,10 +1,7 @@ using System; using System.Collections.Concurrent; -using System.Drawing.Imaging; using System.IO; -using System.Threading; using System.Timers; -using Timer = System.Timers.Timer; namespace Spiff.Core.Utils { @@ -54,8 +51,6 @@ private void TimerOnElapsed(object sender, ElapsedEventArgs elapsedEventArgs) } } - private static readonly ReaderWriterLockSlim ReadWriteLock = new ReaderWriterLockSlim(); - private void WriteToFile(string txt) { //File.AppendAllText(_file, string.Format("[{0}]{1}{2}", DateTime.Now, txt, Environment.NewLine)); @@ -77,7 +72,7 @@ private void WriteToFile(string txt) } } - private void WriteToConsole(string txt) + private static void WriteToConsole(string txt) { Console.WriteLine(txt); } diff --git a/Spiffbot/Spiffbot/ServerGUI.cs b/Spiffbot/Spiffbot/ServerGUI.cs index 9b9128e..1df5fad 100644 --- a/Spiffbot/Spiffbot/ServerGUI.cs +++ b/Spiffbot/Spiffbot/ServerGUI.cs @@ -3,7 +3,6 @@ using System.Windows.Forms; using Spiff.Core; using Spiff.Core.API.EventArgs; -using Spiff.Core.Utils; namespace Spiffbot { @@ -24,9 +23,9 @@ private void InstanceOnOnChatEvent(object sender, OnChatEvent onChatEvent) if (IsDisposed) return; Invoke(new Action(() => { - string name = string.Format("[{0}]", onChatEvent.User.Username); - int length = CurrentChat.Text.Length; - int boldName = name.Length; + var name = string.Format("[{0}]", onChatEvent.User.Username); + var length = CurrentChat.Text.Length; + var boldName = name.Length; CurrentChat.AppendText(string.Format("{0}: {1}{2}", name, onChatEvent.Message, Environment.NewLine)); CurrentChat.Select(length, boldName); @@ -137,7 +136,7 @@ private void kickToolStripMenuItem_Click(object sender, EventArgs e) { if (CurrrentUsers.SelectedIndex > -1) { - SpiffCore.Instance.ViewerManager.GetViewer(CurrrentUsers.SelectedItem.ToString()).Kick(); + SpiffCore.Instance.ViewerManager.GetViewer(CurrrentUsers.SelectedItem.ToString()).Timeout(); } } From a7c5254a8e5f90019c91dad71395615a658b1671 Mon Sep 17 00:00:00 2001 From: Toyz Date: Fri, 27 Mar 2015 12:43:32 -0700 Subject: [PATCH 38/40] Fixed few warnings in Ini system --- Spiffbot/Spiff.IRC/Utils/Ini.cs | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/Spiffbot/Spiff.IRC/Utils/Ini.cs b/Spiffbot/Spiff.IRC/Utils/Ini.cs index dfbbc48..7c5b6d4 100644 --- a/Spiffbot/Spiff.IRC/Utils/Ini.cs +++ b/Spiffbot/Spiff.IRC/Utils/Ini.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Globalization; using System.IO; +using System.Linq; using System.Text; namespace Spiff.Core.Utils @@ -63,8 +64,7 @@ private static string ParseSectionName(string line) { if (!line.StartsWith("[")) return null; if (!line.EndsWith("]")) return null; - if (line.Length < 3) return null; - return line.Substring(1, line.Length - 2); + return line.Length < 3 ? null : line.Substring(1, line.Length - 2); } // *** Parse key+value pair *** @@ -219,14 +219,12 @@ private void PerformFlush() // *** Write all remaining modified values before leaving a section **** if (currentSection.Count > 0) { - foreach (var fkey in currentSection.Keys) + var section = currentSection; + foreach (var fkey in currentSection.Keys.Where(fkey => section.TryGetValue(fkey, out value))) { - if (currentSection.TryGetValue(fkey, out value)) - { - sw.Write(fkey); - sw.Write('='); - sw.WriteLine(value); - } + sw.Write(fkey); + sw.Write('='); + sw.WriteLine(value); } sw.WriteLine(); currentSection.Clear(); @@ -337,10 +335,9 @@ public string GetValue(string sectionName, string key, string defaultValue) // *** Check if the key exists *** string value; - if (!section.TryGetValue(key, out value)) return defaultValue; + return !section.TryGetValue(key, out value) ? defaultValue : value; // *** Return the found value *** - return value; } } @@ -411,7 +408,7 @@ private string EncodeByteArray(byte[] value) } // *** Decode byte array *** - private byte[] DecodeByteArray(string value) + private static byte[] DecodeByteArray(string value) { if (value == null) return null; From d03b59df7b63960a673988a3f24412f8d507eabe Mon Sep 17 00:00:00 2001 From: Toyz Date: Fri, 27 Mar 2015 13:09:31 -0700 Subject: [PATCH 39/40] Warning clean up --- .../Defaults/Commands/ReloadConfigCommand.cs | 8 +- .../Defaults/Commands/WhoIsCommand.cs | 26 +++---- .../Spiff.IRC/Extensions/EscapeSequencer.cs | 74 +++++++++---------- .../Managers/Commands/CommandManager.cs | 5 +- Spiffbot/Spiff.IRC/SpiffCore.cs | 2 +- 5 files changed, 54 insertions(+), 61 deletions(-) diff --git a/Spiffbot/Spiff.IRC/Defaults/Commands/ReloadConfigCommand.cs b/Spiffbot/Spiff.IRC/Defaults/Commands/ReloadConfigCommand.cs index 0c4c460..684f23b 100644 --- a/Spiffbot/Spiff.IRC/Defaults/Commands/ReloadConfigCommand.cs +++ b/Spiffbot/Spiff.IRC/Defaults/Commands/ReloadConfigCommand.cs @@ -17,11 +17,9 @@ public override string CommandInfo public override void Run(string[] parts, string complete, string channel, Viewer nick) { - if (IsOwner(nick.Username)) - { - SpiffCore.Instance.GlobalConfig.Refresh(); - Boardcast("Global Server config has been reloaded!"); - } + if (!IsOwner(nick.Username)) return; + SpiffCore.Instance.GlobalConfig.Refresh(); + Boardcast("Global Server config has been reloaded!"); } } } diff --git a/Spiffbot/Spiff.IRC/Defaults/Commands/WhoIsCommand.cs b/Spiffbot/Spiff.IRC/Defaults/Commands/WhoIsCommand.cs index 49e94e6..a713d30 100644 --- a/Spiffbot/Spiff.IRC/Defaults/Commands/WhoIsCommand.cs +++ b/Spiffbot/Spiff.IRC/Defaults/Commands/WhoIsCommand.cs @@ -17,23 +17,21 @@ public override string CommandInfo public override void Run(string[] parts, string complete, string channel, Viewer nick) { - if (nick.IsMod || IsOwner(nick.Username)) + if (!nick.IsMod && !IsOwner(nick.Username)) return; + if (parts.Length < 2) { - if (parts.Length < 2) - { - SpiffCore.Instance.WriteOut.SendMessage("Usage: !whois nick"); - return; - } - var user = SpiffCore.Instance.ViewerManager.GetViewer(parts[1]); - - if (user == null) - { - SpiffCore.Instance.WriteOut.SendMessage("User does not exist or is not in the chat"); - return; - } + SpiffCore.Instance.WriteOut.SendMessage("Usage: !whois nick"); + return; + } + var user = SpiffCore.Instance.ViewerManager.GetViewer(parts[1]); - SpiffCore.Instance.WriteOut.SendMessage(user.ToString()); + if (user == null) + { + SpiffCore.Instance.WriteOut.SendMessage("User does not exist or is not in the chat"); + return; } + + SpiffCore.Instance.WriteOut.SendMessage(user.ToString()); } } } diff --git a/Spiffbot/Spiff.IRC/Extensions/EscapeSequencer.cs b/Spiffbot/Spiff.IRC/Extensions/EscapeSequencer.cs index 587b409..11b8cb5 100644 --- a/Spiffbot/Spiff.IRC/Extensions/EscapeSequencer.cs +++ b/Spiffbot/Spiff.IRC/Extensions/EscapeSequencer.cs @@ -6,9 +6,9 @@ namespace Spiff.Core.Extensions { public class EscapeSequencer : TextWriter { - private static EscapeSequencer Instance; + private static EscapeSequencer _instance; - private readonly TextWriter textWriter; + private readonly TextWriter _textWriter; private enum States { Text, @@ -20,49 +20,49 @@ private enum States private readonly ConsoleColor _defaultBackgroundColor; private EscapeSequencer(TextWriter textWriter) { - Instance = this; - this.textWriter = textWriter; + _instance = this; + _textWriter = textWriter; _defaultForegroundColor = Console.ForegroundColor; _defaultBackgroundColor = Console.BackgroundColor; } - private States state = States.Text; - private string escapeBuffer; - private byte intense; - private const char ESC = '\x1b'; + private States _state = States.Text; + private string _escapeBuffer; + private byte _intense; + private const char Esc = '\x1b'; public override void Write(char value) { - switch (state) + switch (_state) { case States.Text: - if (value == ESC) + if (value == Esc) { - state = States.Signaled; - escapeBuffer = ""; + _state = States.Signaled; + _escapeBuffer = ""; } else - textWriter.Write(value); + _textWriter.Write(value); break; case States.Signaled: if (value != '[') { - textWriter.Write(ESC); - textWriter.Write(value); - state = States.Text; + _textWriter.Write(Esc); + _textWriter.Write(value); + _state = States.Text; } else { - state = States.Started; + _state = States.Started; } break; case States.Started: if (value != 'm') - escapeBuffer += value; + _escapeBuffer += value; else { byte val; - if (byte.TryParse(escapeBuffer, out val)) + if (byte.TryParse(_escapeBuffer, out val)) { if (val >= 30 && val <= 37) SetForeColor(val); @@ -79,50 +79,50 @@ public override void Write(char value) else if (val == 49) SetDefaultBackColor(); } - state = States.Text; + _state = States.Text; } break; } } - private bool isInverted; + private bool _isInverted; private void SetInverse() { var c = Console.ForegroundColor; Console.ForegroundColor = Console.BackgroundColor; Console.BackgroundColor = c; - isInverted = !isInverted; + _isInverted = !_isInverted; } private void RemoveBold() { - intense--; + _intense--; } private void SetBold() { - intense++; + _intense++; } public static bool Bold { get { - return (Instance.intense > 0); + return (_instance._intense > 0); } set { if (value) - Instance.SetBold(); + _instance.SetBold(); else - Instance.RemoveBold(); + _instance.RemoveBold(); } } private void SetDefaultBackColor() { - if (isInverted) + if (_isInverted) Console.BackgroundColor = _defaultBackgroundColor; else Console.ForegroundColor = _defaultBackgroundColor; @@ -130,13 +130,13 @@ private void SetDefaultBackColor() private void SetDefaultForeColor() { - if (isInverted) + if (_isInverted) Console.BackgroundColor = _defaultForegroundColor; else Console.ForegroundColor = _defaultForegroundColor; } - private readonly ConsoleColor[] ColorMap = { + private readonly ConsoleColor[] _colorMap = { ConsoleColor.Black, ConsoleColor.DarkRed, ConsoleColor.DarkGreen, @@ -158,18 +158,18 @@ private void SetDefaultForeColor() private void SetBackColor(byte val) { - if (isInverted) - Console.ForegroundColor = ColorMap[val - 40 + (intense > 0 ? 8 : 0)]; + if (_isInverted) + Console.ForegroundColor = _colorMap[val - 40 + (_intense > 0 ? 8 : 0)]; else - Console.BackgroundColor = ColorMap[val - 40]; + Console.BackgroundColor = _colorMap[val - 40]; } private void SetForeColor(byte val) { - if (isInverted) - Console.BackgroundColor = ColorMap[val - 30]; + if (_isInverted) + Console.BackgroundColor = _colorMap[val - 30]; else - Console.ForegroundColor = ColorMap[val - 30 + (intense > 0 ? 8 : 0)]; + Console.ForegroundColor = _colorMap[val - 30 + (_intense > 0 ? 8 : 0)]; } public static void Install() @@ -179,7 +179,7 @@ public static void Install() public override Encoding Encoding { - get { return textWriter.Encoding; } + get { return _textWriter.Encoding; } } } diff --git a/Spiffbot/Spiff.IRC/Managers/Commands/CommandManager.cs b/Spiffbot/Spiff.IRC/Managers/Commands/CommandManager.cs index b3da168..af833a3 100644 --- a/Spiffbot/Spiff.IRC/Managers/Commands/CommandManager.cs +++ b/Spiffbot/Spiff.IRC/Managers/Commands/CommandManager.cs @@ -6,11 +6,8 @@ namespace Spiff.Core.Managers.Commands { public class CommandManager { - private readonly SpiffCore _spiffCore; - - public CommandManager(SpiffCore spiffCore) + public CommandManager() { - _spiffCore = spiffCore; CommandObjects = new List(); } diff --git a/Spiffbot/Spiff.IRC/SpiffCore.cs b/Spiffbot/Spiff.IRC/SpiffCore.cs index ee8ba3b..d8286c9 100644 --- a/Spiffbot/Spiff.IRC/SpiffCore.cs +++ b/Spiffbot/Spiff.IRC/SpiffCore.cs @@ -26,7 +26,7 @@ public SpiffCore(string channel, string botName, string outh, string pluginDirec AppDomain.CurrentDomain.AssemblyResolve += CurrentDomainOnAssemblyResolve; ViewerManager = new ViewerManager(this); - CommandManager = new CommandManager(this); + CommandManager = new CommandManager(); DefaultsMananger = new DefaultsMananger(this); //Register built in commands From 735a911277ad71df87b6fc8af445a50c4903c6c9 Mon Sep 17 00:00:00 2001 From: Toyz Date: Fri, 27 Mar 2015 13:12:07 -0700 Subject: [PATCH 40/40] Changed Kick to Timeout --- Spiffbot/Spiff.IRC/API/EventArgs/OnChatEvent.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Spiffbot/Spiff.IRC/API/EventArgs/OnChatEvent.cs b/Spiffbot/Spiff.IRC/API/EventArgs/OnChatEvent.cs index 76504b0..b6bc1ef 100644 --- a/Spiffbot/Spiff.IRC/API/EventArgs/OnChatEvent.cs +++ b/Spiffbot/Spiff.IRC/API/EventArgs/OnChatEvent.cs @@ -17,7 +17,7 @@ public OnChatEvent(string channel, Viewer user, string message) public void RemoveMessage(int timeout = 1) { - User.Kick(timeout); + User.Timeout(timeout); } } } \ No newline at end of file