I'm trying to set up an mIRC bot for my channel, and my current project is playing an audio file on my computer whenever a certain event happens.
I've written a short C# console app that gets the name of the file from the arguments, and plays that file.
This works running it from cmd or using a shortcut, but when I enter the command on my channel, the program comes up, but throws a FileNotFound exception.
I wrote some code using try{} catch{} to see exactly what's happening. In the event that the file fails to play, it will first list the argument that was provided, the extension (I'm going to change this later), and finally the combined string. What it comes up with it this:
args[0]: audiofile
extension: .wav
filename: audiofile.wav
Which is exactly what the file name is, and that plays perfectly from the command line.
Does anybody know what's going on here?
static void Main(string[] args)
{
string extension = ".wav";
string filename = "null";
if (args == null || args.Length == 0)
{
Console.WriteLine("No arguments provided!");
Console.ReadLine();
return;
}
filename = args[0] + extension;
Console.Write("Press enter to play grenade... ");
Console.ReadLine();
try
{
Console.WriteLine("Playing file " + filename);
(new SoundPlayer(filename)).Play();
}
catch
{
Console.WriteLine("Error!");
Console.WriteLine("args[0]: " + args[0]);
Console.WriteLine("extension: " + extension);
Console.WriteLine("filename: " + filename);
}
Console.ReadLine();
}
mIRC script:
on $*:text:!grenade:#: {
/run "c:/users/electrospeed/documents/visual studio 2013/projects/audioplayer/audioplayer/bin/debug/audioplayer.exe" audiofile
}