diff --git a/.gitignore b/.gitignore index 48ba856..ac0a4e6 100644 --- a/.gitignore +++ b/.gitignore @@ -72,3 +72,7 @@ Icon Network Trash Folder 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/GameCommand.cs b/Spiffbot/DefaultCommands/Commands/GameCommand.cs index ebf8827..68fb861 100644 --- a/Spiffbot/DefaultCommands/Commands/GameCommand.cs +++ b/Spiffbot/DefaultCommands/Commands/GameCommand.cs @@ -1,6 +1,6 @@ -using Spiff.Core; -using Spiff.Core.API.Commands; +using Spiff.Core.API.Commands; using Spiff.Core.API.Twitch; +using Spiff.Core.Managers.Viewers; namespace DefaultCommands.Commands { @@ -16,7 +16,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/RandomViewer.cs b/Spiffbot/DefaultCommands/Commands/RandomViewer.cs index 48f80f4..cbad092 100644 --- a/Spiffbot/DefaultCommands/Commands/RandomViewer.cs +++ b/Spiffbot/DefaultCommands/Commands/RandomViewer.cs @@ -1,7 +1,7 @@ using Spiff.Core; using Spiff.Core.API.Commands; -using Spiff.Core.API.Twitch; using Spiff.Core.Extensions; +using Spiff.Core.Managers.Viewers; namespace DefaultCommands.Commands { @@ -17,9 +17,9 @@ 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); + var viewers = SpiffCore.Instance.ViewerManager.AllViewers; Boardcast("Random User is: " + viewers.PickRandom().Username); } diff --git a/Spiffbot/DefaultCommands/DefaultCommands.cs b/Spiffbot/DefaultCommands/DefaultCommands.cs index 72995f6..74fea89 100644 --- a/Spiffbot/DefaultCommands/DefaultCommands.cs +++ b/Spiffbot/DefaultCommands/DefaultCommands.cs @@ -28,17 +28,14 @@ public override int Version public override void Start() { - Logger.Write("Loading Plugin Commands", Name); - RegisterCommand(new AllCommands()); - RegisterCommand(new HelpCommand()); + Logger.Write("Loading Plugin LoadedCommands", Name); RegisterCommand(new GameCommand()); RegisterCommand(new RandomViewer()); - RegisterCommand(new PluginsCommand()); } public override void Destory() { - Logger.Write("[Default Commands]Stopping", Name); + Logger.Write("[Default LoadedCommands]Stopping", Name); } } } 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/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/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/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/API/Commands/Command.cs b/Spiffbot/Spiff.IRC/API/Commands/Command.cs index 3ddf065..17c49f0 100644 --- a/Spiffbot/Spiff.IRC/API/Commands/Command.cs +++ b/Spiffbot/Spiff.IRC/API/Commands/Command.cs @@ -1,5 +1,4 @@ -using System.Linq; -using Spiff.Core.API.Twitch; +using Spiff.Core.Managers.Viewers; namespace Spiff.Core.API.Commands { @@ -7,16 +6,14 @@ public abstract class Command { public abstract string CommandName { get; } 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) { - var users = SiteApi.GetChatters(SpiffCore.Instance.Channel); - var user = (from s in users where s.Username == nick select s).FirstOrDefault(); + var viewer = SpiffCore.Instance.ViewerManager.GetViewer(nick); - return user != null && user.IsMod; + return viewer != null && viewer.IsMod; } protected bool IsOwner(string nick) @@ -24,11 +21,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) @@ -36,4 +31,4 @@ protected void Boardcast(string message) SpiffCore.Instance.WriteOut.SendMessage(message); } } -} +} \ No newline at end of file diff --git a/Spiffbot/Spiff.IRC/API/EventArgs/OnChatEvent.cs b/Spiffbot/Spiff.IRC/API/EventArgs/OnChatEvent.cs index 13caf40..b6bc1ef 100644 --- a/Spiffbot/Spiff.IRC/API/EventArgs/OnChatEvent.cs +++ b/Spiffbot/Spiff.IRC/API/EventArgs/OnChatEvent.cs @@ -1,16 +1,23 @@ -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 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; Message = message; } + + public string Channel { get; private set; } + public Viewer User { get; private set; } + public string Message { get; private set; } + + public void RemoveMessage(int timeout = 1) + { + User.Timeout(timeout); + } } -} +} \ No newline at end of file diff --git a/Spiffbot/Spiff.IRC/API/EventArgs/OnCommandEvent.cs b/Spiffbot/Spiff.IRC/API/EventArgs/OnCommandEvent.cs index f94276c..a4de96f 100644 --- a/Spiffbot/Spiff.IRC/API/EventArgs/OnCommandEvent.cs +++ b/Spiffbot/Spiff.IRC/API/EventArgs/OnCommandEvent.cs @@ -1,19 +1,20 @@ -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[] Args { get; private set; } - public string Complete { 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; } + public string CommandName { get; private set; } + public string[] Args { get; private set; } + public string Complete { get; private set; } + public Viewer Nick { get; private set; } } -} +} \ No newline at end of file diff --git a/Spiffbot/Spiff.IRC/API/EventArgs/OnUserJoinEvent.cs b/Spiffbot/Spiff.IRC/API/EventArgs/OnUserJoinEvent.cs index 1c155bb..f4dcbc7 100644 --- a/Spiffbot/Spiff.IRC/API/EventArgs/OnUserJoinEvent.cs +++ b/Spiffbot/Spiff.IRC/API/EventArgs/OnUserJoinEvent.cs @@ -1,14 +1,16 @@ -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 string Channel { get; private set; } - - public OnUserJoinEvent(string nick, string channel) + public OnUserJoinEvent(Viewer nick, string channel) { Nick = nick; Channel = channel; } + + public Viewer Nick { get; private set; } + public string Channel { get; private set; } } -} +} \ No newline at end of file diff --git a/Spiffbot/Spiff.IRC/API/EventArgs/OnUserLeftEvent.cs b/Spiffbot/Spiff.IRC/API/EventArgs/OnUserLeftEvent.cs index aa4f331..11d752e 100644 --- a/Spiffbot/Spiff.IRC/API/EventArgs/OnUserLeftEvent.cs +++ b/Spiffbot/Spiff.IRC/API/EventArgs/OnUserLeftEvent.cs @@ -1,14 +1,16 @@ -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 OnUserLeftEvent(string nick, string channel) + public OnUserLeftEvent(Viewer nick, string channel) { Channel = channel; Nick = nick; } + + public string Channel { get; private set; } + public Viewer Nick { get; private set; } } -} +} \ No newline at end of file diff --git a/Spiffbot/Spiff.IRC/API/Helpers/Colors.cs b/Spiffbot/Spiff.IRC/API/Helpers/Colors.cs index b5581db..38da276 100644 --- a/Spiffbot/Spiff.IRC/API/Helpers/Colors.cs +++ b/Spiffbot/Spiff.IRC/API/Helpers/Colors.cs @@ -147,7 +147,7 @@ public static class Colors public static Color ToColor(string hex) { - if(!hex.StartsWith("#")) + if (!hex.StartsWith("#")) hex = "#" + hex; return ColorTranslator.FromHtml(hex); diff --git a/Spiffbot/Spiff.IRC/API/Plugin.cs b/Spiffbot/Spiff.IRC/API/Plugin.cs index 1f59aa7..28a0af5 100644 --- a/Spiffbot/Spiff.IRC/API/Plugin.cs +++ b/Spiffbot/Spiff.IRC/API/Plugin.cs @@ -1,27 +1,20 @@ using System.IO; -using System.Linq; using Spiff.Core.API.Commands; +using Spiff.Core.IRC; +using Spiff.Core.Managers.Viewers; using Spiff.Core.Utils; namespace Spiff.Core.API { public abstract class Plugin { + private Ini _config; //Plugin Info public abstract string Name { get; } public abstract string Author { get; } public abstract string Description { get; } public abstract int Version { get; } - //Abstracts - public void Preload() - { - //Can be overried to Preload stuff - } - public abstract void Start(); - public abstract void Destory(); - - private Ini _config; public Ini Config { get @@ -38,15 +31,22 @@ public Ini Config return _config; } } + public SpiffCore SpiffCore { get { return SpiffCore.Instance; } } - public OutUtils Writer + + public IrcWritter Writer { get { return SpiffCore.WriteOut; } } + public ViewerManager ViewerManager + { + get { return SpiffCore.ViewerManager; } + } + public string PluginDirectory { get @@ -59,9 +59,18 @@ public string PluginDirectory } } + //Abstracts + public void Preload() + { + //Can be overried to Preload stuff + } + + public abstract void Start(); + public abstract void Destory(); + protected void RegisterCommand(Command command) { - SpiffCore.Instance.AddCommand(command); + SpiffCore.Instance.CommandManager.RegisterCommand(command); } protected Plugin GetPlugin(string name) @@ -74,4 +83,4 @@ protected Plugin GetPlugin(Plugin plugin) return SpiffCore.PluginLoader.GetPlugin(plugin); } } -} +} \ No newline at end of file diff --git a/Spiffbot/Spiff.IRC/API/PluginLoader.cs b/Spiffbot/Spiff.IRC/API/PluginLoader.cs index dc02fb6..25e6738 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; @@ -12,9 +11,6 @@ namespace Spiff.Core.API public class PluginLoader { private readonly string _directory; - public List LoadedPlugins { get; private set; } - public Dictionary LoadedAssemblies { get; private set; } - public PluginLoader(string directory) { @@ -22,8 +18,13 @@ public PluginLoader(string directory) LoadedPlugins = new List(); LoadedAssemblies = new Dictionary(); + LoadedAppDomains = new Dictionary(); } + public List LoadedPlugins { get; private set; } + public Dictionary LoadedAssemblies { get; private set; } + public Dictionary LoadedAppDomains { get; private set; } + public void LoadPlugins() { foreach ( @@ -32,6 +33,12 @@ var assembly in _directory, "*.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); } @@ -41,7 +48,10 @@ public void LoadPlugin(Assembly plugin, bool start = false) { if (plugin == null) return; var types = plugin.GetTypes(); - foreach (var pin in from type in types where !type.IsInterface && !type.IsAbstract where type.HasAbstract(typeof(Plugin)) select (Plugin)Activator.CreateInstance(type)) + foreach (var pin in from type in types + where !type.IsInterface && !type.IsAbstract + where type.HasAbstract(typeof (Plugin)) + select (Plugin) Activator.CreateInstance(type)) { Logger.Info(string.Format("Loading Plugin - {0}(V -> {1})", pin.Name, pin.Version), "Plugin Engine"); if (start) @@ -81,5 +91,14 @@ public void StartPlugins() plugin.Start(); } } + + //TODO: Fix me so we can use this to load plugins! + public class ProxyClass : MarshalByRefObject + { + public Assembly LoadAssembly(string path) + { + return Assembly.LoadFile(path); + } + } } -} +} \ No newline at end of file diff --git a/Spiffbot/Spiff.IRC/API/Twitch/SiteAPI.cs b/Spiffbot/Spiff.IRC/API/Twitch/SiteAPI.cs index ec45c21..ebf519b 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,23 +61,13 @@ 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()) { - var json = JObject.Parse(client.DownloadString(string.Format("https://api.twitch.tv/kraken/streams/{0}", streamer))); + var json = + JObject.Parse( + client.DownloadString(string.Format("https://api.twitch.tv/kraken/streams/{0}", streamer))); //Console.WriteLine(json["stream"]); try @@ -90,6 +81,8 @@ 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 +96,10 @@ 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) { @@ -119,11 +114,10 @@ public static TwitchJson.Followers.RootObject GetFollowers(string streamer) { using (var client = new WebClient()) { - return JsonConvert.DeserializeObject( client.DownloadString("https://api.twitch.tv/kraken/channels/" + streamer + "/follows")); } } } -} +} \ No newline at end of file diff --git a/Spiffbot/DefaultCommands/Commands/AllCommands.cs b/Spiffbot/Spiff.IRC/Defaults/Commands/AllCommands.cs similarity index 73% rename from Spiffbot/DefaultCommands/Commands/AllCommands.cs rename to Spiffbot/Spiff.IRC/Defaults/Commands/AllCommands.cs index d39fab6..cda5138 100644 --- a/Spiffbot/DefaultCommands/Commands/AllCommands.cs +++ b/Spiffbot/Spiff.IRC/Defaults/Commands/AllCommands.cs @@ -1,7 +1,8 @@ -using Spiff.Core; +using System.Linq; using Spiff.Core.API.Commands; +using Spiff.Core.Managers.Viewers; -namespace DefaultCommands.Commands +namespace Spiff.Core.Defaults.Commands { public class AllCommands : Command { @@ -15,11 +16,11 @@ 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 Commands: " + commands); } } -} +} \ No newline at end of file diff --git a/Spiffbot/DefaultCommands/Commands/HelpCommand.cs b/Spiffbot/Spiff.IRC/Defaults/Commands/HelpCommand.cs similarity index 74% rename from Spiffbot/DefaultCommands/Commands/HelpCommand.cs rename to Spiffbot/Spiff.IRC/Defaults/Commands/HelpCommand.cs index c3ee39d..6653d8e 100644 --- a/Spiffbot/DefaultCommands/Commands/HelpCommand.cs +++ b/Spiffbot/Spiff.IRC/Defaults/Commands/HelpCommand.cs @@ -1,7 +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 { @@ -15,7 +15,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 +23,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(parts[1]); if (command == null) Boardcast("Command does not exist"); @@ -33,4 +31,4 @@ public override void Run(string[] parts, string complete, string channel, string Boardcast(command.CommandName + " - " + command.CommandInfo); } } -} +} \ No newline at end of file diff --git a/Spiffbot/DefaultCommands/Commands/PluginsCommand.cs b/Spiffbot/Spiff.IRC/Defaults/Commands/PluginsCommand.cs similarity index 60% rename from Spiffbot/DefaultCommands/Commands/PluginsCommand.cs rename to Spiffbot/Spiff.IRC/Defaults/Commands/PluginsCommand.cs index 9e37dba..cc72e6a 100644 --- a/Spiffbot/DefaultCommands/Commands/PluginsCommand.cs +++ b/Spiffbot/Spiff.IRC/Defaults/Commands/PluginsCommand.cs @@ -1,15 +1,14 @@ -using System.Collections.Generic; -using System.Linq; -using Spiff.Core; +using System.Linq; using Spiff.Core.API.Commands; +using Spiff.Core.Managers.Viewers; -namespace DefaultCommands.Commands +namespace Spiff.Core.Defaults.Commands { public class PluginsCommand : Command { public override string CommandName { - get { return "plugins"; } + get { return "plugins"; } } public override string CommandInfo @@ -17,11 +16,11 @@ 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(); + var pluginNames = SpiffCore.Instance.PluginLoader.LoadedPlugins.Select(plugin => plugin.Name).ToList(); Boardcast(string.Format("Loaded Plugins({0}): {1}", pluginNames.Count, string.Join(", ", pluginNames))); } } -} +} \ No newline at end of file diff --git a/Spiffbot/Spiff.IRC/Defaults/Commands/ReloadConfigCommand.cs b/Spiffbot/Spiff.IRC/Defaults/Commands/ReloadConfigCommand.cs new file mode 100644 index 0000000..684f23b --- /dev/null +++ b/Spiffbot/Spiff.IRC/Defaults/Commands/ReloadConfigCommand.cs @@ -0,0 +1,25 @@ +using Spiff.Core.API.Commands; +using Spiff.Core.Managers.Viewers; + +namespace Spiff.Core.Defaults.Commands +{ + class ReloadConfigCommand : Command + { + public override string CommandName + { + get { return "reloadconfig"; } + } + + public override string CommandInfo + { + get { return "Reload the running server Config"; } + } + + public override void Run(string[] parts, string complete, string channel, Viewer nick) + { + 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 new file mode 100644 index 0000000..a713d30 --- /dev/null +++ b/Spiffbot/Spiff.IRC/Defaults/Commands/WhoIsCommand.cs @@ -0,0 +1,37 @@ +using Spiff.Core.API.Commands; +using Spiff.Core.Managers.Viewers; + +namespace Spiff.Core.Defaults.Commands +{ + public class WhoIsCommand : Command + { + public override string CommandName + { + get { return "whois"; } + } + + public override string CommandInfo + { + get { return "This returns the whois info on given user"; } + } + + public override void Run(string[] parts, string complete, string channel, Viewer nick) + { + if (!nick.IsMod && !IsOwner(nick.Username)) return; + 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(user.ToString()); + } + } +} diff --git a/Spiffbot/Spiff.IRC/Defaults/DefaultsMananger.cs b/Spiffbot/Spiff.IRC/Defaults/DefaultsMananger.cs new file mode 100644 index 0000000..f8c2565 --- /dev/null +++ b/Spiffbot/Spiff.IRC/Defaults/DefaultsMananger.cs @@ -0,0 +1,24 @@ +using Spiff.Core.Defaults.Commands; + +namespace Spiff.Core.Defaults +{ + //Use this to handle any defaults to the system like plugins and other things + 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()); + _spiffCore.CommandManager.RegisterCommand(new ReloadConfigCommand()); + _spiffCore.CommandManager.RegisterCommand(new WhoIsCommand()); + } + } +} \ No newline at end of file diff --git a/Spiffbot/Spiff.IRC/Extensions/ColorsExtension.cs b/Spiffbot/Spiff.IRC/Extensions/ColorsExtension.cs new file mode 100644 index 0000000..8ffc08b --- /dev/null +++ b/Spiffbot/Spiff.IRC/Extensions/ColorsExtension.cs @@ -0,0 +1,127 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Spiff.Core.Extensions +{ + public static class ColorsExtension + { + public struct ColorWrap + { + public byte Start { get; private set; } + public byte End { get; private set; } + + public ColorWrap(byte start, byte end) + : this() + { + Start = start; + End = end; + } + } + + public static readonly Dictionary DefaultTheme = new Dictionary + { + {"bold", new ColorWrap(1, 22)}, + {"italic", new ColorWrap(3, 23)}, + {"underline", new ColorWrap(4, 24)}, + {"inverse", new ColorWrap(7, 27)}, + + {"reset", new ColorWrap(39, 49)}, + + {"white", new ColorWrap(37, 39)}, + {"grey", new ColorWrap(90, 39)}, + {"black", new ColorWrap(30, 39)}, + + {"blue", new ColorWrap(34, 39)}, + {"cyan", new ColorWrap(36, 39)}, + {"green", new ColorWrap(32, 39)}, + {"magenta", new ColorWrap(35, 39)}, + {"red", new ColorWrap(31, 39)}, + {"yellow", new ColorWrap(33, 39)} + }; + + private static readonly Dictionary Theme = DefaultTheme; + + public static string Bold(this string s) { return Wrap(s, "bold"); } + public static string Italic(this string s) { return Wrap(s, "italic"); } + public static string Underline(this string s) { return Wrap(s, "underline"); } + public static string Inverse(this string s) { return Wrap(s, "inverse"); } + public static string White(this string s) { return Wrap(s, "white"); } + public static string Grey(this string s) { return Wrap(s, "grey"); } + public static string Black(this string s) { return Wrap(s, "black"); } + public static string Blue(this string s) { return Wrap(s, "blue"); } + public static string Cyan(this string s) { return Wrap(s, "cyan"); } + public static string Green(this string s) { return Wrap(s, "green"); } + public static string Magenta(this string s) { return Wrap(s, "magenta"); } + public static string Red(this string s) { return Wrap(s, "red"); } + public static string Yellow(this string s) { return Wrap(s, "yellow"); } + + public static string Reset(this string s) { return Wrap("", "reset") + s; } + + + private static bool _isBg; + public static string On(this string s) + { + _isBg = true; + return s; + } + + public static string Color(this string str, string color) + { + return Wrap(str, color); + } + + private static string Wrap(string str, string color) + { + var w = Theme[color]; + + int start = w.Start; + int end = w.End; + if (_isBg && start >= 30 && start <= 37) + { + _isBg = false; + start += 10; + end += 10; + } + + _isBg = false; + return string.Format("\x1b[{0}m{1}\x1b[{2}m", start, str, end); + } + + private static string Wrap(char c, string color) + { + return Wrap(c.ToString(), color); + } + + public static string RunSequencer(string s, Func sequencer) + { + if (null == s) + return null; + + var sb = new StringBuilder(); + for (int n = 0; n < s.Length; n++) + { + sb.Append(sequencer(s, n, s[n])); + } + + return sb.ToString(); + } + + public static string Zebra(this string s) + { + return RunSequencer( + s, + (str, i, c) => (0 == i % 2) ? Wrap(c, "inverse") : c.ToString() + ); + } + + public static string Rainbow(this string s) + { + var rainbowColors = new[] { "red", "yellow", "green", "blue", "magenta" }; //RoY G BiV + return RunSequencer( + s, + (str, i, c) => (char.IsWhiteSpace(c) ? c.ToString() : Wrap(c, rainbowColors[(i + 1) % rainbowColors.Length])) + ); + } + } +} diff --git a/Spiffbot/Spiff.IRC/Extensions/EscapeSequencer.cs b/Spiffbot/Spiff.IRC/Extensions/EscapeSequencer.cs new file mode 100644 index 0000000..11b8cb5 --- /dev/null +++ b/Spiffbot/Spiff.IRC/Extensions/EscapeSequencer.cs @@ -0,0 +1,186 @@ +using System; +using System.IO; +using System.Text; + +namespace Spiff.Core.Extensions +{ + public class EscapeSequencer : TextWriter + { + private static EscapeSequencer _instance; + + private readonly TextWriter _textWriter; + private enum States + { + Text, + Signaled, + Started + } + + private readonly ConsoleColor _defaultForegroundColor; + private readonly ConsoleColor _defaultBackgroundColor; + private EscapeSequencer(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'; + + public override void Write(char value) + { + switch (_state) + { + case States.Text: + if (value == Esc) + { + _state = States.Signaled; + _escapeBuffer = ""; + } + else + _textWriter.Write(value); + break; + case States.Signaled: + if (value != '[') + { + _textWriter.Write(Esc); + _textWriter.Write(value); + _state = States.Text; + } + else + { + _state = States.Started; + } + break; + case States.Started: + if (value != 'm') + _escapeBuffer += value; + else + { + byte val; + if (byte.TryParse(_escapeBuffer, out val)) + { + if (val >= 30 && val <= 37) + SetForeColor(val); + else if (val == 39) + SetDefaultForeColor(); + else if (val == 1) + SetBold(); + else if (val == 22) + RemoveBold(); + else if (val == 7 || val == 27) + SetInverse(); + else if (val >= 40 && val <= 47) + SetBackColor(val); + else if (val == 49) + SetDefaultBackColor(); + } + _state = States.Text; + } + break; + } + + } + + private bool _isInverted; + private void SetInverse() + { + var c = Console.ForegroundColor; + Console.ForegroundColor = Console.BackgroundColor; + Console.BackgroundColor = c; + _isInverted = !_isInverted; + } + + private void RemoveBold() + { + _intense--; + } + + private void SetBold() + { + _intense++; + } + + public static bool Bold + { + get + { + return (_instance._intense > 0); + } + set + { + if (value) + _instance.SetBold(); + else + _instance.RemoveBold(); + } + } + + private void SetDefaultBackColor() + { + if (_isInverted) + Console.BackgroundColor = _defaultBackgroundColor; + else + Console.ForegroundColor = _defaultBackgroundColor; + } + + private void SetDefaultForeColor() + { + if (_isInverted) + Console.BackgroundColor = _defaultForegroundColor; + else + Console.ForegroundColor = _defaultForegroundColor; + } + + private readonly ConsoleColor[] _colorMap = { + ConsoleColor.Black, + ConsoleColor.DarkRed, + ConsoleColor.DarkGreen, + ConsoleColor.DarkYellow, + ConsoleColor.DarkBlue, + ConsoleColor.DarkMagenta, + ConsoleColor.DarkCyan, + ConsoleColor.Gray, + + ConsoleColor.Black, + ConsoleColor.Red, + ConsoleColor.Green, + ConsoleColor.Yellow, + ConsoleColor.Blue, + ConsoleColor.Magenta, + ConsoleColor.Cyan, + ConsoleColor.White + }; + + private void SetBackColor(byte val) + { + if (_isInverted) + Console.ForegroundColor = _colorMap[val - 40 + (_intense > 0 ? 8 : 0)]; + else + Console.BackgroundColor = _colorMap[val - 40]; + } + + private void SetForeColor(byte val) + { + if (_isInverted) + Console.BackgroundColor = _colorMap[val - 30]; + else + Console.ForegroundColor = _colorMap[val - 30 + (_intense > 0 ? 8 : 0)]; + } + + public static void Install() + { + Console.SetOut(new EscapeSequencer(Console.Out)); + } + + public override Encoding Encoding + { + get { return _textWriter.Encoding; } + } + } + +} diff --git a/Spiffbot/Spiff.IRC/Extensions/ListExtensions.cs b/Spiffbot/Spiff.IRC/Extensions/ListExtensions.cs index 0ead4b9..3464162 100644 --- a/Spiffbot/Spiff.IRC/Extensions/ListExtensions.cs +++ b/Spiffbot/Spiff.IRC/Extensions/ListExtensions.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.ComponentModel; using System.Linq; namespace Spiff.Core.Extensions @@ -24,11 +23,9 @@ public static IEnumerable Shuffle(this IEnumerable source) public static IEnumerable Randomize(this IEnumerable target) { - Random r = new Random(); + var r = new Random(); return target.OrderBy(x => (r.Next())); - } - - + } } -} +} \ No newline at end of file diff --git a/Spiffbot/Spiff.IRC/Extensions/StringExtensions.cs b/Spiffbot/Spiff.IRC/Extensions/StringExtensions.cs index 0787be3..5f72dd1 100644 --- a/Spiffbot/Spiff.IRC/Extensions/StringExtensions.cs +++ b/Spiffbot/Spiff.IRC/Extensions/StringExtensions.cs @@ -24,25 +24,26 @@ public static T Parse(this string value) { // Get default value for type so if string // is empty then we can return default value. - T result = default(T); + var result = default(T); if (!string.IsNullOrEmpty(value)) { // we are not going to handle exception here // if you need SafeParse then you should create // another method specially for that. - TypeConverter tc = TypeDescriptor.GetConverter(typeof(T)); - result = (T)tc.ConvertFrom(value); - } return result; + var tc = TypeDescriptor.GetConverter(typeof (T)); + result = (T) tc.ConvertFrom(value); + } + return result; } public static string Truncate(this string text, int maxLength) { // replaces the truncated string to a ... const string suffix = "..."; - string truncatedString = text; + var truncatedString = text; if (maxLength <= 0) return truncatedString; - int strLength = maxLength - suffix.Length; + var strLength = maxLength - suffix.Length; if (strLength <= 0) return truncatedString; @@ -54,4 +55,4 @@ public static string Truncate(this string text, int maxLength) return truncatedString; } } -} +} \ No newline at end of file diff --git a/Spiffbot/Spiff.IRC/Extensions/TypeExtensions.cs b/Spiffbot/Spiff.IRC/Extensions/TypeExtensions.cs index 82425b2..115f202 100644 --- a/Spiffbot/Spiff.IRC/Extensions/TypeExtensions.cs +++ b/Spiffbot/Spiff.IRC/Extensions/TypeExtensions.cs @@ -9,4 +9,4 @@ public static bool HasAbstract(this Type type, Type @abstract) return type.IsSubclassOf(@abstract); } } -} +} \ No newline at end of file diff --git a/Spiffbot/Spiff.IRC/IRC/IRCClient.cs b/Spiffbot/Spiff.IRC/IRC/IRCClient.cs index 5b6da56..db4d694 100644 --- a/Spiffbot/Spiff.IRC/IRC/IRCClient.cs +++ b/Spiffbot/Spiff.IRC/IRC/IRCClient.cs @@ -1,27 +1,26 @@ using System; +using System.Diagnostics; using System.IO; using System.Net.Sockets; using System.Text; using System.Threading; +using System.Threading.Tasks; using Spiff.Core.Utils; namespace Spiff.Core.IRC { - public class IRCClient + public class IrcClient { private readonly string _channel; - private readonly string _user; private readonly string _oauth; private readonly SpiffCore _twitch; - - private Thread _serverThread; + private readonly string _user; private StreamReader _reader; + private Thread _serverThread; private StreamWriter _streamWriter; - public event EventHandler OnTwitchEvent; - public event EventHandler OnTwitchDataDebugOut; - - public IRCClient(string channel, string user, string oauth, SpiffCore twitch) + private Stopwatch _stopWatch = new Stopwatch(); + public IrcClient(string channel, string user, string oauth, SpiffCore twitch) { _channel = channel; _user = user; @@ -29,6 +28,9 @@ public IRCClient(string channel, string user, string oauth, SpiffCore twitch) _twitch = twitch; } + public event EventHandler OnTwitchDataEvent; + public event EventHandler OnTwitchDebugEvent; + public void Start() { Setup(); @@ -48,7 +50,7 @@ private void Setup() _reader = new StreamReader(nwStream, Encoding.GetEncoding("iso8859-1")); _streamWriter = new StreamWriter(nwStream, Encoding.GetEncoding("iso8859-1")); - _twitch.WriteOut = new OutUtils(_streamWriter, _channel); + _twitch.WriteOut = new IrcWritter(_streamWriter, _channel); } private void Startup() @@ -61,9 +63,9 @@ public void Login() { var writeOut = _twitch.WriteOut; - writeOut.SendCustom("PASS oauth:" + _oauth); - writeOut.SendCustom("NICK " + _user); - writeOut.SendCustom("USER " + _user + " :SpiffBot"); + writeOut.SendCustom("PASS oauth:" + _oauth, true); + writeOut.SendCustom("NICK " + _user, true); + writeOut.SendCustom("USER " + _user + " :SpiffBot", true); writeOut.SendChannelJoin(); } @@ -73,19 +75,31 @@ private void Listener() string data; while ((data = _reader.ReadLine()) != null) { - var ex = data.Split(new[] { ' ' }, 5); + var ex = data.Split(new[] {' '}, 5); if (ex[0] == "PING") { + if (_stopWatch.IsRunning) + { + _stopWatch.Stop(); + Logger.Info(string.Format("PingPong from twitch {0}ms", _stopWatch.ElapsedMilliseconds), "PingPong"); + _stopWatch = new Stopwatch(); + } writeOut.SendCustom("PONG " + ex[1]); + _stopWatch.Start(); continue; } - if(OnTwitchEvent != null) - OnTwitchEvent(this, new TwitchEvent(data)); + var data1 = data; + var ircData = IrcReader.ParseIrcMessageWithRegex(data); + new Task(() => + { + if (OnTwitchDataEvent != null) + OnTwitchDataEvent(this, new IrcDataEvent(data1, ircData)); - if (OnTwitchDataDebugOut != null) - OnTwitchDataDebugOut(this, new TwitchEvent(data)); + if (OnTwitchDebugEvent != null) + OnTwitchDebugEvent(this, new IrcDataEvent(data1, ircData)); + }).Start(); } } } -} +} \ No newline at end of file diff --git a/Spiffbot/Spiff.IRC/IRC/IrcDataEvent.cs b/Spiffbot/Spiff.IRC/IRC/IrcDataEvent.cs new file mode 100644 index 0000000..b8b13cc --- /dev/null +++ b/Spiffbot/Spiff.IRC/IRC/IrcDataEvent.cs @@ -0,0 +1,16 @@ +using System; + +namespace Spiff.Core.IRC +{ + public class IrcDataEvent : EventArgs + { + 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/IRC/IrcWritter.cs b/Spiffbot/Spiff.IRC/IRC/IrcWritter.cs new file mode 100644 index 0000000..d8b4d0f --- /dev/null +++ b/Spiffbot/Spiff.IRC/IRC/IrcWritter.cs @@ -0,0 +1,103 @@ +using System; +using System.Collections.Concurrent; +using System.IO; +using System.Timers; + +namespace Spiff.Core.IRC +{ + public class IrcWritter + { + private readonly string _channel; + private readonly StreamWriter _writer; + private readonly ConcurrentQueue _queue = new ConcurrentQueue(); + public Timer STimer {get; private set; } + + public IrcWritter(StreamWriter writer, string channel) + { + if (writer == null) throw new ArgumentNullException("writer"); + if (channel == null) throw new ArgumentNullException("channel"); + _writer = writer; + _channel = channel; + STimer = new Timer {Interval = 1000, Enabled = true}; + STimer.Elapsed += STimerOnElapsed; + } + + private void STimerOnElapsed(object sender, ElapsedEventArgs elapsedEventArgs) + { + if (_queue.IsEmpty) return; + + string item; + _queue.TryDequeue(out item); + + if (string.IsNullOrEmpty(item)) return; + _writer.WriteLine(item); + _writer.Flush(); + } + + public void SendMessage(string message, bool bypass = false) + { + if (bypass) + { + WriteDirect(string.Format("PRIVMSG #{0} :{1}", _channel, message)); + return; + } + _queue.Enqueue(string.Format("PRIVMSG #{0} :{1}", _channel, message)); + } + + public void SendChannelJoin(bool bypass = false) + { + if (bypass) + { + WriteDirect(string.Format("JOIN #{0}", _channel)); + return; + } + _queue.Enqueue(string.Format("JOIN #{0}", _channel)); + } + + public void TimeoutUser(string user, int timeout, bool bypass = false) + { + if (bypass) + { + SendMessage(string.Format("/timeout {0} {1}", user, timeout), true); + return; + } + SendMessage(string.Format("/timeout {0} {1}", user, timeout)); + } + + public void BanUser(string user, bool bypass = false) + { + if (bypass) + { + SendMessage(string.Format("/ban {0}", user), true); + return; + } + SendMessage(string.Format("/ban {0}", user)); + } + + public void UnbanUser(string user, bool bypass = false) + { + if (bypass) + { + SendMessage(string.Format("/unban {0}", user), true); + return; + } + SendMessage(string.Format("/unban {0}", user)); + } + + public void SendCustom(string command, bool bypass = false) + { + if (bypass) + { + WriteDirect(command); + return; + } + _queue.Enqueue(command); + } + + private void WriteDirect(string body) + { + _writer.WriteLine(body); + _writer.Flush(); + } + } +} \ No newline at end of file diff --git a/Spiffbot/Spiff.IRC/IRC/TwitchEvent.cs b/Spiffbot/Spiff.IRC/IRC/TwitchEvent.cs deleted file mode 100644 index cee58fb..0000000 --- a/Spiffbot/Spiff.IRC/IRC/TwitchEvent.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; - -namespace Spiff.Core.IRC -{ - public class TwitchEvent : EventArgs - { - public string Payload { get; private set; } - - public TwitchEvent(string payload) - { - Payload = payload; - } - } -} diff --git a/Spiffbot/Spiff.IRC/Managers/Commands/CommandManager.cs b/Spiffbot/Spiff.IRC/Managers/Commands/CommandManager.cs new file mode 100644 index 0000000..af833a3 --- /dev/null +++ b/Spiffbot/Spiff.IRC/Managers/Commands/CommandManager.cs @@ -0,0 +1,53 @@ +using System.Collections.Generic; +using System.Linq; +using Spiff.Core.Managers.Viewers; + +namespace Spiff.Core.Managers.Commands +{ + public class CommandManager + { + public CommandManager() + { + CommandObjects = new List(); + } + + public List CommandObjects { get; private set; } + + public CommandObject GetCommandObject(string command) + { + return + (from s in CommandObjects + where Equals(s.CommandName.ToLower(), command.ToLower().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); + } + + 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.Run(args, message, getViewer); + } + } + } +} \ No newline at end of file diff --git a/Spiffbot/Spiff.IRC/Managers/Commands/CommandObject.cs b/Spiffbot/Spiff.IRC/Managers/Commands/CommandObject.cs new file mode 100644 index 0000000..355b856 --- /dev/null +++ b/Spiffbot/Spiff.IRC/Managers/Commands/CommandObject.cs @@ -0,0 +1,41 @@ +using System; +using Spiff.Core.Managers.Viewers; + +namespace Spiff.Core.Managers.Commands +{ + public class CommandObject : ICloneable + { + public CommandObject(API.Commands.Command command) + { + CommandName = command.CommandName; + CommandInfo = command.CommandInfo; + Command = command; + } + + public CommandObject(CommandObject obj) + { + CommandName = obj.CommandName; + CommandInfo = obj.CommandInfo; + Command = obj.Command; + } + + public string CommandName { get; set; } + public string CommandInfo { get; set; } + public API.Commands.Command Command { get; set; } + + public object Clone() + { + return new CommandObject(this); + } + + public override string ToString() + { + return string.Format("Command: {0}, Info: {1}", CommandName, CommandInfo); + } + + public void Run(string[] args, string message, Viewer viewer) + { + Command.Run(args, message, SpiffCore.Instance.Channel, viewer); + } + } +} \ No newline at end of file diff --git a/Spiffbot/Spiff.IRC/Managers/Viewers/Viewer.cs b/Spiffbot/Spiff.IRC/Managers/Viewers/Viewer.cs new file mode 100644 index 0000000..6f6e487 --- /dev/null +++ b/Spiffbot/Spiff.IRC/Managers/Viewers/Viewer.cs @@ -0,0 +1,85 @@ +using System; + +namespace Spiff.Core.Managers.Viewers +{ + public class Viewer : ICloneable + { + public Viewer(string username, bool isMod, DateTime joinTime) + { + IsMod = isMod; + Username = username; + JoinedTime = joinTime; + } + + public Viewer(Viewer viewer) + { + IsMod = viewer.IsMod; + Username = viewer.Username; + JoinedTime = viewer.JoinedTime; + } + + public bool IsMod { get; set; } + public string Username { get; set; } + public DateTime JoinedTime { get; set; } + + 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 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); + } + + public void Unban() + { + SpiffCore.Instance.WriteOut.UnbanUser(Username, true); + } + + public void Warning(string warning) + { + SpiffCore.Instance.WriteOut.SendMessage(string.Format("[warning] {0} - {1}", Username, warning), true); + } + + 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); + } + } +} \ No newline at end of file diff --git a/Spiffbot/Spiff.IRC/Managers/Viewers/ViewerManager.cs b/Spiffbot/Spiff.IRC/Managers/Viewers/ViewerManager.cs new file mode 100644 index 0000000..edb4c90 --- /dev/null +++ b/Spiffbot/Spiff.IRC/Managers/Viewers/ViewerManager.cs @@ -0,0 +1,101 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Spiff.Core.API.Twitch; + +namespace Spiff.Core.Managers.Viewers +{ + public class ViewerManager + { + private readonly SpiffCore _spiffCore; + + public ViewerManager(SpiffCore spiffCore) + { + _spiffCore = spiffCore; + AllViewers = new List(); + } + + public List AllViewers { get; private set; } + + public Viewer AddViewer(string nick) + { + var viewer = + (from s in AllViewers + where String.Equals(s.Username, nick, StringComparison.CurrentCultureIgnoreCase) + select s).FirstOrDefault(); + + if (viewer != null) return viewer; + var owner = nick.ToLower().Equals(_spiffCore.Channel.Replace("#", "").ToLower()); + + viewer = new Viewer(nick, owner, DateTime.Now); + AllViewers.Add(viewer); + + return viewer; + } + + public Viewer AddViewer(Viewer viewer) + { + if (AllViewers.Contains(viewer)) return viewer; + 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); + } + + public void RemoveViewer(Viewer viewer) + { + if (AllViewers.Contains(viewer)) return; + AllViewers.Remove(viewer); + } + + 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) + { + var viewer = + (from s in AllViewers + where String.Equals(s.Username, nick, StringComparison.CurrentCultureIgnoreCase) + select s).FirstOrDefault(); + + return viewer; + } + + public void AddExistingUsers() + { + AllViewers = SiteApi.GetChatters(_spiffCore.Channel); + } + } +} \ No newline at end of file diff --git a/Spiffbot/Spiff.IRC/Properties/AssemblyInfo.cs b/Spiffbot/Spiff.IRC/Properties/AssemblyInfo.cs index ba21350..5d9cfd5 100644 --- a/Spiffbot/Spiff.IRC/Properties/AssemblyInfo.cs +++ b/Spiffbot/Spiff.IRC/Properties/AssemblyInfo.cs @@ -1,10 +1,10 @@ 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("Spiff.IRC")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] @@ -17,9 +17,11 @@ // 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("8c834a83-97ce-42ff-9585-86ac29513ddf")] // Version information for an assembly consists of the following four values: @@ -32,5 +34,6 @@ // 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")] \ No newline at end of file diff --git a/Spiffbot/Spiff.IRC/Spiff.Core.csproj b/Spiffbot/Spiff.IRC/Spiff.Core.csproj index 3dd6403..fafce58 100644 --- a/Spiffbot/Spiff.IRC/Spiff.Core.csproj +++ b/Spiffbot/Spiff.IRC/Spiff.Core.csproj @@ -36,6 +36,7 @@ + @@ -46,7 +47,21 @@ + + + + + + + + + + + + + + @@ -54,17 +69,19 @@ - - + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + 17, 17 + + \ No newline at end of file diff --git a/Spiffbot/Spiffbot/Spiffbot.csproj b/Spiffbot/Spiffbot/Spiffbot.csproj index 3c3b8dd..ff59c45 100644 --- a/Spiffbot/Spiffbot/Spiffbot.csproj +++ b/Spiffbot/Spiffbot/Spiffbot.csproj @@ -34,6 +34,8 @@ + + @@ -43,6 +45,18 @@ + + Form + + + ServerGUI.cs + + + Form + + + WarningDialog.cs + @@ -50,6 +64,14 @@ Spiff.Core + + + ServerGUI.cs + + + WarningDialog.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 diff --git a/Spiffbot/Spiffbot/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache b/Spiffbot/Spiffbot/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache index c25a3a1..185dd40 100644 Binary files a/Spiffbot/Spiffbot/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache and b/Spiffbot/Spiffbot/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache differ diff --git a/Spiffbot/Win32API/Invoke.cs b/Spiffbot/Win32API/Invoke.cs index a3cb522..2d09f32 100644 --- a/Spiffbot/Win32API/Invoke.cs +++ b/Spiffbot/Win32API/Invoke.cs @@ -25,6 +25,12 @@ 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); + + [DllImport("user32.dll")] + static extern bool BlockInput(bool fBlockIt); } } diff --git a/Spiffbot/WordFilter/Censor.cs b/Spiffbot/WordFilter/Censor.cs new file mode 100644 index 0000000..1d34fb4 --- /dev/null +++ b/Spiffbot/WordFilter/Censor.cs @@ -0,0 +1,80 @@ +using System; +using System.Collections.Generic; +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"); + + 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; + + 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 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 +