Skip to content

Commit

Permalink
Merge pull request #6 from projectpokemon/deb9-systemd
Browse files Browse the repository at this point in the history
Remove Watchog and Other Misc Cleanup
  • Loading branch information
evandixon authored Sep 24, 2018
2 parents 2395037 + 5d34170 commit efb8d32
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 231 deletions.
29 changes: 13 additions & 16 deletions Ditto.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,19 @@ VisualStudioVersion = 15.0.27004.2008
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ditto", "Ditto\Ditto.csproj", "{B4D93EE6-97DA-43DD-84CB-DCDC3E843BC8}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IrcDotNet", "IrcDotNet\IrcDotNet.csproj", "{5A8EF7A9-4DFB-4DA6-A73B-C0028E26DBFA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Watchog", "Watchog\Watchog.csproj", "{4E71E8AA-FA91-4D78-A770-2E080E2D8263}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{0E2536C6-C76A-46E2-99EA-2398F2437739}"
ProjectSection(SolutionItems) = preProject
README.MD = README.MD
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IrcDotNet", "IrcDotNet\IrcDotNet.csproj", "{2E1632CE-3048-4EE7-B7A8-318F3007990D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug-IPv4|Any CPU = Debug-IPv4|Any CPU
Release|Any CPU = Release|Any CPU
Release-IPv4|Any CPU = Release-IPv4|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B4D93EE6-97DA-43DD-84CB-DCDC3E843BC8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
Expand All @@ -27,18 +26,16 @@ Global
{B4D93EE6-97DA-43DD-84CB-DCDC3E843BC8}.Debug-IPv4|Any CPU.Build.0 = Debug-IPv4|Any CPU
{B4D93EE6-97DA-43DD-84CB-DCDC3E843BC8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B4D93EE6-97DA-43DD-84CB-DCDC3E843BC8}.Release|Any CPU.Build.0 = Release|Any CPU
{5A8EF7A9-4DFB-4DA6-A73B-C0028E26DBFA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5A8EF7A9-4DFB-4DA6-A73B-C0028E26DBFA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5A8EF7A9-4DFB-4DA6-A73B-C0028E26DBFA}.Debug-IPv4|Any CPU.ActiveCfg = Debug-IPv4|Any CPU
{5A8EF7A9-4DFB-4DA6-A73B-C0028E26DBFA}.Debug-IPv4|Any CPU.Build.0 = Debug-IPv4|Any CPU
{5A8EF7A9-4DFB-4DA6-A73B-C0028E26DBFA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5A8EF7A9-4DFB-4DA6-A73B-C0028E26DBFA}.Release|Any CPU.Build.0 = Release|Any CPU
{4E71E8AA-FA91-4D78-A770-2E080E2D8263}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4E71E8AA-FA91-4D78-A770-2E080E2D8263}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4E71E8AA-FA91-4D78-A770-2E080E2D8263}.Debug-IPv4|Any CPU.ActiveCfg = Debug|Any CPU
{4E71E8AA-FA91-4D78-A770-2E080E2D8263}.Debug-IPv4|Any CPU.Build.0 = Debug|Any CPU
{4E71E8AA-FA91-4D78-A770-2E080E2D8263}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4E71E8AA-FA91-4D78-A770-2E080E2D8263}.Release|Any CPU.Build.0 = Release|Any CPU
{B4D93EE6-97DA-43DD-84CB-DCDC3E843BC8}.Release-IPv4|Any CPU.ActiveCfg = Release-IPv4|Any CPU
{B4D93EE6-97DA-43DD-84CB-DCDC3E843BC8}.Release-IPv4|Any CPU.Build.0 = Release-IPv4|Any CPU
{2E1632CE-3048-4EE7-B7A8-318F3007990D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2E1632CE-3048-4EE7-B7A8-318F3007990D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2E1632CE-3048-4EE7-B7A8-318F3007990D}.Debug-IPv4|Any CPU.ActiveCfg = Debug-IPv4|Any CPU
{2E1632CE-3048-4EE7-B7A8-318F3007990D}.Debug-IPv4|Any CPU.Build.0 = Debug-IPv4|Any CPU
{2E1632CE-3048-4EE7-B7A8-318F3007990D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2E1632CE-3048-4EE7-B7A8-318F3007990D}.Release|Any CPU.Build.0 = Release|Any CPU
{2E1632CE-3048-4EE7-B7A8-318F3007990D}.Release-IPv4|Any CPU.ActiveCfg = Release-IPv4|Any CPU
{2E1632CE-3048-4EE7-B7A8-318F3007990D}.Release-IPv4|Any CPU.Build.0 = Release-IPv4|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
16 changes: 4 additions & 12 deletions Ditto/Ditto.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,18 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
<RuntimeIdentifiers>win10-x64;linux-x64</RuntimeIdentifiers>
<Configurations>Debug;Release;Debug-IPv4</Configurations>
<RuntimeIdentifiers>win-x64;linux-x64;debian.9-x64</RuntimeIdentifiers>
<Configurations>Debug;Release;Debug-IPv4;Release-IPv4</Configurations>
<LangVersion>7.3</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Discord.Net" Version="1.0.2" />
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\IrcDotNet\IrcDotNet.csproj" />
</ItemGroup>

<ItemGroup>
<None Update="shutdown.sh">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="startup.sh">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
144 changes: 67 additions & 77 deletions Ditto/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,100 +16,90 @@ public class Program
private static List<ChannelPair> Pairs;

private static bool _listen;
private static int _exceptionCount;

