|
|
|
@ -6,6 +6,8 @@ using System.Collections.Generic;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
|
using MatrixSDK.Client;
|
|
|
|
|
using MatrixSDK.Structures;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
namespace MpdDj
|
|
|
|
|
{
|
|
|
|
|
[AttributeUsage(AttributeTargets.Method)]
|
|
|
|
@ -18,43 +20,106 @@ namespace MpdDj
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[AttributeUsage(AttributeTargets.Method)]
|
|
|
|
|
public class BotFallback : Attribute {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[AttributeUsage(AttributeTargets.Method)]
|
|
|
|
|
public class BotHelp : Attribute {
|
|
|
|
|
public readonly string HelpText;
|
|
|
|
|
public BotHelp(string help){
|
|
|
|
|
HelpText = help;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class Commands
|
|
|
|
|
{
|
|
|
|
|
[BotCmd("shuffle")]
|
|
|
|
|
public static void Shuffle(string cmd,string sender, MatrixRoom room){
|
|
|
|
|
Console.WriteLine("Shuffle");
|
|
|
|
|
}
|
|
|
|
|
//[BotCmd("shuffle")]
|
|
|
|
|
//public static void Shuffle(string cmd,string sender, MatrixRoom room){
|
|
|
|
|
// Console.WriteLine("Shuffle");
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
[BotCmd("ping")]
|
|
|
|
|
[BotHelp("Ping the server and get the delay.")]
|
|
|
|
|
public static void Ping(string cmd, string sender, MatrixRoom room){
|
|
|
|
|
room.SendMessage ("pong!");
|
|
|
|
|
room.SendMessage ("Pong at" + DateTime.Now.ToLongTimeString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BotCmd("current")]
|
|
|
|
|
[BotHelp("Get the current song title.")]
|
|
|
|
|
public static void GetSongName(string cmd,string sender,MatrixRoom room){
|
|
|
|
|
MPCCurrentSong song = Program.MPCClient.CurrentSong ();
|
|
|
|
|
Program.MPCClient.Status();
|
|
|
|
|
if (song.file != null) {
|
|
|
|
|
FileInfo file = new FileInfo (song.file);
|
|
|
|
|
string name = file.Name.Replace (file.Extension, "");
|
|
|
|
|
name = new string(System.Text.Encoding.UTF8.GetChars (Convert.FromBase64String (name)));
|
|
|
|
|
room.SendMessage (name);
|
|
|
|
|
|
|
|
|
|
string[] time = Program.MPCClient.lastStatus.time.Split(':');
|
|
|
|
|
int elapsed = int.Parse(time[0]);
|
|
|
|
|
int total = int.Parse(time[1]);
|
|
|
|
|
name += String.Format(" {0}:{1}/{2}:{3}", elapsed/60,elapsed%60,total/60,total%60);
|
|
|
|
|
|
|
|
|
|
room.SendNotice (name);
|
|
|
|
|
} else {
|
|
|
|
|
room.SendMessage ("Nothing is currently playing");
|
|
|
|
|
room.SendNotice ("Nothing is currently playing");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[BotCmd("next")]
|
|
|
|
|
[BotHelp("Skip current song.")]
|
|
|
|
|
public static void NextTrack(string cmd, string sender, MatrixRoom room){
|
|
|
|
|
Program.MPCClient.Next ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BotCmd("help")]
|
|
|
|
|
[BotHelp("This help text.")]
|
|
|
|
|
public static void Help(string cmd, string sender, MatrixRoom room){
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
string helptext = "";
|
|
|
|
|
foreach(MethodInfo method in typeof(Commands).GetMethods(BindingFlags.Static|BindingFlags.Public)){
|
|
|
|
|
BotCmd c = method.GetCustomAttribute<BotCmd> ();
|
|
|
|
|
BotHelp h= method.GetCustomAttribute<BotHelp> ();
|
|
|
|
|
|
|
|
|
|
if (c != null) {
|
|
|
|
|
helptext += String.Format("<p><strong>{0}</strong> {1}</p>",c.CMD, h != null ? System.Web.HttpUtility.HtmlEncode(h.HelpText) : "");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
MMessageCustomHTML htmlmsg = new MMessageCustomHTML();
|
|
|
|
|
htmlmsg.body = helptext.Replace("<strong>","").Replace("</strong>","").Replace("<p>","").Replace("</p>","\n");
|
|
|
|
|
htmlmsg.formatted_body = helptext;
|
|
|
|
|
room.SendMessage(htmlmsg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BotCmd("search")]
|
|
|
|
|
[BotFallback()]
|
|
|
|
|
[BotHelp("Get the first youtube result by keywords.")]
|
|
|
|
|
public static void SearchYTForTrack(string cmd, string sender, MatrixRoom room){
|
|
|
|
|
string query = cmd.Replace("search ","");
|
|
|
|
|
if(string.IsNullOrWhiteSpace(query)){
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
string url = Downloaders.GetYoutubeURLFromSearch(query);
|
|
|
|
|
if(url != null){
|
|
|
|
|
DownloadTrack(url,sender,room);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("No videos matching those terms were found");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch(Exception e){
|
|
|
|
|
room.SendNotice ("There was an issue with that request, "+sender+": " + e.Message);
|
|
|
|
|
Console.Error.WriteLine (e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BotCmd("","http://","https://","youtube.com","youtu.be","soundcloud.com")]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BotCmd("[url]","http://","https://","youtube.com","youtu.be","soundcloud.com")]
|
|
|
|
|
[BotHelp("Type a youtube/soundcloud/file url in to add to the playlist.")]
|
|
|
|
|
public static void DownloadTrack(string cmd, string sender, MatrixRoom room)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
@ -69,7 +134,7 @@ namespace MpdDj
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
room.SendMessage ("Sorry, that type of URL isn't supported right now :/");
|
|
|
|
|
room.SendNotice ("Sorry, that type of URL isn't supported right now :/");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -80,22 +145,26 @@ namespace MpdDj
|
|
|
|
|
foreach(string[] res in videos){
|
|
|
|
|
Program.MPCClient.AddFile(res[0]);
|
|
|
|
|
}
|
|
|
|
|
string[] playlist = Program.MPCClient.Playlist();
|
|
|
|
|
//Console.WriteLine(string.Join("\n",playlist));
|
|
|
|
|
int position = playlist.Length-(videos.Count-1);
|
|
|
|
|
//ffConsole.WriteLine(position);
|
|
|
|
|
|
|
|
|
|
Program.MPCClient.Status();
|
|
|
|
|
|
|
|
|
|
#if DEBUG
|
|
|
|
|
Console.WriteLine(JObject.FromObject(Program.MPCClient.lastStatus));
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
int position = Program.MPCClient.lastStatus.playlistlength;
|
|
|
|
|
if(position == 1){
|
|
|
|
|
Program.MPCClient.Play();
|
|
|
|
|
room.SendMessage("Started playing " + videos[0][1] + " | " + Configuration.Config["mpc"]["streamurl"]);
|
|
|
|
|
room.SendNotice("Started playing " + videos[0][1] + " | " + Configuration.Config["mpc"]["streamurl"]);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
room.SendMessage(videos[0][1] + " has been queued at position "+position+".");
|
|
|
|
|
room.SendNotice(videos[0][1] + " has been queued at position "+position+".");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
catch(Exception e){
|
|
|
|
|
room.SendMessage ("There was an issue with that request, "+sender+": " + e.Message);
|
|
|
|
|
room.SendNotice ("There was an issue with that request, "+sender+": " + e.Message);
|
|
|
|
|
Console.Error.WriteLine (e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -132,11 +201,34 @@ namespace MpdDj
|
|
|
|
|
return output;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BotCmd("","stream")]
|
|
|
|
|
[BotCmd("stream")]
|
|
|
|
|
[BotHelp("Get the url of the stream.")]
|
|
|
|
|
public static void StreamUrl(string cmd, string sender, MatrixRoom room){
|
|
|
|
|
room.SendMessage(Configuration.Config["mpc"]["streamurl"]);
|
|
|
|
|
room.SendNotice(Configuration.Config["mpc"]["streamurl"]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BotCmd("lyrics")]
|
|
|
|
|
[BotHelp("Search by lyric")]
|
|
|
|
|
public static void LyricSearch(string cmd, string sender, MatrixRoom room){
|
|
|
|
|
string suggestion = Downloaders.GetSongNameByLyric(cmd.Replace("lyrics ",""));
|
|
|
|
|
if(suggestion == null){
|
|
|
|
|
room.SendNotice("I couldn't find any songs with that lyric :(");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
room.SendNotice(String.Format("Matched '{0}'. Checking Youtube for it",suggestion));
|
|
|
|
|
SearchYTForTrack("search "+suggestion,sender,room);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BotCmd("lyric")]
|
|
|
|
|
[BotHelp("You fear the letter 's'? Aww babe, I'll fix that for you <3")]
|
|
|
|
|
public static void LyricSearchAlias(string cmd, string sender, MatrixRoom room){
|
|
|
|
|
LyricSearch(cmd,sender,room);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BotCmd("playlist")]
|
|
|
|
|
[BotHelp("Display the the shortened playlist.")]
|
|
|
|
|
public static void PlaylistDisplay(string cmd, string sender, MatrixRoom room){
|
|
|
|
|
string[] files = Program.MPCClient.Playlist ();
|
|
|
|
|
string output = "▶ ";
|
|
|
|
@ -148,13 +240,15 @@ namespace MpdDj
|
|
|
|
|
file = new string(System.Text.Encoding.UTF8.GetChars (Convert.FromBase64String (file)));
|
|
|
|
|
output += file + "\n";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
room.SendMessage (output);
|
|
|
|
|
} else {
|
|
|
|
|
room.SendMessage ("The playlist is empty");
|
|
|
|
|
room.SendNotice ("The playlist is empty");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|