Added config parsing and began work on command listener.
parent
7ca760e521
commit
a662b4d997
|
@ -3,6 +3,8 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
|||
# Visual Studio 2012
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MpdDj", "MpdDj\MpdDj.csproj", "{9840E711-4380-43B5-89D9-6243E051BCB8}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MatrixSDK", "..\..\matrix-dotnet-sdk\MatrixSDK\MatrixSDK\MatrixSDK.csproj", "{BF7A3DBC-EFBD-43D2-8609-CCAB4A9DFA07}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x86 = Debug|x86
|
||||
|
@ -13,5 +15,9 @@ Global
|
|||
{9840E711-4380-43B5-89D9-6243E051BCB8}.Debug|x86.Build.0 = Debug|x86
|
||||
{9840E711-4380-43B5-89D9-6243E051BCB8}.Release|x86.ActiveCfg = Release|x86
|
||||
{9840E711-4380-43B5-89D9-6243E051BCB8}.Release|x86.Build.0 = Release|x86
|
||||
{BF7A3DBC-EFBD-43D2-8609-CCAB4A9DFA07}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{BF7A3DBC-EFBD-43D2-8609-CCAB4A9DFA07}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{BF7A3DBC-EFBD-43D2-8609-CCAB4A9DFA07}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{BF7A3DBC-EFBD-43D2-8609-CCAB4A9DFA07}.Release|x86.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using IniParser;
|
||||
using IniParser.Model;
|
||||
namespace MpdDj
|
||||
{
|
||||
public class Configuration
|
||||
{
|
||||
public static IniData Config { get; private set; }
|
||||
public static IniData DefaultConfiguration(){
|
||||
IniData defaultData = new IniData ();
|
||||
SectionData MPC = new SectionData ("mpc");
|
||||
SectionData Matrix = new SectionData ("matrix");
|
||||
|
||||
defaultData.Sections.Add (MPC);
|
||||
defaultData.Sections.Add (Matrix);
|
||||
|
||||
MPC.Keys.AddKey("host","localhost");
|
||||
MPC.Keys.AddKey("port","6600");
|
||||
MPC.Keys.AddKey("streamurl","http://localhost:8000");
|
||||
MPC.Keys.AddKey("music_dir","/var/lib/mpd/music");
|
||||
|
||||
Matrix.Keys.AddKey("host","https://localhost:8448");
|
||||
Matrix.Keys.AddKey("user","username");
|
||||
Matrix.Keys.AddKey("pass","password");
|
||||
Matrix.Keys.AddKey("rooms","#RoomA,#RoomB:localhost,#RoomC");
|
||||
return defaultData;
|
||||
}
|
||||
|
||||
public static void ReadConfig(string cfgpath){
|
||||
if (File.Exists (cfgpath)) {
|
||||
FileIniDataParser parser = new FileIniDataParser ();
|
||||
Config = parser.ReadFile (cfgpath);
|
||||
} else {
|
||||
Console.WriteLine ("[Warn] The config file could not be found. Using defaults");
|
||||
Config = DefaultConfiguration ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -31,10 +31,23 @@
|
|||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="INIFileParser">
|
||||
<HintPath>..\packages\ini-parser.2.2.4\lib\net20\INIFileParser.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Configuration.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\matrix-dotnet-sdk\MatrixSDK\MatrixSDK\MatrixSDK.csproj">
|
||||
<Project>{BF7A3DBC-EFBD-43D2-8609-CCAB4A9DFA07}</Project>
|
||||
<Name>MatrixSDK</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -1,12 +1,48 @@
|
|||
using System;
|
||||
|
||||
using MatrixSDK.Client;
|
||||
using MatrixSDK.Structures;
|
||||
namespace MpdDj
|
||||
{
|
||||
class MainClass
|
||||
{
|
||||
public static MatrixClient client;
|
||||
public static void Main (string[] args)
|
||||
{
|
||||
Console.WriteLine ("Hello World!");
|
||||
Console.WriteLine ("Reading INI File");
|
||||
string cfgpath;
|
||||
if (args.Length > 1) {
|
||||
cfgpath = System.IO.Path.GetFullPath (args [1]);
|
||||
} else {
|
||||
cfgpath = "~/.config/mpddj.ini";
|
||||
}
|
||||
Configuration.ReadConfig (cfgpath);
|
||||
|
||||
Console.WriteLine ("Connecting to Matrix");
|
||||
client = new MatrixClient (Configuration.Config ["mpc"] ["host"]);
|
||||
Console.WriteLine("Connected. Logging in");
|
||||
client.LoginWithPassword (Configuration.Config ["mpc"] ["user"], Configuration.Config ["mpc"] ["pass"]);
|
||||
Console.WriteLine("Logged in OK");
|
||||
Console.WriteLine("Joining Rooms:");
|
||||
foreach (string roomid in Configuration.Config ["mpc"] ["rooms"].Split(',')) {
|
||||
MatrixRoom room = client.JoinRoom (roomid);
|
||||
room.OnMessage += Room_OnMessage;
|
||||
Console.WriteLine("\tJoined " + roomid);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void Room_OnMessage (MatrixRoom room, MatrixSDK.Structures.MatrixEvent evt)
|
||||
{
|
||||
if (evt.age > 3000) {
|
||||
return; // Too old
|
||||
}
|
||||
string msg = ((MatrixMRoomMessage)evt.content).body;
|
||||
|
||||
if (msg.StartsWith ("!mpddj")) {
|
||||
msg = msg.Substring (7);
|
||||
Console.WriteLine ("Got message okay");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="ini-parser" version="2.2.4" targetFramework="net45" />
|
||||
</packages>
|
Loading…
Reference in New Issue