<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;

using CwIRC;
using MBFunctionInterface;

using Libmpc;

namespace Internet
{
    public class ModdTunes : Function
    {
        public ModdTunes()
        {
            Help = "m(odd)t(unes) - Tells you what Moddington's internet radio is currently playing.";
            Type = Types.Command;
            AccessLevel = AccessLevels.Anyone;
        }

        public override List<IRCResponse> GetResponse(BotMessage message)
        {
            if (Regex.IsMatch(message.Command, "^(m(odd)?t(unes)?)$", RegexOptions.IgnoreCase))
            {
                Mpc mpc = new Mpc();

                var addresses = System.Net.Dns.GetHostAddresses("moddington.net");
                if (addresses.Length > 0)
                {
                    mpc.Connection = new MpcConnection(new IPEndPoint(addresses[0], 6600));

                    var song = mpc.CurrentSong();
                    string songMsg = song.Title + " - " + song.Artist;

                    var status = mpc.Status();
                    TimeSpan elapsed = TimeSpan.FromSeconds(status.TimeElapsed);
                    TimeSpan total = TimeSpan.FromSeconds(status.TimeTotal);
                    string timeMsg = (elapsed.Hours > 0 ? elapsed.Hours + ":" : "") + elapsed.Minutes + ":" + elapsed.Seconds.ToString("D2") + "/" +
                        (total.Hours > 0 ? total.Hours + ":" : "") + total.Minutes + ":" + total.Seconds.ToString("D2");

                    string output = "Playing: " + songMsg +
                        " [" + timeMsg + "] - Listen here: http://moddington.net:8000/moddtunes.ogg";

                    return new List<IRCResponse>() { new IRCResponse(ResponseType.Say, output, message.ReplyTo) };
                }
                else
                {
                    return new List<IRCResponse>() { new IRCResponse(ResponseType.Say, "moddington.net seems to be down", message.ReplyTo) };
                }
            }
            
            return null;
        }
    }
}<commit_msg>Made ModdTunes handle songs without some or any metadata. Closes #22<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;

using CwIRC;
using MBFunctionInterface;

using Libmpc;

namespace Internet
{
    public class ModdTunes : Function
    {
        public ModdTunes()
        {
            Help = "m(odd)t(unes) - Tells you what Moddington's internet radio is currently playing.";
            Type = Types.Command;
            AccessLevel = AccessLevels.Anyone;
        }

        public override List<IRCResponse> GetResponse(BotMessage message)
        {
            if (Regex.IsMatch(message.Command, "^(m(odd)?t(unes)?)$", RegexOptions.IgnoreCase))
            {
                Mpc mpc = new Mpc();

                var addresses = System.Net.Dns.GetHostAddresses("moddington.net");
                if (addresses.Length > 0)
                {
                    mpc.Connection = new MpcConnection(new IPEndPoint(addresses[0], 6600));

                    var song = mpc.CurrentSong();
                    string songMsg = "";
                    if (song.HasTitle || song.HasArtist)
                    {
                        if (song.HasTitle) songMsg += song.Title;
                        else songMsg += "<Unknown Title>";
                        if (song.HasArtist) songMsg += " - " + song.Artist;
                        else songMsg += "<Unknown Artist>";
                    }
                    else
                    {
                        songMsg += song.File;
                    }

                    var status = mpc.Status();
                    TimeSpan elapsed = TimeSpan.FromSeconds(status.TimeElapsed);
                    TimeSpan total = TimeSpan.FromSeconds(status.TimeTotal);
                    string timeMsg = (elapsed.Hours > 0 ? elapsed.Hours + ":" : "") + elapsed.Minutes + ":" + elapsed.Seconds.ToString("D2") + "/" +
                        (total.Hours > 0 ? total.Hours + ":" : "") + total.Minutes + ":" + total.Seconds.ToString("D2");

                    string output = "Playing: " + songMsg +
                        " [" + timeMsg + "] - Listen here: http://moddington.net:8000/moddtunes.ogg";

                    return new List<IRCResponse>() { new IRCResponse(ResponseType.Say, output, message.ReplyTo) };
                }
                else
                {
                    return new List<IRCResponse>() { new IRCResponse(ResponseType.Say, "moddington.net seems to be down", message.ReplyTo) };
                }
            }
            
            return null;
        }
    }
}
{'fraction_non_alphanumeric': 0.11330561330561331, 'fraction_numerical': 0.006237006237006237, 'mean_word_length': 1.5907377490576198, 'pattern_counts': {'":': 8, '<': 11, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2966080', 'n_tokens_mistral': 1366, 'n_tokens_neox': 1264, 'n_words': 274}