public static void Main(string[] args)
public static async Task Main(string[] args)
{
_exceptionCount = 0;
_listen = true;
while (_listen && _exceptionCount < 10)
try
{
try
{
MainAsync(args).Wait();
}
catch (Exception ex)
{
File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), $"Exception-{DateTime.Now.ToString("YYYY-MM-DD-hh-mm-ss")}.txt"), ex.ToString());
_exceptionCount += 1;
}
Task.Delay(30000).Wait();
}
}
Console.WriteLine("Starting...");
Pairs = new List<ChannelPair>();

public static async Task MainAsync(string[] args)
{
Pairs = new List<ChannelPair>();

var discordFilenames = Directory.GetFiles(".", "*.discord.json");
foreach (var discordFilename in discordFilenames)
{
var ircFilename = discordFilename.Replace(".discord.json", ".irc.json");
if (File.Exists(ircFilename))
var discordFilenames = Directory.GetFiles(".", "*.discord.json");
Console.WriteLine("Found " + discordFilenames.Length.ToString() + " Discord settings");
foreach (var discordFilename in discordFilenames)
{
var discordInfo = JsonConvert.DeserializeObject<DiscordConnectionInfo>(File.ReadAllText(discordFilename));
var ircInfo = JsonConvert.DeserializeObject<IrcConnectionInfo>(File.ReadAllText(ircFilename));
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), discordInfo);
if (args.Contains("noprompt"))
{
pair.EnableConsoleLogging = false;
}
Console.WriteLine("Connecting...");
await pair.Connect();
Console.WriteLine("Ready.");
Pairs.Add(pair);
}
else
{
pair.EnableConsoleLogging = false;
Console.Write("Did not find IRC settings. Not creating pair.");
}
Console.WriteLine("Connecting...");
pair.Connect().Wait();
Console.WriteLine("Ready.");
Pairs.Add(pair);
}
}

if (_exceptionCount > 0)
{
await Task.Delay(30000);
await Pairs[0].SendDiscordMessage("Ditto just recovered from a fatal exception.");
}

// Listen for mannual commands
if (args.Contains("noprompt"))
{
while (true)
// Listen for mannual commands
if (args.Contains("noprompt"))
{
// Block until process is manually stopped
while (true)
{
// Block until process is manually stopped
}
}
}
else
{
while (_listen)
else
{
var input = Console.ReadLine();
var cmd = input.Split(" ".ToCharArray(), 2);
switch (cmd[0].ToLower())
while (_listen)
{
case "say":
if (Pairs.Count > 1)
{
Console.WriteLine("There is currently more than 1 channel pair active. Manual input is not currently supported.");
break;
}
var input = Console.ReadLine();
var cmd = input.Split(" ".ToCharArray(), 2);
switch (cmd[0].ToLower())
{
case "say":
if (Pairs.Count > 1)
{
Console.WriteLine("There is currently more than 1 channel pair active. Manual input is not currently supported.");
break;
}

if (cmd.Length > 1)
{
await Pairs[0].SendDiscordMessage(cmd[1]);
Pairs[0].SendIrcMessage(cmd[1]);
}
else
{
Console.WriteLine("Usage: say <message>");
}
break;
case "exit":
case "quit":
_listen = false;
break;
default:
break;
if (cmd.Length > 1)
{
await Pairs[0].SendDiscordMessage(cmd[1]);
Pairs[0].SendIrcMessage(cmd[1]);
}
else
{
Console.WriteLine("Usage: say <message>");
}
break;
case "exit":
case "quit":
_listen = false;
break;
default:
break;
}
}
}
}
}
catch (Exception ex)
{
Console.Write(ex.ToString());
throw;
}
}
}
}
17 changes: 0 additions & 17 deletions Ditto/shutdown.sh

This file was deleted.

15 changes: 0 additions & 15 deletions Ditto/startup.sh

This file was deleted.

7 changes: 5 additions & 2 deletions IrcDotNet/IrcDotNet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@
<PackageLicenseUrl>https://github.com/IrcDotNet/IrcDotNet/License.txt</PackageLicenseUrl>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<Description>Library for communicating via Internet Relay Chat (IRC) protocol and its extensions</Description>
<Configurations>Debug;Release;Debug-IPv4</Configurations>
<Configurations>Debug;Release;Debug-IPv4;Release-IPv4</Configurations>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug-IPv4|AnyCPU'">
<PropertyGroup Condition="'$(Configuration)'=='Debug-IPv4'">
<DefineConstants>TRACE;DEBUG_IPV4;NETSTANDARD1_5;IPV4</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)'=='Release-IPv4'">
<DefineConstants>TRACE;DEBUG_IPV4;NETSTANDARD1_5;IPV4</DefineConstants>
</PropertyGroup>

Expand Down
9 changes: 6 additions & 3 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
* Watchog - Starts Ditto and watches to make sure it's online, restarting it if necessary. This is needed because on some systems, Ditto dies so hard its error handling doesn't kick in, whenever there's a Discord outage for any length.

## Usage
1. Create the json settings files. Instructions coming eventually.
2. Run startup.sh
3. Run shutdown.sh to shutdown
1. Create the json settings files. You need two of them that deserialize into each of these classes:
- [https://github.com/projectpokemon/Ditto/blob/master/Ditto/DiscordConnectionInfo.cs](DiscordConnectionInfo)
- [https://github.com/projectpokemon/Ditto/blob/master/Ditto/IrcConnectionInfo.cs](IrcConnectionInfo)
You can create as many of these as you want, and you can link them by naming them accordingly. For example, Server1.discord.json and Server1.irc.json are a single linked pair, and Server2.discord.json and Server2.irc.json are another linked pair.
2. Place them in the working directory
3. Run Ditto.
72 changes: 0 additions & 72 deletions Watchog/Program.cs

This file was deleted.

Loading

0 comments on commit efb8d32

Please sign in to comment.