Skip to content

Commit

Permalink
Merge pull request #7 from projectpokemon/better-blocking
Browse files Browse the repository at this point in the history
Better blocking
  • Loading branch information
evandixon authored Sep 25, 2018
2 parents efb8d32 + ed65301 commit f2e1ac6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Ditto/ChannelPair.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public async Task SendDiscordMessage(string msg)
}
catch (Exception ex)
{
Console.WriteLine("Failed to send message to Discord: " + ex.ToString());
if (EnableConsoleLogging) Console.WriteLine("Failed to send message to Discord: " + ex.ToString());
}
}

Expand Down
31 changes: 16 additions & 15 deletions Ditto/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,45 +19,46 @@ public class Program

public static async Task Main(string[] args)
{
var noprompt = args.Contains("noprompt");
try
{
Console.WriteLine("Starting...");
if (!noprompt) Console.WriteLine("Starting...");
Pairs = new List<ChannelPair>();

var discordFilenames = Directory.GetFiles(".", "*.discord.json");
Console.WriteLine("Found " + discordFilenames.Length.ToString() + " Discord settings");
if (!noprompt) Console.WriteLine("Found " + discordFilenames.Length.ToString() + " Discord settings");
foreach (var discordFilename in discordFilenames)
{
Console.WriteLine(discordFilename);
if (!noprompt) Console.WriteLine(discordFilename);
var ircFilename = discordFilename.Replace(".discord.json", ".irc.json");
if (File.Exists(ircFilename))
{
Console.Write(ircFilename);
var discordInfo = JsonConvert.DeserializeObject<DiscordConnectionInfo>(File.ReadAllText(discordFilename));
var ircInfo = JsonConvert.DeserializeObject<IrcConnectionInfo>(File.ReadAllText(ircFilename));

var pair = new ChannelPair(new IrcConnection(ircInfo), discordInfo);
if (args.Contains("noprompt"))
var pair = new ChannelPair(new IrcConnection(ircInfo) { EnableConsoleLogging = !noprompt }, discordInfo)
{
pair.EnableConsoleLogging = false;
}
Console.WriteLine("Connecting...");
EnableConsoleLogging = !noprompt
};
if (!noprompt) Console.WriteLine("Connecting...");
await pair.Connect();
Console.WriteLine("Ready.");
if (!noprompt) Console.WriteLine("Ready.");
Pairs.Add(pair);
}
else
{
Console.Write("Did not find IRC settings. Not creating pair.");
if (!noprompt) Console.Write("Did not find IRC settings. Not creating pair.");
}
}

// Listen for mannual commands
if (args.Contains("noprompt"))
if (noprompt)
{
while (true)
{
// Block until process is manually stopped
await Task.Delay(int.MaxValue);
}
}
else
Expand All @@ -71,7 +72,7 @@ public static async Task Main(string[] args)
case "say":
if (Pairs.Count > 1)
{
Console.WriteLine("There is currently more than 1 channel pair active. Manual input is not currently supported.");
if (!noprompt) Console.WriteLine("There is currently more than 1 channel pair active. Manual input is not currently supported.");
break;
}

Expand All @@ -82,7 +83,7 @@ public static async Task Main(string[] args)
}
else
{
Console.WriteLine("Usage: say <message>");
if (!noprompt) Console.WriteLine("Usage: say <message>");
}
break;
case "exit":
Expand All @@ -99,7 +100,7 @@ public static async Task Main(string[] args)
{
Console.Write(ex.ToString());
throw;
}
}
}
}
}
}

0 comments on commit f2e1ac6

Please sign in to comment.