From 720f08438f1ad75b1d951e286213a9d7acfd3c2a Mon Sep 17 00:00:00 2001 From: SlidyBat <25954912+SlidyBat@users.noreply.github.com> Date: Sat, 3 Feb 2018 21:34:54 +1100 Subject: [PATCH] No more space/tab mixing --- IRC-Relay/IRC.cs | 84 +++++++++++++++---------------- IRC-Relay/Program.cs | 18 +++---- IRC-Relay/Settings.cs | 58 +++++++++++----------- IRC-Relay/XmlSerializable.cs | 96 ++++++++++++++++++------------------ 4 files changed, 128 insertions(+), 128 deletions(-) diff --git a/IRC-Relay/IRC.cs b/IRC-Relay/IRC.cs index 0a00d0c..0a96144 100644 --- a/IRC-Relay/IRC.cs +++ b/IRC-Relay/IRC.cs @@ -9,8 +9,8 @@ namespace IRCRelay { public class IRC { - private IrcClient ircClient; - private System.Timers.Timer timer = null; + private IrcClient ircClient; + private System.Timers.Timer timer = null; private string server; private int port; @@ -22,83 +22,83 @@ public class IRC private string targetGuild; private string targetChannel; - private bool logMessages; + private bool logMessages; public IRC(string server, int port, string nick, string channel, string loginName, string authstring, string authuser, string targetGuild, string targetChannel, bool logMessages) { ircClient = new IrcClient(); - ircClient.Encoding = System.Text.Encoding.UTF8; - ircClient.SendDelay = 200; + ircClient.Encoding = System.Text.Encoding.UTF8; + ircClient.SendDelay = 200; - ircClient.ActiveChannelSyncing = true; + ircClient.ActiveChannelSyncing = true; + + ircClient.AutoRetry = true; + ircClient.AutoRejoin = true; + ircClient.AutoRelogin = true; + ircClient.AutoRejoinOnKick = true; - ircClient.AutoRetry = true; - ircClient.AutoRejoin = true; - ircClient.AutoRelogin = true; - ircClient.AutoRejoinOnKick = true; + ircClient.OnError += this.OnError; + ircClient.OnChannelMessage += this.OnChannelMessage; + ircClient.OnDisconnected += this.OnDisconnected; - ircClient.OnError += this.OnError; - ircClient.OnChannelMessage += this.OnChannelMessage; - ircClient.OnDisconnected += this.OnDisconnected; + timer = new System.Timers.Timer(); - timer = new System.Timers.Timer(); + timer.Elapsed += Timer_Callback; - timer.Elapsed += Timer_Callback; - - timer.Enabled = true; - timer.AutoReset = true; + timer.Enabled = true; + timer.AutoReset = true; timer.Interval = TimeSpan.FromSeconds(30.0).TotalMilliseconds; /* Connection Info */ - this.server = server; - this.port = port; - this.nick = nick; - this.channel = channel; - this.loginName = loginName; - this.authstring = authstring; + this.server = server; + this.port = port; + this.nick = nick; + this.channel = channel; + this.loginName = loginName; + this.authstring = authstring; this.authuser = authuser; this.targetGuild = targetGuild; this.targetChannel = targetChannel; this.logMessages = logMessages; - } + } public void SendMessage(string message) { ircClient.SendMessage(SendType.Message, channel, message); - } + } public void SpawnBot() { - new Thread(() => - { - try - { - ircClient.Connect(server, port); + new Thread(() => + { + try + { + ircClient.Connect(server, port); ircClient.Login(nick, loginName); if (authstring.Length != 0) - { + { ircClient.SendMessage(SendType.Message, authuser, authstring); - Thread.Sleep(1000); // login delay - } + Thread.Sleep(1000); // login delay + } - ircClient.RfcJoin(channel); + ircClient.RfcJoin(channel); - ircClient.Listen(); + ircClient.Listen(); - timer.Start(); + timer.Start(); } - catch (Exception ex) - { - Console.WriteLine(ex.Message); + catch (Exception ex) + { + Console.WriteLine(ex.Message); return; - } + } - }).Start(); + }).Start(); } private void Timer_Callback(Object source, ElapsedEventArgs e) diff --git a/IRC-Relay/Program.cs b/IRC-Relay/Program.cs index e21c279..6e16b40 100644 --- a/IRC-Relay/Program.cs +++ b/IRC-Relay/Program.cs @@ -32,17 +32,17 @@ public static void Main(string[] args) private async Task MainAsync() { - try - { - config = Settings.Config.Load(); - } - catch - { - Console.WriteLine("Unable to load config. Ensure Settings.xml is formatted correctly."); + try + { + config = Settings.Config.Load(); + } + catch + { + Console.WriteLine("Unable to load config. Ensure Settings.xml is formatted correctly."); config = Settings.Config.CreateDefaultConfig(); Settings.Config.Save(config); - return; - } + return; + } client = new DiscordSocketClient(); commands = new CommandService(); diff --git a/IRC-Relay/Settings.cs b/IRC-Relay/Settings.cs index 4910024..a5c6ed3 100644 --- a/IRC-Relay/Settings.cs +++ b/IRC-Relay/Settings.cs @@ -3,12 +3,12 @@ namespace IRCRelay.Settings { - public class Config - { - // --------------------------------------------------------------------------------------- - // Insert configurable values below: - public string IRCServer; - public string IRCPort; + public class Config + { + // --------------------------------------------------------------------------------------- + // Insert configurable values below: + public string IRCServer; + public string IRCPort; public string IRCChannel; public string IRCNick; @@ -21,19 +21,19 @@ public class Config public string DiscordBotToken; public string DiscordGuildName; public string DiscordChannelName; - // --------------------------------------------------------------------------------------- + // --------------------------------------------------------------------------------------- - // Name of configuration file. - [XmlIgnore] - public const string FileName = "Settings.xml"; + // Name of configuration file. + [XmlIgnore] + public const string FileName = "Settings.xml"; - // Empty constructor for XmlSerializer. - public Config() - { - } + // Empty constructor for XmlSerializer. + public Config() + { + } - // Used to load the default configuration if Load() fails. - public static Config CreateDefaultConfig() + // Used to load the default configuration if Load() fails. + public static Config CreateDefaultConfig() { Config config = new Config() { @@ -56,20 +56,20 @@ public static Config CreateDefaultConfig() // Loads the configuration from file. public static Config Load() - { - var serializer = new XmlSerializer(typeof(Config)); + { + var serializer = new XmlSerializer(typeof(Config)); - using (var fStream = new FileStream(Config.FileName, FileMode.Open)) - return (Config)serializer.Deserialize(fStream); - } + using (var fStream = new FileStream(Config.FileName, FileMode.Open)) + return (Config)serializer.Deserialize(fStream); + } - // Saves the configuration to file. - public static void Save(Config config) - { - var serializer = new XmlSerializer(typeof(Config)); + // Saves the configuration to file. + public static void Save(Config config) + { + var serializer = new XmlSerializer(typeof(Config)); - using (var fStream = new FileStream(Config.FileName, FileMode.Create)) - serializer.Serialize(fStream, config); - } - } + using (var fStream = new FileStream(Config.FileName, FileMode.Create)) + serializer.Serialize(fStream, config); + } + } } \ No newline at end of file diff --git a/IRC-Relay/XmlSerializable.cs b/IRC-Relay/XmlSerializable.cs index 25628a8..63a1abe 100644 --- a/IRC-Relay/XmlSerializable.cs +++ b/IRC-Relay/XmlSerializable.cs @@ -7,56 +7,56 @@ namespace IRCRelay.Config { - public class XmlSerializable - where T : XmlSerializable - { - public static T Load(string fileName) - { - FileStream fs = null; - T ret = null; - try - { - fs = File.Open(fileName, FileMode.Open, FileAccess.Read, FileShare.Read); - XmlSerializer xs = new XmlSerializer(typeof(T)); - ret = (T)xs.Deserialize(fs); - } - catch (Exception) - { - throw; - } - finally - { - if (fs != null) - fs.Close(); - } + public class XmlSerializable + where T : XmlSerializable + { + public static T Load(string fileName) + { + FileStream fs = null; + T ret = null; + try + { + fs = File.Open(fileName, FileMode.Open, FileAccess.Read, FileShare.Read); + XmlSerializer xs = new XmlSerializer(typeof(T)); + ret = (T)xs.Deserialize(fs); + } + catch (Exception) + { + throw; + } + finally + { + if (fs != null) + fs.Close(); + } - return ret; - } + return ret; + } - public static bool Save(string fileName, T data) - { - FileStream fs = null; - try - { - fs = File.Create(fileName); - XmlSerializer xs = new XmlSerializer(typeof(T)); - xs.Serialize(fs, data); + public static bool Save(string fileName, T data) + { + FileStream fs = null; + try + { + fs = File.Create(fileName); + XmlSerializer xs = new XmlSerializer(typeof(T)); + xs.Serialize(fs, data); - return true; - } - catch - { - throw; - } - finally - { - if (fs != null) - fs.Close(); - } - } + return true; + } + catch + { + throw; + } + finally + { + if (fs != null) + fs.Close(); + } + } - public bool Save(string fileName) - { + public bool Save(string fileName) + { if (this is T s) { return Save(fileName, s); @@ -65,6 +65,6 @@ public bool Save(string fileName) { return false; } - } - } + } + } } \ No newline at end of file